Beispiel #1
0
        // Token: 0x060002D6 RID: 726 RVA: 0x0000E814 File Offset: 0x0000CA14
        private static void TraceDiffs(NameObjectCollectionBase original, NameObjectCollectionBase revised, HashSet <string> notInterestingNames, StringBuilder result)
        {
            HashSet <string> hashSet = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

            foreach (object obj in original)
            {
                string text = (string)obj;
                if (!notInterestingNames.Contains(text))
                {
                    string value  = PfdTracer.GetValue(revised, text);
                    string value2 = PfdTracer.GetValue(original, text);
                    if (value == null)
                    {
                        result.Append("-" + text + ",");
                    }
                    else
                    {
                        hashSet.Add(text);
                        if (string.Compare(value2, value, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            result.Append("*" + text + ",");
                        }
                    }
                }
            }
            foreach (object obj2 in revised)
            {
                string text2 = (string)obj2;
                if (!notInterestingNames.Contains(text2) && !hashSet.Contains(text2))
                {
                    result.Append("+" + text2 + ",");
                }
            }
        }
Beispiel #2
0
 public AppContext(HttpContext httpContext, string currentUserId, string currentUserName) : this(currentUserId, currentUserName)
 {
     this._SessionWrapper = new SessionWrapper(httpContext.Session);
     this._Items          = httpContext.Items;
     this._Application    = httpContext.Application;
     httpContext.Items[HTTP_CONTEXT_KEY] = this;
 }
Beispiel #3
0
        public void WriteData(AMFWriter writer, object data)
        {
            NameObjectCollectionBase base2 = data as NameObjectCollectionBase;

            object[] customAttributes = base2.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if ((customAttributes != null) && (customAttributes.Length > 0))
            {
                DefaultMemberAttribute attribute = customAttributes[0] as DefaultMemberAttribute;
                PropertyInfo           property  = base2.GetType().GetProperty(attribute.MemberName, new Type[] { typeof(string) });
                if (property != null)
                {
                    ASObject obj2 = new ASObject();
                    for (int i = 0; i < base2.Keys.Count; i++)
                    {
                        string key  = base2.Keys[i];
                        object obj3 = property.GetValue(base2, new object[] { key });
                        obj2.Add(key, obj3);
                    }
                    writer.WriteByte(10);
                    writer.WriteAMF3Object(obj2);
                    return;
                }
            }
            writer.WriteByte(10);
            writer.WriteAMF3Object(data);
        }
Beispiel #4
0
        public void WriteData(AMFWriter writer, object data)
        {
            NameObjectCollectionBase collection = data as NameObjectCollectionBase;

            object[] attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if (attributes != null && attributes.Length > 0)
            {
                DefaultMemberAttribute defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
                PropertyInfo           pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new Type[] { typeof(string) });
                if (pi != null)
                {
                    ASObject aso = new ASObject();
                    for (int i = 0; i < collection.Keys.Count; i++)
                    {
                        string key   = collection.Keys[i];
                        object value = pi.GetValue(collection, new object[] { key });
                        aso.Add(key, value);
                    }
                    writer.WriteByte(AMF3TypeCode.Object);
                    writer.WriteAMF3Object(aso);
                    return;
                }
            }

            //We could not access an indexer so write out as it is.
            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(data);
        }
Beispiel #5
0
        public void WriteData(AMFWriter writer, object data)
        {
            NameObjectCollectionBase collection = data as NameObjectCollectionBase;

            object[] attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if (attributes != null && attributes.Length > 0)
            {
                DefaultMemberAttribute defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
                PropertyInfo           pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new Type[] { typeof(string) });
                if (pi != null)
                {
                    ASObject aso = new ASObject();

                    IEnumerator enumList = collection.Keys.GetEnumerator();

                    //为了兼容 webplayer 和手机 platform 而改掉的代码,原来的代码见后面的注释内容.
                    while (enumList.MoveNext())
                    {
                        string key   = enumList.Current as string;
                        object value = pi.GetValue(collection, new object[] { key });

                        aso.Add(key, value);
                    }
                    writer.WriteByte(AMF3TypeCode.Object);
                    writer.WriteAMF3Object(aso);
                    return;
                }
            }

            //We could not access an indexer so write out as it is.
            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(data);
        }
Beispiel #6
0
        private static void XmlSerializeNameObjects(XmlWriter writer, NameObjectCollectionBase obj, Type valueType)
        {
            Type objType = obj.GetType();

            writer.WriteStartElement(GetCleanName(objType.Name));
            bool writeValueType = (valueType == null) || valueType.Equals(Generic <object> .Type);

            if (!writeValueType)
            {
                writer.WriteAttributeString("valueType", GetTypeName(valueType));
            }
            object[] values = objType.GetMethod("BaseGetAllValues", BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null).Invoke(obj, null) as object[];
            for (int i = 0; i < values.Length; i++)
            {
                writer.WriteStartElement("Item");
                writer.WriteAttributeString("name", obj.Keys[i]);
                if (values[i] != null)
                {
                    Type type = values[i].GetType();
                    if (!((!writeValueType && (type == valueType)) || IsKnownType(type)))
                    {
                        writer.WriteAttributeString("valueType", GetTypeName(type));
                    }
                }
                XmlWriterSerialize(writer, values[i], valueType);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
        }
Beispiel #7
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="collection"></param>
 public NameValueEnumerator(NameObjectCollectionBase collection)
 {
     _collection = collection;
     _nv         = collection as NameValueCollection;
     _index      = -1;
     _count      = collection.Count;
     Error       = null;
 }
Beispiel #8
0
 public AppContext(string currentUserId, string currentUserName)
 {
     _Context             = this;
     this._SessionWrapper = new SessionWrapper();
     this._Items          = new Dictionary <string, object>();
     this._Application    = new NameObjectCollection();
     CurrentUserId        = currentUserId;
     CurrentUserName      = currentUserName;
 }
Beispiel #9
0
 public static IReadOnlyCollection <string> Keys(
     [NotNull] this NameObjectCollectionBase nameObjectCollection)
 {
     if (nameObjectCollection == null)
     {
         throw new ArgumentNullException(nameof(nameObjectCollection));
     }
     return(nameObjectCollection.Keys.Cast <string>().ToArray());
 }
        private static void VerifyGetAllValues(NameObjectCollectionBase nameObjectCollection, Array values)
        {
            Assert.Equal(nameObjectCollection.Count, values.Length);

            for (int i = 0; i < values.Length; i++)
            {
                Assert.Equal(new Foo("Value_" + i), values.GetValue(i));
            }
        }
        private static void VerifyGetAllValues(NameObjectCollectionBase nameObjectCollection, Array values)
        {
            Assert.Equal(nameObjectCollection.Count, values.Length);

            for (int i = 0; i < values.Length; i++)
            {
                Assert.Equal(new Foo("Value_" + i), values.GetValue(i));
            }
        }
 /// <summary>
 /// 获取序列中符合条件的第一个元素,如果序列中不包含指定条件的元素,则返回默认值
 /// </summary>
 /// <typeparam name="T">泛型</typeparam>
 /// <param name="collection">名称对象集合</param>
 /// <param name="filter">过滤条件</param>
 /// <returns></returns>
 public static T FirstOrDefault <T>(this NameObjectCollectionBase collection, Func <T, bool> filter)
 {
     foreach (T item in collection)
     {
         if (filter(item))
         {
             return(item);
         }
     }
     return(default(T));
 }
Beispiel #13
0
 public static IReadOnlyDictionary <string, object> ToDictionary(
     [NotNull] this NameObjectCollectionBase nameObjectCollection)
 {
     if (nameObjectCollection == null)
     {
         throw new ArgumentNullException(nameof(nameObjectCollection));
     }
     // ReSharper disable EventExceptionNotDocumented
     return(_getEntriesFunc(nameObjectCollection)
            .Cast <object>()
            .ToDictionary(_getNameObjectEntryKeyFunc, _getNameObjectEntryValueFunc));
     // ReSharper restore EventExceptionNotDocumented
 }
Beispiel #14
0
 public static IReadOnlyCollection <object> Values(
     [NotNull] this NameObjectCollectionBase nameObjectCollection)
 {
     if (nameObjectCollection == null)
     {
         throw new ArgumentNullException(nameof(nameObjectCollection));
     }
     // ReSharper disable EventExceptionNotDocumented
     return(_getEntriesFunc(nameObjectCollection)
            .Cast <object>()
            .Select(_getNameObjectEntryValueFunc)
            .ToArray());
     // ReSharper restore EventExceptionNotDocumented
 }
Beispiel #15
0
        public static string Join(this NameObjectCollectionBase c, string separator = ";", Func <string, object, string> transform = null)
        {
            var sb = new StringBuilder();
            Func <string, object, string> _transform = (key, value) =>
            {
                var _result = transform == null ? $"{key}={value}{separator}" : transform(key, value);

                return(_result ?? $"{key}={value}{separator}");
            };
            var i = 0;

            foreach (var obj in c)
            {
                sb.Append(_transform(c.Keys[i++], obj));
            }

            return(sb.ToString());
        }
Beispiel #16
0
        private static StringBuilder ToJsonString(NameObjectCollectionBase collection, Json json, StringBuilder builder)
        {
            if (builder == null)
            {
                builder = new StringBuilder();
            }

            builder.Append("[");
            foreach (object obj in collection.Keys)
            {
                builder.Append(ToJsonString(obj) + ": " + ToJsonString(json.BaseGet(obj + string.Empty)) + ", ");
            }
            if (builder.Length > 2)
            {
                builder.Remove(builder.Length - 2, 2);
            }
            builder.Append(" ]");
            return(builder);
        }
Beispiel #17
0
        private static object XmlDeserializeNameObjects(XmlReader reader, Type objType, Type valueType)
        {
            string key;
            object value;
            Type   itemValueType;
            NameObjectCollectionBase obj = Activator.CreateInstance(objType) as NameObjectCollectionBase;
            MethodInfo baseSet           = objType.GetMethod("BaseSet", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { Generic <string> .Type, Generic <object> .Type }, null);

            XmlDeserializeChildElements(reader, delegate(XmlReader _reader, object[] args)
            {
                itemValueType = TryGetType(reader, "valueType", valueType);
                key           = reader["name"];
                if (reader.Read())
                {
                    value = XmlReaderDeserialize(reader, itemValueType);
                    baseSet.Invoke(obj, new object[] { key, value });
                }
            }, new object[0]);
            return(obj);
        }
        private IDictionary <string, string> Convert(Func <dynamic, NameObjectCollectionBase> collectionGetter, Func <NameObjectCollectionBase, object, string> valueFromCollectionGetter = null)
        {
            if (this.httpContext == null)
            {
                return(null);
            }

            if (valueFromCollectionGetter == null)
            {
                valueFromCollectionGetter = (c, key) => ((NameValueCollection)c)[key.ToString()];
            }

            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            try
            {
                NameObjectCollectionBase collection = collectionGetter.Invoke(this.httpContext);

                foreach (var key in collection.Keys)
                {
                    string stringKey = key as string;

                    // NOTE: Ignore these keys as they just add duplicate information. [asbjornu]
                    if (stringKey == "ALL_HTTP" || stringKey == "ALL_RAW")
                    {
                        continue;
                    }

                    var value = valueFromCollectionGetter(collection, key);
                    dictionary.Add(key.ToString(), value);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            return(dictionary);
        }
        private IDictionary <string, string> Convert(Func <dynamic, NameObjectCollectionBase> collectionGetter, Func <NameObjectCollectionBase, object, string> valueFromCollectionGetter = null)
        {
            if (httpContext == null)
            {
                return(Enumerable.Empty <string>().ToDictionary(x => x, x => x));
            }

            if (valueFromCollectionGetter == null)
            {
                valueFromCollectionGetter = (c, key) => ((NameValueCollection)c)[key.ToString()];
            }

            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            try
            {
                NameObjectCollectionBase collection = collectionGetter.Invoke(this.httpContext);

                foreach (string key in collection.Keys)
                {
                    // NOTE: Ignore these keys as they just add duplicate information. [asbjornu]
                    if ("ALL_HTTP".Equals(key, StringComparison.OrdinalIgnoreCase) || "ALL_RAW".Equals(key, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var value = valueFromCollectionGetter(collection, key);
                    dictionary.Add(key.ToString(), value);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            return(dictionary);
        }
 internal KeysCollection(NameObjectCollectionBase collection)
 {
     _collection = collection;
 }
Beispiel #21
0
 public static void UnlockAndAdd([NotNull] this NameObjectCollectionBase thisValue, [NotNull] params (string, object)[] values)
Beispiel #22
0
 public static void UnlockAndAdd([NotNull] this NameObjectCollectionBase thisValue, [NotNull] string name, object value)
 {
     UnlockAndAdd(thisValue, (name, value));
 }
 // Methods
 internal KeysCollection(NameObjectCollectionBase coll)
 {
     this._coll = coll;
 }
Beispiel #24
0
 protected virtual void OnRequestReceived(NameObjectCollectionBase request)
 => invokeEventHandler(RequestReceived, request);
Beispiel #25
0
 /// <summary>
 /// Determines whether security token request contains parameter with specified key.
 /// </summary>
 /// <param name="collection">Security token request parameters.</param>
 /// <param name="key">Parameter key.</param>
 /// <returns>
 ///     <c>true</c> if security token request contains parameter with key; otherwise, <c>false</c>.
 /// </returns>
 protected static bool ContainsKey(NameObjectCollectionBase collection, string key)
 {
     return(collection.Keys.Cast <string>().Any(ckey => ckey.Equals(key, StringComparison.Ordinal)));
 }
Beispiel #26
0
        /// <summary>
        /// 获取某个属性的值
        /// </summary>
        /// <param name="container">数据源</param>
        /// <param name="propName">属性名</param>
        /// <param name="exist">是否存在此属性</param>
        /// <returns>属性值</returns>
        internal static object GetPropertyValue(object container, string propName, out bool exist)
        {
            exist = false;
            object value = null;

            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (string.IsNullOrEmpty(propName))
            {
                throw new ArgumentNullException("propName");
            }
            if (Utility.IsInteger(propName))
            {
                #region 索引值部分
                //属性名只为数字.则取数组索引
                int index = Utility.ConverToInt32(propName);
                if (container is IList)
                {
                    IList iList = (IList)container;
                    if (iList.Count > index)
                    {
                        exist = true;
                        value = iList[index];
                    }
                }
                else if (container is ICollection)
                {
                    ICollection ic = (ICollection)container;
                    if (ic.Count > index)
                    {
                        exist = true;
                        IEnumerator ie = ic.GetEnumerator();
                        int         i  = 0;
                        while (i++ <= index)
                        {
                            ie.MoveNext();
                        }
                        value = ie.Current;
                    }
                }
                else
                {
                    //判断是否含有索引属性
                    PropertyInfo item = container.GetType().GetProperty("Item", new Type[] { typeof(int) });
                    if (item != null)
                    {
                        try
                        {
                            value = item.GetValue(container, new object[] { index });
                            exist = true;
                        }
                        catch
                        {
                            exist = false;
                        }
                    }
                }
                #endregion
            }
            else
            {
                #region 字段/属性/键值
                //容器是类型.则查找静态属性或字段
                Type         type  = container is Type ? (Type)container : container.GetType();
                BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase;
                if (!(container is Type))
                {
                    flags |= BindingFlags.Instance;
                }

                //查找字段
                FieldInfo field = type.GetField(propName, flags);
                if (field != null)
                {
                    exist = true;
                    value = field.GetValue(container);
                }
                else
                {
                    //查找属性
                    PropertyInfo property = type.GetProperty(propName, flags, null, null, Type.EmptyTypes, new ParameterModifier[0]);
                    if (property != null)
                    {
                        exist = true;
                        value = property.GetValue(container, null);
                    }
                    else if (container is ICustomTypeDescriptor)
                    {
                        //已实现ICustomTypeDescriptor接口
                        ICustomTypeDescriptor ictd       = (ICustomTypeDescriptor)container;
                        PropertyDescriptor    descriptor = ictd.GetProperties().Find(propName, true);
                        if (descriptor != null)
                        {
                            exist = true;
                            value = descriptor.GetValue(container);
                        }
                    }
                    else if (container is IDictionary)
                    {
                        //是IDictionary集合
                        IDictionary idic = (IDictionary)container;
                        if (idic.Contains(propName))
                        {
                            exist = true;
                            value = idic[propName];
                        }
                    }
                    else if (container is NameObjectCollectionBase)
                    {
                        //是NameObjectCollectionBase派生对象
                        NameObjectCollectionBase nob = (NameObjectCollectionBase)container;

                        //调用私有方法
                        MethodInfo method = nob.GetType().GetMethod("BaseGet", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string) }, new ParameterModifier[] { new ParameterModifier(1) });
                        if (method != null)
                        {
                            value = method.Invoke(container, new object[] { propName });
                            exist = value != null;
                        }
                    }
                    else
                    {
                        //判断是否含有索引属性
                        PropertyInfo item = type.GetProperty("Item", new Type[] { typeof(string) });
                        if (item != null)
                        {
                            try
                            {
                                value = item.GetValue(container, new object[] { propName });
                                exist = true;
                            }
                            catch
                            {
                                exist = false;
                            }
                        }
                    }
                }
                #endregion
            }
            return(value);
        }
Beispiel #27
0
        /// <summary>
        /// 获取某个属性的值
        /// </summary>
        /// <param name="container">数据源</param>
        /// <param name="propName">属性名</param>
        /// <param name="exist">是否存在此属性</param>
        /// <returns>属性值</returns>
        internal static object GetPropertyValue(object container, string propName, out bool exist)
        {
            exist = false;
            object value = null;

            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            if (string.IsNullOrEmpty(propName))
            {
                throw new ArgumentNullException("propName");
            }
            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(container).Find(propName, true);

            if (descriptor != null)
            {
                exist = true;
                value = descriptor.GetValue(container);
            }
            else if (container is IDictionary)
            {
                //是IDictionary集合
                IDictionary idic = (IDictionary)container;
                if (idic.Contains(propName))
                {
                    exist = true;
                    value = idic[propName];
                }
            }
            else if (container is NameObjectCollectionBase)
            {
                NameObjectCollectionBase nob = (NameObjectCollectionBase)container;
                MethodInfo method            = nob.GetType().GetMethod("BaseGet", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(string) }, new ParameterModifier[] { new ParameterModifier(1) });
                if (method != null)
                {
                    value = method.Invoke(container, new object[] { propName });
                    exist = value == null;
                }
            }
            else if (container is Type)
            {
                Type type = (Type)container;
                //查找字段
                FieldInfo field = type.GetField(propName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
                if (field != null)
                {
                    exist = true;
                    value = field.GetValue(container);
                }
                else
                {
                    //查找属性
                    PropertyInfo property = type.GetProperty(propName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase, null, null, new Type[0], new ParameterModifier[0]);
                    if (property != null)
                    {
                        exist = true;
                        value = property.GetValue(container, null);
                    }
                    else
                    {
                        //查找方法
                        MethodInfo method = type.GetMethod(propName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase, null, new Type[0], new ParameterModifier[0]);
                        if (method != null)
                        {
                            value = method.Invoke(container, null);
                            exist = value == null;
                        }
                    }
                }
            }
            return(value);
        }
Beispiel #28
0
 private static string GetValueFromCookieCollection(NameObjectCollectionBase cookieCollection, object key)
 {
     return(((dynamic)cookieCollection)[key.ToString()].Value);
 }
 internal NameObjectKeysEnumerator(NameObjectCollectionBase coll)
 {
     _coll    = coll;
     _version = _coll._version;
     _pos     = -1;
 }