Ejemplo n.º 1
0
        /// <summary>
        /// 注册热键
        /// </summary>
        private void RegHotKey()
        {
            if (string.IsNullOrWhiteSpace(Resources.GetRes().CashDrawer))
            {
                return;
            }
            try
            {
                hk.KeyCode  = Keys.Z;
                hk.Alt      = true;
                hk.Pressed += delegate
                {
                    Common.GetCommon().OpenCashDrawer();
                };

                if (!hk.GetCanRegister(this))
                {
                    ExceptionPro.ExpErrorLog("Open cash drawer key can't register!");
                }
                else
                {
                    hk.Register(this);
                }
            }
            catch (Exception ex)
            {
                ExceptionPro.ExpLog(ex);
            }
        }
Ejemplo n.º 2
0
 protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
 {
     ExceptionPro.ExpErrorLog("=> Exception " + exceptionContext.Error.Message);
     if (exceptionContext.Error.InnerException != null)
     {
         ExceptionPro.ExpErrorLog("=> Inner Exception " + exceptionContext.Error.InnerException.Message);
     }
     base.OnIncomingError(exceptionContext, invokerContext);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 保存到指定文件
 /// </summary>
 /// <param name="url"></param>
 /// <param name="filename"></param>
 /// <returns></returns>
 public static bool GetAndSaveToFile(string url, string filename)
 {
     try
     {
         using (FileStream stream = new FileStream(filename, FileMode.Create, FileAccess.Write))
         {
             byte[] data = Get(url);
             stream.Write(data, 0, data.Length);
         }
         return(true);
     }
     catch (Exception ex)
     {
         ExceptionPro.ExpErrorLog(ex.Message);
         return(false);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 从GAC加载没能加载的程序集, 比如System.Data.SQLite
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        private System.Reflection.Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
        {
            try
            {
                if (args.Name.Contains("System.Data.SQLite"))
                {
                    return(System.Reflection.Assembly.Load("System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139")); //System.Data.SQLite, Version=1.0.98.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
                }
                // SignalR
                else if (args.Name.Contains("Microsoft.Owin.Host.HttpListener"))
                {
                    return(System.Reflection.Assembly.Load("Microsoft.Owin.Host.HttpListener, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"));
                }
                else if (args.Name.Contains("Microsoft.Owin,"))
                {
                    return(System.Reflection.Assembly.Load("Microsoft.Owin, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"));
                }
                else if (args.Name.Contains("System.Web.Cors,"))
                {
                    return(System.Reflection.Assembly.Load("System.Web.Cors, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"));
                }
                else if (args.Name.Contains("Newtonsoft.Json,"))
                {
                    return(System.Reflection.Assembly.Load("Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"));
                }
                else if (args.Name.Contains("Microsoft.Owin.Security,"))
                {
                    return(System.Reflection.Assembly.Load("Microsoft.Owin.Security, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"));
                }

                return(null);
            }
            catch (Exception ex)
            {
                ExceptionPro.ExpErrorLog("load throw exception:" + ex.Message);
                return(null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 注册热键(为备注)
        /// </summary>
        private void RegHotKey2()
        {
            try
            {
                hk2.KeyCode  = System.Windows.Forms.Keys.F9;
                hk2.Pressed += delegate
                {
                    Oybab.Res.View.Component.RemarkEvent.Instance.ActionRemark(null, null, null);
                };

                if (!hk2.GetCanRegister(this))
                {
                    ExceptionPro.ExpErrorLog("Open remark key can't register!");
                }
                else
                {
                    hk2.Register(this);
                }
            }
            catch (Exception ex)
            {
                ExceptionPro.ExpLog(ex);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 查找新版本
        /// </summary>
        public static void SearchUpdate(string more, Action <UpdateModel> FindNewVersion = null)
        {
            Action action = new Action(() =>
            {
                try
                {
                    //1分钟后执行
                    System.Threading.Thread.Sleep(1000 * 60 * 1);
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                    string version = assembly.GetName().Version.ToString();//获取主版本号

                    //获取硬件号
                    string uid = Res.Server.OperatesService.GetOperates().ServiceUID();
                    //
                    //定义webClient对象
                    CookieAwareWebClient webClient = new CookieAwareWebClient();
                    //定义通信地址 和 JSON数据
                    string URL = "https://www.oybab.net/software/update/";
                    //string URL = "http://192.168.1.100/OyBabNet/software/update/";

                    //组装数据
                    NameValueCollection postValues = new NameValueCollection();
                    //postValues.Add("json_data", jsonString);
                    postValues.Add("version", version);
                    postValues.Add("uid", uid);
                    postValues.Add("lang", Resources.GetRes().GetLangByLangIndex(Resources.GetRes().CurrentLangIndex).Culture.Name);
                    postValues.Add("app", Resources.GetRes().SOFT_SERVICE_NAME);
                    postValues.Add("more", more);
                    postValues.Add("name", Resources.GetRes().KEY_NAME_0);
                    postValues.Add("os", OSCheck.GetOS());
                    postValues.Add("ostype", OSCheck.GetOSType());

                    //向服务器发送POST数据
                    byte[] responseArray = webClient.UploadValues(URL, postValues);
                    string data          = Encoding.UTF8.GetString(responseArray);

                    //如果空
                    if (string.IsNullOrWhiteSpace(data))
                    {
                         #if DEBUG
                        ExceptionPro.ExpInfoLog("Response empty!");
                        #endif
                        return;
                    }

                    UpdateModel model = UpdateModel.FromJsonTo <UpdateModel>(data);
                    if (null != model)
                    {
                        //如果成功
                        if (model.Code == "1")
                        {
                            if (null != FindNewVersion)
                            {
                                FindNewVersion(model);
                            }
                        }
                        //如果需要锁住
                        else if (model.Code == "-4")
                        {
                            if (Res.Server.OperatesService.GetOperates().ServiceLock())
                            {
                                postValues.Add("ConfirmLock", "1");
                                postValues.Add("TId", model.TId);
                                webClient.UploadValues(URL, postValues);
                                //ExceptionPro.ExpInfoLog("Lock Key Success!");
                                //#if DEBUG
                                ExceptionPro.ExpErrorLog("LS");
                                //#endif
                            }
                            else
                            {
                                postValues.Add("ConfirmLock", "0");
                                postValues.Add("TId", model.TId);
                                webClient.UploadValues(URL, postValues);
                                //ExceptionPro.ExpErrorLog("Lock Key Faild!");
                                //#if DEBUG
                                ExceptionPro.ExpErrorLog("LF");
                                //#endif
                            }
                            return;
                        }
                        //如果其他或失败
                        else
                        {
                            #if DEBUG
                            if (!string.IsNullOrWhiteSpace(model.ErrorMsg))
                            {
                                throw new OybabException(model.ErrorMsg, true);
                            }
                            else
                            {
                                throw new OybabException(string.Format(Res.Resources.GetRes().GetString("UpdateUnableError"), model.Code), true);
                            }
                            #endif
                        }
                    }
                    //数据返回空或解析失败
                    else
                    {
                        #if DEBUG
                        throw new OybabException(Res.Resources.GetRes().GetString("UpdateNonReturnOrCantRead"), true);
                        #endif
                    }
                }
                catch
#if DEBUG
                (Exception ex)
#endif
                {
#if DEBUG
                    ExceptionPro.ExpLog(ex, null, true);
#endif
                }
            });

            action.BeginInvoke(null, null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 查找新版本
        /// </summary>
        public static void SearchUpdate(string more, Action <UpdateModel> FindNewVersion = null)
        {
            Task.Run(async() =>
            {
                try
                {
                    //1分钟后执行
                    await ExtX.Sleep(1000 * 60 * 1);

                    string version = OperatesService.Instance.AllVersion;

                    //获取硬件号
                    string uid = await OperatesService.Instance.ServiceUID();

                    CookieContainer CookieContainer = new CookieContainer();
                    //
                    //定义webClient对象
                    var cookieContainer = new CookieContainer();
                    using (var handler = new HttpClientHandler()
                    {
                        CookieContainer = cookieContainer, UseCookies = true
                    })
                    {
                        //定义通信地址 和 JSON数据
                        string URL = "https://www.oybab.net/software/update/";
                        //string URL = "http://localhost:3282/software/update/";

                        using (var client = new HttpClient(handler)
                        {
                            BaseAddress = new Uri(URL)
                        })
                        {
                            var values = new Dictionary <string, string>();
                            values.Add("version", version);
                            values.Add("uid", uid);
                            values.Add("lang", TradingSystemX.Res.Instance.GetLangByLangIndex(TradingSystemX.Res.Instance.CurrentLangIndex).Culture.Name);
                            values.Add("app", Resources.Instance.SOFT_SERVICE_NAME);
                            values.Add("more", more);
                            values.Add("name", Resources.Instance.KEY_NAME_0);
                            values.Add("os", OperatesService.Instance.GetOS());
                            values.Add("ostype", DeviceInfo.VersionString);

                            var content = new FormUrlEncodedContent(values);



                            //向服务器发送POST数据
                            var response = await client.PostAsync(URL, content);
                            string data  = Encoding.UTF8.GetString(await response.Content.ReadAsByteArrayAsync());

                            //如果空
                            if (string.IsNullOrWhiteSpace(data))
                            {
#if DEBUG
                                ExceptionPro.ExpInfoLog("Response empty!");
#endif
                                return;
                            }

                            UpdateModel model = data.DeserializeObject <UpdateModel>();
                            if (null != model)
                            {
                                //如果成功
                                if (model.Code == "1")
                                {
                                    if (null != FindNewVersion)
                                    {
                                        FindNewVersion(model);
                                    }
                                }
                                //如果需要锁住
                                else if (model.Code == "-4")
                                {
                                    if (await OperatesService.Instance.ServiceLock())
                                    {
                                        values.Add("ConfirmLock", "1");
                                        values.Add("TId", model.TId);

                                        var content2 = new FormUrlEncodedContent(values);


                                        await client.PostAsync(URL, content2);

                                        ExceptionPro.ExpErrorLog("LS");
                                    }
                                    else
                                    {
                                        values.Add("ConfirmLock", "0");
                                        values.Add("TId", model.TId);

                                        var content2 = new FormUrlEncodedContent(values);

                                        await client.PostAsync(URL, content2);

                                        ExceptionPro.ExpErrorLog("LF");
                                    }
                                    return;
                                }
                                //如果其他或失败
                                else
                                {
#if DEBUG
                                    if (!string.IsNullOrWhiteSpace(model.ErrorMsg))
                                    {
                                        throw new OybabException(model.ErrorMsg, true);
                                    }
                                    else
                                    {
                                        throw new OybabException(string.Format(TradingSystemX.Res.Instance.GetString("UpdateUnableError"), model.Code), true);
                                    }
#endif
                                }
                            }
                            //数据返回空或解析失败
                            else
                            {
#if DEBUG
                                throw new OybabException(TradingSystemX.Res.Instance.GetString("UpdateNonReturnOrCantRead"), true);
#endif
                            }
                        }
                    }
                }
                catch
#if DEBUG
                (Exception ex)
#endif
                {
#if DEBUG
                    ExceptionPro.ExpLog(ex, null, true);
#endif
                }
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 记录
        /// </summary>
        /// <param name="IsAuto"></param>
        internal void BackupFile(bool IsAutoBackup = false, bool IsForce = false)
        {
            try
            {
                // 如果获取到的备份位置不是空的, 则继续
                if (!string.IsNullOrWhiteSpace(Resources.GetRes().BackupFolderPath))
                {
                    if (new Regex(@"^(([a-zA-Z]:\\)|(//)).*").Match((Resources.GetRes().BackupFolderPath)).Success)
                    {
                        string disk = Path.GetPathRoot(Resources.GetRes().BackupFolderPath);
                        if (!Directory.Exists(disk))
                        {
                            ExceptionPro.ExpErrorLog("Backup failed! backup path disk name not exists!");
                            return;
                        }
                    }
                    else
                    {
                        Resources.GetRes().BackupFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Resources.GetRes().BackupFolderPath.Replace('/', '\\').TrimStart("\\"));
                    }


                    // 没有文件夹就先创建
                    if (!Directory.Exists(Resources.GetRes().BackupFolderPath))
                    {
                        Directory.CreateDirectory(Resources.GetRes().BackupFolderPath);
                        //DirectoryInfo di = new DirectoryInfo(Resources.GetRes().BackupFolderPath);
                        //di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
                    }

                    // 如果上次备份时间不是今天, 则把数量重置
                    if (lastBackup.Date != DateTime.Today)
                    {
                        BackCount = 1;
                    }


                    DateTime systemDateTimeNow = System.DateTime.Now;

                    // 检查是否备份
                    if (IsForce || CheckforSave())
                    {
                        // 首次打开, 非自动模式要求备份时, 也不是强制的. 也是第一次备份时(时间为0说明刚启动). 暂时停留数秒. 以便防止有些电脑还没启动好就备份导致出现问题(不过已通过改Windows服务启动类型设置为自动(延迟)来暂时解决这个问题,
                        // 不过可能导致启动速度变慢, 所以下次改造需要直接把整个Windows改成自动后, 把这个程序启动后等待1分钟后再继续执行, 免得启动太快出现硬盘还未识别之类的奇葩错误!
                        if (!IsAutoBackup && !IsForce && lastBackup == DateTime.MinValue)
                        {
#if !DEBUG
                            //System.Threading.Thread.Sleep(1000 * 15);
#endif
                        }

                        int systemDateTimeNowDayOfWeek = (int)systemDateTimeNow.DayOfWeek;

                        string fileName = "";

                        if (!IsForce)
                        {
                            fileName = "backup{0}-{1}.bak";
                        }
                        else
                        {
                            fileName = "backup{0}-c.bak";
                        }

                        fileName = string.Format(fileName, systemDateTimeNowDayOfWeek == 0 ? 7 : systemDateTimeNowDayOfWeek, BackCount);
                        string fullFilePath = Path.Combine(Resources.GetRes().BackupFolderPath, fileName);

                        try
                        {
                            using (ZipFile zip = new ZipFile())
                            {
                                //zip.UseUnicodeAsNecessary = true;  // utf-8

                                //zip.Encryption = EncryptionAlgorithm.WinZipAes256;
                                zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;
                                zip.AddFile(Path.Combine(Resources.GetRes().BackupFolderPath, AppDomain.CurrentDomain.BaseDirectory, "ts.db"), "");
                                zip.AddFile(Path.Combine(Resources.GetRes().BackupFolderPath, AppDomain.CurrentDomain.BaseDirectory, "ServerConfig.txt"), "");
                                zip.Comment = "This file was created at " + systemDateTimeNow.ToString("yyyy-MM-dd HH:mm:ss");

                                zip.Save(fullFilePath);
                            }

                            lastBackup = systemDateTimeNow;
                            Session.Instance.ChangeInterval(true);
                        }
                        catch (Exception ex)
                        {
                            Session.Instance.ChangeInterval(false);
                            ExceptionPro.ExpLog(ex, null, false, "Backup failed!");
                        }
                    }
                    else
                    {
                        lastBackup = systemDateTimeNow;
                        Session.Instance.ChangeInterval(true);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPro.ExpLog(ex, null, false, "Backup check operate failed!");
            }
        }