Example #1
0
        public void runReplace(
            CommandOption Path,
            CommandOption configPath,
            CommandOption templatePath) //run for replace
        {
            Execute  exe = new Execute();
            ACConfig AC  = new ACConfig();
            Output   obj = new Output();

            var paths = getDefaultPaths(Path, configPath, templatePath);

            fileproof();
            var config        = File.ReadAllText(paths.configPath + @"\Config.json");                   //get json
            var configuration = JsonConvert.DeserializeObject <ACConfig>(config);                       //get path to json
            var changePath    = configuration.userpath;
            var myconfig      = JsonConvert.DeserializeObject <ACConfig>(File.ReadAllText(changePath)); //open json to use
            var dirs          = exe.findFilesInDirectory(configuration.changeDirectory);                //search all files in Directory

            foreach (var file in dirs)
            {
                AC = exe.parseinobject(new StreamReader(file)); //parses current configuration into the AC object
                if (myconfig.configureNetwork != null)
                {
                    AC = exe.replaceitem(AC, myconfig.configureNetwork.networkdev, "networkdev");
                    AC = exe.replaceitem(AC, myconfig.configureNetwork.interfacenetworkif, "interfacenetworkif");
                }
                if (myconfig.configureviop != null)
                {
                    AC = exe.replaceitem(AC, myconfig.configureviop.proxyset, "proxyset");
                    AC = exe.replaceitem(AC, myconfig.configureviop.proxyip, "proxyip"); //replaces the wanted details
                }
                var objList = obj.objectToList(AC);
                obj.writeOutput(objList, file); //output
            }
        }
Example #2
0
        public void runReplace(
            CommandOption Path,
            CommandOption configPath,
            CommandOption templatePath,
            CommandOption customer,
            CommandOption country) //run for replace
        {
            ACConfig      AC  = new ACConfig();
            Output        obj = new Output();
            Execute       exe = new Execute();
            ACConfig      ConfigWithChanges = new ACConfig();
            List <string> dirs = new List <string>();

            new Arrangement().prepareForStart(Path, configPath, templatePath, out ConfigWithChanges, out dirs);
            //search all files in Directory
            foreach (var file in dirs)
            {
                AC = new InputToACObject().parseinobject(new StreamReader(file)); //parses current configuration into the AC object
                if (ConfigWithChanges.configureNetwork != null)
                {
                    AC = exe.replaceitem(AC, ConfigWithChanges.configureNetwork.networkdev, "networkdev", country, customer);
                    AC = exe.replaceitem(AC, ConfigWithChanges.configureNetwork.interfacenetworkif, "interfacenetworkif", country, customer);
                }
                if (ConfigWithChanges.configureviop != null)
                {
                    AC = exe.replaceitem(AC, ConfigWithChanges.configureviop.proxyset, "proxyset", country, customer);
                    AC = exe.replaceitem(AC, ConfigWithChanges.configureviop.proxyip, "proxyip", country, customer); //replaces the wanted details
                }
                var objList = obj.objectToList(AC);
                obj.writeOutput(objList, file); //output
            }
        }
Example #3
0
        public ACConfig replaceitem(ACConfig AC, dynamic list, string whatlist, CommandOption country, CommandOption customer)
        {
            if (list == null)
            {
                return(AC);
            }
            foreach (var config in list)
            {
                switch (whatlist)   // switches on which list is now given
                {
                case "networkdev":
                    foreach (var configItem in AC.configureNetwork.networkdev)
                    {
                        if (config.listid != configItem.listid)
                        {
                            continue;
                        }
                        change(configItem, config, country, customer);
                    }
                    break;

                case "interfacenetworkif":
                    foreach (var configItem in AC.configureNetwork.interfacenetworkif)
                    {
                        if (config.listid != configItem.listid)
                        {
                            continue;
                        }
                        change(configItem, config, country, customer);
                    }
                    break;

                case "proxyset":
                    foreach (var configItem in AC.configureviop.proxyset)
                    {
                        if (config.listid != configItem.listid)
                        {
                            continue;
                        }
                        change(configItem, config, country, customer);
                    }
                    break;

                case "proxyip":
                    foreach (var configItem in AC.configureviop.proxyip)
                    {
                        if (config.ip != configItem.ip)
                        {
                            continue;
                        }
                        change(configItem, config, country, customer);
                    }
                    break;

                default:
                    break;
                }
            }
            return(AC);
        }
Example #4
0
        public ACConfig replaceitem(ACConfig AC, dynamic list, string whatlist)
        {
            if (list == null)
            {
                return(AC);
            }
            foreach (var config in list)
            {
                switch (whatlist)   // switches on which list is now given
                {
                case "networkdev":
                    foreach (var i in AC.configureNetwork.networkdev)
                    {
                        if (config.listid == i.listid)
                        {
                            change(i, config);
                        }
                    }
                    break;

                case "interfacenetworkif":
                    foreach (var i in AC.configureNetwork.interfacenetworkif)
                    {
                        if (config.listid == i.listid)
                        {
                            change(i, config);
                        }
                    }
                    break;

                case "proxyset":
                    foreach (var i in AC.configureviop.proxyset)
                    {
                        if (config.listid == i.listid)
                        {
                            change(i, config);
                        }
                    }
                    break;

                case "proxyip":
                    foreach (var i in AC.configureviop.proxyip)
                    {
                        if (config.ip == i.ip)
                        {
                            change(i, config);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            return(AC);
        }
Example #5
0
 private static void AddNetworkDevices(ACConfig AC, List <string> configback)
 {
     if (AC.configureNetwork.networkdev == null)
     {
         return;
     }
     foreach (var item in AC.configureNetwork.networkdev)
     {
         configback.AddRange(GetConfigStringFromObject(item));
     }
 }
Example #6
0
 private static void AddInterfaces(ACConfig AC, List <string> configback)
 {
     if (AC.configureNetwork.interfacenetworkif == null)
     {
         return;
     }
     foreach (var item in AC.configureNetwork.interfacenetworkif)
     {
         configback.AddRange(GetConfigStringFromObject(item));
     }
 }
Example #7
0
 private static void AddProxy(ACConfig AC, List <string> configback)
 {
     if (AC.configureviop.proxyset == null)
     {
         return;
     }
     foreach (var item in AC.configureviop.proxyset)
     {
         configback.AddRange(GetConfigStringFromObject(item));
     }
 }
Example #8
0
        public List <string> objectToList(ACConfig AC)
        {
            List <string> configback = new List <string>();

            if (AC.configureNetwork != null)
            {
                configback.Add("configure network");
                AddNetworkDevices(AC, configback);
                AddInterfaces(AC, configback);
                configback.Add("exit");
            }
            if (AC.configureviop != null)
            {
                configback.Add("configure voip");
                AddProxy(AC, configback);
                AddProxyIp(AC, configback);
                configback.Add("exit");
            }
            return(configback);
        }
        private ACConfig SetInTheRightList(ACConfig Config, dynamic myList, string subIdent)
        {
            switch (subIdent) // returns the right Config
            {
            case ParserVariables.networkDev:
                Config.configureNetwork.networkdev = myList;
                return(Config);

            case ParserVariables.interfaceNetwokIf:
                Config.configureNetwork.interfacenetworkif = myList;
                return(Config);

            case ParserVariables.proxySet:
                Config.configureviop.proxyset = myList;
                return(Config);

            case ParserVariables.proxyIp:
                Config.configureviop.proxyip = myList;
                return(Config);

            default:
                return(Config);
            }
        }
        /// <summary>
        /// setzt die Value in aus dfem Bereich in die Passende liste an der Richtigen stelle
        /// </summary>
        /// <param name="Config">Loaded Config</param>
        /// <param name="Name"> Name of item to change</param>
        /// <param name="Value"> some Value of the setting</param>
        /// <param name="Index"></param>
        /// <param name="myList">SubList like Network-dev</param>
        /// <param name="subIdent">Name of the Subident like network-dev</param>
        /// <returns>ACConfig</returns>
        protected ACConfig ListParsing <T>(ACConfig Config, string Name, dynamic Value, int Index, IList <T> myList, string subIdent) where T : class
        {
            if (String.IsNullOrWhiteSpace(Value.ToString())) // falls es keine Value gibt brauch es nix machen
            {
                return(Config);
            }
            var property     = myList[Index].GetType().GetProperties().Where(a => a.Name == Name).FirstOrDefault(); // Gets the type of the property
            var propertyType = property.PropertyType;

            if (propertyType == typeof(Int32) || propertyType == typeof(Nullable <Int32>)) //if type = int then parse Value into an integer
            {
                property.SetValue(myList[Index], Convert.ToInt32(Value));
            }
            else if (propertyType.IsEnum) // if type = enum then parse Value into a enum
            {
                var newValue = selectRightEnummember(Value, property);
                if (newValue == null)
                {
                    return(Config);
                }
                else
                {
                    property.SetValue(myList[Index], newValue); // List all fields of an enum
                }
            }
            else if (propertyType == typeof(Boolean)) // if type = boolean then parse Value into a boolean
            {
                property.SetValue(myList[Index], Convert.ToBoolean(Value));
            }
            else                            //if type is something else (hopefully a string) then replace the old value with the new
            {
                property.SetValue(myList[Index], Value);
            }

            return(SetInTheRightList(Config, myList, subIdent));
        }
        public ACConfig parseinobject(StreamReader Reader)
        {
            Configureviop             vo                  = new Configureviop();
            ConfigureNetwork          co                  = new ConfigureNetwork();
            List <Networkdev>         networkDevs         = new List <Networkdev>();
            List <Interfacenetworkif> interfaceNetworkIfs = new List <Interfacenetworkif>();
            List <Proxyip>            proxyIps            = new List <Proxyip>();
            List <Proxyset>           proxySets           = new List <Proxyset>();
            ACConfig AC = new ACConfig();


            AC.configureNetwork = co;
            AC.configureviop    = vo;

            AC.configureNetwork.networkdev         = networkDevs;
            AC.configureNetwork.interfacenetworkif = interfaceNetworkIfs;

            AC.configureviop.proxyip  = proxyIps;
            AC.configureviop.proxyset = proxySets;

            string ident                      = String.Empty;
            bool   configureExit              = true;
            string subIdent                   = String.Empty;
            bool   subIdentExit               = true;
            string subIdentValue              = String.Empty;
            int    networkDevListTndex        = -1;
            int    interfaceNetwokIfListTndex = -1;
            int    proxySetListTndex          = -1;
            int    proxyIpListTndex           = -1;
            string Name = string.Empty;

            using (Reader)
            {
                string line = " ";
                while ((line = Reader.ReadLine()) != null)                                                  // zu editierende File einlesen (Zeile für Zeile)
                {
                    if (line == string.Empty || line == "")                                                 // wenn leere Zeile überspringe
                    {
                        continue;
                    }
                    if (configureExit)                                                                      // wenn True -> kein Überbereich(configure voip // configure network) in dem die Konfig definiert wird
                    {
                        getConfigureIdent(line, out configureExit, out ident);
                        continue;
                    }
                    if (subIdentExit)
                    {
                        getIdentNameAndValue(line, out configureExit, out subIdentExit, out subIdent, out subIdentValue);                   // wenn true -> keien Bereich(networkDev / interfaceNetworkIf) in dem Konfig konfiguriert wird
                        Name = returnRealName(subIdent);
                        if (Name == null)
                        {
                            continue;
                        }
                        switch (subIdent)
                        {
                        case ParserVariables.networkDev:
                            Networkdev newListNetworkDev = new Networkdev();
                            networkDevs.Add(newListNetworkDev);
                            networkDevListTndex++;
                            AC = ListParsing(AC, Name, subIdentValue, networkDevListTndex, AC.configureNetwork.networkdev, subIdent);
                            continue;

                        case ParserVariables.interfaceNetwokIf:
                            Interfacenetworkif newListInterfaceNetworkIf = new Interfacenetworkif();
                            interfaceNetworkIfs.Add(newListInterfaceNetworkIf);
                            interfaceNetwokIfListTndex++;
                            AC = ListParsing(AC, Name, subIdentValue, interfaceNetwokIfListTndex, AC.configureNetwork.interfacenetworkif, subIdent);
                            continue;

                        case ParserVariables.proxyIp:
                            Proxyip newListProxyIp = new Proxyip();
                            proxyIps.Add(newListProxyIp);
                            proxyIpListTndex++;
                            AC = ListParsing(AC, Name, subIdentValue, proxyIpListTndex, AC.configureviop.proxyip, subIdent);
                            continue;

                        case ParserVariables.proxySet:
                            Proxyset newListProxySet = new Proxyset();
                            proxySets.Add(newListProxySet);
                            proxySetListTndex++;
                            AC = ListParsing(AC, Name, subIdentValue, proxySetListTndex, AC.configureviop.proxyset, subIdent);
                            continue;

                        default:
                            continue;;
                        }
                    }
                    Name = ParserGrammar.NameParser.Parse(line);
                    if (Name == ParserVariables.exit)
                    {
                        subIdentExit = true;

                        continue;
                    }
                    Name = returnRealName(Name);
                    if (Name == null)
                    {
                        continue;
                    }
                    switch (subIdent)
                    {
                    case ParserVariables.networkDev:
                        AC = AddToList(AC, Name, AC.configureNetwork.networkdev, subIdent, networkDevListTndex, getVar(Name, line));
                        continue;

                    case ParserVariables.interfaceNetwokIf:
                        AC = AddToList(AC, Name, AC.configureNetwork.interfacenetworkif, subIdent, interfaceNetwokIfListTndex, getVar(Name, line));
                        continue;

                    case ParserVariables.proxyIp:
                        AC = AddToList(AC, Name, AC.configureviop.proxyip, subIdent, proxyIpListTndex, getVar(Name, line));
                        continue;

                    case ParserVariables.proxySet:
                        AC = AddToList(AC, Name, AC.configureviop.proxyset, subIdent, proxySetListTndex, getVar(Name, line));
                        continue;

                    default:
                        break;
                    }
                }
            }
            return(AC);
        }
 public ACConfig AddToList(ACConfig AC, string Name, dynamic List, string subIdent, int Index, dynamic value)
 {
     AC = ListParsing(AC, Name, value, Index, List, subIdent);
     return(AC);
 }
Example #13
0
        public void prepareForStart(CommandOption Path, CommandOption configPath, CommandOption templatePath, out ACConfig ConfigWithChanges, out List <string> dirs)
        {
            var paths         = getDefaultPaths(Path, configPath, templatePath);
            var configuration = LoadSystemConfig(System.IO.Path.GetFullPath(System.IO.Path.Combine(paths.configPath, "Config.json")));
            var outputPath    = fileproof(paths.path, configuration.outputDirectory);
            var changePath    = System.IO.Path.GetFullPath(System.IO.Path.Combine(fileproof(paths.path, configuration.outputDirectory), "change.json"));

            ConfigWithChanges = JsonConvert.DeserializeObject <ACConfig>(File.ReadAllText(changePath));//open json to use
            dirs = findFilesInDirectory(outputPath);
        }
Example #14
0
        protected ACConfig ListParsing(ACConfig Config, string Name, dynamic Value, int Index, dynamic myList, string subIdent) //setzt die Value in aus dfem Bereich in die Passende liste an der Richtigen stelle
        {
            if (String.IsNullOrWhiteSpace(Value.ToString()))                                                                    // falls es keine Value gibt brauch es nix machen
            {
                return(Config);
            }
            foreach (var item in myList[Index].GetType().GetProperties()) //property aus index X   bekommeb
            {
                var property = item;
                if (property.Name != Name) // wenn die property nicht den selben bezeichner hat wie der gegebene Name
                {
                    continue;
                }
                var propertyType = property.PropertyType;                                      // Gets the type of the property

                if (propertyType == typeof(Int32) || propertyType == typeof(Nullable <Int32>)) //if type = int then parse Value into an integer
                {
                    property.SetValue(myList[Index], Convert.ToInt32(Value));
                }
                else if (propertyType.IsEnum) // if type = enum then parse Value into a enum
                {
                    var enumMember = propertyType
                                     .GetFields(); // List all fields of an enum
                    foreach (var member in enumMember)
                    {
                        if (member.Name == Convert.ToString(Value) ||
                            Convert.ToString(Value) == Convert.ToString(member.GetCustomAttributes(typeof(NameAttribute), false)))  // if the name of the field = Name or the Attribute = Name
                        {
                            if (member == null)
                            {
                                Console.WriteLine($"Warn: skip property {property.Name} because the value {Value} is not valid for this field.");
                                return(Config);
                            }
                            var enumValue = Enum.Parse(propertyType, member.Name);  // parses Value into an enumValue
                            property.SetValue(myList[Index], enumValue);
                        }  //Console.WriteLine($"Warn: skip property {property.Name} because enums currently not supported.");
                    }
                }
                else if (propertyType == typeof(Boolean)) // if type = boolean then parse Value into a boolean
                {
                    property.SetValue(myList[Index], Convert.ToBoolean(Value));
                }
                else                            //if type is something else (hopefully a string) then replace the old value with the new
                {
                    property.SetValue(myList[Index], Value);
                }
                switch (subIdent) // returns the right Config
                {
                case ParserVariables.networkDev:
                    Config.configureNetwork.networkdev = myList;
                    return(Config);

                case ParserVariables.interfaceNetwokIf:
                    Config.configureNetwork.interfacenetworkif = myList;
                    return(Config);

                case ParserVariables.proxySet:
                    Config.configureviop.proxyset = myList;
                    return(Config);

                case ParserVariables.proxyIp:
                    Config.configureviop.proxyip = myList;
                    return(Config);

                default:
                    break;
                }
                return(Config);
            }
            return(Config);
        }
Example #15
0
        protected ACConfig parseinobject(StreamReader Reader)
        {
            Configureviop             vo                  = new Configureviop();
            ConfigureNetwork          co                  = new ConfigureNetwork();
            List <Networkdev>         networkDevs         = new List <Networkdev>();
            List <Interfacenetworkif> interfaceNetworkIfs = new List <Interfacenetworkif>();
            List <Proxyip>            proxyIps            = new List <Proxyip>();
            List <Proxyset>           proxySets           = new List <Proxyset>();
            ACConfig AC = new ACConfig();


            AC.configureNetwork = co;
            AC.configureviop    = vo;

            AC.configureNetwork.networkdev         = networkDevs;
            AC.configureNetwork.interfacenetworkif = interfaceNetworkIfs;

            AC.configureviop.proxyip  = proxyIps;
            AC.configureviop.proxyset = proxySets;

            string ident                      = " ";
            bool   configureExit              = true;
            string subIdent                   = " ";
            bool   subIdentExit               = true;
            string subIdentValue              = "";
            int    networkDevListTndex        = 0;
            int    interfaceNetwokIfListTndex = 0;
            int    proxySetListTndex          = 0;
            int    proxyIpListTndex           = 0;

            using (Reader)
            {
                string line = " ";
                while ((line = Reader.ReadLine()) != null)                                                  // zu editierende File einlesen (Zeile für Zeile)
                {
                    if (line == string.Empty || line == "")                                                 // wenn leere Zeile überspringe
                    {
                        continue;
                    }
                    if (configureExit)                                                                      // wenn True -> kein Überbereich(configure voip // configure network) in dem die Konfig definiert wird
                    {
                        getConfigureIdent(line, out configureExit, out ident);
                        continue;
                    }
                    if (subIdentExit)
                    {
                        getIdentNameAndValue(line, out configureExit, out subIdentExit, out subIdent, out subIdentValue);  // wenn true -> keien Bereich(networkDev / interfaceNetworkIf) in dem Konfig konfiguriert wird
                        var Name = returnRealName(subIdent);
                        if (Name != null && subIdent == ParserVariables.networkDev)
                        {
                            Networkdev newListNetworkDev = new Networkdev();
                            networkDevs.Add(newListNetworkDev);                                            //neue Liste wird erstellt für jede Bereich von networkDev
                            AC = ListParsing(AC, Name, subIdentValue, networkDevListTndex, AC.configureNetwork.networkdev, subIdent);
                        }
                        else if (Name != null && subIdent == ParserVariables.interfaceNetwokIf)
                        {
                            Interfacenetworkif newListInterfaceNetworkIf = new Interfacenetworkif();
                            interfaceNetworkIfs.Add(newListInterfaceNetworkIf);
                            AC = ListParsing(AC, Name, subIdentValue, interfaceNetwokIfListTndex, AC.configureNetwork.interfacenetworkif, subIdent);
                        }
                        else if (Name != null && subIdent == ParserVariables.proxySet)
                        {
                            Proxyset newListProxySet = new Proxyset();
                            proxySets.Add(newListProxySet);
                            AC = ListParsing(AC, Name, subIdentValue, proxySetListTndex, AC.configureviop.proxyset, subIdent);
                        }
                        else if (Name != null && subIdent == ParserVariables.proxyIp)
                        {
                            Proxyip newListProxyIp = new Proxyip();
                            proxyIps.Add(newListProxyIp);
                            AC = ListParsing(AC, Name, subIdentValue, proxyIpListTndex, AC.configureviop.proxyip, subIdent);
                        }
                        continue;
                    }

                    if (configureExit == false && subIdentExit == false && ident == "configure network" && subIdent == ParserVariables.networkDev)
                    {
                        var Name = ParserGrammar.NameParser.Parse(line);
                        if (Name == ParserVariables.exit) // Bereich wird durch exit beendet -> Listenindex wird erhöht und es gibt keinen Bereich in dem definiert die Konfig defoiniert wird
                        {
                            subIdentExit = true;
                            networkDevListTndex++;
                            continue;
                        }
                        Name = returnRealName(Name);
                        if (Name == null)
                        {
                            continue;
                        }
                        if (Name == ParserVariables.activate) //boolscher wert der in der KOnfiguration keinen weiteren Wert zugewieden bekommt -> entweder da oder nicht
                        {
                            var Value = true;
                            AC = ListParsing(AC, Name, Value, networkDevListTndex, AC.configureNetwork.networkdev, subIdent);
                        }
                        else
                        {
                            var Value = ParserGrammar.ValueParser.Parse(line);
                            AC = ListParsing(AC, Name, Value, networkDevListTndex, AC.configureNetwork.networkdev, subIdent);
                        }


                        continue;
                    }
                    else if (configureExit == false && subIdentExit == false && ident == "configure network" && subIdent == ParserVariables.interfaceNetwokIf)
                    {
                        var Name = ParserGrammar.NameParser.Parse(line);
                        if (Name == ParserVariables.exit)
                        {
                            subIdentExit = true;
                            interfaceNetwokIfListTndex++;
                            continue;
                        }
                        Name = returnRealName(Name);
                        if (Name == null)
                        {
                            continue;
                        }
                        if (Name == ParserVariables.activate)
                        {
                            var Value = true;
                            AC = ListParsing(AC, Name, Value, interfaceNetwokIfListTndex, AC.configureNetwork.interfacenetworkif, subIdent);
                        }
                        else
                        {
                            var Value = ParserGrammar.ValueParser.Parse(line);
                            AC = ListParsing(AC, Name, Value, interfaceNetwokIfListTndex, AC.configureNetwork.interfacenetworkif, subIdent);
                        }
                        continue;
                    }
                    if (configureExit == false && subIdentExit == false && ident == "configure voip" && subIdent == ParserVariables.proxySet)
                    {
                        var Name = ParserGrammar.NameParser.Parse(line);
                        if (Name == ParserVariables.exit)
                        {
                            subIdentExit = true;
                            proxySetListTndex++;
                            continue;
                        }
                        Name = returnRealName(Name);
                        if (Name == null)
                        {
                            continue;
                        }
                        if (Name == ParserVariables.activate)
                        {
                            var Value = true;
                            AC = ListParsing(AC, Name, Value, proxySetListTndex, AC.configureviop.proxyset, subIdent);
                        }
                        else
                        {
                            var Value = ParserGrammar.ValueParser.Parse(line);
                            AC = ListParsing(AC, Name, Value, proxySetListTndex, AC.configureviop.proxyset, subIdent);
                        }
                        continue;
                    }
                    else if (configureExit == false && subIdentExit == false && ident == "configure voip" && subIdent == ParserVariables.proxyIp)
                    {
                        var Name = ParserGrammar.NameParser.Parse(line);
                        if (Name == ParserVariables.exit)
                        {
                            subIdentExit = true;
                            proxyIpListTndex++;
                            continue;
                        }
                        Name = returnRealName(Name);
                        if (Name == null)
                        {
                            continue;
                        }
                        if (Name == ParserVariables.activate)
                        {
                            var Value = true;
                            AC = ListParsing(AC, Name, Value, proxyIpListTndex, AC.configureviop.proxyip, subIdent);
                        }
                        else
                        {
                            var Value = ParserGrammar.ValueParser.Parse(line);
                            AC = ListParsing(AC, Name, Value, proxyIpListTndex, AC.configureviop.proxyip, subIdent);
                        }
                        continue;
                    }
                }
            }
            return(AC);
        }