Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tradeJournal"></param>
        /// <returns></returns>
        public string GenerateSignedParams(TradeJournal tradeJournal)
        {
            tradeJournal.AssertNotNull("tradeJournal");
            if (null == tradeJournal.PayRoute || null == this.PayRoutes || false == this.PayRoutes.ContainsKey(tradeJournal.PayRoute))
            {
                throw new ArgumentOutOfRangeException("payment:PayRoute", string.Format("Not support the PayRoute : {0}-{1}", tradeJournal.PayWay, tradeJournal.PayRoute));
            }

            var signedParams = BuilderSignParams(tradeJournal);

            if (tradeJournal.PayRoute == PayWays.Route_H5)
            {
                tradeJournal.SignedParams = signedParams.ToJson();
                var code   = ObjectIOCFactory.GetSingleton <PaymentEngine>().CacheSignedPayment(tradeJournal);
                var payUrl = this.H5PayUrl + "?code=" + code;
                return(payUrl);
            }
            else if (tradeJournal.PayRoute == PayWays.Route_QRCODE)
            {
                var qrcode = this.LoadQRCodeContent(tradeJournal, signedParams);
                return(qrcode);
            }
            else
            {
                var signedParamsQuery = BuildUrlQuery(signedParams).ToString();
                return(signedParamsQuery.ToString());
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult WechatPaidRedirect()
        {
            var tradeCode = this.Request.QueryString.Get("out_trade_no");

            if (string.IsNullOrEmpty(tradeCode))
            {
                return(Content("failed"));
            }

            var wechatProvider = (WechatProvider)ObjectIOCFactory.GetSingleton <PaymentEngine>().PaymentProviders[PayWays.Wechat];

            var paymentDetail = new Dictionary <string, string>();

            paymentDetail["out_trade_no"] = tradeCode;
            var xml = WechatProvider.ToXmlParams(paymentDetail);

            var tradeJournal = ObjectIOCFactory.GetSingleton <PaymentEngine>().PaymentCompleted(tradeCode, PayWays.Wechat, null, xml);

            if (null != tradeJournal)
            {
                if (false == string.IsNullOrEmpty(tradeJournal.ReturnUrl))
                {
                    return(this.Redirect(string.Format("{0}{1}out_trade_no={2}", tradeJournal.ReturnUrl, tradeJournal.ReturnUrl.Contains("?") ? "&" : "?", tradeCode)));
                }
                else
                {
                    return(Content("success"));
                }
            }
            return(Content("failed"));
        }
        void WaitForMainAppExit()
        {
            var exitMessageFile = string.Format("{0}.exit", this.MainAppId);

            exitMessageFile = Path.Combine(ObjectIOCFactory.GetSingleton <ServiceHostConfig>().Host.RunDirectory, exitMessageFile);

            if (File.Exists(exitMessageFile) == false)
            {
                var nowText = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                for (var i = 0; i < 3; i++)
                {
                    try
                    {
                        using (var sw = new StreamWriter(exitMessageFile))
                        {
                            sw.WriteLine(nowText);
                        }
                        break;
                    }
                    catch
                    {
                        Thread.Sleep(1000);
                    }
                }

                Console.WriteLine("WaitForMainAppExit:{0}[{1}]", nowText, exitMessageFile);
            }
            this.DisabledApp = true;
            this.MainAppHandle.WaitForExit();
        }
Esempio n. 4
0
        public PaymentResult PaymentCompleted([FromBody] PaymentResult paymentResult)
        {
            if (null == paymentResult || string.IsNullOrEmpty(paymentResult.TradeCode))
            {
                this.ReturnPreconditionFailedMessage();
                return(null);
            }

            LogManager.GetLogger().Info("==>paymentResult[PaymentCompleted]: {0}", TradeSystem.JsonExtension.ToJson(paymentResult));

            var tradeJournal = ObjectIOCFactory.GetSingleton <PaymentEngine>().PaymentCompleted(paymentResult.TradeCode, paymentResult.PayWay, null, paymentResult.PaidDetail);

            if (null != tradeJournal)
            {
                return new PaymentResult()
                       {
                           Success = true, TradeCode = tradeJournal.TradeCode, TargetBizTradeCode = tradeJournal.TargetBizTradeCode
                       }
            }
            ;
            else
            {
                return new PaymentResult()
                       {
                           Success = false, ErrorMessage = "Paid failed."
                       }
            };
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult WechatPaidCallback()
        {
            var xml = string.Empty;

            using (var reader = new StreamReader(this.Request.InputStream))
            {
                xml = reader.ReadToEnd();
            }
            if (string.IsNullOrEmpty(xml))
            {
                return(Content(WechatProvider.FailCallbackResult));
            }

            LogManager.GetLogger().Info("==>WechatPaidCallback-0: {0}", xml);

            var paidWay       = PayWays.Wechat;
            var paymentDetail = WechatProvider.ToDictionary(xml);

            if (null == paymentDetail || false == paymentDetail.ContainsKey("out_trade_no"))
            {
                return(Content(WechatProvider.FailCallbackResult));
            }

            var tradeCode    = paymentDetail["out_trade_no"];
            var tradeJournal = ObjectIOCFactory.GetSingleton <PaymentEngine>().PaymentCompleted(tradeCode, paidWay, null, xml);
            var result       = (null != tradeJournal) ? WechatProvider.SuccessCallbackResult : WechatProvider.FailCallbackResult;

            LogManager.GetLogger().Info("==>WechatPaidCallback-1: {0}", result);
            return(Content(result));
        }
        public ActionResult AlipayPaidRedirect()
        {
            var tradeCode     = this.Request.QueryString.Get("out_trade_no");
            var paidWay       = PayWays.Alipay;
            var paymentDetail = this.Request.Url.Query;

            if (null == paymentDetail || false == paymentDetail.StartsWith("?"))
            {
                return(Content("failed"));
            }

            paymentDetail = paymentDetail.Substring(1);
            var tradeJournal = ObjectIOCFactory.GetSingleton <PaymentEngine>().PaymentCompleted(tradeCode, paidWay, null, paymentDetail);

            if (null != tradeJournal)
            {
                if (false == string.IsNullOrEmpty(tradeJournal.ReturnUrl))
                {
                    return(this.Redirect(string.Format("{0}{1}out_trade_no={2}", tradeJournal.ReturnUrl, tradeJournal.ReturnUrl.Contains("?") ? "&" : "?", tradeCode)));
                }
                else
                {
                    return(Content("success"));
                }
            }
            return(Content("failed"));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="algorithmName"></param>
        /// <returns></returns>
        public static IPassportSecurityStrategy LoadSecurityStrategy(string algorithmName)
        {
            IPassportSecurityStrategy securityStrategy = null;

            if (string.IsNullOrEmpty(algorithmName))
            {
                securityStrategy = ObjectIOCFactory.GetSingleton <IPassportSecurityStrategy>(ModuleEnvironment.DefaultSecurityProvider);
            }
            else
            {
                if (algorithmName.StartsWith(MD5SecurityStrategy.AlgorithmName))
                {
                    securityStrategy = ObjectIOCFactory.GetSingleton <MD5SecurityStrategy>();
                }
                else if (algorithmName.StartsWith(BCryptSecurityStrategy.AlgorithmName))
                {
                    securityStrategy = ObjectIOCFactory.GetSingleton <BCryptSecurityStrategy>();
                }
                else
                {
                    securityStrategy = ObjectIOCFactory.GetSingleton <IPassportSecurityStrategy>(ModuleEnvironment.DefaultSecurityProvider);
                }
            }
            return(securityStrategy);
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameterValues"></param>
        /// <returns></returns>
        public override object ExecuteScalar(SqlWrap sql, IDictionary <string, object> parameterValues)
        {
            ArgumentAssertion.IsNotNull(sql, "sql");

            Stopwatch stopwatch    = null;
            var       sqlProcessor = ObjectIOCFactory.GetSingleton <DataSettings>().SqlProcessor;

            if (sqlProcessor.EnableTrace)
            {
                stopwatch = Stopwatch.StartNew();
            }

            var sqlText = this.TransformSql(sql.SqlText, parameterValues);

            var result = MySqlHelper.ExecuteScalar(this.ConnectionString, sqlText, sql.CommandTimeout, ConvertToDbParams(parameterValues));

            if (result == DBNull.Value)
            {
                result = null;
            }

            if (sqlProcessor.EnableTrace)
            {
                stopwatch.Stop();
                sqlProcessor.Log(LogLevel.Trace, string.Format("[{0}]ExecuteSql({1})\r\n\t{2}", stopwatch.Elapsed, sql.FullName, sqlText), null);
            }
            return(result);
        }
        private static void SyncIMAccount(ThirdIMAccount source)
        {
            var imAccount = ThirdIMAccount.CreateNew(source.PassportId, source.Platform, source.PlatformAccountId);

            imAccount.Nickname = source.Nickname;

            if (null == imAccount)
            {
                return;
            }

            if (imAccount.IsSync)
            {
                ObjectIOCFactory.GetSingleton <IIMProvider>(ModuleEnvironment.IMProviderName).ChangeNickname(imAccount);
            }
            else
            {
                var isSync = ObjectIOCFactory.GetSingleton <IIMProvider>(ModuleEnvironment.IMProviderName).CreateAccount(imAccount);
                if (isSync)
                {
                    imAccount.IsSync = isSync;
                    imAccount.Save();
                }
            };
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult AlipayPaidCallback()
        {
            var tradeCode     = this.Request.QueryString.Get("out_trade_no");
            var paymentDetail = string.Empty;

            using (var reader = new StreamReader(this.Request.InputStream))
            {
                paymentDetail = reader.ReadToEnd();
            }
            if (false == string.IsNullOrEmpty(paymentDetail))
            {
                var postParamCollection = HttpUtility.ParseQueryString(paymentDetail);
                if (postParamCollection.AllKeys.ToList().Contains("out_trade_no"))
                {
                    tradeCode = postParamCollection["out_trade_no"];
                }
            }

            LogManager.GetLogger().Info("==>AlipayPaidCallback-0: {0}", paymentDetail);

            var paidWay = PayWays.Alipay;

            if (string.IsNullOrEmpty(paymentDetail) || string.IsNullOrEmpty(tradeCode))
            {
                return(Content("failed"));
            }

            var tradeJournal = ObjectIOCFactory.GetSingleton <PaymentEngine>().PaymentCompleted(tradeCode, paidWay, null, paymentDetail);
            var result       = (null != tradeJournal) ? "success" : "failed";

            LogManager.GetLogger().Info("==>AlipayPaidCallback-1: {0}", result);
            return(Content(result));
        }
Esempio n. 11
0
        public void RefundTest()
        {
            var tradeCode = "201609191657217132408866";
            var source    = TradeJournal.FindById(tradeCode);

            Assert.NotNull(source);


            var payment = new Payment();

            payment.ParentTradeCode   = source.TradeCode;
            payment.OwnerId           = source.SellerId;
            payment.PayWay            = source.PaidWay;
            payment.TradeMode         = TradeMode.Payoff;
            payment.BizSource         = PaymentSources.RejectService;
            payment.CommodityCategory = source.CommodityCategory;
            payment.CommodityCode     = source.CommodityCode;
            payment.CommodityQuantity = source.CommodityQuantity;
            payment.CommoditySubject  = string.Format("Reject the service {0} for user {1} [¥{2}].", source.CommodityCode, source.BuyerId, -source.TotalFee);
            payment.CommoditySummary  = null;
            payment.TotalFee          = 0 - source.TotalFee;
            payment.BuyerId           = source.BuyerId;
            payment.SellerId          = source.SellerId;

            var refunded = ObjectIOCFactory.GetSingleton <PaymentEngine>().Refund(payment);

            Assert.IsTrue(refunded);
        }
Esempio n. 12
0
        public void PayoffTest()
        {
            var payment = new Payment();

            payment.OwnerId           = 95838;
            payment.TradeMode         = TradeMode.Payoff;
            payment.PayWay            = PayWays.Wallet;
            payment.BizSource         = BizSources.Deposit;
            payment.CommodityCategory = "充值";
            payment.CommodityCode     = "";
            payment.CommodityQuantity = 1;
            payment.TotalFee          = 500;
            payment.CommoditySubject  = string.Format("充值 ¥{0}", payment.TotalFee);
            payment.BuyerId           = payment.OwnerId;
            var signed = ObjectIOCFactory.GetSingleton <PaymentEngine>().CreateTrade(payment);

            Assert.IsTrue(signed);

            Console.WriteLine("Sign:{0}", payment.SignedParams);
            var paymentDetail = "TradeCode=" + payment.TradeCode;
            var tradeJournal  = ObjectIOCFactory.GetSingleton <PaymentEngine>().PaymentCompleted(payment.TradeCode, payment.PayWay, null, paymentDetail);
            var isPaid        = null != tradeJournal;

            Assert.IsTrue(isPaid);
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            var hostConfig       = ObjectIOCFactory.GetSingleton <ServiceHostConfig>();
            var commandArguments = new CommandArguments(args);

            if (commandArguments.ContainsArgument("service"))
            {
                hostConfig.Host.RunInService = true;
            }
            if (commandArguments.ContainsArgument("debug"))
            {
                hostConfig.App.Debug = true;
            }

            if (hostConfig.Host.RunInService)
            {
                ServiceBase.Run(new WinService());
            }
            else
            {
                var exitHanlder = new ConsoleExitHanlder();
                exitHanlder.Exit += new EventHandler((source, e) => applicationHost.Stop());

                applicationHost = ApplicationHost.GetInstance(args);
                ObjectIOCFactory.GetSingleton <ApplicationHub>().Register(ObjectIOCFactory.GetSingleton <ApplicationContainer>());
                applicationHost.Start();
                ExecuteSystemCommand();
            }
        }
Esempio n. 14
0
        static ILog GetSystemLogger()
        {
            var log = ObjectIOCFactory.GetSingleton <SystemLogger>();

            log.Warn("not create a LogFactory");
            return(log);
        }
        public void ResolveInstanceTest()
        {
            var groupA = ObjectIOCFactory.ResolveInstance <ServerGroup>();
            var groupB = ObjectIOCFactory.GetSingleton <ServerGroup>();

            Assert.AreNotEqual(groupA, groupB);
        }
        public PaymentResult Withdraw([FromBody] Payment payment)
        {
            payment.AssertNotNull("payment");

            if (payment.OwnerId < 0)
            {
                throw new ArgumentOutOfRangeException("payment:OwnerId", "Not support OwnerId is 0.");
            }
            if (payment.BuyerId < 0)
            {
                throw new ArgumentOutOfRangeException("payment:OwnerId", "Not support BuyerId is 0.");
            }

            var paymentEngine = ObjectIOCFactory.GetSingleton <PaymentEngine>();
            var tradeJournal  = paymentEngine.Withdraw(payment);

            if (null != tradeJournal)
            {
                return(new PaymentResult()
                {
                    Success = true, TradeCode = tradeJournal.TradeCode
                });
            }
            else
            {
                return(new PaymentResult()
                {
                    Success = false, ErrorMessage = "Withdraw failed."
                });
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="payment"></param>
        /// <returns></returns>
        public PaymentResult ShareIncome([FromBody] Payment payment)
        {
            payment.AssertNotNull("payment");
            payment.BizSource.AssertNotNull("payment:BizSource");
            payment.ParentTradeCode.AssertNotNull("payment:ParentTradeCode");

            if (payment.OwnerId < 0)
            {
                throw new ArgumentOutOfRangeException("payment:OwnerId", "Not support OwnerId is 0.");
            }

            var paymentEngine = ObjectIOCFactory.GetSingleton <PaymentEngine>();
            var tradeJournal  = paymentEngine.ShareIncome(payment);

            if (null != tradeJournal)
            {
                return(new PaymentResult()
                {
                    Success = true, TradeCode = payment.TradeCode
                });
            }
            else
            {
                return(new PaymentResult()
                {
                    Success = false, ErrorMessage = "ShareIncome failed."
                });
            }
        }
Esempio n. 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="parameterValues"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public override DataTable ExecutePaginationTable(SqlWrap sql, IDictionary <string, object> parameterValues, Pagination pagination)
        {
            ArgumentAssertion.IsNotNull(sql, "sql");
            ArgumentAssertion.IsNotNull(pagination, "pagination");

            Stopwatch stopwatch    = null;
            var       sqlProcessor = ObjectIOCFactory.GetSingleton <DataSettings>().SqlProcessor;

            if (sqlProcessor.EnableTrace)
            {
                stopwatch = Stopwatch.StartNew();
            }

            var sqlText = GetPaginationSql(sql, pagination);

            sqlText = this.TransformSql(sqlText, parameterValues);

            var dataSet    = MySqlHelper.ExecuteDataSet(this.ConnectionString, sqlText, sql.CommandTimeout, ConvertToDbParams(parameterValues));
            var totalCount = dataSet.Tables[0].Rows[0][0].Convert <int>();

            pagination.TotalCount = totalCount;

            if (sqlProcessor.EnableTrace)
            {
                stopwatch.Stop();
                sqlProcessor.Log(LogLevel.Trace, string.Format("[{0}]ExecuteSql({1})\r\n\t{2}", stopwatch.Elapsed, sql.FullName, sqlText), null);
            }

            return(dataSet.Tables[1]);
        }
Esempio n. 19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sourceFileName"></param>
 /// <returns></returns>
 public string GetRunAppFileName(string sourceFileName)
 {
     if (ObjectIOCFactory.GetSingleton <ServiceHostConfig>().App.RenameForHost == false)
     {
         return(sourceFileName);
     }
     return(string.Format("{0}[{1}]_{2}", this.ApplicationHost.HostProcessName, this.ApplicationHost.HostProcessId, sourceFileName));
 }
Esempio n. 20
0
 /// <summary>
 /// 获取ILog的指定类别的实例
 /// </summary>
 /// <param name="categoryName"></param>
 /// <returns></returns>
 public static ILog GetLogger(string categoryName)
 {
     if (typeof(ILogFactory).GetMapType().CanCreated() == false)
     {
         return(GetSystemLogger());
     }
     return(ObjectIOCFactory.GetSingleton <ILogFactory>().GetLogger(categoryName));
 }
        public void OnStart(ApplicationHost onwer, CommandArguments args)
        {
            foreach (var item in this.extensions)
            {
                item.OnStart(this.ApplicationHost, this.CommandArguments);
            }

            var hostConfig    = ObjectIOCFactory.GetSingleton <ServiceHostConfig>();
            var targetAppName = this.fileManager.GetRunAppFileName(hostConfig.App.ExeFile);
            var targetAppPath = Path.Combine(hostConfig.Host.RunDirectory, targetAppName);

            this.DisabledApp = false;

            var mainProcess = new Process();

            mainProcess.EnableRaisingEvents = true;
            mainProcess.Exited             += new EventHandler(mainApp_Exited);
            mainProcess.StartInfo.FileName  = targetAppPath;
            mainProcess.StartInfo.Arguments = this.GetAppArguments();

            var enableDebug = false;

            if (hostConfig.Host.RunInService == false && hostConfig.App.Debug == true)
            {
                enableDebug = true;
            }

            if (enableDebug)
            {
                mainProcess.StartInfo.WindowStyle    = ProcessWindowStyle.Normal;
                mainProcess.StartInfo.CreateNoWindow = false;
            }
            else
            {
                mainProcess.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                mainProcess.StartInfo.CreateNoWindow = true;
            }

            Console.WriteLine("[{0}]{1}", mainProcess.StartInfo.FileName, mainProcess.StartInfo.Arguments);

            try
            {
                mainProcess.Start();
            }
            catch (Exception ex)
            {
                new FatalException(string.Concat(ex.Message, " - ", targetAppPath, " - ", mainProcess.StartInfo.Arguments), ex)
                .HandleException();

                ApplicationHost.GetInstance(null).Stop();
            }

            if (null != this.MainAppHandle)
            {
                this.MainAppHandle.Refresh();
            }
            this.MainAppHandle = mainProcess;
        }
Esempio n. 22
0
        public PaymentResult QueryTrade(string tradeCode)
        {
            if (string.IsNullOrEmpty(tradeCode))
            {
                return(null);
            }

            return(ObjectIOCFactory.GetSingleton <PaymentEngine>().QueryTrade(tradeCode));
        }
Esempio n. 23
0
        public string[] GetPayWays(string os, string bizSource, string payWays = null)
        {
            if (false == string.IsNullOrEmpty(payWays))
            {
                return(payWays.Split(','));
            }

            return(ObjectIOCFactory.GetSingleton <PaymentEngine>().GetPayWays(os, bizSource));
        }
Esempio n. 24
0
        public void VaTest()
        {
            var code             = "201604142157482746705110";
            var paymentDetail    = string.Format("<xml><out_trade_no>{0}</out_trade_no></xml>", code);
            var provider         = ObjectIOCFactory.GetSingleton <PaymentEngine>().PaymentProviders[PayWays.Wechat];
            var paymentDetailDic = provider.ParsePaymentDetail(paymentDetail);
            var isPaid           = provider.VerifyPaymentResult(ref paymentDetailDic);

            Assert.IsTrue(isPaid);
        }
Esempio n. 25
0
        public PaymentResult CreateTrade([FromBody] Payment payment)
        {
            payment.AssertNotNull("payment");
            if (string.IsNullOrEmpty(payment.BizSource))
            {
                throw new ArgumentNullException("payment:BizSource");
            }
            if (string.IsNullOrEmpty(payment.CommoditySubject))
            {
                throw new ArgumentNullException("payment:CommoditySubject");
            }

            if (payment.OwnerId == 0 && (payment.TradeType == TradeType.OrganizationToPersonal || payment.TradeType == TradeType.OrganizationToOrganization))
            {
                throw new ArgumentOutOfRangeException("payment:OwnerId", string.Format("Not support OwnerId is 0 from OrganizationTo*** trade.", payment.TradeMode));
            }

            if (string.IsNullOrEmpty(payment.PayRoute))
            {
                payment.PayRoute = PayWays.Route_APP;
            }

            payment.BuyerId = MvcContext.Current.PassportId;
            if (payment.TradeType == TradeType.PersonalToPersonal || payment.TradeType == TradeType.PersonalToOrganization)
            {
                payment.OwnerId = payment.BuyerId;
            }
            payment.ClientIP = "8.8.8.8";
            try
            {
                var paymentEngine = ObjectIOCFactory.GetSingleton <PaymentEngine>();
                var signed        = paymentEngine.CreateTrade(payment);
                if (signed)
                {
                    return(new PaymentResult()
                    {
                        Success = true, TradeCode = payment.TradeCode, SignedParams = payment.SignedParams
                    });
                }
                else
                {
                    return(new PaymentResult()
                    {
                        Success = false, ErrorMessage = "Create sign failed."
                    });
                }
            }
            catch (ArgumentOutOfRangeException ex)
            {
                this.ReturnPreconditionFailedMessage(ex.Message);
                return(null);
            }
        }
Esempio n. 26
0
        public void OnStart(ApplicationHost onwer, CommandArguments args)
        {
            try
            {
                var syncSuccessFlag = false;
                while (syncSuccessFlag == false)
                {
                    try
                    {
                        var hostConfig = ObjectIOCFactory.GetSingleton <ServiceHostConfig>();
                        var source     = hostConfig.Host.SourceDirectory;
                        var target     = hostConfig.Host.RunDirectory;
                        if (Directory.Exists(target) == false)
                        {
                            Directory.CreateDirectory(target);
                        }

                        var xcopyArgs = string.Format("{0}\\* {1} /s /y /d", source, target);

                        using (var copyProcess = new Process())
                        {
                            copyProcess.EnableRaisingEvents   = true;
                            copyProcess.StartInfo.FileName    = "xcopy";
                            copyProcess.StartInfo.Arguments   = xcopyArgs;
                            copyProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                            copyProcess.Start();
                            copyProcess.WaitForExit();
                        }

                        this.DeleteTempAppFiles();
                        this.RenameAppFiles();

                        syncSuccessFlag = true;
                    }
                    catch (Exception ex)
                    {
                        LogManager.GetLogger().Error(ex);
                        Console.WriteLine("{0}:{1}", ex.GetType().FullName, ex.Message);
                        Console.WriteLine("StackTrace:{0}", ex.StackTrace);
                        Thread.Sleep(1000);
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.GetLogger().Error(ex);
                Console.WriteLine("Ex:{0}", ex.Message);
                Console.WriteLine("StackTrace:{0}", ex.StackTrace);
                Console.ReadLine();
                return;
            }
        }
Esempio n. 27
0
        /// <summary>
        /// 获取IRepository的实例
        /// </summary>
        /// <returns></returns>
        public static TRepository GetRepository <TRepository>(string categoryName)
        {
            var repositoryFactoryName = string.Concat("RepositoryFactory.", categoryName);

            if (null == TypeExtension.GetMapType(repositoryFactoryName))
            {
                return(ObjectIOCFactory.GetSingleton <TRepository>());
            }
            else
            {
                return(ObjectIOCFactory.GetSingleton <IRepositoryFactory>("RepositoryFactory." + categoryName).GetRepository <TRepository>());
            }
        }
Esempio n. 28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="productCode"></param>
        /// <param name="queryResult"></param>
        /// <returns></returns>
        public static IDictionary <string, object> ParseQueryResult(string productCode, string queryResult)
        {
            queryResult.AssertNotNull("queryResult");

            var client = ObjectIOCFactory.GetSingleton <SinowayClient>();

            if (null == client.ApiProviders || false == client.ApiProviders.ContainsKey(productCode))
            {
                throw new ArgumentOutOfRangeException("productCode", string.Format("Not support the productCode : {0}", productCode));
            }

            return(client.ApiProviders[productCode].ParseQueryResult(queryResult));
        }
        public void GetSingletonTest()
        {
            var poolA = ObjectIOCFactory.GetSingleton <SmartThreadPool>();
            var poolB = ObjectIOCFactory.GetSingleton <SmartThreadPool>();

            Assert.AreEqual(poolA, poolB);


            var processorA = ObjectIOCFactory.GetSingleton <TaskProcessor>();
            var processorB = ObjectIOCFactory.GetSingleton <TaskProcessor>();

            Assert.AreEqual(processorA, processorB);
        }
Esempio n. 30
0
        void DeleteTempAppFiles()
        {
            var hostConfig = ObjectIOCFactory.GetSingleton <ServiceHostConfig>();

            if (Directory.Exists(hostConfig.Host.RunDirectory))
            {
                var searchPattern = string.Format("{0}[*]_{1}.*", this.ApplicationHost.HostProcessName, Path.GetFileNameWithoutExtension(hostConfig.App.ExeFile));
                var appFiles      = Directory.GetFiles(hostConfig.Host.RunDirectory, searchPattern);
                foreach (var appFile in appFiles)
                {
                    File.Delete(appFile);
                }
            }
        }