Esempio n. 1
0
 /// <summary>
 /// 服务器初始化确定在线离线
 /// </summary>
 /// <param name="url">在线服务地址</param>
 /// <returns>返回是否初始化成功</returns>
 public static bool ServiceIni(string url)
 {
     try
     {
         //检测服务是否正常连接  若无法连接 开启离线模式
         GlobalVar.TestService = new CoreClient(url);
         GlobalVar.TestService.Send("Test");
         IsOnLine = true;
     }
     catch (Exception ex)
     {
         CoreLog.Error(ex);
         //离线服务开启
         if (DialogResult.Yes != MessageBox.Show(@"离线中!是否还要继续?", @"提示", MessageBoxButtons.YesNo))
         {
             return(false);
         }
         IsOnLine = false;
         var httpUrl = new CoreClientHost(typeof(Test.Service.Ws)).Open();
         GlobalVar.TestService = new CoreClient(httpUrl);
         //设置本地数据库
         LocalDatabaseHelp.SetDatabase();
     }
     return(true);
 }
Esempio n. 2
0
 public void ServiceIni()
 {
     try
     {
         Api.Url = Url;
         Api.GetTest();
         MessageBox.Show(@"服务连接成功");
     }
     catch (Exception e)
     {
         CoreLog.Error(e);
         MessageBox.Show(@"服务连接失败");
     }
 }
Esempio n. 3
0
 public static bool IsTokenValid()
 {
     try
     {
         var userInfoJson = CoreEncrypt.AesDecrypt(AuthHelper.GetAuth(), GlobalConst.AesKey);
         var userInfo     = CoreConvert.JsonToObj <UserInfo>(userInfoJson);
         var text         = CoreEncrypt.AesDecrypt(userInfo.Token, CoreEncrypt.Md5(userInfo.UserName));
         var expiredTime  = DateTime.Parse(text);
         return(expiredTime >= DateTime.UtcNow);
     }
     catch (Exception ex)
     {
         CoreLog.Error(ex);
         return(false);
     }
 }
Esempio n. 4
0
        /// <inheritdoc/>
        /// <exception cref="InvalidOperationException">Current scope differs from this one.</exception>
        public void Dispose()
        {
            bool      bStop = false;
            Exception error = null;

            while (!bStop)
            {
                try {
                    if (currentScopeAsync == null)
                    {
                        bStop = true;
                        throw new InvalidOperationException(Strings.ExScopeCantBeDisposed);
                    }
                    else if (currentScopeAsync.Value == this)
                    {
                        bStop = true;
                        currentScopeAsync.Value.Dispose(true);
                    }
                    else
                    {
                        currentScopeAsync.Value.Dispose();
                    }
                }
                catch (Exception e) {
                    if (error == null)
                    {
                        error = e;
                    }
                    try {
                        CoreLog.Error(e, Strings.LogScopeDisposeError);
                    }
                    catch {}
                }
            }
            currentScopeAsync.Value = outerScope;
            context    = null;
            outerScope = null;
            if (error != null)
            {
                throw error;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 服务器初始化确定在线离线
 /// </summary>
 /// <param name="url">在线服务地址</param>
 /// <returns>返回是否初始化成功</returns>
 public static void ServiceIni(string url)
 {
     try
     {
         if (!Debugger.IsAttached)
         {
             throw new Exception("调试默认离线模式!");
         }
         //设定要连接的服务地址
         Api.Url = url;
         var test = Api.GetTest();
         Console.WriteLine(test);
         IsOnLine = true;
     }
     catch (Exception ex)
     {
         CoreLog.Error("在线异常:" + ex);
         try
         {
             //初始化本地数据库
             LocalDatabaseHelp.SetDatabase();
             //离线服务开启
             if (MessageBox.Show(@"离线中!是否还要继续?", @"提示", MessageBoxButtons.YesNo) != DialogResult.Yes)
             {
                 return;
             }
             IsOnLine = false;
             url      = CoreWebApiHost.OpenAsync("Service\\Api\\Test.Api");
             Api.Url  = url;
             var test = Api.GetTest();
             Console.WriteLine(test);
             MessageBox.Show(@"离线服务创建成功!");
         }
         catch (Exception e)
         {
             CoreLog.Error("离线异常:" + e);
             MessageBox.Show(@"离线服务创建失败!");
         }
     }
 }
Esempio n. 6
0
        /// <inheritdoc/>
        /// <exception cref="InvalidOperationException">Current scope differs from this one.</exception>
        public void Dispose()
        {
            Exception error = null;

            try {
                while (true)
                {
                    try {
                        var currentScope = currentScopeAsync.Value;
                        if (currentScope == null)
                        {
                            throw new InvalidOperationException(Strings.ExScopeCantBeDisposed);
                        }

                        if (currentScope == this)
                        {
                            currentScope.Dispose(true);
                            break;
                        }

                        currentScope.Dispose();
                    }
                    catch (Exception e) {
                        error = e;
                        CoreLog.Error(e, Strings.LogScopeDisposeError);
                        break;
                    }
                }
            }
            finally {
                currentScopeAsync.Value = outerScope;
                context    = null;
                outerScope = null;
                if (error != null)
                {
                    ExceptionDispatchInfo.Throw(error);
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// 服务器初始化确定在线离线
 /// </summary>
 /// <param name="url">在线服务地址</param>
 /// <returns>返回是否初始化成功</returns>
 public static bool ServiceIni(string url)
 {
     try
     {
         //检测服务是否正常连接  若无法连接 开启离线模式
         GlobalVar.ServiceBaseUrl = url;
         App.CreateWsService().Test();
         GlobalVar.UserInfo = App.CreateWsService().GetUserInfo(new UserInfo {
             UserName = "******"
         });
         IsOnLine = true;
     }
     catch (Exception ex)
     {
         CoreLog.Error(ex);
         //离线服务开启
         if (MessageBoxX.Show(@"离线中!是否还要继续?", @"提示", null, MessageBoxButton.YesNo) != MessageBoxResult.Yes)
         {
             return(false);
         }
         IsOnLine = false;
         var httpUrl = new CoreHost(typeof(Test.Service.Ws)).Open();
         try
         {
             GlobalVar.ServiceBaseUrl = httpUrl;
             App.CreateWsService().Test();
             GlobalVar.UserInfo = App.CreateWsService().GetUserInfo(new UserInfo {
                 UserName = "******"
             });
         }
         catch (Exception e)
         {
             CoreLog.Error(e);
             return(false);
         }
     }
     return(true);
 }
Esempio n. 8
0
 public static WsSoap CreateWsService(string url = null, int timeoutSeconds = 60)
 {
     try
     {
         var client = new WsSoapClient();
         client.Endpoint.Address = new EndpointAddress(url ?? GlobalVar.ServiceBaseUrl);
         var userInfo      = GlobalVar.UserInfo ?? new UserInfo();
         var userInfoJson  = CoreConvert.ObjToJson(userInfo);
         var authorization = CoreEncrypt.AesEncrypt(userInfoJson, GlobalConst.AesKey);
         client.Endpoint.Behaviors.Add(AuthHelper.CreateAuthHeaderBehavior(authorization));
         if (client.Endpoint.Binding == null)
         {
             return(client);
         }
         client.Endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 0, 0, timeoutSeconds);
         client.Endpoint.Binding.SendTimeout    = new TimeSpan(0, 0, 0, timeoutSeconds);
         return(client);
     }
     catch (Exception e)
     {
         CoreLog.Error(e);
         throw new Exception("服务连接失败");
     }
 }
 public static void LogError(Type type, object message, Exception ex)
 {
     CoreLog.Error(ReplaceNewLines(String.Format(TypeBldStr, type, (ex.Message + ex.StackTrace ?? ex.StackTrace))));
 }
Esempio n. 10
0
 public static void Error(object message, Object context)
 {
     CoreLog.Error(message, context);
 }
Esempio n. 11
0
 public static void Error(object message)
 {
     CoreLog.Error(message);
 }
Esempio n. 12
0
 private static void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
 {
     CoreLog.Error(e.Exception);
     e.Handled = true;
 }
Esempio n. 13
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());

            CoreLog.Error(str);
        }
Esempio n. 14
0
        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            var str = GetExceptionMsg(e.Exception, e.ToString());

            CoreLog.Error(str);
        }
 public static void LogError(Exception ex)
 {
     CoreLog.Error(ReplaceNewLines(ex.Message + ex.StackTrace ?? ex.StackTrace));
 }
 public static void LogErrorDot(Type type, string message)
 {
     CoreLog.Error(ReplaceNewLines(String.Format(TypePeriodBldStr, type, message)));
 }
 public static void LogError(Type type, object message)
 {
     CoreLog.Error(ReplaceNewLines(String.Format(TypeBldStr, type, message)));
 }