Example #1
0
 public override Nodo Clone()
 {
     ComNodo n = new ComNodo(name, null, abilitazione);
     foreach (Nodo child in children)
     {
         n.Append((child.Clone()));
     }
     n.rebuild();
     return n;
 }
Example #2
0
        public static ComNodo importCSVCOM(string fileName)
        {
            ComNodo retValue = new ComNodo();
            StreamReader sr = null;
            List<List<string>> groupMap = new List<List<string>>();
            int varCount = 0;
            try
            {
                sr = new StreamReader(fileName);
                string[] intestazioni = sr.ReadLine().Split('#');
                List<string> gruppi = new List<string>();
                foreach (string i in intestazioni)
                {
                    //gruppi.Add(i.Substring(0, i.IndexOf(';')));
                    List<string> l = new List<string>();
                    l.Add(i.Split(';').ElementAt(1));
                    groupMap.Add(l);
                }
                intestazioni = sr.ReadLine().Split(new string[] { ";#;" }, StringSplitOptions.None);
                for (int j = 0; j < intestazioni.Length; j++)
                {
                    groupMap[j].AddRange(intestazioni[j].Split(';').ToList());
                }
                int nIndent = 0;
                foreach (string s in groupMap[0])       //conto il numero di indentazioni
                {
                    if (Regex.IsMatch(s, "Nome Variabile"))
                        nIndent++;
                }
                while (!sr.EndOfStream)
                {

                    string line = sr.ReadLine();
                    List<string> groups = line.Split(new string[] { ";#;" }, StringSplitOptions.None).ToList();
                    retValue.addComCSV(groups, groupMap);
                    varCount++;
                }
                Logger.Log(varCount + " canali importati.");
            }
            catch (Exception e)
            {
                Logger.Log("Errore di importazione CSV: " + e.Message, "Red");
            }
            finally
            {
                sr.Close();
            }
            return retValue;
        }
Example #3
0
 internal void addComCSV(List<string> groups, List<List<string>> groupMap)
 {
     Nodo n = this, m = null;
     string[] path = groups[0].Split(';');
     string fieldString = "";
     for (int i = 0; i < path.Length; i++)
     {
         m = n.Children.FirstOrDefault(x => x.Name == path[i]);
         if (m == null)
         {
             if (i == path.Length - 1 || String.IsNullOrWhiteSpace(path[i + 1]))
             {
                 int c = 1;
                 for (; c < groups.Count; c++)
                 {
                     if (!String.IsNullOrWhiteSpace(groups[c].Replace(";", "")))
                     {
                         fieldString = groups[c];
                         break;
                     }
                 }
                 m = new Canale(path[i], n, fieldString.Split(';'), groupMap[c]);
                 n.Children.Add(m);
                 return;
             }
             else
             {
                 m = new ComNodo(path[i], n, true);
                 n.Append(m);
                 n = m;
             }
         }
         else
         {
             n = m;
         }
     }
 }
Example #4
0
        internal void addComNodeGPRJ(string path, Dictionary<string, string> props)
        {
            string[] pathFields = path.Split(';');
            Nodo actualNode = this, nextNode = null;
            for (int i = 0; i < pathFields.Length; i++)
            {
                nextNode = actualNode.Children.FirstOrDefault(x => x.name == pathFields[i]);
                if (nextNode != null)
                {
                    actualNode = nextNode;
                    continue;
                }
                else if (i != pathFields.Length - 1)
                {
                    actualNode.Append(nextNode = new ComNodo(pathFields[i], actualNode, true));
                }
                else
                {
                    switch (props["Tipo"])
                    {
                        case "Nodo":
                            actualNode.Append(nextNode = new ComNodo(pathFields[i], actualNode, Boolean.Parse(props["Enabled"].ToLower())));
                            break;
                        case "Comunication":
                            actualNode.Append(nextNode = new Canale(pathFields[i], actualNode, Boolean.Parse(props["Enabled"].ToLower())));
                            Canale c = nextNode as Canale;
                            c.ProtocolName = props["SottoTipo"];
                            if (c.ProtocolDefs == null)
                            {
                                var pname = ComDefinitions.Map.Keys.FirstOrDefault(x => Regex.IsMatch(props["SottoTipo"], x, RegexOptions.IgnoreCase));
                                if (pname != null)
                                    c.ProtocolName = pname;
                                else
                                {
                                    Logger.Log("Protocollo non trovato per il canale " + c.Path, "Red");
                                    continue;
                                }
                            }
                            foreach (var pt in c.ProtocolDefs)
                            {
                                if (!pt.Value.Visibile) continue;
                                //if (Regex.IsMatch(pt.Value.name, "SottoTipo|Tipo|NameNodo|Enabled|PathNode|Addres|GPMExportFile|Percorso|^a$", RegexOptions.IgnoreCase)) continue;
                                string v = null;
                                if (props.ContainsKey(pt.Value.NomeSalvato))
                                    v = props[pt.Value.NomeSalvato];
                                c.propertylist.Add(new PropertyItem(pt.Value.NomeVisualizzato, v, pt.Value));
                            }
                            break;
                    }
                }
                actualNode = nextNode;
            }

        }