Ejemplo n.º 1
0
 AIValidationError AIValidation(AI_Information info)
 {
     Dictionary<string, AI_Information>.ValueCollection tot = eithers.Values;
     foreach (AI_Information either in tot)
     {
         if (info.ServerName.Equals(either.ServerName)) return AIValidationError.ServerName;
         if (info.URL.Equals(either.URL)) return AIValidationError.URL;
     }
     if (!info.GetLinked()) return AIValidationError.Link;
     return AIValidationError.None;
 }
Ejemplo n.º 2
0
 void AIInsert(AI_Information info)
 {
     XmlDocument doc = new XmlDocument();
     doc.Load("AIConfig.xml");
     XmlNode root = doc.SelectSingleNode("Root");
     XmlElement ep = doc.CreateElement("EndPoint");
     XmlElement ele;
     ele = doc.CreateElement("ServerName");
     ele.InnerText = info.ServerName;
     ep.AppendChild(ele);
     ele = doc.CreateElement("URL");
     ele.InnerText = info.URL;
     ep.AppendChild(ele);
     ele = doc.CreateElement("Type");
     ele.InnerText = info.Type.ToString();
     ep.AppendChild(ele);
     ele = doc.CreateElement("Level");
     ele.InnerText = info.Level.ToString();
     ep.AppendChild(ele);
     root.AppendChild(ep);
     doc.Save("AIConfig.xml");
 }
Ejemplo n.º 3
0
 private void AIReload()
 {
     eithers = new Dictionary<string, AI_Information>();
     whites = new Dictionary<string, AI_Information>();
     blacks = new Dictionary<string, AI_Information>();
     XmlDocument doc = new XmlDocument();
     doc.Load("AIConfig.xml");
     XmlNodeList eps = doc.SelectSingleNode("Root").ChildNodes;
     foreach (XmlNode ep in eps)
     {
         AI_Information info = new AI_Information();
         XmlNode ele;
         ele = ep.SelectSingleNode("ServerName");
         info.ServerName = ele.InnerText;
         ele = ep.SelectSingleNode("URL");
         info.URL = ele.InnerText;
         ele = ep.SelectSingleNode("Type");
         for (int i = 0; i < AI_Information.AITypeStr.Length; ++i)
             if (AI_Information.AITypeStr[i] == ele.InnerText[0]) info.Type = (AIType)i;
         if (AIValidation(info) == AIValidationError.None)
         {
             eithers.Add(info.ServerName, info);
             if (info.Type != AIType.Black) whites.Add(info.ServerName, info);
             if (info.Type != AIType.White) blacks.Add(info.ServerName, info);
         }
         ele = ep.SelectSingleNode("Level");
         info.Level = int.Parse(ele.InnerText);
     }
     WhiteComboBox.Items.Clear();
     foreach (string info in whites.Keys)
     {
         ComboBoxItem item = new ComboBoxItem();
         item.Content = info;
         WhiteComboBox.Items.Insert(WhiteComboBox.Items.Count, item);
     }
     BlackComboBox.Items.Clear();
     foreach (string info in blacks.Keys)
     {
         ComboBoxItem item = new ComboBoxItem();
         item.Content = info;
         BlackComboBox.Items.Insert(BlackComboBox.Items.Count, item);
     }
 }
Ejemplo n.º 4
0
 private void NewAI_Click(object sender, RoutedEventArgs e)
 {
     AI_Information info = new AI_Information();
     NewAIWindow window = new NewAIWindow(info);
     window.ShowDialog();
     AIValidationError err = AIValidationError.None;
     if ((bool)window.DialogResult && (err = AIValidation(info)) == AIValidationError.None)
     {
         AIInsert(info);
         AIReload();
     } else switch (err) {
         case AIValidationError.ServerName:
             MessageBox.Show("The server name is already used!");
             break;
         case AIValidationError.URL:
             MessageBox.Show("The URL is already used!");
             break;
         case AIValidationError.Link:
             MessageBox.Show("Cannot contact with the service, please re-check the URL");
             break;
     }
 }