Exemple #1
0
        public static void startReadingConfigFile(string filepath, bool step)
        {
            PuppetMasterReadConfig readConfig = new PuppetMasterReadConfig();

            //TODO FileNotFound Exception

            if (fileLines == null)
            {
                try
                {
                    fileLines = File.ReadAllLines(filepath);
                }
                catch (FileNotFoundException e)
                {
                    PuppetMaster.formPuppetMaster.addNewLineToLog("File not found");
                    return;
                }
            }

            int limit = 0;

            if (step)
            {
                limit = lastLine + 1;
                if (limit > fileLines.Length)
                {
                    limit = fileLines.Length;
                }
            }
            else
            {
                limit = fileLines.Length;
            }


            for (int i = lastLine; i < limit; i++)
            {
                lastLine++;
                string[] line = fileLines[i].Split();
                if (!String.IsNullOrEmpty(line[0]))
                {
                    int cont = i + 1;
                    Debug.WriteLine("line " + cont + "=" + line[0]);
                    Dictionary <string, string> lineContentDictionary = readConfig.readLine(line);
                    string lineID = lineContentDictionary["LINE_ID"];
                    Debug.WriteLine("lineID = " + lineID);

                    if (lineID.Equals("LOGGING_LEVEL"))
                    {
                        PuppetMaster.formPuppetMaster.addNewLineToLog("Logging Level set to " + lineContentDictionary["TYPE"]);
                        loggingType = lineContentDictionary["TYPE"];
                    }

                    if (lineID.Equals("SEMANTICS"))
                    {
                        PuppetMaster.formPuppetMaster.addNewLineToLog("Semantics set to " + lineContentDictionary["TYPE"]);
                        semantics = lineContentDictionary["TYPE"];
                    }

                    if (lineID.Equals("OP"))
                    {
                        int    replicaCount = 0;
                        string operatorID   = lineContentDictionary["OPERATOR_ID"];
                        foreach (string address in lineContentDictionary["ADDRESSES"].Split('$'))
                        {
                            string replicaID = operatorID + "-" + replicaCount;
                            operatorsAddresses.Add(replicaID, address);
                            replicaCount++;
                        }

                        foreach (string key in lineContentDictionary.Keys)
                        {
                            string value = lineContentDictionary[key];
                            PuppetMaster.formPuppetMaster.addNewLineToLog(key + " = " + value);
                        }
                        PuppetMaster.formPuppetMaster.addNewLineToLog("\r\n");
                        lineContentDictionary["LOGGING_LEVEL"] = loggingType;
                        lineContentDictionary["SEMANTICS"]     = semantics;
                        services.sendOperatorInfoToPCS(lineContentDictionary);
                    }

                    else if (lineID.Equals("START"))
                    {
                        string operatorID = lineContentDictionary["OPERATOR_ID"];
                        foreach (string replicaID in operatorsAddresses.Keys)
                        {
                            if (replicaID.Contains(operatorID))
                            {
                                new Thread(() => doRemoteCommand(operatorsAddresses[replicaID], "START")).Start();
                            }
                        }
                    }

                    else if (lineID.Equals("INTERVAL"))
                    {
                        string operatorID = lineContentDictionary["OPERATOR_ID"];
                        int    time       = Int32.Parse(lineContentDictionary["TIME"]);
                        PuppetMaster.formPuppetMaster.addNewLineToLog("Setting an interval of " + time + "ms for " + operatorID);
                        foreach (string replicaID in operatorsAddresses.Keys)
                        {
                            if (replicaID.Contains(operatorID))
                            {
                                new Thread(() => doRemoteCommand(operatorsAddresses[replicaID], "INTERVAL-" + time)).Start();
                            }
                        }
                    }

                    else if (lineID.Equals("STATUS"))
                    {
                        PuppetMaster.formPuppetMaster.addNewLineToLog("I'm sending to all operators a request for status");
                        foreach (string operatorAddress in operatorsAddresses.Values)
                        {
                            PuppetMaster.formPuppetMaster.addNewLineToLog("OPERATOR ADDRESS = " + operatorAddress);

                            new Thread(() => doRemoteCommand(operatorAddress, "STATUS")).Start();
                        }
                    }

                    else if (lineID.Equals("FREEZE"))
                    {
                        string operatorID  = lineContentDictionary["OPERATOR_ID"];
                        string replicaID   = lineContentDictionary["REPLICA_ID"];
                        string keyOperator = operatorID + "-" + replicaID;
                        PuppetMaster.formPuppetMaster.addNewLineToLog("Freezing " + keyOperator);

                        new Thread(() => doRemoteCommand(operatorsAddresses[keyOperator], "FREEZE")).Start();
                    }

                    else if (lineID.Equals("UNFREEZE"))
                    {
                        string operatorID  = lineContentDictionary["OPERATOR_ID"];
                        string replicaID   = lineContentDictionary["REPLICA_ID"];
                        string keyOperator = operatorID + "-" + replicaID;
                        PuppetMaster.formPuppetMaster.addNewLineToLog("Unfreezing " + keyOperator);

                        new Thread(() => doRemoteCommand(operatorsAddresses[keyOperator], "UNFREEZE")).Start();
                    }

                    else if (lineID.Equals("WAIT"))
                    {
                        int sleepTime = Int32.Parse(lineContentDictionary["TIME"]);
                        Thread.Sleep(sleepTime);
                    }

                    else if (lineID.Equals("CRASH"))
                    {
                        string operatorID  = lineContentDictionary["OPERATOR_ID"];
                        string replicaID   = lineContentDictionary["REPLICA_ID"];
                        string keyOperator = operatorID + "-" + replicaID;
                        PuppetMaster.formPuppetMaster.addNewLineToLog("Crashing " + keyOperator);
                        new Thread(() => doRemoteCommand(operatorsAddresses[keyOperator], "CRASH")).Start();
                    }
                }
            }
        }
Exemple #2
0
        public static void startReadingConfigFile(string filepath, bool step)
        {
            PuppetMasterReadConfig readConfig = new PuppetMasterReadConfig();

            //TODO FileNotFound Exception

            if (fileLines == null)
            {
                fileLines = File.ReadAllLines(filepath);
            }

            int limit = 0;

            if (step)
            {
                limit = lastLine + 1;
                if (limit > fileLines.Length)
                {
                    limit = fileLines.Length;
                }
            }
            else
            {
                limit = fileLines.Length;
            }

            for (int i = lastLine; i < limit; i++)
            {
                lastLine++;
                string[] line = fileLines[i].Split();
                if (!String.IsNullOrEmpty(line[0]))
                {
                    int cont = i + 1;
                    Debug.WriteLine("line " + cont + "=" + line[0]);
                    Dictionary <string, string> lineContentDictionary = readConfig.readLine(line);
                    string lineID = lineContentDictionary["LINE_ID"];
                    Debug.WriteLine("lineID = " + lineID);

                    if (lineID.Equals("OP"))
                    {
                        int    replicaCount = 0;
                        string operatorID   = lineContentDictionary["OPERATOR_ID"];
                        foreach (string address in lineContentDictionary["ADDRESSES"].Split('$'))
                        {
                            string replicaID = operatorID + "-" + replicaCount;
                            operatorsAddresses.Add(replicaID, address);
                            replicaCount++;
                        }

                        foreach (string key in lineContentDictionary.Keys)
                        {
                            string value = lineContentDictionary[key];
                            PuppetMaster.formPuppetMaster.addNewLineToLog(key + " = " + value);
                        }
                        PuppetMaster.formPuppetMaster.addNewLineToLog("\r\n");
                        services.sendOperatorInfoToPCS(lineContentDictionary);
                    }

                    else if (lineID.Equals("START"))
                    {
                        string operatorID = lineContentDictionary["OPERATOR_ID"];
                        PuppetMaster.formPuppetMaster.addNewLineToLog("PCS is about to start: " + operatorID);

                        foreach (string replicaID in operatorsAddresses.Keys)
                        {
                            if (replicaID.Contains(operatorID))
                            {
                                Debug.WriteLine("REPLICA ADDRESS = " + operatorsAddresses[replicaID]);
                                PuppetMaster.formPuppetMaster.addNewLineToLog("REPLICA ADDRESS = " + operatorsAddresses[replicaID]);
                                opServices = (OperatorServices)Activator.GetObject(
                                    typeof(OperatorServices),
                                    operatorsAddresses[replicaID]);

                                opServices.startToProcess();
                            }
                        }
                    }

                    else if (line.Equals("INTERVAL"))
                    {
                        //TODO
                    }

                    else if (line.Equals("STATUS"))
                    {
                        //TODO
                    }

                    else if (line.Equals("CRASH"))
                    {
                        //TODO
                    }

                    else if (line.Equals("FREEZE"))
                    {
                        //TODO
                    }

                    else if (line.Equals("UNFREEZE"))
                    {
                        //TODO
                    }

                    else if (line.Equals("WAIT"))
                    {
                        //TODO
                    }
                }
            }
        }