Microsoft_WindowsAzure
[ class tree: Microsoft_WindowsAzure ] [ index: Microsoft_WindowsAzure ] [ all elements ]

Source for file ConfigurationInstance.php

Documentation is available at ConfigurationInstance.php

  1. <?php
  2. /**
  3.  * Copyright (c) 2009 - 2011, RealDolmen
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions are met:
  8.  *     * Redistributions of source code must retain the above copyright
  9.  *       notice, this list of conditions and the following disclaimer.
  10.  *     * Redistributions in binary form must reproduce the above copyright
  11.  *       notice, this list of conditions and the following disclaimer in the
  12.  *       documentation and/or other materials provided with the distribution.
  13.  *     * Neither the name of RealDolmen nor the
  14.  *       names of its contributors may be used to endorse or promote products
  15.  *       derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20.  * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26.  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  *
  28.  * @category   Microsoft
  29.  * @package    Microsoft_WindowsAzure
  30.  * @subpackage Diagnostics
  31.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  32.  * @license    http://phpazure.codeplex.com/license
  33.  * @version    $Id: Storage.php 45989 2010-05-03 12:19:10Z unknown $
  34.  */
  35.  
  36. /**
  37.  * @see Microsoft_AutoLoader
  38.  */
  39. require_once dirname(__FILE__'/../../AutoLoader.php';
  40.  
  41. /**
  42.  * @category   Microsoft
  43.  * @package    Microsoft_WindowsAzure
  44.  * @subpackage Diagnostics
  45.  * @copyright  Copyright (c) 2009 - 2011, RealDolmen (http://www.realdolmen.com)
  46.  * @license    http://phpazure.codeplex.com/license
  47.  *
  48.  * @property Microsoft_WindowsAzure_Diagnostics_ConfigurationDataSources    DataSources    Data sources
  49.  */
  50. {
  51.     /**
  52.      * Constructor
  53.      */
  54.     public function __construct()
  55.     {
  56.         $this->_data = array(
  57.             'datasources'    => new Microsoft_WindowsAzure_Diagnostics_ConfigurationDataSources()
  58.         );
  59.     }
  60.  
  61.     /**
  62.      * Load configuration XML
  63.      * 
  64.      * @param string $configurationXml Configuration XML
  65.      */
  66.     public function loadXml($configurationXml)
  67.     {
  68.         // Convert to SimpleXMLElement
  69.         $configurationXml simplexml_load_string($configurationXml);
  70.     
  71.         // Assign general settings
  72.         $this->DataSources->OverallQuotaInMB = (int)$configurationXml->DataSources->OverallQuotaInMB;
  73.  
  74.         // Assign Logs settings    
  75.         $this->DataSources->Logs->BufferQuotaInMB = (int)$configurationXml->DataSources->Logs->BufferQuotaInMB;
  76.         $this->DataSources->Logs->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->Logs->ScheduledTransferPeriodInMinutes;
  77.         $this->DataSources->Logs->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->Logs->ScheduledTransferLogLevelFilter;
  78.  
  79.         // Assign DiagnosticInfrastructureLogs settings
  80.         $this->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB = (int)$configurationXml->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB;
  81.         $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes;
  82.         $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter;
  83.  
  84.         // Assign PerformanceCounters settings
  85.         $this->DataSources->PerformanceCounters->BufferQuotaInMB = (int)$configurationXml->DataSources->PerformanceCounters->BufferQuotaInMB;
  86.         $this->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes;
  87.         if ($configurationXml->DataSources->PerformanceCounters->Subscriptions
  88.             && $configurationXml->DataSources->PerformanceCounters->Subscriptions->PerformanceCounterConfiguration{
  89.             $subscriptions $configurationXml->DataSources->PerformanceCounters->Subscriptions;
  90.             if (count($subscriptions->PerformanceCounterConfiguration1{
  91.                 $subscriptions $subscriptions->PerformanceCounterConfiguration;
  92.             else {
  93.                 $subscriptions array($subscriptions->PerformanceCounterConfiguration);
  94.             }
  95.             foreach ($subscriptions as $subscription{
  96.                 $this->DataSources->PerformanceCounters->addSubscription((string)$subscription->CounterSpecifier(int)$subscription->SampleRateInSeconds);
  97.             }
  98.         }
  99.                 
  100.         // Assign WindowsEventLog settings
  101.         $this->DataSources->WindowsEventLog->BufferQuotaInMB = (int)$configurationXml->DataSources->WindowsEventLog->BufferQuotaInMB;
  102.         $this->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes;
  103.         $this->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter;
  104.         if ($configurationXml->DataSources->WindowsEventLog->Subscriptions
  105.             && $configurationXml->DataSources->WindowsEventLog->Subscriptions->string{
  106.             $subscriptions $configurationXml->DataSources->WindowsEventLog->Subscriptions;
  107.             if (count($subscriptions->string1{
  108.                 $subscriptions $subscriptions->string;
  109.             else {
  110.                 $subscriptions array($subscriptions->string);
  111.             }
  112.             foreach ($subscriptions as $subscription{
  113.                 $this->DataSources->WindowsEventLog->addSubscription((string)$subscription);
  114.             }
  115.         }
  116.         
  117.         // Assign Directories settings
  118.         $this->DataSources->Directories->BufferQuotaInMB = (int)$configurationXml->DataSources->Directories->BufferQuotaInMB;
  119.         $this->DataSources->Directories->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->Directories->ScheduledTransferPeriodInMinutes;
  120.  
  121.         if ($configurationXml->DataSources->Directories->Subscriptions
  122.             && $configurationXml->DataSources->Directories->Subscriptions->DirectoryConfiguration{
  123.             $subscriptions $configurationXml->DataSources->Directories->Subscriptions;
  124.             if (count($subscriptions->DirectoryConfiguration1{
  125.                 $subscriptions $subscriptions->DirectoryConfiguration;
  126.             else {
  127.                 $subscriptions array($subscriptions->DirectoryConfiguration);
  128.             }
  129.             foreach ($subscriptions as $subscription{
  130.                 $this->DataSources->Directories->addSubscription((string)$subscription->Path(string)$subscription->Container(int)$subscription->DirectoryQuotaInMB);
  131.             }
  132.         }
  133.     }
  134.     
  135.     /**
  136.      * Create configuration XML
  137.      * 
  138.      * @return string 
  139.      */
  140.     public function toXml()
  141.     {
  142.         // Return value
  143.         $returnValue array();
  144.         
  145.         // Build XML
  146.         $returnValue['<?xml version="1.0"?>';
  147.         $returnValue['<ConfigRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">';
  148.         
  149.         // Add data sources
  150.         $returnValue['  <DataSources>';
  151.         
  152.         $returnValue['    <OverallQuotaInMB>' $this->DataSources->OverallQuotaInMB '</OverallQuotaInMB>';
  153.         
  154.         $returnValue['    <Logs>';
  155.         $returnValue['      <BufferQuotaInMB>' $this->DataSources->Logs->BufferQuotaInMB '</BufferQuotaInMB>';
  156.         $returnValue['      <ScheduledTransferPeriodInMinutes>' $this->DataSources->Logs->ScheduledTransferPeriodInMinutes '</ScheduledTransferPeriodInMinutes>';
  157.         $returnValue['      <ScheduledTransferLogLevelFilter>' $this->DataSources->Logs->ScheduledTransferLogLevelFilter '</ScheduledTransferLogLevelFilter>';
  158.         $returnValue['    </Logs>';
  159.         
  160.         $returnValue['    <DiagnosticInfrastructureLogs>';
  161.         $returnValue['      <BufferQuotaInMB>' $this->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB '</BufferQuotaInMB>';
  162.         $returnValue['      <ScheduledTransferPeriodInMinutes>' $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes '</ScheduledTransferPeriodInMinutes>';
  163.         $returnValue['      <ScheduledTransferLogLevelFilter>' $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter '</ScheduledTransferLogLevelFilter>';
  164.         $returnValue['    </DiagnosticInfrastructureLogs>';
  165.         
  166.         $returnValue['    <PerformanceCounters>';
  167.         $returnValue['      <BufferQuotaInMB>' $this->DataSources->PerformanceCounters->BufferQuotaInMB '</BufferQuotaInMB>';
  168.         $returnValue['      <ScheduledTransferPeriodInMinutes>' $this->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes '</ScheduledTransferPeriodInMinutes>';
  169.         if (count($this->DataSources->PerformanceCounters->Subscriptions== 0{
  170.             $returnValue['      <Subscriptions />';
  171.         else {
  172.             $returnValue['      <Subscriptions>';
  173.             foreach ($this->DataSources->PerformanceCounters->Subscriptions as $subscription{
  174.                 $returnValue['        <PerformanceCounterConfiguration>';
  175.                 $returnValue['          <CounterSpecifier>' $subscription->CounterSpecifier '</CounterSpecifier>';
  176.                 $returnValue['          <SampleRateInSeconds>' $subscription->SampleRateInSeconds '</SampleRateInSeconds>';
  177.                 $returnValue['        </PerformanceCounterConfiguration>';
  178.             }
  179.             $returnValue['      </Subscriptions>';
  180.         }
  181.         $returnValue['    </PerformanceCounters>';
  182.         
  183.         $returnValue['    <WindowsEventLog>';
  184.         $returnValue['      <BufferQuotaInMB>' $this->DataSources->WindowsEventLog->BufferQuotaInMB '</BufferQuotaInMB>';
  185.         $returnValue['      <ScheduledTransferPeriodInMinutes>' $this->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes '</ScheduledTransferPeriodInMinutes>';
  186.             if (count($this->DataSources->WindowsEventLog->Subscriptions== 0{
  187.             $returnValue['      <Subscriptions />';
  188.         else {
  189.             $returnValue['      <Subscriptions>';
  190.             foreach ($this->DataSources->WindowsEventLog->Subscriptions as $subscription{
  191.                 $returnValue['      <string>' $subscription '</string>';
  192.             }
  193.             $returnValue['      </Subscriptions>';
  194.         }
  195.         $returnValue['      <ScheduledTransferLogLevelFilter>' $this->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter '</ScheduledTransferLogLevelFilter>';
  196.         $returnValue['    </WindowsEventLog>';
  197.         
  198.         $returnValue['    <Directories>';
  199.         $returnValue['      <BufferQuotaInMB>' $this->DataSources->Directories->BufferQuotaInMB '</BufferQuotaInMB>';
  200.         $returnValue['      <ScheduledTransferPeriodInMinutes>' $this->DataSources->Directories->ScheduledTransferPeriodInMinutes '</ScheduledTransferPeriodInMinutes>';
  201.         if (count($this->DataSources->Directories->Subscriptions== 0{
  202.             $returnValue['      <Subscriptions />';
  203.         else {
  204.             $returnValue['      <Subscriptions>';
  205.             foreach ($this->DataSources->Directories->Subscriptions as $subscription{
  206.                 $returnValue['        <DirectoryConfiguration>';
  207.                 $returnValue['          <Path>' $subscription->Path '</Path>';
  208.                 $returnValue['          <Container>' $subscription->Container '</Container>';
  209.                 $returnValue['          <DirectoryQuotaInMB>' $subscription->DirectoryQuotaInMB '</DirectoryQuotaInMB>';
  210.                 $returnValue['        </DirectoryConfiguration>';
  211.             }
  212.             $returnValue['      </Subscriptions>';
  213.         }
  214.         $returnValue['    </Directories>';
  215.         
  216.         $returnValue['  </DataSources>';
  217.         $returnValue['  <IsDefault>false</IsDefault>';
  218.         $returnValue['</ConfigRequest>';
  219.         
  220.         // Return
  221.         return implode("\r\n"$returnValue);
  222.     }
  223. }

Documentation generated on Wed, 18 May 2011 12:06:24 +0200 by phpDocumentor 1.4.3