public static ApiConfiguration Read()
        {
            var result = new ApiConfiguration();

            if (File.Exists(CONFIG_FILEPATH))
            {
                try
                {
                    var xml = new XmlDocument();
                    xml.Load(CONFIG_FILEPATH);

                    foreach (XmlNode node in xml.DocumentElement.ChildNodes)
                    {
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            if (node.InnerText != "")
                            {
                                Type c = typeof(ApiConfiguration);
                                PropertyInfo info = c.GetProperty(node.Name);

                                if (info != null)
                                {
                                    Type t = info.PropertyType;
                                    info.SetValue(result, Convert.ChangeType(node.InnerText, t), null);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex) { Logger.Log("Exception :: " + ex.Message); }
            }

            return result;
        }
        public static bool Create(ApiConfiguration config)
        {
            bool result = false;

            Remove();

            if (config != null)
            {
                var xml = CreateDocument(config);
                Tools.XML.Files.WriteDocument(xml, CONFIG_FILEPATH);
            }

            return result;
        }
Ejemplo n.º 3
0
 private void ApiMonitor_ApiConfigurationChanged(ApiConfiguration config)
 {
     if (config != null && config.DataHost != ApiConfiguration.LOCAL_API_HOST) Stop();
     else Start();
 }
 public static void SetTrakHoundCloud()
 {
     var apiConfig = new ApiConfiguration();
     apiConfig.DataHost = CLOUD_API_HOST;
     apiConfig.AuthenticationHost = CLOUD_API_HOST;
     Set(apiConfig);
     Create(apiConfig);
 }
        private static XmlDocument CreateDocument(ApiConfiguration config)
        {
            var result = new XmlDocument();

            XmlNode docNode = result.CreateXmlDeclaration("1.0", "UTF-8", null);
            result.AppendChild(docNode);

            XmlNode root = result.CreateElement("ApiConfiguration");
            result.AppendChild(root);

            foreach (var info in typeof(ApiConfiguration).GetProperties())
            {
                XmlNode node = result.CreateElement(info.Name);
                var val = info.GetValue(config, new object[] { });
                if (val != null) node.InnerText = val.ToString();
                root.AppendChild(node);
            }

            return result;
        }
 public static void SetLocal()
 {
     var apiConfig = new ApiConfiguration();
     apiConfig.DataHost = LOCAL_API_HOST;
     apiConfig.AuthenticationHost = CLOUD_API_HOST;
     Set(apiConfig);
     Create(apiConfig);
 }
        public static void SetDataHost(ApiConfiguration apiConfig)
        {
            if (apiConfig != null && !string.IsNullOrEmpty(apiConfig.DataHost))
            {
                try
                {
                    DataApiHost = new Uri(apiConfig.DataHost);
                }
                catch (Exception ex) { Logger.Log("API Data Host Configuration Error : Exception : " + ex.Message); }
            }
            else
            {
                DataApiHost = new Uri(LOCAL_API_HOST);
            }

            Logger.Log("TrakHound Data API Host set to " + DataApiHost);
        }
        public static void SetAuthenticationHost(ApiConfiguration apiConfig)
        {
            if (apiConfig != null && !string.IsNullOrEmpty(apiConfig.AuthenticationHost))
            {
                try
                {
                    AuthenticationApiHost = new Uri(apiConfig.AuthenticationHost);
                }
                catch (Exception ex) { Logger.Log("API Authentication Host Configuration Error : Exception : " + ex.Message); }
            }
            else
            {
                AuthenticationApiHost = new Uri(CLOUD_API_HOST);
            }

            Logger.Log("TrakHound Authentication API Host set to " + AuthenticationApiHost);
        }
 public static void Set(ApiConfiguration apiConfig)
 {
     SetDataHost(apiConfig);
     SetAuthenticationHost(apiConfig);
 }
Ejemplo n.º 10
0
 private void ApiMonitor_ApiConfigurationChanged(ApiConfiguration config)
 {
     ApiConfiguration.Set(config);
     Login();
 }