Esempio n. 1
0
        private void SaveAll()
        {
            int length = 4;

            string[] strArr = new string[length];
            string[] strVal = new string[length];

            strArr[0] = Constants.XML_CONF_ATTR_API;
            strArr[1] = Constants.XML_CONF_ATTR_TKN;
            strArr[2] = Constants.XML_CONF_ATTR_INTR;
            strArr[3] = Constants.XML_CONF_ATTR_DB;

            strVal[0] = api;
            strVal[1] = api_key;
            strVal[2] = interval;
            strVal[3] = db_name;

            API      = api;
            API_KEY  = api_key;
            INTERVAL = int.Parse(interval);
            DB_NAME  = db_name;

            XmlLoadFormat XLF = new XmlLoadFormat();

            XLF._mode     = 1;
            XLF._path     = XML_PATH;
            XLF._node     = Constants.XML_NODE_CHD;
            XLF._multiKey = strArr;
            XLF._storeVal = strVal;

            Messenger.Default.Send <XmlLoadFormat>(XLF);

            strArr = null;
            strVal = null;
            XLF    = null;

            ServerConfig SC = new ServerConfig();

            SC.HOST    = api;
            SC.TOKEN   = api_key;
            SC.DB_PATH = db_name;
            Messenger.Default.Send <ServerConfig>(SC);
            Messenger.Default.Send <Command>(new Command()
            {
                _cmd = Constants.CMD_CLOSE_CONFIG
            });
            Messenger.Default.Send <Busy>(new Busy()
            {
                busy = false
            });
        }
Esempio n. 2
0
        void Dynamics(XmlLoadFormat xml)
        {
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(xml._path);
                XmlNode _node    = xmldoc.SelectSingleNode("configuration");
                XmlNode _nodeSet = _node.SelectSingleNode(xml._node);
                switch (xml._mode)
                {
                case 0:     // LOAD SINGLE VALUE
                    foreach (XmlNode d in _nodeSet)
                    {
                        if (d.Attributes["key"].Value == xml._singleKey)
                        {
                            xml._callback(d.Attributes["value"].Value);
                            Messenger.Default.Send <NotificationMessage>(new NotificationMessage("LOAD :" + d.Attributes["key"].Value + " VAL: " + d.Attributes["value"].Value));
                        }
                    }
                    break;

                case 1:     // SAVE MULTIPLE
                    int length = xml._multiKey.Length;
                    foreach (XmlNode d in _nodeSet)
                    {
                        for (int i = 0; i < length; i++)
                        {
                            if (d.Attributes["key"].Value == xml._multiKey[i])
                            {
                                d.Attributes["value"].Value = xml._storeVal[i];
                                Messenger.Default.Send <NotificationMessage>(new NotificationMessage("SAVE :" + d.Attributes["key"].Value + " VAL: " + d.Attributes["value"].Value));
                            }
                        }
                    }
                    xmldoc.Save(xml._path);
                    xmldoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                    break;
                }
            } catch (Exception e)
            {
                Console.WriteLine(e + " XML NOT FOUND: " + AppDomain.CurrentDomain.BaseDirectory + AppDomain.CurrentDomain.FriendlyName + ".config");
            }
        }
Esempio n. 3
0
        private void Load()
        {
            XmlLoadFormat XLF     = new XmlLoadFormat();
            int           counter = -1;

            XLF._mode      = 0;
            XLF._path      = XML_PATH;
            XLF._node      = Constants.XML_NODE_CHD;
            XLF._singleKey = Constants.XML_CONF_ATTR_API;
            XLF._callback  = (callback) => api = callback;

            Messenger.Default.Send <XmlLoadFormat>(XLF);
            while (String.IsNullOrEmpty(api))
            {
                counter++;
                System.Threading.Thread.Sleep(1000);
                Console.WriteLine(counter);
                if (counter > 0)
                {
                    api = "null";
                    break;
                }
            }
            counter = -1;

            XLF._singleKey = Constants.XML_CONF_ATTR_TKN;
            XLF._callback  = (callback) => api_key = callback;

            Messenger.Default.Send <XmlLoadFormat>(XLF);
            while (String.IsNullOrEmpty(api_key))
            {
                counter++;
                System.Threading.Thread.Sleep(1000);
                Console.WriteLine(counter);
                if (counter > 0)
                {
                    api_key = "null";
                    break;
                }
            }
            counter = -1;

            XLF._singleKey = Constants.XML_CONF_ATTR_INTR;
            XLF._callback  = (callback) => interval = callback;

            Messenger.Default.Send <XmlLoadFormat>(XLF);
            while (String.IsNullOrEmpty(interval))
            {
                counter++;
                System.Threading.Thread.Sleep(1000);
                Console.WriteLine(counter);
                if (counter > 0)
                {
                    interval = "0";
                    break;
                }
            }
            counter        = -1;
            XLF._singleKey = Constants.XML_CONF_ATTR_DB;
            XLF._callback  = (callback) => db_name = callback;

            Messenger.Default.Send <XmlLoadFormat>(XLF);
            while (String.IsNullOrEmpty(db_name))
            {
                counter++;
                System.Threading.Thread.Sleep(1000);
                Console.WriteLine(counter);
                if (counter > 0)
                {
                    db_name = "null";
                    break;
                }
            }

            XLF      = null;
            API      = api;
            API_KEY  = api_key;
            INTERVAL = int.Parse(interval);
            DB_NAME  = db_name;

            ServerConfig SC = new ServerConfig();

            SC.HOST    = api;
            SC.TOKEN   = api_key;
            SC.DB_PATH = db_name;
            Messenger.Default.Send <ServerConfig>(SC);
        }