Exemple #1
0
        public void checkReplicas(ConfigFileLine op)
        {
            int m = 1;
            int n = Int32.Parse(op.rep_fact);

            if (n > 1)
            {
                replicas = new List <ConfigFileLine>();
                while (m < n)
                {
                    ConfigFileLine replica = new ConfigFileLine();
                    replica.name            = op.name + "_R" + (m);
                    replica.operator_spec   = op.operator_spec;
                    replica.input_ops       = op.input_ops;
                    replica.rep_fact        = op.rep_fact;
                    replica.routing         = op.routing;
                    replica.address         = op.address;
                    replica.semantics       = op.semantics;
                    replica.loggingLevel    = op.loggingLevel;
                    replica.previousRepFact = op.previousRepFact;
                    replicas.Add(replica);
                    pcs.Add(replica); //lista para o pcs criar
                    m++;
                }
                opReplicas.Add(op.name, replicas);
            }
        }
Exemple #2
0
        public MainWindow()
        {
            CultureInfo cultureInfo = CultureInfo.CurrentCulture;

            language = cultureInfo.TwoLetterISOLanguageName == "pl" ? "pl" : "en";

            string[] commandLineArgs = Environment.GetCommandLineArgs();

            bool hideWindow = false;
            bool started    = false;

            foreach (var item in commandLineArgs)
            {
                switch (item)
                {
                case "Log":
                    LoggingEnabled = true;     //Włączenie logowania błędów do pliku
                    break;

                case "HideWindow":
                    hideWindow = true;     //Ukrywa okno po uruchomieniu aplikacji
                    break;

                case "Started":
                    started = true;     //Uruchamia serwer od razu po uruchomieniu aplikacji
                    break;

                default:
                    break;
                }
            }

            try
            {
                if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Pilot Server\\config.ini")) //Odczyt lub utworzenie pliku konfiguracyjnego
                {
                    UpdateConfigFile(port, password, language, "False", autostart.ToString());
                }
                else
                {
                    using (StreamReader ConfigFile = File.OpenText(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Pilot Server\\config.ini"))
                    {
                        string ConfigFileLine;
                        while ((ConfigFileLine = ConfigFile.ReadLine()) != null)
                        {
                            string[] value = ConfigFileLine.Split('=');
                            switch (value[0])
                            {
                            case "PORT":
                                port = short.Parse(value[1]);
                                break;

                            case "PASSWORD":
                                password = value[1];
                                break;

                            case "LANGUAGE":
                                language = value[1];
                                break;

                            case "LOGGING":
                                logging = value[1] == "True" ? true : false;
                                break;

                            case "AUTOSTART":
                                autostart = value[1] == "True" ? true : false;
                                break;

                            default:
                                UpdateLog(DateTime.Now.ToString("HH:mm:ss") + " " + Properties.Resources.ConfigFileError);
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                UpdateLog(DateTime.Now.ToString("HH:mm:ss") + " " + error.ToString());

                if (LoggingEnabled)
                {
                    StreamWriter LogFile = File.CreateText(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Pilot Server\\log.txt");
                    LogFile.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " " + error.ToString());
                    LogFile.Close();
                }
            }

            ChangeUILanguage(language);

            InitializeComponent();
            MyNotifyIcon.Visibility = Visibility.Collapsed;

            Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Pilot Server");
            UpdateLog(Properties.Resources.AppDataDirectory + " " + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Pilot Server", true);

            enableWindowLogCheckbox.IsChecked = logging;

            this.Closing      += MainWindow_Closing;
            this.StateChanged += MainWindow_StateChanged;

            if (hideWindow)
            {
                WindowState             = WindowState.Minimized;
                MyNotifyIcon.Visibility = Visibility.Visible;
                Hide();
            }

            if (started)
            {
                serverStateButton_Click(null, null);
            }
        }
Exemple #3
0
        public void FileParser(string name)
        {
            try
            {
                string[] fileLines = File.ReadAllLines("../../../" + name);
                string[] words;
                int      operator_index = 0;
                string   semantics      = "";
                string   loggingLevel   = "";
                for (int i = 0; i < fileLines.Length; i++)
                {
                    words = fileLines[i].Split();
                    if (fileLines[i].Contains("Semantics"))
                    {
                        semantics = words[1];
                    }
                    if (fileLines[i].Contains("LoggingLevel"))
                    {
                        loggingLevel = words[1];
                    }

                    if (fileLines[i].Contains("input ops") && !fileLines[i].Contains("%") && !fileLines[i].Contains("%%"))
                    {
                        ConfigFileLine op = new ConfigFileLine();
                        op.name      = words[0];
                        op.input_ops = words[3];

                        op.rep_fact     = words[6];
                        op.routing      = words[8];
                        op.address      = new List <string>();
                        op.semantics    = semantics;
                        op.loggingLevel = loggingLevel;
                        if (words[10].Contains(','))
                        {
                            int num = 10;
                            while (num < words.Length)
                            {
                                if (words[num].Equals("operator"))
                                {
                                    operator_index = num;
                                    break;
                                }
                                op.address.Add(words[num]);
                                num++;
                            }
                            op.operator_spec = words[operator_index + 2] + "_" + words[operator_index + 3];
                        }
                        else
                        {
                            op.address.Add(words[10]);
                            int num = 13;
                            while (num < words.Length)
                            {
                                op.operator_spec += words[num] + " ";
                                num++;
                            }
                        }
                        pcs.Add(op);
                        primaryReplicas.Add(op);
                        for (var j = 1; j < pcs.Count; j++)
                        {
                            if (pcs[j - 1].rep_fact != null)
                            {
                                pcs[j].previousRepFact = pcs[j - 1].rep_fact;
                            }
                        }
                        checkReplicas(op); //checka a existencia de replicas
                    }
                    if (fileLines[i].Contains("Start") && !fileLines[i].Contains("%") && !fileLines[i].Contains("%%"))
                    {
                        string comando = string.Join(" ", words);
                        configCommands.Add(comando);
                    }
                    if (fileLines[i].Contains("Interval") && !fileLines[i].Contains("%") && !fileLines[i].Contains("%%"))
                    {
                        string comando = string.Join(" ", words);
                        configCommands.Add(comando);
                    }
                    if (fileLines[i].Contains("Status") && !fileLines[i].Contains("%") && !fileLines[i].Contains("%%"))
                    {
                        string comando = string.Join(" ", words);
                        configCommands.Add(comando);
                    }
                    if (fileLines[i].Contains("Wait") && !fileLines[i].Contains("%") && !fileLines[i].Contains("%%"))
                    {
                        string comando = string.Join(" ", words);
                        configCommands.Add(comando);
                    }
                    if (fileLines[i].Contains("Freeze") && !fileLines[i].Contains("%") && !fileLines[i].Contains("%%"))
                    {
                        string comando = string.Join(" ", words);
                        configCommands.Add(comando);
                    }
                    if (fileLines[i].Contains("Unfreeze") && !fileLines[i].Contains("%") && !fileLines[i].Contains("%%"))
                    {
                        string comando = string.Join(" ", words);
                        configCommands.Add(comando);
                    }
                    if (fileLines[i].Contains("Crash") && !fileLines[i].Contains("%") && !fileLines[i].Contains("%%"))
                    {
                        string comando = string.Join(" ", words);
                        configCommands.Add(comando);
                    }
                }
            }
            catch (Exception)
            {
                addMsgToLog("Invalid File!");
            }
        }