web/lib/Zend/Service/WindowsAzure/Diagnostics/ConfigurationInstance.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Service_WindowsAzure
       
    17  * @subpackage Diagnostics
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id$
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see Zend_Service_WindowsAzure_Diagnostics_Exception
       
    25  */
       
    26 require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php';
       
    27 
       
    28 /**
       
    29  * @see Zend_Service_WindowsAzure_Diagnostics_ConfigurationObjectBaseAbstract
       
    30  */
       
    31 require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationObjectBaseAbstract.php';
       
    32 
       
    33 /**
       
    34  * @see Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources
       
    35  */
       
    36 require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationDataSources.php';
       
    37 
       
    38 /**
       
    39  * @category   Zend
       
    40  * @package    Zend_Service_WindowsAzure
       
    41  * @subpackage Diagnostics
       
    42  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    43  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    44  *
       
    45  * @property Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources	DataSources	Data sources
       
    46  */
       
    47 class Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance
       
    48 	extends Zend_Service_WindowsAzure_Diagnostics_ConfigurationObjectBaseAbstract
       
    49 {
       
    50 	/**
       
    51 	 * Constructor
       
    52 	 */
       
    53 	public function __construct()
       
    54 	{
       
    55         $this->_data = array(
       
    56             'datasources'	=> new Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources()
       
    57         );
       
    58 	}
       
    59 
       
    60 	/**
       
    61 	 * Load configuration XML
       
    62 	 * 
       
    63 	 * @param string $configurationXml Configuration XML
       
    64 	 */
       
    65 	public function loadXml($configurationXml)
       
    66 	{
       
    67 		// Convert to SimpleXMLElement
       
    68 		$configurationXml = simplexml_load_string($configurationXml);
       
    69 	
       
    70 		// Assign general settings
       
    71 		$this->DataSources->OverallQuotaInMB = (int)$configurationXml->DataSources->OverallQuotaInMB;
       
    72 
       
    73 		// Assign Logs settings	
       
    74 		$this->DataSources->Logs->BufferQuotaInMB = (int)$configurationXml->DataSources->Logs->BufferQuotaInMB;
       
    75 		$this->DataSources->Logs->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->Logs->ScheduledTransferPeriodInMinutes;
       
    76 		$this->DataSources->Logs->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->Logs->ScheduledTransferLogLevelFilter;
       
    77 
       
    78 		// Assign DiagnosticInfrastructureLogs settings
       
    79 		$this->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB = (int)$configurationXml->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB;
       
    80 		$this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes;
       
    81 		$this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter;
       
    82 
       
    83 		// Assign PerformanceCounters settings
       
    84 		$this->DataSources->PerformanceCounters->BufferQuotaInMB = (int)$configurationXml->DataSources->PerformanceCounters->BufferQuotaInMB;
       
    85 		$this->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes;
       
    86 		if ($configurationXml->DataSources->PerformanceCounters->Subscriptions
       
    87 			&& $configurationXml->DataSources->PerformanceCounters->Subscriptions->PerformanceCounterConfiguration) {
       
    88 			$subscriptions = $configurationXml->DataSources->PerformanceCounters->Subscriptions;
       
    89 			if (count($subscriptions->PerformanceCounterConfiguration) > 1) {
       
    90 				$subscriptions = $subscriptions->PerformanceCounterConfiguration;
       
    91 			} else {
       
    92 				$subscriptions = array($subscriptions->PerformanceCounterConfiguration);
       
    93 			}
       
    94 			foreach ($subscriptions as $subscription) {
       
    95 				$this->DataSources->PerformanceCounters->addSubscription((string)$subscription->CounterSpecifier, (int)$subscription->SampleRateInSeconds);
       
    96 			}
       
    97 		}
       
    98 				
       
    99 		// Assign WindowsEventLog settings
       
   100 		$this->DataSources->WindowsEventLog->BufferQuotaInMB = (int)$configurationXml->DataSources->WindowsEventLog->BufferQuotaInMB;
       
   101 		$this->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes;
       
   102 		$this->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter;
       
   103 		if ($configurationXml->DataSources->WindowsEventLog->Subscriptions
       
   104 			&& $configurationXml->DataSources->WindowsEventLog->Subscriptions->string) {
       
   105 			$subscriptions = $configurationXml->DataSources->WindowsEventLog->Subscriptions;
       
   106 			if (count($subscriptions->string) > 1) {
       
   107 				$subscriptions = $subscriptions->string;
       
   108 			} else {
       
   109 				$subscriptions = array($subscriptions->string);
       
   110 			}
       
   111 			foreach ($subscriptions as $subscription) {
       
   112 				$this->DataSources->WindowsEventLog->addSubscription((string)$subscription);
       
   113 			}
       
   114 		}
       
   115 		
       
   116 		// Assign Directories settings
       
   117 		$this->DataSources->Directories->BufferQuotaInMB = (int)$configurationXml->DataSources->Directories->BufferQuotaInMB;
       
   118 		$this->DataSources->Directories->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->Directories->ScheduledTransferPeriodInMinutes;
       
   119 		if ($configurationXml->DataSources->Directories->Subscriptions
       
   120 			&& $configurationXml->DataSources->Directories->Subscriptions->DirectoryConfiguration) {
       
   121 			$subscriptions = $configurationXml->DataSources->WindowsEventLog->Subscriptions;
       
   122 			if (count($subscriptions->DirectoryConfiguration) > 1) {
       
   123 				$subscriptions = $subscriptions->DirectoryConfiguration;
       
   124 			} else {
       
   125 				$subscriptions = array($subscriptions->DirectoryConfiguration);
       
   126 			}
       
   127 			foreach ($subscriptions as $subscription) {
       
   128 				$this->DataSources->Directories->addSubscription((string)$subscription->Path, (string)$subscription->Container, (int)$subscription->DirectoryQuotaInMB);
       
   129 			}
       
   130 		}
       
   131 	}
       
   132 	
       
   133 	/**
       
   134 	 * Create configuration XML
       
   135 	 * 
       
   136 	 * @return string
       
   137 	 */
       
   138 	public function toXml()
       
   139 	{
       
   140 		// Return value
       
   141 		$returnValue = array();
       
   142 		
       
   143 		// Build XML
       
   144 		$returnValue[] = '<?xml version="1.0"?>';
       
   145 		$returnValue[] = '<ConfigRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">';
       
   146 		
       
   147 		// Add data sources
       
   148 		$returnValue[] = '  <DataSources>';
       
   149 		
       
   150 		$returnValue[] = '    <OverallQuotaInMB>' . $this->DataSources->OverallQuotaInMB . '</OverallQuotaInMB>';
       
   151 		
       
   152 		$returnValue[] = '    <Logs>';
       
   153 		$returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->Logs->BufferQuotaInMB . '</BufferQuotaInMB>';
       
   154 		$returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->Logs->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
       
   155 		$returnValue[] = '      <ScheduledTransferLogLevelFilter>' . $this->DataSources->Logs->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
       
   156 		$returnValue[] = '    </Logs>';
       
   157 		
       
   158 		$returnValue[] = '    <DiagnosticInfrastructureLogs>';
       
   159 		$returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB . '</BufferQuotaInMB>';
       
   160 		$returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
       
   161 		$returnValue[] = '      <ScheduledTransferLogLevelFilter>' . $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
       
   162 		$returnValue[] = '    </DiagnosticInfrastructureLogs>';
       
   163 		
       
   164 		$returnValue[] = '    <PerformanceCounters>';
       
   165 		$returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->PerformanceCounters->BufferQuotaInMB . '</BufferQuotaInMB>';
       
   166 		$returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
       
   167 		if (count($this->DataSources->PerformanceCounters->Subscriptions) == 0) {
       
   168 			$returnValue[] = '      <Subscriptions />';
       
   169 		} else {
       
   170 			$returnValue[] = '      <Subscriptions>';
       
   171 			foreach ($this->DataSources->PerformanceCounters->Subscriptions as $subscription) {
       
   172 				$returnValue[] = '        <PerformanceCounterConfiguration>';
       
   173 				$returnValue[] = '          <CounterSpecifier>' . $subscription->CounterSpecifier . '</CounterSpecifier>';
       
   174 				$returnValue[] = '          <SampleRateInSeconds>' . $subscription->SampleRateInSeconds . '</SampleRateInSeconds>';
       
   175 				$returnValue[] = '        </PerformanceCounterConfiguration>';
       
   176 			}
       
   177 			$returnValue[] = '      </Subscriptions>';
       
   178 		}
       
   179 		$returnValue[] = '    </PerformanceCounters>';
       
   180 		
       
   181 		$returnValue[] = '    <WindowsEventLog>';
       
   182 		$returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->WindowsEventLog->BufferQuotaInMB . '</BufferQuotaInMB>';
       
   183 		$returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
       
   184 			if (count($this->DataSources->WindowsEventLog->Subscriptions) == 0) {
       
   185 			$returnValue[] = '      <Subscriptions />';
       
   186 		} else {
       
   187 			$returnValue[] = '      <Subscriptions>';
       
   188 			foreach ($this->DataSources->WindowsEventLog->Subscriptions as $subscription) {
       
   189 				$returnValue[] = '      <string>' . $subscription . '</string>';
       
   190 			}
       
   191 			$returnValue[] = '      </Subscriptions>';
       
   192 		}
       
   193 		$returnValue[] = '      <ScheduledTransferLogLevelFilter>' . $this->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
       
   194 		$returnValue[] = '    </WindowsEventLog>';
       
   195 		
       
   196 		$returnValue[] = '    <Directories>';
       
   197 		$returnValue[] = '      <BufferQuotaInMB>' . $this->DataSources->Directories->BufferQuotaInMB . '</BufferQuotaInMB>';
       
   198 		$returnValue[] = '      <ScheduledTransferPeriodInMinutes>' . $this->DataSources->Directories->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
       
   199 		if (count($this->DataSources->Directories->Subscriptions) == 0) {
       
   200 			$returnValue[] = '      <Subscriptions />';
       
   201 		} else {
       
   202 			$returnValue[] = '      <Subscriptions>';
       
   203 			foreach ($this->DataSources->Directories->Subscriptions as $subscription) {
       
   204 				$returnValue[] = '        <DirectoryConfiguration>';
       
   205 				$returnValue[] = '          <Path>' . $subscription->Path . '</Path>';
       
   206 				$returnValue[] = '          <Container>' . $subscription->Container . '</Container>';
       
   207 				$returnValue[] = '          <DirectoryQuotaInMB>' . $subscription->DirectoryQuotaInMB . '</DirectoryQuotaInMB>';
       
   208 				$returnValue[] = '        </DirectoryConfiguration>';
       
   209 			}
       
   210 			$returnValue[] = '      </Subscriptions>';
       
   211 		}
       
   212 		$returnValue[] = '    </Directories>';
       
   213 		
       
   214 		$returnValue[] = '  </DataSources>';
       
   215 		$returnValue[] = '</ConfigRequest>';
       
   216 		
       
   217 		// Return
       
   218 		return implode("\r\n", $returnValue);
       
   219 	}
       
   220 }