Example #1
0
 private static object ObjectFromXml(SecurityElement elObject)
 {
     if (elObject.Attribute("class") != null)
     {
         ISecurityEncodable securityEncodable = XMLUtil.CreateCodeGroup(elObject) as ISecurityEncodable;
         if (securityEncodable != null)
         {
             securityEncodable.FromXml(elObject);
             return((object)securityEncodable);
         }
     }
     return(new BinaryFormatter().Deserialize((Stream) new MemoryStream(Hex.DecodeHexString(elObject.Attribute("Data")))));
 }
Example #2
0
        private static object ObjectFromXml(SecurityElement elObject)
        {
            if (elObject.Attribute("class") != null)
            {
                ISecurityEncodable encodable = XMLUtil.CreateCodeGroup(elObject) as ISecurityEncodable;
                if (encodable != null)
                {
                    encodable.FromXml(elObject);
                    return(encodable);
                }
            }
            MemoryStream    serializationStream = new MemoryStream(Hex.DecodeHexString(elObject.Attribute("Data")));
            BinaryFormatter formatter           = new BinaryFormatter();

            return(formatter.Deserialize(serializationStream));
        }
Example #3
0
        private static Object ObjectFromXml(SecurityElement elObject)
        {
            BCLDebug.Assert(elObject != null, "You need to pass in a security element");

            if (elObject.Attribute("class") != null)
            {
                ISecurityEncodable encodableObj = XMLUtil.CreateCodeGroup(elObject) as ISecurityEncodable;
                if (encodableObj != null)
                {
                    encodableObj.FromXml(elObject);
                    return(encodableObj);
                }
            }

            string          objectData = elObject.Attribute("Data");
            MemoryStream    stream     = new MemoryStream(Hex.DecodeHexString(objectData));
            BinaryFormatter formatter  = new BinaryFormatter();

            return(formatter.Deserialize(stream));
        }
Example #4
0
 internal void ParseChildren()
 {
     lock (this)
     {
         ArrayList list = ArrayList.Synchronized(new ArrayList());
         if ((this.m_element != null) && (this.m_element.InternalChildren != null))
         {
             this.m_element.Children = (ArrayList)this.m_element.InternalChildren.Clone();
             ArrayList list2    = ArrayList.Synchronized(new ArrayList());
             Evidence  evidence = new Evidence();
             int       count    = this.m_element.InternalChildren.Count;
             int       index    = 0;
             while (index < count)
             {
                 SecurityElement el = (SecurityElement)this.m_element.Children[index];
                 if (el.Tag.Equals("CodeGroup"))
                 {
                     CodeGroup group = XMLUtil.CreateCodeGroup(el);
                     if (group != null)
                     {
                         group.FromXml(el, this.m_parentLevel);
                         if (this.ParseMembershipCondition(true))
                         {
                             group.Resolve(evidence);
                             group.MembershipCondition.Check(evidence);
                             list.Add(group);
                             index++;
                         }
                         else
                         {
                             this.m_element.InternalChildren.RemoveAt(index);
                             count = this.m_element.InternalChildren.Count;
                             list2.Add(new CodeGroupPositionMarker(index, list.Count, el));
                         }
                     }
                     else
                     {
                         this.m_element.InternalChildren.RemoveAt(index);
                         count = this.m_element.InternalChildren.Count;
                         list2.Add(new CodeGroupPositionMarker(index, list.Count, el));
                     }
                 }
                 else
                 {
                     index++;
                 }
             }
             IEnumerator enumerator = list2.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 CodeGroupPositionMarker current = (CodeGroupPositionMarker)enumerator.Current;
                 CodeGroup group2 = XMLUtil.CreateCodeGroup(current.element);
                 if (group2 == null)
                 {
                     throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_FailedCodeGroup"), new object[] { current.element.Attribute("class") }));
                 }
                 group2.FromXml(current.element, this.m_parentLevel);
                 group2.Resolve(evidence);
                 group2.MembershipCondition.Check(evidence);
                 list.Insert(current.groupIndex, group2);
                 this.m_element.InternalChildren.Insert(current.elementIndex, current.element);
             }
         }
         this.m_children = list;
     }
 }
Example #5
0
 internal void ParseChildren()
 {
     lock (this)
     {
         ArrayList local_2 = ArrayList.Synchronized(new ArrayList());
         if (this.m_element != null && this.m_element.InternalChildren != null)
         {
             this.m_element.Children = (ArrayList)this.m_element.InternalChildren.Clone();
             ArrayList local_3 = ArrayList.Synchronized(new ArrayList());
             Evidence  local_4 = new Evidence();
             int       local_5 = this.m_element.InternalChildren.Count;
             int       local_6 = 0;
             while (local_6 < local_5)
             {
                 SecurityElement local_8 = (SecurityElement)this.m_element.Children[local_6];
                 if (local_8.Tag.Equals("CodeGroup"))
                 {
                     CodeGroup local_9 = XMLUtil.CreateCodeGroup(local_8);
                     if (local_9 != null)
                     {
                         local_9.FromXml(local_8, this.m_parentLevel);
                         if (this.ParseMembershipCondition(true))
                         {
                             local_9.Resolve(local_4);
                             local_9.MembershipCondition.Check(local_4);
                             local_2.Add((object)local_9);
                             ++local_6;
                         }
                         else
                         {
                             this.m_element.InternalChildren.RemoveAt(local_6);
                             local_5 = this.m_element.InternalChildren.Count;
                             local_3.Add((object)new CodeGroupPositionMarker(local_6, local_2.Count, local_8));
                         }
                     }
                     else
                     {
                         this.m_element.InternalChildren.RemoveAt(local_6);
                         local_5 = this.m_element.InternalChildren.Count;
                         local_3.Add((object)new CodeGroupPositionMarker(local_6, local_2.Count, local_8));
                     }
                 }
                 else
                 {
                     ++local_6;
                 }
             }
             foreach (CodeGroupPositionMarker item_0 in local_3)
             {
                 CodeGroup local_11 = XMLUtil.CreateCodeGroup(item_0.element);
                 if (local_11 == null)
                 {
                     throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_FailedCodeGroup"), (object)item_0.element.Attribute("class")));
                 }
                 local_11.FromXml(item_0.element, this.m_parentLevel);
                 local_11.Resolve(local_4);
                 local_11.MembershipCondition.Check(local_4);
                 local_2.Insert(item_0.groupIndex, (object)local_11);
                 this.m_element.InternalChildren.Insert(item_0.elementIndex, (object)item_0.element);
             }
         }
         this.m_children = (IList)local_2;
     }
 }
Example #6
0
 internal void ParseChildren()
 {
     lock (this)
     {
         ArrayList arrayList = ArrayList.Synchronized(new ArrayList());
         if (this.m_element != null && this.m_element.InternalChildren != null)
         {
             this.m_element.Children = (ArrayList)this.m_element.InternalChildren.Clone();
             ArrayList arrayList2 = ArrayList.Synchronized(new ArrayList());
             Evidence  evidence   = new Evidence();
             int       count      = this.m_element.InternalChildren.Count;
             int       i          = 0;
             while (i < count)
             {
                 SecurityElement securityElement = (SecurityElement)this.m_element.Children[i];
                 if (securityElement.Tag.Equals("CodeGroup"))
                 {
                     CodeGroup codeGroup = XMLUtil.CreateCodeGroup(securityElement);
                     if (codeGroup != null)
                     {
                         codeGroup.FromXml(securityElement, this.m_parentLevel);
                         if (this.ParseMembershipCondition(true))
                         {
                             codeGroup.Resolve(evidence);
                             codeGroup.MembershipCondition.Check(evidence);
                             arrayList.Add(codeGroup);
                             i++;
                         }
                         else
                         {
                             this.m_element.InternalChildren.RemoveAt(i);
                             count = this.m_element.InternalChildren.Count;
                             arrayList2.Add(new CodeGroupPositionMarker(i, arrayList.Count, securityElement));
                         }
                     }
                     else
                     {
                         this.m_element.InternalChildren.RemoveAt(i);
                         count = this.m_element.InternalChildren.Count;
                         arrayList2.Add(new CodeGroupPositionMarker(i, arrayList.Count, securityElement));
                     }
                 }
                 else
                 {
                     i++;
                 }
             }
             foreach (object obj in arrayList2)
             {
                 CodeGroupPositionMarker codeGroupPositionMarker = (CodeGroupPositionMarker)obj;
                 CodeGroup codeGroup2 = XMLUtil.CreateCodeGroup(codeGroupPositionMarker.element);
                 if (codeGroup2 == null)
                 {
                     throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_FailedCodeGroup"), codeGroupPositionMarker.element.Attribute("class")));
                 }
                 codeGroup2.FromXml(codeGroupPositionMarker.element, this.m_parentLevel);
                 codeGroup2.Resolve(evidence);
                 codeGroup2.MembershipCondition.Check(evidence);
                 arrayList.Insert(codeGroupPositionMarker.groupIndex, codeGroup2);
                 this.m_element.InternalChildren.Insert(codeGroupPositionMarker.elementIndex, codeGroupPositionMarker.element);
             }
         }
         this.m_children = arrayList;
     }
 }