/// <summary> /// Create new session attribute from session description field. /// </summary> /// <param name="sessionDescriptionField">Session description field.</param> /// <returns>Session attribute object.</returns> /// <exception cref="SdpFormatException">Invalid format of session description field.</exception> public static SessionAttribute CreateAttribute(string sessionDescriptionField) { string fieldValue = GetFieldValue(sessionDescriptionField); string[] attributeValues = fieldValue.Split(new char[] { ':' }, 2, StringSplitOptions.None); SessionAttribute at; switch (attributeValues.Length) { case 1: // flag attribute at = new SessionAttribute(attributeValues[0]); break; case 2: // value attribute at = new SessionAttribute(attributeValues[0], attributeValues[1]); break; default: throw new SdpFormatException("Invalid format of SDP attribute."); } at.OriginalField = sessionDescriptionField; return(at); }
protected void set(object value) { StackFrame caller = new StackFrame(1); MethodBase method = caller.GetMethod(); string propName = method.Name.Substring(4); Type type = method.ReflectedType; PropertyInfo pi = type.GetProperty(propName); object[] attributes = pi.GetCustomAttributes(typeof(SessionAttribute), true); if (attributes != null && attributes.Length == 1) { SessionAttribute ssAttr = attributes[0] as SessionAttribute; Session[ssAttr.Key] = value; } }
protected dynamic get() { StackFrame caller = new StackFrame(1); MethodBase method = caller.GetMethod(); string propName = method.Name.Substring(4); Type type = method.ReflectedType; PropertyInfo pi = type.GetProperty(propName); object[] attributes = pi.GetCustomAttributes(typeof(SessionAttribute), true); if (attributes != null && attributes.Length == 1) { SessionAttribute ssAttr = attributes[0] as SessionAttribute; if (Session.ContainsKey(ssAttr.Key)) { return(Session[ssAttr.Key]); } } return(default(dynamic)); }
public void Specificationhelper_CreateSessionAttribute_Success() { // *** ARRANGE *** string flagAtField = "a=recvonly"; string varAtField = "a=path:msrp://bobpc.example.com:8888/9di4ea;tcp"; SessionAttribute flagAtExpected = new SessionAttribute("recvonly"); SessionAttribute varAtExpected = new SessionAttribute("path", "msrp://bobpc.example.com:8888/9di4ea;tcp"); // *** ACT *** SessionAttribute flagAtResult = SpecificationHelpers.CreateAttribute(flagAtField); SessionAttribute varAtResult = SpecificationHelpers.CreateAttribute(varAtField); // *** ASSERT *** string efEncoded = flagAtExpected.Encode(); string rfEncoded = flagAtResult.Encode(); Assert.Equal(efEncoded, rfEncoded); string evEncoded = varAtExpected.Encode(); string rvEncoded = varAtResult.Encode(); Assert.Equal(evEncoded, rvEncoded); }
public static ErrorCode AddSessionAttribute(SessionAttribute sessionAttribute) { return(new ErrorCode()); }