Exemple #1
0
        /// <summary>
        /// Business logic: If we are replacing A with AB then recurring replacing call will generae ABBB...B
        /// So if replaceString contains targetString, replace all replaceString with targetString then again do the reverse
        /// </summary>
        /// <param name="targetString"></param>
        /// <param name="replaceString"></param>
        public void ReplaceText(string targetString, string replaceString)
        {
            if (replaceString.ToLower().Contains(targetString.ToLower()))
            {
                // targetString = Software People, replaceString = Software People Bangladesh
                // First replace all "Software People Bangladesh" with "Software People"
                Processer.ReplaceText(document, replaceString: targetString, matchString: replaceString);

                // After that replace all "Software People" with "Software People Bangladesh"
            }

            Processer.ReplaceText(document, targetString, replaceString);
        }
        private void ProcessCommands()
        {
            if (m_processer == null)
            {
                m_processer = new Processer <GameCommandBase>(info.buff.Commands);
            }

            if (info.remainingTime < 0 || info.layCount <= 0)
            {
                OnBuffEffectEnded?.Invoke(this);
                return;
            }

            OnBuffEffectPreStart?.Invoke(this);

            m_currentProcesserTimes = 0;
            m_processer.Start(OnBuffEnded);
        }
        static void Main()
        {
            using (var logger = new LoggerConfiguration()
                                .MinimumLevel.Debug()
                                .ReadFrom.AppSettings()
                                .WriteTo.Console()
                                .CreateLogger())
            {
                Log.Logger = logger;

                Log.Logger.Information("-------Starting Application-------");

                try
                {
                    var serviceBusConfiguration = new ServiceBusConfiguration(ConfigurationManager.AppSettings, ConfigurationManager.ConnectionStrings);

                    using (var activator = new BuiltinHandlerActivator())
                    {
                        Configure.With(activator)
                        .Logging(l => l.Serilog(Log.Logger))
                        .Transport(t => t.UseMsmq(serviceBusConfiguration.Queue))
                        .Subscriptions(s => s.StoreInSqlServer(serviceBusConfiguration.BackPlaneSqlConnectionString, serviceBusConfiguration.BackPlaneDatabaseTableName, isCentralized: true))
                        .Start();

                        Task.Run(async() =>
                        {
                            await Processer.Process(serviceBusConfiguration, activator);
                        })
                        .Wait();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Something went wrong");
                }
                finally
                {
                    Log.CloseAndFlush();
                    Log.Logger.Information("-------Closing Application-------");
                }
            }
        }
        public static HttpReturn Request(HttpRequest request, HttpMessage httpMessage, HttpTag httpTag)
        {
            var requestInfo = new RequestInfo()
            {
                HttpRequest = request,
                HttpTag     = httpTag,
            };

            try
            {
                if (httpMessage == null)
                {
                    throw new Exception(string.Format("找不到相关接口配置,未调用接口.AppID:{0},Method:{1},Version:{2}", request.AppID, request.Method, httpTag.Version));
                }
                else
                {
                    requestInfo.HttpMessage = httpMessage;
                }
                #region 状态禁用禁止调用

                if (httpMessage.Status != Status.Normal)
                {
                    return(new HttpReturn()
                    {
                        Method = httpMessage.Method,
                        Url = httpMessage.Url,
                        AppID = httpMessage.AppID,
                        HttpMethod = httpMessage.HttpType.ToString(),
                        RequestObjs = new List <string>(),
                        Exception = "",
                        ExceptionMessage = "接口被禁用,禁止调用",
                        Response = "",
                        ResponseEncrypt = "",
                        RequestEncrypt = "",
                        Request = "",
                        Moudle = httpMessage.Moudle,
                        StatusCode = 0,
                    });
                }

                #endregion

                if (httpMessage.InterfaceArgsCount != requestInfo.HttpRequest.RequestObjs.Count)
                {
                    throw new BException("请求参数数量异常!");
                }

                #region 判断参数类型和是否为空
                var args = httpMessage.GetInterfaceArgs();
                for (int i = 0; i < args.Count; i++)
                {
                    var arg = args[i];
                    var obj = requestInfo.HttpRequest.RequestObjs[i].Trim();
                    if (arg.IsAllowNull == false)
                    {
                        if (string.IsNullOrWhiteSpace(obj))
                        {
                            var err = arg.Name + "为空";
                            if (httpMessage.IsValid)
                            {
                                var e = httpMessage.GetWsExcepitons().FirstOrDefault(r => r.Name == err);
                                if (e != null)
                                {
                                    throw new BException(e.Value.Trim());
                                }
                            }
                            throw new BException(err);
                        }
                    }
                    if (string.IsNullOrWhiteSpace(obj) == false)
                    {
                        if (arg.Type != "String")
                        {
                            #region 类型判断
                            var isNoneError = true;
                            if (arg.Type == "Guid")
                            {
                                Guid t;
                                isNoneError &= Guid.TryParse(obj, out t);
                            }
                            else if (arg.Type == "Boolean")
                            {
                                isNoneError &= (obj.ToLower() == "true" || obj.ToLower() == "false");
                            }
                            else if (arg.Type == "Int32")
                            {
                                int t;
                                isNoneError &= int.TryParse(obj, out t);
                            }
                            else if (arg.Type == "Decimal")
                            {
                                decimal t;
                                isNoneError &= decimal.TryParse(obj, out t);
                            }
                            else if (arg.Type == "Double")
                            {
                                double t;
                                isNoneError &= double.TryParse(obj, out t);
                            }
                            else if (arg.Type == "Int32[]")
                            {
                                var arr = obj.Split(',');
                                foreach (var item in arr)
                                {
                                    int t;
                                    isNoneError &= int.TryParse(item, out t);
                                }
                            }
                            else if (arg.Type == "Guid[]")
                            {
                                var arr = obj.Split(',');
                                foreach (var item in arr)
                                {
                                    Guid t;
                                    isNoneError &= Guid.TryParse(item, out t);
                                }
                            }
                            if (isNoneError == false)
                            {
                                var err = arg.Name + "类型错误";
                                if (httpMessage.IsValid)
                                {
                                    var e = httpMessage.GetWsExcepitons().FirstOrDefault(r => r.Name == err);
                                    if (e != null)
                                    {
                                        throw new BException(e.Value.Trim());
                                    }
                                }
                                throw new BException(err);
                            }
                            #endregion
                        }
                        else
                        {
                            if (arg.MaxLength.HasValue)
                            {
                                if (obj.Length > arg.MaxLength.Value)
                                {
                                    throw new BException(arg.Name + "最大长度为:" + arg.MaxLength + ",当前长度为:" + obj.Length);
                                }
                            }
                        }
                    }
                }
                #endregion

                #region 计算配置

                if (httpConfigs.Count == 0 || DateTime.Now.Subtract(time).TotalMinutes > 3)
                {
                    ProcessConfig();
                }
                if (httpMessage.Url.Contains(httpConfigPrefix))
                {
                    var url = string.Join("/", httpMessage.Url.Split('/').Select(ProcessUrlSegment));
                    httpMessage.Url = url;
                }
                #endregion

                requestInfo.Start();
                return(Processer.Process(requestInfo));
            }
            catch (Exception ex)
            {
                if (ex is BException)
                {
                    return(new HttpReturn()
                    {
                        Exception = ex.GetType().Name,
                        ExceptionMessage = ex.Message.Replace("601|", ""),
                        HttpMethod = "",
                        AppID = request.AppID,
                        Method = request.Method,
                        Request = "",
                        RequestObjs = request.RequestObjs,
                        Response = "",
                        Url = "",
                        Moudle = "",
                        ResponseEncrypt = "",
                        RequestEncrypt = "",
                        StatusCode = 601
                    });
                }
                else if (ex is IDRefException)
                {
                    return(new HttpReturn()
                    {
                        Exception = ex.GetType().Name,
                        ExceptionMessage = ex.Message.Replace("804|", ""),
                        HttpMethod = "",
                        AppID = request.AppID,
                        Method = request.Method,
                        Request = "",
                        RequestObjs = request.RequestObjs,
                        Response = "",
                        Url = "",
                        Moudle = "",
                        ResponseEncrypt = "",
                        RequestEncrypt = "",
                        StatusCode = 804
                    });
                }
                else
                {
                    return(new HttpReturn()
                    {
                        Exception = ex.GetType().Name,
                        ExceptionMessage = ex.Message,
                        HttpMethod = "",
                        AppID = request.AppID,
                        Method = request.Method,
                        Request = "",
                        RequestObjs = request.RequestObjs,
                        Response = "",
                        Url = "",
                        Moudle = "",
                        ResponseEncrypt = "",
                        RequestEncrypt = "",
                        StatusCode = 0
                    });
                }
            }
        }
Exemple #5
0
 public void Add(uint id, Processer processer)
 {
     _processers.Add(id, processer);
 }
Exemple #6
0
 public DefaultConfigLoader(IFileReaderFactory factory)
 {
     _factory   = factory;
     _processor = new ConfigTextMemoryStreamProcessor <DefaultConfigBuilder, Entities.Config>();
 }
		public async Task CommandRecivedTest()
		{
			bool called = false;
			CommandArgs expected = new CommandArgs();
			expected.Type = CommandType.Get;
			expected.Command = Command.RGBLed;
			expected.Value = new byte[] { 122, 30, 112 };

			var bytes = generatePacket(expected);
			MemoryStream stream = new MemoryStream(bytes);
			stream.Seek(0, SeekOrigin.Begin);
			Processer processer = new Processer();
			processer.CommandRecived += (sender, actual) =>
				{
					called = true;
					Assert.AreEqual(expected.Type, actual.Type, "actual.Type");
					Assert.AreEqual(expected.Command, actual.Command, "actual.Command");
					Assert.AreEqual(expected.Value.Length, actual.Value.Length, "actual.Value.Length");
					for (int i = 0; i < actual.Value.Length; i++)
					{
						Assert.AreEqual(expected.Value[i], actual.Value[i], "actual.Value[i]");
					}
				};
			processer.SetInputStream(stream);
			await Task.Delay(500); // Delay to make sure the data has been read in by the processInput Task
			Assert.IsTrue(called, "called");
		}
		public async Task SendCommandAsyncTest()
		{
			CommandArgs args = new CommandArgs();
			args.Type = CommandType.Set;
			args.Command = Command.Relay;
			args.Value = new byte[] { 243, 221, 255 };

			var expected = generatePacket(args);
			Processer processer = new Processer();
			MemoryStream outstream = new MemoryStream();
			processer.SetOutputStream(outstream);
			await processer.SendCommandAsync(args);

			var actual = outstream.ToArray();

			Assert.IsNotNull(actual);
			Assert.AreEqual(expected.Length, actual.Length, "actual.Length");
			for (int i = 0; i < actual.Length; i++)
			{
				Assert.AreEqual(expected[i], actual[i], "actual[i]");
			}
		}