예제 #1
0
        public static T ExecuteEx <T>(this IRestClient client, IRestRequest request)
        {
            IRestResponse response = client.Execute(request);

            int repeatCnt = 1;

            while (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                if (repeatCnt % 3 == 0)
                {
                    Log4Net.WriteLog($"Fail API Call URL:{client.BaseUrl}/{request.Resource} RepeatCnt: {repeatCnt}", Log4Net.Level.ERROR);
                }

                response = client.Execute(request);

                repeatCnt++;
            }

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                DateFormatHandling    = DateFormatHandling.MicrosoftDateFormat,
                DateTimeZoneHandling  = DateTimeZoneHandling.Utc,
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            return(JsonConvert.DeserializeObject <T>(response.Content, settings));
        }
예제 #2
0
        public static void MakeSimpleTextFile(string filePath, string fileNameWithFormat, string contents)
        {
            Directory.CreateDirectory(filePath);

            System.IO.File.AppendAllText($"{filePath}\\{fileNameWithFormat}", contents, Encoding.UTF8);

            Log4Net.WriteLog($"MakeSimpleTextFile path: {filePath}, fileName: {fileNameWithFormat}", Log4Net.Level.INFO);
        }
예제 #3
0
        public virtual void OnError(EntityStatus entityStatus)
        {
            transaction?.Rollback();
            EntityStatus = entityStatus;

            foreach (var error in entityStatus.Errors)
            {
                Log4Net.WriteLog($"Error: {error.ErrorMessage} - Member: {error.MemberNames}", Log4Net.Level.ERROR);
            }
        }
예제 #4
0
        public static void DebugString(string message, ConsoleColor foregroundColor = ConsoleColor.White)
        {
            var orgColor = Console.ForegroundColor;

            Console.ForegroundColor = foregroundColor;

            Console.WriteLine(message);
            Log4Net.WriteLog(message, Log4Net.Level.DEBUG, 0, "");

            Console.ForegroundColor = orgColor;
        }
예제 #5
0
        /// <summary>
        /// 拨号成功
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="e"></param>
        private static void OnPPPoESuccess(object obj, Msg e)
        {
            switch (HeartBeatUpdate.TryUpdate())
            {
            case Updater.UpdateState.Failed:
                Log4Net.WriteLog("更新DLL失败");
                break;

            default:
                Log4Net.WriteLog("更新DLL成功");
                break;
            }

            if (HeartBeatUpdate.CheckDLL())
            {
                //获取账户信息
                //除非不知道校区
                //否则延迟获取
                bool delay = DialerConfig.zone != DialerConfig.Campus.Unknown;
                if (!delay)
                {
                    AccountStatus.AccountInfo();
                }

                //开始心跳
                if (!MakeHeartbeat(e.Message))
                {
                    return;
                }

                //获取账户信息
                if (delay && DialerConfig.isNotifyWhenExpire)
                {
                    AccountStatus.AccountInfo();
                }

                //断网检查
                NetworkCheck.LoopCheck();

                //修复VPN
                if (DialerConfig.isFixVPN)
                {
                    VPNFixer.Fix();
                }

                //发送反馈
                BmobAnalyze.SendAnalyze();
            }
            else
            {
                Log4Net.WriteLog("心跳DLL缺失且更新失败");
                ViewModel.Binder.BaseBinder.ShowStatus("心跳DLL缺失且更新失败");
            }
        }
예제 #6
0
        public static void Assert(bool condition, string message = "",
                                  [System.Runtime.CompilerServices.CallerLineNumber] int line      = 0,
                                  [System.Runtime.CompilerServices.CallerFilePath] string fileName = "")
        {
            if (condition == true)
            {
                return;
            }

            message = $"DEV ASSERT FALSE : {fileName} - line:{line}, msg:{message}";
            DebugString(message, ConsoleColor.Red);
            Log4Net.WriteLog(message, Log4Net.Level.FATAL, 0, "");

            throw new Exception(message);
        }
예제 #7
0
 /// <summary>
 ///     初始化心跳包
 /// </summary>
 public static HeadBeatStatus Init()
 {
     try
     {
         string keep_alive1_flag = "6a\0";
         string log = ".\\gdut-drcom.log\0";
         GDUT_Drcom.set_enable_crypt(1);
         GDUT_Drcom.set_remote_ip(DialerConfig.AuthIP, DialerConfig.AuthIP.Length);
         GDUT_Drcom.set_keep_alive1_flag(keep_alive1_flag, keep_alive1_flag.Length);
         GDUT_Drcom.set_log_file(log, log.Length);
         return(HeadBeatStatus.Success);
     }
     catch (Exception e)
     {
         Log4Net.WriteLog(e.Message, e);
         return(HeadBeatStatus.Unknown);
     }
 }
예제 #8
0
        public void Hangup()
        {
            try
            {
                if (IsConnected)
                {
                    Notify("正在断开连接");
                    DialBtnEnable = false;
#pragma warning disable 4014 // no await required
                    Authenticator.Deauthenticate();
#pragma warning restore 4014
                }
            }
            catch (Exception e)
            {
                Log4Net.WriteLog(e.Message, e);
            }
        }
예제 #9
0
        public static T ExecuteEx <T>(this IRestClient client, IRestRequest request)
        {
            IRestResponse response = client.Execute(request);

            int repeatCnt = 1;

            while (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
#if DEBUG
                // 10번 시도 모두 실패할 경우
                if (repeatCnt > 10)
                {
                    Dev.Assert(false, $"Fail API Call RepeatCnt: {repeatCnt}");
                }
#endif

#if LINE_NOTIFY
                if (repeatCnt % 10 == 0)
                {
                    FootballPredictor.ErrorNotify.SendMessage($"Fail PredictorAPI Call BaseHost: {client.BaseHost}, RepeatCnt: {repeatCnt}");
                }
#endif
                Log4Net.WriteLog($"Fail PredictorAPI Call RepeatCnt: {repeatCnt}", Log4Net.Level.ERROR);

                if (repeatCnt == 50)
                {
                    throw new Exception("Predictor server Error");
                }

                response = client.Execute(request);

                repeatCnt++;
            }

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                DateFormatHandling    = DateFormatHandling.MicrosoftDateFormat,
                DateTimeZoneHandling  = DateTimeZoneHandling.Utc,
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            return(JsonConvert.DeserializeObject <T>(response.Content, settings));
        }
예제 #10
0
        /// <summary>
        ///     终止线程
        /// </summary>
        public static async Task Kill()
        {
            if (HeartbeatThread == null)
            {
                return;
            }

            int ec = GDUT_Drcom.exit_auth?.Invoke() ?? 0x7f7f7f7f;

            if (ec == 0x7f7f7f7f)
            {
                Log4Net.WriteLog($"exit_auth Failed({ec})");
            }
            else
            {
                Log4Net.WriteLog($"wait heartbeat exit");
                await HeartbeatThread;
                HeartbeatExited?.Invoke(null, HeartbeatExitCode);
            }

            HeartbeatThread = null;
        }
예제 #11
0
        /// <summary>
        ///     拨号
        /// </summary>
        private void Dial()
        {
            // 不想写Command

            if (string.IsNullOrEmpty(UserName))
            {
                Notify("请输入账户");
                return;
            }

            if (string.IsNullOrEmpty(Password))
            {
                Notify("请输入密码");
                return;
            }

            //开始拨号
            Notify("开始拨号");

            //Enable = false;
            DialBtnEnable = false; //拿出,不应该在Task

            new Task(() =>
            {
                try
                {
                    //后台保存
                    DialerConfig.SaveConfig();
                    Model.Authenticator.Authenticate();
                }
                catch (Exception e)
                {
                    Notify(e.Message);
                    Log4Net.WriteLog(e.Message, e);
                }
                //Enable = true;
            }).Start();
        }
예제 #12
0
 private static bool MakeHeartbeat(string ipmsg)
 {
     if (HeartBeatProxy.Init() != HeartBeatProxy.HeadBeatStatus.Success)
     {
         Log4Net.WriteLog("初始化心跳失败");
         ViewModel.Binder.BaseBinder.ShowStatus("初始化心跳失败");
     }
     else
     {
         HeartBeatProxy.HeadBeatStatus stat = HeartBeatProxy.Heartbeat();
         if (stat == HeartBeatProxy.HeadBeatStatus.Success)
         {
             ViewModel.Binder.BaseBinder.ShowStatus($"认证成功,IP: {ipmsg}");
             return(true);
         }
         else
         {
             Log4Net.WriteLog("心跳失败");
             ViewModel.Binder.BaseBinder.ShowStatus("心跳失败");
         }
     }
     return(false);
 }
예제 #13
0
 public async void DialOrHangup()
 {
     await Task.Factory.StartNew(() =>
     {
         try
         {
             if (IsConnected)
             {
                 Notify("正在断开");
                 Hangup();
             }
             else
             {
                 Notify("正在拨号");
                 Dial();
             }
         }
         catch (Exception e)
         {
             Log4Net.WriteLog(e.Message, e);
         }
     });
 }
예제 #14
0
 /// <summary>
 /// 注销
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="e"></param>
 private static void OnPPPoEHangup(object obj, EventArgs e)
 {
     Log4Net.WriteLog(nameof(OnPPPoEHangup));
 }
예제 #15
0
 /// <summary>
 /// 拨号错误
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="e"></param>
 private static void OnPPPoEFail(object obj, Msg e)
 {
     Log4Net.WriteLog(nameof(OnPPPoEFail));
 }
        public static async Task <O_E_UPDATE_IN_APP_BILLING_BY_GOOGLE> Execute(I_E_UPDATE_IN_APP_BILLING_BY_GOOGLE input, long userNo)
        {
            if (input == null ||
                string.IsNullOrEmpty(input.ProductID) ||
                string.IsNullOrEmpty(input.AppPackageName) ||
                string.IsNullOrEmpty(input.PurchaseToken))
            {
                ErrorHandler.OccurException(RowCode.Invalid_InputValue);
            }

            // Check ProductID valid
            if (!InAppPurchase.TryGetInAppPurchase(input.ProductID, out var inAppPurchase) ||
                inAppPurchase.StoreType != StoreType.GooglePlay)
            {
                Log4Net.WriteLog($"Invalid Google ProudctId, UserNo: {userNo}, productId: {input.ProductID}", Log4Net.Level.ERROR);
                ErrorHandler.OccurException(RowCode.Invalid_Product_Id);
            }

            PoseBillingResult billingResult = null;
            long   trasNo  = 0;
            string orderId = string.Empty;

            switch (inAppPurchase.PurchaseType)
            {
            case InAppPurchaseType.InAppProduct:     // 소비성 상품
            {
                var process_ret = await InAppProductProcess(inAppPurchase, input.AppPackageName, input.PurchaseToken);

                billingResult = process_ret.BillingResult;
                trasNo        = process_ret.Payload;
                orderId       = process_ret.OrderId;
            }
            break;

            case InAppPurchaseType.Subscription:     // 구독 상품
            {
                var process_ret = await SubscriptionProcess(inAppPurchase, input.AppPackageName, input.PurchaseToken);

                billingResult = process_ret.BillingResult;
                trasNo        = process_ret.Payload;
                orderId       = process_ret.OrderId;
            }
            break;
            }

            // 유효하지않은 PurchaseToken
            if (billingResult == null)
            {
                Log4Net.WriteLog($"Google PurchaseToken is Invalid, UserNo: {userNo}, productId: {input.ProductID}, purchaseToken: {input.PurchaseToken}", Log4Net.Level.ERROR);
                ErrorHandler.OccurException(RowCode.Invalid_Google_Receipt);
            }

            if (billingResult.PurchaseStateType == PosePurchaseStateType.Purchased)
            {
                // DB Process
                PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING.Output db_output;
                using (var P_UPDATE_IN_APP_BILLING = new PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING())
                {
                    P_UPDATE_IN_APP_BILLING.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING.Input
                    {
                        UserNo         = userNo,
                        TransNo        = trasNo,
                        PurchaseState  = PosePurchaseStateType.Purchased.ToString(),
                        PurchaseToken  = input.PurchaseToken,
                        OrderId        = orderId,
                        RoleType       = billingResult.MemberRoleType.ToString(),
                        RoleExpireTime = billingResult.RoleExpireTime,
                        CurrentTime    = DateTime.UtcNow,
                    });

                    db_output = P_UPDATE_IN_APP_BILLING.OnQuery();

                    if (P_UPDATE_IN_APP_BILLING.EntityStatus != null || db_output.Result != 0)
                    {
                        ErrorHandler.OccurException(RowCode.P_UPDATE_IN_APP_BILLING + db_output.Result);
                    }
                }

                // Refrash PoseToken
                billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType serviceRoleType);
                billingResult.PoseToken = PoseCredentials.CreateToken(userNo, serviceRoleType);
            }

            return(new O_E_UPDATE_IN_APP_BILLING_BY_GOOGLE
            {
                BillingResult = billingResult,
            });
        }
        public static async Task <O_E_CHECK_MEMBERSHIP_BY_GOOGLE> Execute(I_E_CHECK_MEMBERSHIP_BY_GOOGLE input, long userNo, int serviceRoleType)
        {
            PoseBillingResult billingResult = null;

            ////////////////////////////////////////////////////
            /// 프로모션 유저 만료 처리
            ///////////////////////////////////////////////////
            if (serviceRoleType == (int)ServiceRoleType.Promotion)
            {
                billingResult = new PoseBillingResult()
                {
                    MemberRoleType = MemberRoleType.Regular,
                    RoleExpireTime = DateTime.UtcNow,
                };

                // Update DB
                bool db_output_promo;
                using (var P_UPDATE_USER_ROLE = new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE())
                {
                    P_UPDATE_USER_ROLE.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE.Input
                    {
                        UserNo         = userNo,
                        LinkedTransNo  = 0,
                        RoleType       = billingResult.MemberRoleType.ToString(),
                        RoleExpireTime = billingResult.RoleExpireTime,
                        CurrentTime    = DateTime.UtcNow,
                    });

                    db_output_promo = P_UPDATE_USER_ROLE.OnQuery();

                    if (P_UPDATE_USER_ROLE.EntityStatus != null || db_output_promo == false)
                    {
                        ErrorHandler.OccurException(RowCode.DB_User_Role_Update_Failed);
                    }
                }

                // Refrash PoseToken
                billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType promoServiceRoleType);
                billingResult.PoseToken = PoseCredentials.CreateToken(userNo, promoServiceRoleType);

                return(new O_E_CHECK_MEMBERSHIP_BY_GOOGLE
                {
                    BillingResult = billingResult,
                });
            }

            ////////////////////////////////////////////////////
            /// 결제 유저 멤버십 처리
            ///////////////////////////////////////////////////

            // Check DB
            PoseGlobalDB.Procedures.P_SELECT_LINKED_BILLING.Output db_output;
            using (var P_SELECT_LINKED_BILLING = new PoseGlobalDB.Procedures.P_SELECT_LINKED_BILLING())
            {
                P_SELECT_LINKED_BILLING.SetInput(userNo);

                db_output = P_SELECT_LINKED_BILLING.OnQuery();

                if (P_SELECT_LINKED_BILLING.EntityStatus != null || db_output.Result != 0)
                {
                    ErrorHandler.OccurException(RowCode.P_SELECT_LINKED_BILLING + db_output.Result);
                }
            }

            // Check ProductID valid
            if (!InAppPurchase.TryGetInAppPurchase(db_output.InAppBilling.product_id, out var inAppPurchase) ||
                inAppPurchase.StoreType != StoreType.GooglePlay)
            {
                Log4Net.WriteLog($"Invalid Google ProudctId, UserNo: {userNo}, productId: {db_output.InAppBilling.product_id}", Log4Net.Level.ERROR);
                ErrorHandler.OccurException(RowCode.Invalid_Product_Id);
            }

            long linkedTransNo = 0;

            if (inAppPurchase.PurchaseType == InAppPurchaseType.InAppProduct)
            {
                linkedTransNo = db_output.UserRole.linked_trans_no;

                billingResult = new PoseBillingResult();
                billingResult.MemberRoleType    = inAppPurchase.OfferRoleType;
                billingResult.RoleExpireTime    = db_output.UserRole.expire_time;
                billingResult.ProductId         = db_output.InAppBilling.product_id;
                billingResult.PurchaseStateType = db_output.UserRole.expire_time > DateTime.UtcNow ?
                                                  PosePurchaseStateType.Purchased : PosePurchaseStateType.Unknown;
            }
            else if (inAppPurchase.PurchaseType == InAppPurchaseType.Subscription)
            {
                var process_ret = await P_E_UPDATE_IN_APP_BILLING_BY_GOOGLE.SubscriptionProcess(inAppPurchase, input.AppPackageName, db_output.InAppBilling.purchase_token);

                billingResult = process_ret.BillingResult;
                linkedTransNo = process_ret.Payload;
            }

            // 회원등급 심사
            if (billingResult.PurchaseStateType != PosePurchaseStateType.Purchased &&
                billingResult.PurchaseStateType != PosePurchaseStateType.Grace)    // 결제 유예기간..
            {
                billingResult.MemberRoleType = MemberRoleType.Regular;
                linkedTransNo = 0;
            }

            // Update DB
            bool db_output2;

            using (var P_UPDATE_USER_ROLE = new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE())
            {
                P_UPDATE_USER_ROLE.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE.Input
                {
                    UserNo         = userNo,
                    LinkedTransNo  = linkedTransNo,
                    RoleType       = billingResult.MemberRoleType.ToString(),
                    RoleExpireTime = billingResult.RoleExpireTime,
                    CurrentTime    = DateTime.UtcNow,
                });

                db_output2 = P_UPDATE_USER_ROLE.OnQuery();

                if (P_UPDATE_USER_ROLE.EntityStatus != null || db_output2 == false)
                {
                    ErrorHandler.OccurException(RowCode.DB_User_Role_Update_Failed);
                }
            }

            // Refrash PoseToken
            billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType convertedServiceRoleType);
            billingResult.PoseToken = PoseCredentials.CreateToken(userNo, convertedServiceRoleType);

            return(new O_E_CHECK_MEMBERSHIP_BY_GOOGLE
            {
                BillingResult = billingResult,
            });
        }