예제 #1
0
파일: AppAgent.cs 프로젝트: Kjubo/xms.core
		/// <summary>
		/// 从现有AppAgent中创建应用代理块,如果请求中不包含 。
		/// 适用于仅向特定服务的特定方法传播 app-agent 的场景。
		/// </summary>
		/// <returns></returns>
		public static AppAgentScope CreateFromExistsAppAgent(AppAgent agent)
		{
			if (agent == null)
			{
				throw new ArgumentNullException("agent");
			}

			return new AppAgentScope(agent.Name, agent.Version, agent.Platform, agent.IsMobileDevice, agent.MobileDeviceManufacturer, agent.MobileDeviceModel, agent.MobileDeviceId);
		}
예제 #2
0
파일: AppAgent.cs 프로젝트: Kjubo/xms.core
		private static AppAgent ParseComplex(string agentStr)
		{
			if (!String.IsNullOrEmpty(agentStr))
			{
				Match match = regexAgent.Match(agentStr);
				if (match.Success)
				{
					AppAgent agent = new AppAgent(false, agentStr);
					agent.name = match.Groups[1].Value;
					agent.version = match.Groups[2].Value;

					agent.allProperties.Add("appName", agent.name);
					agent.allProperties.Add("appVersion", agent.version);

					if (!String.IsNullOrEmpty(match.Groups[5].Value))
					{
						for (int i = 0; i < match.Groups[6].Captures.Count; i++)
						{
							agent.allProperties.Add(match.Groups[6].Captures[i].Value, match.Groups[7].Captures[i].Value);

							switch (match.Groups[6].Captures[i].Value.ToLower())
							{
								case "platform":
									agent.platform = match.Groups[7].Captures[i].Value;
									break;
								case "mobiledevice":
									string[] mobileDevices = match.Groups[7].Captures[i].Value.Split('/');
									agent.mobileDeviceManufacturer = mobileDevices.Length > 0 ? HttpUtility.UrlDecode(mobileDevices[0], Encoding.UTF8) : null;
									agent.mobileDeviceModel = mobileDevices.Length > 1 ? HttpUtility.UrlDecode(mobileDevices[1], Encoding.UTF8) : null;
									break;
								case "mobiledeviceid":
									agent.isMobileDevice = true;
									agent.mobileDeviceId = match.Groups[7].Captures[i].Value;
									break;
								default:
									break;
							}
						}
					}
					return agent;
				}
			}
			return null;
		}
예제 #3
0
파일: AppAgent.cs 프로젝트: Kjubo/xms.core
		private static AppAgent ParseSimple(string agentStr)
		{
			if (!String.IsNullOrEmpty(agentStr))
			{
				Match match = regexAgentSimple.Match(agentStr);
				if (match.Success)
				{
					AppAgent agent = new AppAgent(false, agentStr);
					agent.name = match.Groups[1].Value;
					agent.version = match.Groups[2].Value;

					agent.allProperties.Add(SimpleAppAgentDescription.Instance.AppNameKey, agent.name);
					agent.allProperties.Add(SimpleAppAgentDescription.Instance.AppVersionKey, agent.version);

					if (!String.IsNullOrEmpty(match.Groups[5].Value))
					{
						System.Text.RegularExpressions.CaptureCollection captures = match.Groups[6].Captures;
						for(int i=0; i<captures.Count; i++)
						{
							if( i < SimpleAppAgentDescription.Instance.ExtendPropertyKeys.Count)
							{
								string[] values = captures[i].Value.Split('/');
								for(int j=0; j<values.Length; j++)
								{
									if(j < SimpleAppAgentDescription.Instance.ExtendPropertyKeys[i].Length)
									{
										agent.allProperties.Add(SimpleAppAgentDescription.Instance.ExtendPropertyKeys[i][j], values[j]);

										switch (SimpleAppAgentDescription.Instance.ExtendPropertyKeys[i][j].ToLower())
										{
											case "platform":
												agent.platform = values[j];
												break;
											case "mobiledevicemanufacturer":
												agent.mobileDeviceManufacturer = HttpUtility.UrlDecode(values[j], Encoding.UTF8);
												break;
											case "mobiledevicemodel":
												agent.mobileDeviceModel = HttpUtility.UrlDecode(values[j], Encoding.UTF8);
												break;
											case "mobiledeviceid":
												agent.isMobileDevice = true;
												agent.mobileDeviceId = values[j];
												break;
											default:
												break;
										}
									}
								}
							}
						}
					}
					return agent;
				}
			}

			return null;
		}
예제 #4
0
파일: AppAgent.cs 프로젝트: Kjubo/xms.core
		/// <summary>
		/// 从请求中获取应用代理对象。
		/// </summary>
		/// <returns></returns>
		internal static AppAgent GetFromRequest(HttpContext httpContext, OperationContext operationContext)
		{
			AppAgent agent = null;

			if (operationContext != null)
			{
				int headerIndex = operationContext.IncomingMessageHeaders.FindHeader(XMS.Core.WCF.AppAgentHeader.Name, XMS.Core.WCF.AppAgentHeader.NameSpace);
				if (headerIndex >= 0)
				{
					agent = Parse(operationContext.IncomingMessageHeaders.GetHeader<string>(headerIndex));
					if (agent != null)
					{
						return agent;
					}
				}

				if (operationContext.IncomingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name))
				{
					HttpRequestMessageProperty requestMessageProperty = operationContext.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
					if (requestMessageProperty != null)
					{
						agent = Parse(requestMessageProperty.Headers.Get(XMS.Core.WCF.AppAgentHeader.Name));
						if (agent != null)
						{
							return agent;
						}
					}
				}
			}

			if (httpContext != null)
			{
				System.Web.HttpRequest httpRequest = httpContext.TryGetRequest();

				if (httpRequest != null)
				{
					// 从查询参数中获取代理并用完整模式解析
					agent = Parse(httpRequest[XMS.Core.WCF.AppAgentHeader.Name]);

					if (agent == null)
					{
						// 从Asp.Net底层生成代理
						agent = new AppAgent(false, null);

						agent.name = httpRequest.Browser.Browser;
						agent.version = httpRequest.Browser.Version;
						agent.platform = httpRequest.Browser.Platform;
						agent.isMobileDevice = httpRequest.Browser.IsMobileDevice;
						agent.mobileDeviceModel = httpRequest.Browser.MobileDeviceModel;
						agent.mobileDeviceManufacturer = httpRequest.Browser.MobileDeviceManufacturer;
						agent.mobileDeviceId = httpRequest["DeviceID"];
					}

					return agent;
				}
			}

			if (agent == null)
			{
				return AppAgent.Empty;
			}

			return agent;
		}
예제 #5
0
		internal void InitAppAgent(string appName, string appVersion, string platform, bool isMobileDevice, string manufacturer, string model, string deviceId)
		{
			if (this.appAgent == null)
			{
				this.appAgent = new AppAgent(appName, appVersion, platform, isMobileDevice, manufacturer, model, deviceId);
			}
		}
예제 #6
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="httpContext"></param>
		/// <param name="operationContext"></param>
		private SecurityContext(HttpContext httpContext, OperationContext operationContext)
		{
			this.user = UserPrincipal.GetFromRequest(httpContext, operationContext);
			this.ip = GetUserIPFromRequest(httpContext, operationContext);
			this.appAgent = AppAgent.GetFromRequest(httpContext, operationContext);

			this.invokeChain = ServiceInvokeChain.GetFromRequest(httpContext, operationContext);
		}