internal void UploadFonts()
        {
            _path = "/Fonts";

            // Get fonts from local machine
            InstalledFontCollection installedFontCollection = new InstalledFontCollection();

            FontFamily[]  fontFamilies  = installedFontCollection.Families;
            List <string> localFontList = fontFamilies.Select(t => t.Name).ToList();

            if (Zk.Exists(_path, false) == null)
            {
                try
                {
                    var createdPath = Zk.Create(_path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                    AppendLineShow("Created: " + createdPath);
                }
                catch (KeeperException e)
                {
                    AppendLineShow(string.Format("Znode {0} isn't valid!", _input1));
                }
                catch (InvalidOperationException e)
                {
                    AppendLineShow(string.Format("Znode {0} isn't valid!", _input1));
                }
            }

            //Upload to zookeeper
            AppendLineShow("\n+++ Write in ZK +++");
            foreach (string font in localFontList)
            {
                _input1 = "Fonts/" + font;
                Create(false);
            }
        }
        /// <summary>
        /// Writes a value in znode
        /// </summary>
        public void Write()
        {
            _path = GetPath(_input1);

            try
            {
                var stat = Zk.Exists(_path, false);
                if (stat == null)
                {
                    Zk.Create(_path, Encoding.Default.GetBytes(_input2), Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                    AppendLineShow(String.Format("Znode {0} does not exist! Creating one..", _input1));
                }
                else
                {
                    Zk.SetData(_path, Encoding.Default.GetBytes(_input2), -1);
                    AppendLineShow(String.Format("{0} set value {1}", _input1, _input2));
                }
            }
            catch (KeeperException e)
            {
                AppendLineShow(string.Format("Znode {0} isn't valid!", _input1));
            }
            catch (InvalidOperationException e)
            {
                AppendLineShow(string.Format("Znode {0} isn't valid!", _input1));
            }
            catch (ArgumentNullException e)
            {
                AppendLineShow("Insert in textboxes!");
            }
        }
Exemple #3
0
        private ZookeeperRedialManager()
        {
            _lockerFilePath = $"{_root}/redialer.lock";

            if (Zk.Exists(_root, false) == null)
            {
                Zk.Create(_root, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
            }

            AtomicExecutor = new ZookeeperAtomicExecutor(this);
        }
        internal void UploadConfig()
        {
            var keys = ConfigurationManager.AppSettings;

            _path = "/FirmID-ClientNames";

            // Create parent folder if != exist
            if (Zk.Exists(_path, false) == null)
            {
                try
                {
                    var createdPath = Zk.Create(_path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent);
                    AppendLineShow("Created: " + createdPath);
                }
                catch (KeeperException e)
                {
                    AppendLineShow(string.Format("Znode {0} isn't valid!", _input1));
                }
                catch (InvalidOperationException e)
                {
                    AppendLineShow(string.Format("Znode {0} isn't valid!", _input1));
                }
            }

            // Upload to zookeeper
            AppendLineShow("\n+++ Write in ZK +++");
            foreach (var key in keys)
            {
                var value = keys.GetValues(key.ToString());
                if (value != null)
                {
                    _input1 = "FirmID-ClientNames/" + (string)value.GetValue(0);
                }
                _input2 = key.ToString();
                Write();
            }


            // Show the config
            AppendLineShow("\n+++ Keys and values in App.config +++");
            foreach (var key in keys)
            {
                var strings = keys.GetValues(key.ToString());
                if (strings == null)
                {
                    continue;
                }

                var value1 = strings.GetValue(0);
                AppendLineShow(key + " - " + value1.ToString());
            }
        }
Exemple #5
0
        public string Create(string path, byte[] data, List <ACL> acl, CreateMode createMode)
        {
            string pathValue = null;

            try
            {
                pathValue = Zk.Create(path, data, acl, createMode);
            }
            catch (Exception e)
            {
                log.Error(String.Format("An error occured while trying to create. Exception: {0}", e.ToString()));
            }
            return(pathValue);
        }
        public T Execute <T>(string name, Func <T> func)
        {
            WaitforRedial.WaitforRedialFinish();
            string id = GetPath(name);

            try
            {
                Zk.Create(id, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Ephemeral);
                return(func());
            }
            finally
            {
                Zk.Delete(id, -1);
            }
        }
        public void Execute(string name, Action <object> action, object obj)
        {
            WaitforRedial.WaitforRedialFinish();

            string id = GetPath(name);

            try
            {
                Zk.Create(id, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Ephemeral);
                action(obj);
            }
            finally
            {
                Zk.Delete(id, -1);
            }
        }
        /// <summary>
        /// Creates a znode
        /// </summary>
        /// <param name="eph"> eph stands for Ephemeral</param>
        public void Create(bool eph)
        {
            _path = GetPath(eph ? _input1 + "/" + _input2 : _input1);

            try
            {
                var createdPath = Zk.Create(_path, null, Ids.OPEN_ACL_UNSAFE,
                                            eph ? CreateMode.EphemeralSequential : CreateMode.Persistent);
                AppendLineShow("Created: " + createdPath);
            }
            catch (KeeperException e)
            {
                AppendLineShow(string.Format("Znode {0} isn't valid!", _input1));
            }
            catch (InvalidOperationException e)
            {
                AppendLineShow(string.Format("Znode {0} isn't valid!", _input1));
            }
        }