protected DesktopServiceConfiguration(string path, bool useRemoteConfig)
        {
            filePath = path;
            configDoc = XDocument.Load(path);
            XElement configXml = configDoc.XPathSelectElement("//selfServiceDesktops");
            if (configXml == null) {
                throw new ArgumentException("No <selfServiceDesktops/> configuration element found in : " + path);
            }
            config = Deserialize(configXml);

            if (useRemoteConfig && (config.RemoteConfig != null)) {
                try {
                    configXml = GetXml(new Uri(config.RemoteConfig));
                    string remoteConfig = config.RemoteConfig;
                    config = Deserialize(configXml);
                    // If the remote config does not have an agent URI, infer it from the remote Url in the local config
                    if (config.AgentUri == null) {
                        config.SetAgentUriFrom(remoteConfig);
                    }

                } catch (Exception e) {
                    throw new ConfigurationErrorsException("Unable to load configuration from remote server", e);
                }
            }
            ValidateConfiguration();
        }
 public DesktopServiceConfigurationModel(DesktopServiceConfigurationElement config)
 {
     this.AgentUriBase = config.Agent == null ? null : config.Agent.BaseUrl;
     this.BrokerUri = config.Broker == null ? null : config.Broker.Url;
     this.CloudStackUri = config.CloudStack == null ? null : config.CloudStack.Url;
     this.Domain = config.Domain;
     this.HashCloudStackPassword = config.HashCloudStackPassword;
     this.ListenPort = config.ListenPort;
     this.ScriptPath = config.PowerShellScriptBase.Path;
     this.Frequency = config.PowerShellScriptBase.FrequencyBase;
     this.DebugScript = config.PowerShellScriptBase.Debug;
 }
 public DesktopServiceConfigurationElement Update(DesktopServiceConfigurationElement config)
 {
     config.Agent = new DesktopServiceConfigurationElement.AgentElement() { BaseUrl = this.AgentUriBase };
     config.Broker = new DesktopServiceConfigurationElement.BrokerElement() { Url = this.BrokerUri };
     config.CloudStack = new DesktopServiceConfigurationElement.CloudStackElement() {
         Url = this.CloudStackUri,
         Domain = this.Domain,
         HashPassword = this.HashCloudStackPassword
     };
     config.Listen = new DesktopServiceConfigurationElement.ListenElement() { Port = this.ListenPort };
     config.PowerShellScriptBase = new PowerShellScriptElement() {
         Path = ScriptPath,
         FrequencyBase = Frequency,
         Debug = DebugScript
     };
     return config;
 }
 /// <summary>
 /// Serialize the configuration to Xml
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 protected XElement Serialize(DesktopServiceConfigurationElement config)
 {
     try {
         XmlSerializer serializer = new XmlSerializer(typeof(DesktopServiceConfigurationElement));
         MemoryStream stream = new MemoryStream();
         serializer.Serialize(stream, config);
         stream.Position = 0;
         return XElement.Load(stream);
     } catch (Exception e) {
         CtxTrace.TraceError(e);
         throw;
     }
 }