Beispiel #1
0
        public static Config[] readFromFile()
        {
            Config[] configs = null;

            String file =
                "SSID-->AA/27,.," +
                "FINGERPRINT--><title>LOGIN PAGE</title>,.," +

                "ACTION_TYPE-->FILL,.," +
                "ACTION_TAG-->input,.," +
                "ACTION_INDEX-->0,.," +
                "ACTION_VALUE-->yohanesmario,.," +

                "ACTION_TYPE-->FILL,.," +
                "ACTION_TAG-->input,.," +
                "ACTION_INDEX-->1,.," +
                "ACTION_VALUE-->whitemouse,.," +

                "ACTION_TYPE-->CLICK,.," +
                "ACTION_TAG-->button,.," +
                "ACTION_INDEX-->0,.," +

                "|**|" +

                "SSID-->Yohanes Mario Chandra,.," +
                "FINGERPRINT--><title>LOGIN PAGE - TESTING</title>,.," +

                "ACTION_TYPE-->FILL,.," +
                "ACTION_TAG-->input,.," +
                "ACTION_INDEX-->0,.," +
                "ACTION_VALUE-->username,.," +

                "ACTION_TYPE-->FILL,.," +
                "ACTION_TAG-->input,.," +
                "ACTION_INDEX-->1,.," +
                "ACTION_VALUE-->password,.,";

            String[] separator = {"|**|"};
            String[] components = file.Split(separator, StringSplitOptions.RemoveEmptyEntries);

            configs = new Config[components.Length];
            int i = 0;

            foreach (String component in components) {
                String trimedComponent = component.Trim();
                separator[0] = ",.,";
                String[] lines = trimedComponent.Split(separator, StringSplitOptions.RemoveEmptyEntries);

                configs[i] = new Config();

                String[][] commands = new String[lines.Length][];
                int j = 0;

                int fingerprintCounter = 0;
                int actionCounter = 0;
                foreach (String line in lines) {
                    commands[j] = new String[2];
                    String trimedLine = line.Trim();
                    separator[0] = "-->";
                    commands[j] = trimedLine.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                    commands[j][0] = commands[j][0].Trim();
                    commands[j][1] = commands[j][1].Trim();
                    if (commands[j][0].Equals("ACTION_TYPE")) {
                        actionCounter++;
                    }
                    else if (commands[j][0].Equals("FINGERPRINT")) {
                        fingerprintCounter++;
                    }
                    j++;
                }

                String[] fingerprints = new String[fingerprintCounter];

                int[] actionType = new int[actionCounter];
                String[] actionTag = new String[actionCounter];
                int[] actionIndex = new int[actionCounter];
                String[] actionValue = new String[actionCounter];

                int fingerprintIdx = 0;
                int actionIdx = 0;
                for (int idx = 0; idx < commands.Length; idx++) {
                    if (commands[idx][0].Equals("SSID")) {
                        configs[i].SSID = commands[idx][1];
                    }
                    else if (commands[idx][0].Equals("FINGERPRINT")) {
                        fingerprints[fingerprintIdx] = commands[idx][1];
                        fingerprintIdx++;
                    }
                    else if (commands[idx][0].Equals("ACTION_TYPE")) {
                        if (commands[idx][1].Equals("FILL")) {
                            actionType[actionIdx] = Config.ACTION_TYPE_FILL;
                            actionTag[actionIdx] = commands[idx + 1][1];
                            actionIndex[actionIdx] = int.Parse(commands[idx + 2][1]);
                            actionValue[actionIdx] = commands[idx + 3][1];
                            idx += 3;
                        }
                        else if (commands[idx][1].Equals("CLICK")) {
                            actionType[actionIdx] = Config.ACTION_TYPE_CLICK;
                            actionTag[actionIdx] = commands[idx + 1][1];
                            actionIndex[actionIdx] = int.Parse(commands[idx + 2][1]);
                            actionValue[actionIdx] = null;
                            idx += 2;
                        }
                        actionIdx++;
                    }
                }

                configs[i].fingerprints = fingerprints;
                configs[i].actionType = actionType;
                configs[i].actionTag = actionTag;
                configs[i].actionIndex = actionIndex;
                configs[i].actionValue = actionValue;

                i++;
            }

            return configs;
        }
Beispiel #2
0
 private void SaveConfig()
 {
     try
     {
         Config currentConfig = new Config();
         currentConfig.ImagePath = ImagePath;
         currentConfig.Interval = Interval / 60000;
         XmlSerializer xmlConfig = new XmlSerializer(typeof(Config));
         TextWriter configFile = new StreamWriter(HomePath + @"\config");
         xmlConfig.Serialize(configFile, currentConfig);
         configFile.Close();
     }
     catch { }
 }