示例#1
0
        public static void StoreEndPoints2DB(Group group)
        {
            string str = @"Select groups.index from groups where name = ?name";
            MySqlCommand cmd = new MySqlCommand(str, m_sqlConn);
            cmd.Parameters.AddWithValue("?name", group.name);
            cmd.Connection.Open();

            MySqlDataReader reader = cmd.ExecuteReader();
            int group_index = -1;
            while (reader.Read())
            {
                group_index = reader.GetInt32(0);
            }

            cmd.Connection.Close();

            if (group_index == -1)
                return;

            foreach (EndPoint e in group.endpoints)
            {

                try
                {
                    str = @"INSERT INTO endpoints
                        (index_endpoint, index_group, name, server, request_heartbeat, port, context_prefix, conn_group)
                         VALUES(?index_endpoint, ?index_group, ?name, ?server, ?request_heartbeat, ?port, ?context_prefix, ?conn_group)";
                    cmd = new MySqlCommand(str, m_sqlConn);

                    cmd.Parameters.AddWithValue("?index_endpoint", e.index);
                    cmd.Parameters.AddWithValue("?index_group", group_index);
                    cmd.Parameters.AddWithValue("?name", e.name == null ? "" : e.name);
                    cmd.Parameters.AddWithValue("?server", e.server == null ? "" : e.server);
                    cmd.Parameters.AddWithValue("?request_heartbeat", e.request_heartbeat);
                    cmd.Parameters.AddWithValue("?port", e.port == null ? "" : e.port);
                    cmd.Parameters.AddWithValue("?context_prefix", e.context_prefix == null ? "" : e.context_prefix);
                    cmd.Parameters.AddWithValue("?conn_group", e.is_conn_group);

                    cmd.Connection.Open();
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                }
                catch (MySqlException ex)
                {
                    Console.WriteLine(ex.ToString());
                }

            }
        }
示例#2
0
        public static void ParseRegFiles()
        {
            // string path = System.IO.Directory.GetCurrentDirectory();
            DirectoryInfo di = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
            FileInfo[] fiarr = di.GetFiles("*.reg");

            List<Group> groups = new List<Group>();
            foreach(FileInfo fri in fiarr)
            {
                Group group = new Group();
                List<EndPoint> endpoints = new List<EndPoint>();
              //  Console.WriteLine(fri.ToString());
               // Console.WriteLine("========================================");
                StreamReader sr = new StreamReader(fri.FullName, System.Text.Encoding.Default);

                string line;
                bool isEndpoint = false;
                string name = "";
                int index = -1;
                bool firstEndpoint = true;
                EndPoint endpoint = new EndPoint();
                while((line = sr.ReadLine())!=null)
                {
                    if (line.Length == 0 || line == "")
                        continue;

                    if (line.StartsWith("[HKEY"))
                    {
                        //tell if is a group or endpoint
                        IsEndpoint(line, out isEndpoint, out name, out index);

                        if (isEndpoint)
                        {
                            if (!firstEndpoint)
                                endpoints.Add(endpoint);
                            firstEndpoint = false;
                            endpoint = new EndPoint();
                            endpoint.index = index;

                        }

                        continue;
                    }

                    if (!isEndpoint)
                    {
                        if (name.Length > 0)
                            group.name = name;

                        if (line.StartsWith("\"m_strServerTypes\""))
                        {
                            group.server_types = getValue(line);
                            continue;
                        }

                        if (line.StartsWith("\"m_zNoManFillFees\""))
                        {
                            group.no_manual_fill_fees = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_iPositionBackColorAdjust\""))
                        {
                            group.back_color = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_zManFillsEnabled\""))
                        {
                            group.manual_fills_enabled = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_zAltFillDB\""))
                        {
                            group.alt_fill_db = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_strFrontMonth\""))
                        {
                            group.front_month = getValue(line);
                            continue;
                        }

                        if (line.StartsWith("\"m_zManFillWipeEnabled\""))
                        {
                            group.manual_fill_wipe_enabled = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_zPositionSnapshots\""))
                        {
                            group.position_snapshot = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_strManFillFilter\""))
                        {
                            group.maunal_fill_filter = getValue(line);
                            continue;
                        }

                        if (line.StartsWith("\"m_zAllDayPnlLogging\""))
                        {
                            group.all_day_pnl_logging = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_strAxPriceServer\""))
                        {
                            group.ax_price_server = getValue(line);
                            continue;
                        }

                    }
                    else
                    {
                        if (line.StartsWith("\"m_strName\""))
                        {
                            endpoint.name = getValue(line);
                            continue;
                        }

                        if (line.StartsWith("\"m_strServer\""))
                        {
                            endpoint.server = getValue(line);
                            continue;
                        }

                        if (line.StartsWith("\"m_iDisabled\""))
                        {
                            endpoint.is_disabled = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_zRequestHeartbeat\""))
                        {
                            endpoint.request_heartbeat = Int32.Parse(getValue(line));
                            continue;
                        }

                        if (line.StartsWith("\"m_iPort\""))
                        {
                            endpoint.port = getValue(line);
                            continue;
                        }

                        if (line.StartsWith("\"m_strContextPrefix\""))
                        {
                            endpoint.context_prefix = getValue(line);
                            continue;
                        }

                    }

                }

                endpoints.Add(endpoint);
                group.endpoints = endpoints;
                groups.Add(group);

            }

            //foreach (Group g in groups)
            //{
            //    Console.WriteLine(g.name);
            //    foreach (EndPoint e in g.endpoints)
            //    {
            //        Console.WriteLine(e.index);
            //        Console.WriteLine(e.name);
            //    }
            //}

            StoreGroups2DB(groups)
            foreach (Group g in groups)
                StoreEndPoints2DB(g);
        }