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!"); } }
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); }
public override RedialResult Redial() { if (Skip) { return(RedialResult.Skip); } if (Zk.Exists(_lockerFilePath, false) != null) { while (true) { Thread.Sleep(50); if (Zk.Exists(_lockerFilePath, false) == null) { return(RedialResult.OtherRedialed); } } } else { try { using (var zk = ZookeeperUtil.GetShortSessionZk(120)) { zk.Create(_lockerFilePath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.Ephemeral); // wait all operation stop. Thread.Sleep(5000); Logger.Warn("Wait atomic action to finish..."); AtomicExecutor.WaitAtomicAction(); Logger.Warn("Try to redial network..."); RedialInternet(); Logger.Warn("Redial finished."); return(RedialResult.Sucess); } } catch (IOException) { // 有极小可能同时调用File.Open时抛出异常 return(Redial()); } catch (Exception) { return(RedialResult.Failed); } } }
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()); } }
public Stat Exists(string path, bool watch) { Stat stat = null; try { stat = Zk.Exists(path, watch); } catch (Exception e) { log.Error(String.Format("An error occured while trying to check if exists. Exception: {0}", e.ToString())); } return(stat); }
public void Watch() { _path = GetPath(_input1); try { Zk.Exists(_path, this); AppendLineShow(String.Format("Watch added to {0}", _input1)); } catch (KeeperException) { AppendLineShow(string.Format("Znode {0} isn't valid!", _input1)); } catch (InvalidOperationException e) { AppendLineShow(string.Format("Znode {0} isn't valid!", _input1)); } }
public override void WaitforRedialFinish() { if (Skip) { return; } if (Zk.Exists(_lockerFilePath, false) != null) { for (int i = 0; i < RedialTimeout; ++i) { Thread.Sleep(50); if (Zk.Exists(_lockerFilePath, false) == null) { break; } } } }