File indexing completed on 2024-12-29 05:28:03

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Service_WindowsAzure
0017  * @subpackage Diagnostics
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Service_WindowsAzure_Diagnostics_ConfigurationObjectBaseAbstract
0025  */
0026 // require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationObjectBaseAbstract.php';
0027 
0028 /**
0029  * @see Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources
0030  */
0031 // require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationDataSources.php';
0032 
0033 /** Zend_Xml_Security */
0034 // require_once 'Zend/Xml/Security.php';
0035 
0036 /**
0037  * @category   Zend
0038  * @package    Zend_Service_WindowsAzure
0039  * @subpackage Diagnostics
0040  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0041  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0042  *
0043  * @property Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources DataSources Data sources
0044  */
0045 class Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance
0046   extends Zend_Service_WindowsAzure_Diagnostics_ConfigurationObjectBaseAbstract
0047 {
0048   /**
0049    * Constructor
0050    */
0051   public function __construct()
0052   {
0053         $this->_data = array(
0054             'datasources' => new Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources()
0055         );
0056   }
0057 
0058   /**
0059    * Load configuration XML
0060    * 
0061    * @param string $configurationXml Configuration XML
0062    */
0063   public function loadXml($configurationXml)
0064   {
0065     // Convert to SimpleXMLElement
0066     $configurationXml = Zend_Xml_Security::scan($configurationXml);
0067   
0068     // Assign general settings
0069     $this->DataSources->OverallQuotaInMB = (int)$configurationXml->DataSources->OverallQuotaInMB;
0070 
0071     // Assign Logs settings 
0072     $this->DataSources->Logs->BufferQuotaInMB = (int)$configurationXml->DataSources->Logs->BufferQuotaInMB;
0073     $this->DataSources->Logs->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->Logs->ScheduledTransferPeriodInMinutes;
0074     $this->DataSources->Logs->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->Logs->ScheduledTransferLogLevelFilter;
0075 
0076     // Assign DiagnosticInfrastructureLogs settings
0077     $this->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB = (int)$configurationXml->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB;
0078     $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes;
0079     $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter;
0080 
0081     // Assign PerformanceCounters settings
0082     $this->DataSources->PerformanceCounters->BufferQuotaInMB = (int)$configurationXml->DataSources->PerformanceCounters->BufferQuotaInMB;
0083     $this->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes;
0084     if ($configurationXml->DataSources->PerformanceCounters->Subscriptions
0085       && $configurationXml->DataSources->PerformanceCounters->Subscriptions->PerformanceCounterConfiguration) {
0086       $subscriptions = $configurationXml->DataSources->PerformanceCounters->Subscriptions;
0087       if (count($subscriptions->PerformanceCounterConfiguration) > 1) {
0088         $subscriptions = $subscriptions->PerformanceCounterConfiguration;
0089       } else {
0090         $subscriptions = array($subscriptions->PerformanceCounterConfiguration);
0091       }
0092       foreach ($subscriptions as $subscription) {
0093         $this->DataSources->PerformanceCounters->addSubscription((string)$subscription->CounterSpecifier, (int)$subscription->SampleRateInSeconds);
0094       }
0095     }
0096         
0097     // Assign WindowsEventLog settings
0098     $this->DataSources->WindowsEventLog->BufferQuotaInMB = (int)$configurationXml->DataSources->WindowsEventLog->BufferQuotaInMB;
0099     $this->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes;
0100     $this->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter;
0101     if ($configurationXml->DataSources->WindowsEventLog->Subscriptions
0102       && $configurationXml->DataSources->WindowsEventLog->Subscriptions->string) {
0103       $subscriptions = $configurationXml->DataSources->WindowsEventLog->Subscriptions;
0104       if (count($subscriptions->string) > 1) {
0105         $subscriptions = $subscriptions->string;
0106       } else {
0107         $subscriptions = array($subscriptions->string);
0108       }
0109       foreach ($subscriptions as $subscription) {
0110         $this->DataSources->WindowsEventLog->addSubscription((string)$subscription);
0111       }
0112     }
0113     
0114     // Assign Directories settings
0115     $this->DataSources->Directories->BufferQuotaInMB = (int)$configurationXml->DataSources->Directories->BufferQuotaInMB;
0116     $this->DataSources->Directories->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->Directories->ScheduledTransferPeriodInMinutes;
0117 
0118     if ($configurationXml->DataSources->Directories->Subscriptions
0119       && $configurationXml->DataSources->Directories->Subscriptions->DirectoryConfiguration) {
0120       $subscriptions = $configurationXml->DataSources->Directories->Subscriptions;
0121       if (count($subscriptions->DirectoryConfiguration) > 1) {
0122         $subscriptions = $subscriptions->DirectoryConfiguration;
0123       } else {
0124         $subscriptions = array($subscriptions->DirectoryConfiguration);
0125       }
0126       foreach ($subscriptions as $subscription) {
0127         $this->DataSources->Directories->addSubscription((string)$subscription->Path, (string)$subscription->Container, (int)$subscription->DirectoryQuotaInMB);
0128       }
0129     }
0130   }
0131   
0132   /**
0133    * Create configuration XML
0134    * 
0135    * @return string
0136    */
0137   public function toXml()
0138   {
0139     // Return value
0140     $returnValue = array();
0141     
0142     // Build XML
0143     $returnValue[] = '<?xml version="1.0"?>';
0144     $returnValue[] = '<ConfigRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">';
0145     
0146     // Add data sources
0147     $returnValue[] = '  <DataSources>';
0148     
0149     $returnValue[] = '    <OverallQuotaInMB>' . $this->DataSources->OverallQuotaInMB . '</OverallQuotaInMB>';
0150     
0151     $returnValue[] = '    <Logs>';
0152     $returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->Logs->BufferQuotaInMB . '</BufferQuotaInMB>';
0153     $returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->Logs->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
0154     $returnValue[] = '      <ScheduledTransferLogLevelFilter>' . $this->DataSources->Logs->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
0155     $returnValue[] = '    </Logs>';
0156     
0157     $returnValue[] = '    <DiagnosticInfrastructureLogs>';
0158     $returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB . '</BufferQuotaInMB>';
0159     $returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
0160     $returnValue[] = '      <ScheduledTransferLogLevelFilter>' . $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
0161     $returnValue[] = '    </DiagnosticInfrastructureLogs>';
0162     
0163     $returnValue[] = '    <PerformanceCounters>';
0164     $returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->PerformanceCounters->BufferQuotaInMB . '</BufferQuotaInMB>';
0165     $returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
0166     if (count($this->DataSources->PerformanceCounters->Subscriptions) == 0) {
0167       $returnValue[] = '      <Subscriptions />';
0168     } else {
0169       $returnValue[] = '      <Subscriptions>';
0170       foreach ($this->DataSources->PerformanceCounters->Subscriptions as $subscription) {
0171         $returnValue[] = '        <PerformanceCounterConfiguration>';
0172         $returnValue[] = '          <CounterSpecifier>' . $subscription->CounterSpecifier . '</CounterSpecifier>';
0173         $returnValue[] = '          <SampleRateInSeconds>' . $subscription->SampleRateInSeconds . '</SampleRateInSeconds>';
0174         $returnValue[] = '        </PerformanceCounterConfiguration>';
0175       }
0176       $returnValue[] = '      </Subscriptions>';
0177     }
0178     $returnValue[] = '    </PerformanceCounters>';
0179     
0180     $returnValue[] = '    <WindowsEventLog>';
0181     $returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->WindowsEventLog->BufferQuotaInMB . '</BufferQuotaInMB>';
0182     $returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
0183       if (count($this->DataSources->WindowsEventLog->Subscriptions) == 0) {
0184       $returnValue[] = '      <Subscriptions />';
0185     } else {
0186       $returnValue[] = '      <Subscriptions>';
0187       foreach ($this->DataSources->WindowsEventLog->Subscriptions as $subscription) {
0188         $returnValue[] = '      <string>' . $subscription . '</string>';
0189       }
0190       $returnValue[] = '      </Subscriptions>';
0191     }
0192     $returnValue[] = '      <ScheduledTransferLogLevelFilter>' . $this->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
0193     $returnValue[] = '    </WindowsEventLog>';
0194     
0195     $returnValue[] = '    <Directories>';
0196     $returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->Directories->BufferQuotaInMB . '</BufferQuotaInMB>';
0197     $returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->Directories->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
0198     if (count($this->DataSources->Directories->Subscriptions) == 0) {
0199       $returnValue[] = '      <Subscriptions />';
0200     } else {
0201       $returnValue[] = '      <Subscriptions>';
0202       foreach ($this->DataSources->Directories->Subscriptions as $subscription) {
0203         $returnValue[] = '        <DirectoryConfiguration>';
0204         $returnValue[] = '          <Path>' . $subscription->Path . '</Path>';
0205         $returnValue[] = '          <Container>' . $subscription->Container . '</Container>';
0206         $returnValue[] = '          <DirectoryQuotaInMB>' . $subscription->DirectoryQuotaInMB . '</DirectoryQuotaInMB>';
0207         $returnValue[] = '        </DirectoryConfiguration>';
0208       }
0209       $returnValue[] = '      </Subscriptions>';
0210     }
0211     $returnValue[] = '    </Directories>';
0212     
0213     $returnValue[] = '  </DataSources>';
0214     $returnValue[] = '  <IsDefault>false</IsDefault>';
0215     $returnValue[] = '</ConfigRequest>';
0216     
0217     // Return
0218     return implode("\r\n", $returnValue);
0219   }
0220 }