Ejemplo n.º 1
0
        private void LoadFirst()
        {
            // Проверка авторизации
            Properties.Settings settings = Properties.Settings.Default;
            Registered = Data.Authorization(settings.CopyOwner, settings.CopyKey);
            Bonus      = !Registered;

            string configfilename = Application.StartupPath + "\\config.ini";

            if (File.Exists(configfilename))
            {
                MemIniFile mif     = new MemIniFile(configfilename);
                string     section = "Application";
                mif.WriteInteger(section, "Station", Properties.Settings.Default.Station);
                mif.WriteString(section, "StartupPath", Application.StartupPath);
                mif.WriteBool(section, "Registered", Registered);
                mif.WriteBool(section, "Bonus", Bonus);
                string[] channels = Properties.Settings.Default.Channels.Split('\t');

                // Загрузка плагина точек KR500
                PointPlugin.LoadPlugin(Application.StartupPath + "\\Points.KR500.dll");

                FetchKR500Functions.StartFetch(
                    new Tuple <int, string[], string, exitApp, int>(
                        Properties.Settings.Default.Station,
                        channels, mif.ToString(), closeServer,
                        Properties.Settings.Default.TimeOut));
            }
        }
Ejemplo n.º 2
0
        public HistoryEntry(string fileName)
        {
            this.iniFile = new MemIniFile(FileOperations.StripFileName(fileName));
            iniFile.Load();
            TranslationId = iniFile.ReadString("Settings", "TranslationId", string.Empty);

            if (!string.IsNullOrEmpty(TranslationId))
            {
                caption = SR.Keys.GetString(TranslationId);
            }
            else
            {
                caption = string.Empty;
            }

            if (string.IsNullOrEmpty(caption))
            {
                if (TextHelper.SameText(GlobalConfig.HomeCircleName, fileName))
                {
                    caption = SR.DefaultRingName;
                }
                else
                {
                    caption = Path.GetFileNameWithoutExtension(fileName);
                }
            }

            description = iniFile.ReadString("Settings", "Description", string.Empty);
            logoFile    = iniFile.ReadString("Settings", "Logo", string.Empty);
        }
Ejemplo n.º 3
0
 public KrentoRing(MemIniFile iniFile)
 {
     this.iniFile = iniFile;
     FileName     = FileOperations.StripFileName(iniFile.FileName);
     LoadIniFileData();
     LoadLogo(logoFile);
 }
Ejemplo n.º 4
0
 public void LoadReport(string reportname, string reportsconfig)
 {
     if (reportname.Length > 0)
     {
         ReportName = reportname;
         byte[] image = Data.GetReportData(reportname);
         if (image != null)
         {
             MemIniFile mif = new MemIniFile(String.Empty);
             mif.FromString(reportsconfig);
             this.PrintAuto   = mif.ReadBool(reportname, "PrintAuto", false);
             this.PrintTime   = mif.ReadDate(reportname, "PrintTime", DateTime.Parse("08:05:00"));
             this.PrintPeriod = mif.ReadInteger(reportname, "PrintPeriod", 0);
             //------------------------------------------
             SelList.Clear();
             PlotList.Clear();
             GC.Collect();
             string          content = Encoding.Unicode.GetString(image);
             PrinterSettings ps      = printDocument.PrinterSettings;
             string[]        lines   = content.Split(new string[] { "\r\n" }, StringSplitOptions.None);
             ImportLines(ref ps, lines);
             printDocument.PrinterSettings = ps;
             Update();
         }
     }
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./LogicServer");
            //异常
            GameBase.Core.GlobalException.InitException();
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            m_DicSession = new Dictionary <Socket, GameBase.Network.GameSession>();
            m_DicSession.Clear();

            String sIP   = ini.ReadValue(TextDefine.LogicServerSection, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int    nPort = ini.ReadValue(TextDefine.LogicServerSection, TextDefine.NormalPortKey, TextDefine.LoginServerPort);

            m_Key             = ini.ReadValue(TextDefine.GlobalSection, TextDefine.EncodeKey, System.Environment.TickCount);
            m_Key2            = ini.ReadValue(TextDefine.GlobalSection, TextDefine.EncodeKey2, System.Environment.TickCount);
            m_GameServerIP    = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            m_GameServerPort  = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalPortKey, TextDefine.GameServerPort);
            server            = new TcpServer();
            server.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
            server.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
            server.onClose   += new TcpServerEvent.OnCloseEventHandler(OnClose);
            if (!server.Start(sIP, nPort))
            {
                Console.WriteLine("start server error!");
                return;
            }

            //连接dbserver
            mDBPacket = new InternalPacket();
            GenerateKey.Init(m_Key, m_Key2);
            sIP                   = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            nPort                 = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalPortKey, TextDefine.DBServerPort);
            mTcpClient            = new GameBase.Network.TcpClient();
            mTcpClient.onConnect += new TcpClientEvent.OnConnectEventHandler(OnDBConnect);
            mTcpClient.onReceive += new TcpClientEvent.OnReceiveEventHandler(OnDBReceive);
            mTcpClient.onClose   += new TcpClientEvent.OnCloseEventHandler(OnDBClose);
            mTcpClient.Connect(sIP, nPort);
            //逻辑处理
            Thread logicThread = new Thread(new ThreadStart(LogicTimer));

            logicThread.IsBackground = true;
            logicThread.Start();


            while (true)
            {
                String command = Console.ReadLine();
                if (command == "exit")
                {
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private static string configString(string content, string channelkey)
        {
            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(content);
            if (mif.SectionExists(servname) && mif.KeyExists(servname, channelkey))
            {
                return(mif.ReadString(servname, channelkey, String.Empty));
            }
            return(String.Empty);
        }
Ejemplo n.º 7
0
 public override void SaveConfiguration(MemIniFile ini)
 {
     if (!IsVirtual)
     {
         base.SaveConfiguration(ini);
         if (!string.IsNullOrEmpty(TargetName))
         {
             ini.WriteString(this.StoneID, "Target", TargetName);
         }
     }
 }
Ejemplo n.º 8
0
        private static void SaveSettings()
        {
            MemIniFile mif     = new MemIniFile(Application.StartupPath + "\\config.ini");
            string     section = "ServerSQL";

            mif.WriteString(section, "Host", Settings.Host);
            mif.WriteString(section, "Port", Settings.Port);
            mif.WriteString(section, "User", Settings.User);
            mif.WriteString(section, "Password", Settings.Password);
            mif.WriteString(section, "Fetchbase", Settings.Fetchbase);
            mif.WriteString(section, "Database", Settings.Database);
            mif.UpdateFile();
        }
Ejemplo n.º 9
0
 public override void SaveConfiguration(MemIniFile ini)
 {
     if (!IsVirtual)
     {
         base.SaveConfiguration(ini);
         if (!string.IsNullOrEmpty(TargetDescription))
         {
             ini.WriteString(this.StoneID, "Description", TargetDescription);
         }
         if (!string.IsNullOrEmpty(CustomIcon))
         {
             ini.WriteString(this.StoneID, "CustomIcon", FileOperations.UnExpandPath(CustomIcon));
         }
     }
 }
Ejemplo n.º 10
0
 protected virtual void ReadConfiguration()
 {
     try
     {
         Random     rnd     = new Random();
         MemIniFile iniFile = new MemIniFile(settingFileName, true);
         iniFile.Load();
         Left = iniFile.ReadInteger("Settings", "Left", rnd.Next(0, PrimaryScreen.Bounds.Width - 96));
         Top  = iniFile.ReadInteger("Settings", "Top", rnd.Next(0, (int)((PrimaryScreen.Bounds.Height - 96) / 2)));
         OnLoadSettings(new IniFileAccessArgs(iniFile));
         iniFile.Dispose();
     }
     catch
     {
     }
 }
Ejemplo n.º 11
0
        private void saveCustomReportProps()
        {
            //Data.SetReportProps(printReport.ReportName, printReport.PrintAuto,
            //    printReport.PrintTime, printReport.PrintPeriod);
            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(Properties.Settings.Default.ReportsConfig);
            mif.WriteString(internalname, "ReportName", printReport.ReportName);
            mif.WriteBool(internalname, "PrintAuto", printReport.PrintAuto);
            mif.WriteDate(internalname, "PrintTime", printReport.PrintTime);
            mif.WriteInteger(internalname, "PrintPeriod", printReport.PrintPeriod);
            //mif.UpdateFile();
            Properties.Settings settings = Properties.Settings.Default;
            settings.ReportsConfig = mif.ToString();
            settings.Save();
        }
Ejemplo n.º 12
0
        private void AutoPrintReports(DateTime now)
        {
            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(Properties.Settings.Default.ReportsConfig);
            // выбор автозапускаемых отчётов на текущее время в список list
            List <string> list = new List <string>();

            foreach (string section in mif.ReadSections())
            {
                bool auto = mif.ReadBool(section, "PrintAuto", false);
                if (auto)
                {
                    string   name   = mif.ReadString(section, "ReportName", section);
                    DateTime time   = mif.ReadDate(section, "PrintTime", DateTime.Parse("08:05:00"));
                    int      period = mif.ReadInteger(section, "PrintPeriod", 0);
                    if (period == 0) // ежедневно
                    {
                        if (time.Hour == now.Hour && time.Minute == now.Minute)
                        {
                            list.Add(name);
                        }
                    }
                    else if (period == 1) // ежемесячно 1 числа
                    {
                        if (now.Day == 1 && time.Hour == now.Hour &&
                            time.Minute == now.Minute)
                        {
                            list.Add(name);
                        }
                    }
                }
            }
            // отправка на печать отчётов, печатаемых в настоящий момент
            foreach (string name in list)
            {
                using (PrintDocument printDoc = new PrintDocument())
                {
                    printDoc.PrintPage += printDoc_PrintPage;
                    printReport         = new PrintReport(printDoc);
                    printReport.LoadReport(name, Properties.Settings.Default.ReportsConfig);
                    printDoc.Print();
                    printDoc.PrintPage -= printDoc_PrintPage;
                }
            }
        }
Ejemplo n.º 13
0
        public static System.Timers.Timer m_LogicTimer; //逻辑处理定时器
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./Accserver");
            //异常
            GameBase.Core.GlobalException.InitException();


            //读取全局配置
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            String sIP   = ini.ReadValue(TextDefine.ACCServerSection, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int    nPort = ini.ReadValue(TextDefine.ACCServerSection, TextDefine.NormalPortKey, TextDefine.AccServerPort);

            Console.Title = "AccServer";
            // m_DicSession = new Dictionary<Socket, GameBase.Network.GameSession>();
            //m_DicSession.Clear();
            server.onConnect += new GameBase.Network.TcpServerEvent.OnConnectEventHandler(OnConnect);
            server.onReceive += new GameBase.Network.TcpServerEvent.OnReceiveEventHandler(OnRecv);
            server.onClose   += new GameBase.Network.TcpServerEvent.OnCloseEventHandler(OnClose);
            //启动服务器
            Log.Instance().WriteLog("bind ip:" + sIP + "bindport:" + nPort.ToString());
            if (!server.Start(sIP, nPort))
            {
                Log.Instance().WriteLog("start tcpserver error!");
            }
            Log.Instance().WriteLog("start server success!!");
            //数据包处理
            m_LogicTimer          = new System.Timers.Timer(1);
            m_LogicTimer.Elapsed += new ElapsedEventHandler(LogicTimer);
            m_LogicTimer.Enabled  = true;
            while (true)
            {
                String command = Console.ReadLine();
                if (command == "quit" || command == "exit")
                {
                    server.Stop();
                    Log.Instance().Dispose();
                    break;
                }
            }
        }
Ejemplo n.º 14
0
 protected virtual void SaveConfiguration()
 {
     try
     {
         MemIniFile iniFile = new MemIniFile(settingFileName);
         iniFile.Load();
         iniFile.WriteInteger("Settings", "Left", Left);
         iniFile.WriteInteger("Settings", "Top", Top);
         iniFile.WriteBool("Toy", "Enabled", ToyEnabled);
         OnSaveSettings(new IniFileAccessArgs(iniFile));
         iniFile.Save();
         iniFile.Dispose();
     }
     catch
     {
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ToyAboutBox"/> class.
        /// </summary>
        public ToyAboutBox(string configFileName)
        {
            MemIniFile iniFile = new MemIniFile(configFileName);

            iniFile.Load();

            window = new AboutWindow();
            window.TopMostWindow = true;
            window.KeyDown      += new System.Windows.Forms.KeyEventHandler(window_KeyDown);
            window.MouseClick   += new System.Windows.Forms.MouseEventHandler(window_MouseClick);
            window.BigIcon       = Path.Combine(Path.GetDirectoryName(configFileName), iniFile.ReadString("Toy", "Icon"));
            window.Copyright     = iniFile.ReadString("Toy", "Copyright");
            window.Author        = "Author: " + iniFile.ReadString("Toy", "Author");
            window.Version       = "Version: " + iniFile.ReadString("Toy", "Version");
            window.Description   = iniFile.ReadString("Toy", "Description");
            window.AboutText     = iniFile.ReadString("Toy", "AboutText");
            iniFile.Dispose();
        }
Ejemplo n.º 16
0
 public override void SaveConfiguration(MemIniFile ini)
 {
     if (!IsVirtual)
     {
         base.SaveConfiguration(ini);
         if (!string.IsNullOrEmpty(TargetName))
         {
             ini.WriteString(this.StoneID, "Target", TargetName);
         }
         if (!string.IsNullOrEmpty(TargetParameters))
         {
             ini.WriteString(this.StoneID, "Parameters", TargetParameters);
         }
         if (!string.IsNullOrEmpty(ArgumentDescription))
         {
             ini.WriteString(this.StoneID, "Argument", ArgumentDescription);
         }
     }
 }
Ejemplo n.º 17
0
        public override void ReadConfiguration(MemIniFile ini)
        {
            if (!IsVirtual)
            {
                string stringValue;

                //we need target name before reading the base config
                try
                {
                    stringValue = ini.ReadString(this.StoneID, "Target", null);
                    if (!string.IsNullOrEmpty(stringValue))
                    {
                        TargetName = stringValue;
                    }
                }
                catch (Exception ex)
                {
                    throw new StoneSettingsException("Read stone settings error", ex);
                }

                base.ReadConfiguration(ini);

                try
                {
                    stringValue = ini.ReadString(this.StoneID, "Parameters", null);
                    if (!string.IsNullOrEmpty(stringValue))
                    {
                        TargetParameters = stringValue;
                    }

                    stringValue = ini.ReadString(this.StoneID, "Argument", null);
                    if (!string.IsNullOrEmpty(stringValue))
                    {
                        ArgumentDescription = stringValue;
                    }
                }
                catch (Exception ex)
                {
                    throw new StoneSettingsException("Read stone settings error", ex);
                }
            }
        }
Ejemplo n.º 18
0
 public virtual void SaveConfiguration(MemIniFile ini)
 {
     if (!IsVirtual)
     {
         try
         {
             ini.WriteInteger(this.stoneID, "RunCount", RunCount);
             ini.WriteInteger(this.stoneID, "Rating", Rating);
             ini.WriteInteger(this.stoneID, "RunLevel", RunLevel);
             if (!string.IsNullOrEmpty(translationId))
             {
                 ini.WriteString(this.stoneID, "TranslationId", translationId);
             }
         }
         catch (Exception ex)
         {
             throw new StoneSettingsException(SR.WriteSettingsError, ex);
         }
     }
 }
Ejemplo n.º 19
0
        public override void ReadConfiguration(MemIniFile ini)
        {
            if (!IsVirtual)
            {
                string stringValue;

                base.ReadConfiguration(ini);
                try
                {
                    stringValue = ini.ReadString(this.StoneID, "CustomIcon", null);
                    if (!string.IsNullOrEmpty(stringValue))
                    {
                        CustomIcon = FileOperations.StripFileName(stringValue);
                    }
                }
                catch (Exception ex)
                {
                    throw new StoneSettingsException("Read stone settings error", ex);
                }
            }
        }
Ejemplo n.º 20
0
        public void Init()
        {
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                Log.Instance().WriteLog("load golbalconfig error!");
                return;
            }
            //连接dbserver的客户 InternalPacket
            mDBPacket               = new InternalPacket();
            mTcpDBClient            = new GameBase.Network.TcpClient();
            mTcpDBClient.onConnect += new TcpClientEvent.OnConnectEventHandler(OnDBConnectEventHandler);
            mTcpDBClient.onReceive += new TcpClientEvent.OnReceiveEventHandler(OnDBReceiveEventHandler);
            mTcpDBClient.onClose   += new TcpClientEvent.OnCloseEventHandler(OnDBClose);

            String sIP   = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int    nPort = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalPortKey, TextDefine.DBServerPort);

            mTcpDBClient.Connect(sIP, nPort);
        }
Ejemplo n.º 21
0
        private void LoadFirst()
        {
            // Проверка авторизации
            Properties.Settings settings = Properties.Settings.Default;
            Registered = Data.Authorization(settings.CopyOwner, settings.CopyKey);
            Bonus      = !Registered;

            string configfilename = Application.StartupPath + "\\config.ini";

            if (File.Exists(configfilename))
            {
                MemIniFile mif     = new MemIniFile(configfilename);
                string     section = "Application";
                mif.WriteInteger(section, "Station", Properties.Settings.Default.Station);
                mif.WriteString(section, "StartupPath", Application.StartupPath);
                mif.WriteBool(section, "Registered", Registered);
                mif.WriteBool(section, "Bonus", Bonus);
                FetchVirtualFunctions.StartFetch(new Tuple <int, string, exitApp>(
                                                     Properties.Settings.Default.Station, mif.ToString(), closeServer));
            }
        }
Ejemplo n.º 22
0
        public static void StartFetch(string[] args)
        {
            string ApplicationStartupPath = (args.Length >= 1) ? args[0] : String.Empty;
            string ConfigContent          = (args.Length >= 2) ? args[1] : String.Empty;

            Station = (args.Length >= 3) ? int.Parse(args[2]) : 0;
            //
            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(ConfigContent);
            string section = "FetchServices";

            if (mif.SectionExists(section) &&
                mif.KeyExists(section, servname) &&
                mif.ReadBool(section, servname, false) &&
                mif.SectionExists(servname))
            {
                string[] keys = mif.ReadSectionKeys(servname);
                foreach (string key in keys)
                {
                    int channel;
                    if (key.StartsWith("Channel") &&
                        int.TryParse(key.Substring(7), out channel))
                    {
                        string desc = "Канал " + channel + " сервера опроса";
                        Data.SendToSystemLog(Station, "Опрос KR500", desc + " загружен");
                        string           ClientID = Data.ClientLogin(String.Empty, "F", Station, desc + " KR500");
                        BackgroundWorker worker   = new BackgroundWorker();
                        workers.Add(new Tuple <string, BackgroundWorker>(
                                        ClientID, worker));
                        worker.DoWork                    += worker_DoWork;
                        worker.ProgressChanged           += worker_ProgressChanged;
                        worker.WorkerSupportsCancellation = true;
                        //worker.WorkerReportsProgress = true;
                        worker.RunWorkerAsync(new Tuple <string, string, string, int, string>(
                                                  ClientID, ApplicationStartupPath, ConfigContent, channel, key));
                    }
                }
            }
        }
Ejemplo n.º 23
0
        public static bool Start()
        {
            bool ret = true;

            Log.Instance().Init("./MapServer");
            GlobalException.InitException();
            //载入配置文件
            try
            {
                ConfigManager.Instance().LoadConfig();
                MemIniFile ini = new MemIniFile();
                if (!ini.LoadFromFile(TextDefine.GoldConfig))
                {
                    Log.Instance().WriteLog("load golbalconfig error!");
                    return(false);
                }
                String sIP   = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalIPKey, TextDefine.NormalIP);
                int    nPort = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalPortKey, TextDefine.GameServerPort);

                mTcpServer            = new TcpServer();
                mTcpServer.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
                mTcpServer.onClose   += new TcpServerEvent.OnCloseEventHandler(OnClose);
                mTcpServer.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
                if (!mTcpServer.Start(sIP, nPort))
                {
                    return(false);
                }
            }
            catch (System.Exception ex)
            {
                Log.Instance().WriteLog("启动服务器失败");
                Log.Instance().WriteLog(ex.Message);
                Log.Instance().WriteLog(ex.StackTrace);
                return(false);
            }



            return(ret);
        }
Ejemplo n.º 24
0
        private void Load()
        {
            try
            {
                iniFile = new MemIniFile(FileName);
                try
                {
                    iniFile.Load();
                    LoadIniFileData();
                }
                finally
                {
                    iniFile.Dispose();
                    iniFile = null;
                }

                LoadLogo(logoFile);
            }
            catch (Exception ex)
            {
                TraceDebug.Trace(ex);
            }
        }
Ejemplo n.º 25
0
        public virtual void ReadConfiguration(MemIniFile ini)
        {
            if (!IsVirtual)
            {
                try
                {
                    string stringValue;

                    RunCount    = ini.ReadInteger(this.stoneID, "RunCount", 0);
                    Rating      = ini.ReadInteger(this.stoneID, "Rating", 0);
                    RunLevel    = ini.ReadInteger(this.stoneID, "RunLevel", 0);
                    stringValue = ini.ReadString(this.stoneID, "TranslationId", null);
                    if (!string.IsNullOrEmpty(stringValue))
                    {
                        TranslationId = stringValue;
                    }
                    TargetDescription = ini.ReadString(this.StoneID, "Description", null);
                }
                catch (Exception ex)
                {
                    throw new StoneSettingsException("Read stone settings error", ex);
                }
            }
        }
Ejemplo n.º 26
0
 public void Save()
 {
     if (iniFile == null)
     {
         iniFile = new MemIniFile(FileName);
         try
         {
             iniFile.Load();
             iniFile.WriteString("Settings", "Description", Description);
             iniFile.WriteString("Settings", "Logo", logoFile);
             iniFile.Save();
         }
         finally
         {
             iniFile.Dispose();
         }
     }
     else
     {
         iniFile.WriteString("Settings", "Description", Description);
         iniFile.WriteString("Settings", "Logo", logoFile);
         iniFile.Save();
     }
 }
Ejemplo n.º 27
0
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./DBServer");
            //异常
            GameBase.Core.GlobalException.InitException();
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            //载入名称过滤文件
            if (!Filter.Instance().LoadFilterNameFile(TextDefine.CONFIG_FILTERNAME))
            {
                Log.Instance().WriteLog("载入名称过滤文件失败");
            }
            //连接mysql
            String sip       = ini.ReadValue(TextDefine.MysqlSection, "IP", "127.0.0.1");
            int    nPort     = ini.ReadValue(TextDefine.MysqlSection, "Port", 3306);
            String sUser     = ini.ReadValue(TextDefine.MysqlSection, "User", "root");
            String sPaswd    = ini.ReadValue(TextDefine.MysqlSection, "Passwd", "test");
            String sDataBase = ini.ReadValue(TextDefine.MysqlSection, "database", "soul");

            if (!MysqlConn.Connect(sip, nPort, sUser, sPaswd, sDataBase))
            {
                Log.Instance().WriteLog("connect mysql error!");
                return;
            }

            LoadGameKernel();
            //启动tcp服务器=
            sip                   = ini.ReadValue(TextDefine.DBServerSestion, "IP", "0.0.0.0");
            nPort                 = ini.ReadValue(TextDefine.DBServerSestion, "Port", 1500);
            mTcpServer            = new TcpServer();
            mTcpServer.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
            mTcpServer.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
            mTcpServer.onClose   += new TcpServerEvent.OnCloseEventHandler(OnClose);
            if (!mTcpServer.Start(sip, nPort))
            {
                Console.WriteLine("start server error!");
                MysqlConn.Dispose();
                return;
            }
            //启动工作线程-

            Thread logicThread = new Thread(new ThreadStart(LogicRun));

            logicThread.IsBackground = true;
            logicThread.Start();

            while (true)
            {
                String sCommand = Console.ReadLine();
                if (sCommand == "quit" ||
                    sCommand == "exit")
                {
                    break;
                }
            }
            MysqlConn.Dispose();
        }
Ejemplo n.º 28
0
        private static void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker        worker = (BackgroundWorker)sender;
            Tuple <string, exitApp> args   = (Tuple <string, exitApp>)e.Argument;

            MemIniFile mif = new MemIniFile(String.Empty);

            mif.FromString(args.Item1);
            string  section = "Application";
            int     station = mif.ReadInteger(section, "Station", 1);
            string  ApplicationStartupPath = mif.ReadString(section, "StartupPath", ".");
            bool    Registered             = mif.ReadBool(section, "Registered", false);
            bool    Bonus     = mif.ReadBool(section, "Bonus", false);
            exitApp DoExitApp = args.Item2;

            Data.RestoreSQLsettingsFromString(args.Item1);
            DateTime TurnOnTime = DateTime.Now;
            // Загрузка плагина виртуальных точек
            IDictionary <string, IPointPlugin> plugins =
                PointPlugin.LoadPlugin(ApplicationStartupPath + "\\Points.Virtuals.dll");

            // Инициализация, создание баз, если их раньше не было
            Settings.CreateDataAndFetchBases();
            // Загрузка виртуальных точек из базы данных
            Data.LoadBase(plugins);
            string desc = "Сервер опроса виртуальных значений";

            Data.SendToSystemLog(station, "Опрос виртуальных", "Сервер опроса загружен");
            ClientID = Data.ClientLogin(ClientID, "F", Station, desc);
            // Заполнение списка для опроса
            LoadFirst(worker);
            bool _exit     = false;
            bool _continue = true;

            while (_continue)
            {
                _continue = !worker.CancellationPending;
                if (!Data.ImLive(ClientID, "F", Station, desc))
                {
                    ClientID = Data.ClientLogin(ClientID, "F", Station, desc);
                }
                string[] command = Data.GetClientCommand(ClientID);
                //if (command[0].Equals("RELOAD"))
                //{
                //}
                if (!Registered)
                {
                    if (DateTime.Now.AddHours(-2.5) > TurnOnTime)
                    {
                        Bonus = false;
                    }
                }
                if (Registered || Bonus)
                {
                    try
                    {
                        FetchBase(worker, plugins);
                        Thread.Sleep(50);
                    }
                    catch (Exception ex)
                    {
                        Data.SendToSystemLog(0, "Опрос виртуальных", ex.Message);
                    }
                }
                else
                if (!_exit)
                {
                    _exit = true;
                    Data.SendToSystemLog(station,
                                         "Опрос виртуальных", "Прекращена работа неавторизованного сервера опроса");
                    DoExitApp();
                }
            }
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            string path     = System.Environment.CurrentDirectory + "\\";
            string filename = path + "base_afh2.txt";
            string ininame  = path + "base_afh2.ini";

            if (File.Exists(filename))
            {
                MemIniFile mif = new MemIniFile(ininame);
                mif.Clear();
                string[] lines   = System.IO.File.ReadAllLines(filename);
                string[] headers = new string[0];
                bool     first   = true;
                foreach (string line in lines)
                {
                    if (first)
                    {
                        first   = false;
                        headers = line.Split(new char[] { '\t' });
                    }
                    else
                    {
                        string[] values = line.Split(new char[] { '\t' });
                        if (headers.Length >= values.Length)
                        {
                            string npp    = String.Empty;
                            string ngroup = String.Empty;
                            string ptname = String.Empty;
                            string ptdesc = String.Empty;
                            string pttype = String.Empty;
                            for (int i = 0; i < headers.Length; i++)
                            {
                                string header = headers[i];
                                string value  = (i < values.Length) ? values[i].Trim() : String.Empty;
                                switch (i)
                                {
                                case 0: npp = value; break;

                                case 1: ngroup = value; break;

                                case 2:
                                    ptname = value;
                                    mif.WriteString(ptname, header, value);
                                    mif.WriteString(ptname, "Plugin", "KR500");
                                    break;

                                case 3:
                                    ptdesc = value;
                                    mif.WriteString(ptname, header, value);
                                    break;

                                case 4:
                                    if (value.Length == 0)
                                    {
                                        value = "FA";
                                    }
                                    pttype = value;
                                    mif.WriteString(ptname, header, value);
                                    switch (value)
                                    {
                                    case "ND":
                                    case "SM":
                                        mif.WriteString(ptname, "PtKind", "0");
                                        break;

                                    case "AI":
                                    case "AO":
                                    case "CR":
                                    case "FA":
                                        mif.WriteString(ptname, "PtKind", "1");
                                        mif.WriteString(ptname, "Trend", "False");
                                        mif.WriteString(ptname, "Koeff", "1");
                                        mif.WriteString(ptname, "Offset", "0");
                                        break;

                                    case "DI":
                                    case "DO":
                                        mif.WriteString(ptname, "PtKind", "2");
                                        mif.WriteString(ptname, "Trend", "False");
                                        break;

                                    case "GP":
                                    case "GO":
                                    case "GR":
                                    case "FD":
                                    case "VC":
                                        mif.WriteString(ptname, "PtKind", "3");
                                        break;
                                    }
                                    break;

                                default:
                                    if (value.Length > 0 && !header.Equals("Station") &&
                                        !header.Equals("TimeUnit"))
                                    {
                                        switch (header)
                                        {
                                        case "Opros":   header = "Actived"; break;

                                        case "Alarm":   header = "Logged";  break;

                                        case "Confirm": header = "Asked";   break;

                                        case "TimeBase": header = "FetchTime"; break;

                                        case "Controller": header = "Node"; break;

                                        case "Algoblock": header = "Block"; break;

                                        case "InOut": header = "Place"; break;

                                        case "PVSource": header = "Source"; value = ""; break;

                                        case "PVFormat": header = "FormatPV"; break;

                                        case "PVEUHI": header = "PVEUHi"; break;

                                        case "PVEULO": header = "PVEULo"; break;
                                        }
                                        if (header.StartsWith("Link"))
                                        {
                                            header = "Child" + header.Substring(4);
                                        }
                                        switch (value)
                                        {
                                        case "D0": value = "0"; break;

                                        case "D1": value = "1"; break;

                                        case "D2": value = "2"; break;

                                        case "D3": value = "3"; break;

                                        case "Нет": value = "False"; break;

                                        case "Да": value = "True"; break;
                                        }
                                        mif.WriteString(ptname, header, value);
                                        switch (header)
                                        {
                                        case "Source":
                                            mif.WriteString(ptname, "Parent", "");
                                            break;

                                        case "PVEUHi":
                                            mif.WriteString(ptname, "PVSUHi", value);
                                            break;

                                        case "PVEULo":
                                            mif.WriteString(ptname, "PVSULo", value);
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                mif.UpdateFile();
            }
        }
Ejemplo n.º 30
0
        private static void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Tuple <int, string, string, exitApp, string, int> args =
                (Tuple <int, string, string, exitApp, string, int>)e.Argument;
            int        channel = args.Item1;
            string     info    = args.Item2;
            MemIniFile mif     = new MemIniFile(String.Empty);

            mif.FromString(args.Item3);
            exitApp DoExitApp = args.Item4;
            string  ClientID  = args.Item5;
            int     timeout   = args.Item6;

            string section = "Application";
            int    station = mif.ReadInteger(section, "Station", 1);
            string ApplicationStartupPath = mif.ReadString(section, "StartupPath", ".");
            bool   Registered             = mif.ReadBool(section, "Registered", false);
            bool   Bonus = mif.ReadBool(section, "Bonus", false);

            Data.RestoreSQLsettingsFromString(args.Item3);
            BackgroundWorker worker     = (BackgroundWorker)sender;
            DateTime         TurnOnTime = DateTime.Now;
            IDictionary <string, IPointPlugin> plugins =
                PointPlugin.LoadPlugin(ApplicationStartupPath + "\\Points.Modbus.dll");

            // Инициализация, создание баз, если их раньше не было
            Settings.CreateDataAndFetchBases();
            string desc = "Канал " + channel + " сервера опроса";

            // Заполнение списка для опроса
            LoadFirst(worker, ClientID, channel, plugins);

            bool _exit     = false;
            bool _continue = true;

            while (_continue)
            {
                if (!Data.ImLive(ClientID, "F", Station, desc + " Modbus"))
                {
                    ClientID = Data.ClientLogin(ClientID, "F", station, desc + " Modbus");
                }
                string[] command = Data.GetClientCommand(ClientID);
                //if (command[0].Equals("RELOAD"))
                //{
                //}
                if (!Registered)
                {
                    if (DateTime.Now.AddHours(-2.5) > TurnOnTime)
                    {
                        Bonus = false;
                    }
                }
                if (Registered || Bonus)
                {
                    try
                    {
                        FetchBase(worker, ClientID, channel, info, timeout, plugins);
                        Thread.Sleep(50);
                    }
                    catch (Exception ex)
                    {
                        Data.SendToSystemLog(0, "Опрос Modbus", ex.Message);
                    }
                }
                else
                if (!_exit)
                {
                    _exit = true;
                    Data.SendToSystemLog(Station,
                                         "Опрос Modbus", "Прекращена работа неавторизованного сервера опроса");
                    DoExitApp();
                }
            }
        }