Beispiel #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MessageSvc.Default.MessageReceived += RegisterLogService;

            Constants.SettingFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), string.Format(@"JStock\{0}", Constants.SettingFileName));
            try
            {
                if (File.Exists(Constants.SettingFilePath))
                {
                    string    settingData = File.ReadAllText(Constants.SettingFilePath, Encoding.UTF8);
                    JSettings settings    = SerializeHelper.XmlDeserialize <JSettings>(settingData);
                    if (settings == null)
                    {
                        MessageBox.Show(string.Format("加载配置{0}信息出错", Constants.SettingFilePath));
                    }
                    CheckSetting(settings);
                    //if (settings.DBPath.IndexOf("\\") == -1)
                    //{
                    //    settings.DBPath = Path.Combine(Application.StartupPath, settings.DBPath);
                    //}
                    if (File.Exists(settings.DBPath))
                    {
                        Constants.ResetDBConnString(settings.DBPath);
                    }
                    Constants.Setting = settings;
                    RequestFactory.ServiceProvider = settings.MonitorSite;
                    var form = new DeskStocks(Constants.SettingFilePath);
                    MessageSvc.Default.Write(MessageLevel.Debug, "Start");

                    Application.Run(form);
                }
                else
                {
                    JSettings settings = new JSettings();
                    CheckSetting(settings);

                    XmlDocument xmlDoc  = new XmlDocument();
                    string      xmlData = SerializeHelper.XmlSerialize <JSettings>(settings);
                    xmlDoc.LoadXml(xmlData);
                    xmlDoc.Save(Constants.SettingFilePath);
                    MessageSvc.Default.Write(MessageLevel.Warn, "配置信息{0}不存在,已新建默认配置,请重新打开程序!", Constants.SettingFilePath);
                }
            }
            catch (Exception ex)
            {
                MessageSvc.Default.Write(MessageLevel.Error, ex);
            }
        }
Beispiel #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MessageSvc.Default.MessageReceived += RegisterLogService;

            Constants.SettingFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), string.Format(@"JStock\{0}", Constants.SettingFileName));
            try
            {
                if (File.Exists(Constants.SettingFilePath))
                {
                    string settingData = File.ReadAllText(Constants.SettingFilePath, Encoding.UTF8);
                    JSettings settings = SerializeHelper.XmlDeserialize<JSettings>(settingData);
                    if (settings == null)
                    {
                        MessageBox.Show(string.Format("加载配置{0}信息出错", Constants.SettingFilePath));
                    }
                    CheckSetting(settings);
                    //if (settings.DBPath.IndexOf("\\") == -1)
                    //{
                    //    settings.DBPath = Path.Combine(Application.StartupPath, settings.DBPath);
                    //}
                    if (File.Exists(settings.DBPath))
                    {
                        Constants.ResetDBConnString(settings.DBPath);
                    }
                    Constants.Setting = settings;
                    RequestFactory.ServiceProvider = settings.MonitorSite;
                    var form = new DeskStocks(Constants.SettingFilePath);
                    MessageSvc.Default.Write(MessageLevel.Debug, "Start");

                    Application.Run(form);
                }
                else
                {
                    JSettings settings = new JSettings();
                    CheckSetting(settings);

                    XmlDocument xmlDoc = new XmlDocument();
                    string xmlData = SerializeHelper.XmlSerialize<JSettings>(settings);
                    xmlDoc.LoadXml(xmlData);
                    xmlDoc.Save(Constants.SettingFilePath);
                    MessageSvc.Default.Write(MessageLevel.Warn, "配置信息{0}不存在,已新建默认配置,请重新打开程序!", Constants.SettingFilePath);
                }
            }
            catch (Exception ex)
            {
                MessageSvc.Default.Write(MessageLevel.Error, ex);
            }
        }