Example #1
0
        private static void AddKeyValue(Hashtable keyTable, string key, XPathNavigator value, bool checkDuplicates)
        {
            ArrayList?list = (ArrayList?)keyTable[key];

            if (list == null)
            {
                list = new ArrayList();
                keyTable.Add(key, list);
            }
            else
            {
                Debug.Assert(
                    value.ComparePosition((XPathNavigator?)list[list.Count - 1]) != XmlNodeOrder.Before,
                    "The way we traversing nodes should garantees node-order"
                    );
                if (checkDuplicates)
                {
                    // it's posible that this value already was assosiated with current node
                    // but if this happened the node is last in the list of values.
                    if (value.ComparePosition((XPathNavigator?)list[list.Count - 1]) == XmlNodeOrder.Same)
                    {
                        return;
                    }
                }
                else
                {
                    Debug.Assert(
                        value.ComparePosition((XPathNavigator?)list[list.Count - 1]) != XmlNodeOrder.Same,
                        "checkDuplicates == false : We can't have duplicates"
                        );
                }
            }
            list.Add(value.Clone());
        }
Example #2
0
        private static string?GetAsOneString(ArrayList?list)
        {
            int n = (list != null) ? list.Count : 0;

            if (n == 1)
            {
                Debug.Assert(list != null);
                return((string?)list[0]);
            }
            else if (n > 1)
            {
                Debug.Assert(list != null);
                StringBuilder s = new StringBuilder((string?)list[0]);

                for (int i = 1; i < n; i++)
                {
                    s.Append(',');
                    s.Append((string?)list[i]);
                }

                return(s.ToString());
            }
            else
            {
                return(null);
            }
        }
Example #3
0
            public override object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
            {
                XsltCompileContext xsltCompileContext = (XsltCompileContext)xsltContext;

                string local, prefix;

                PrefixQName.ParseQualifiedName(ToString(args[0]), out prefix, out local);
                string?          ns      = xsltContext.LookupNamespace(prefix);
                XmlQualifiedName keyName = new XmlQualifiedName(local, ns);

                XPathNavigator root = docContext.Clone();

                root.MoveToRoot();

                ArrayList?resultCollection = null;

                foreach (Key key in xsltCompileContext._processor !.KeyList !)
                {
                    if (key.Name == keyName)
                    {
                        Hashtable?keyTable = key.GetKeys(root);
                        if (keyTable == null)
                        {
                            keyTable = xsltCompileContext.BuildKeyTable(key, root);
                            key.AddKey(root, keyTable);
                        }

                        XPathNodeIterator?it = args[1] as XPathNodeIterator;
                        if (it != null)
                        {
                            it = it.Clone();
                            while (it.MoveNext())
                            {
                                resultCollection = AddToList(resultCollection, (ArrayList?)keyTable[it.Current !.Value]);
Example #4
0
        //-------------------------- Public Methods -----------------------------

        internal void AddAttributeSafe(string name, string value)
        {
            if (_attributes == null)
            {
                _attributes = new ArrayList(AttributesTypical);
            }
            else
            {
                int iMax = _attributes.Count;
                Debug.Assert(iMax % 2 == 0, "Odd number of strings means the attr/value pairs were not added correctly");

                for (int i = 0; i < iMax; i += 2)
                {
                    string?strAttrName = (string?)_attributes[i];

                    if (string.Equals(strAttrName, name))
                    {
                        throw new ArgumentException(SR.Argument_AttributeNamesMustBeUnique);
                    }
                }
            }

            _attributes.Add(name);
            _attributes.Add(value);
        }
Example #5
0
        //
        // Access by name
        //

        /// <devdoc>
        ///    <para>Adds an entry with the specified name and value into the
        ///    <see cref='System.Collections.Specialized.NameValueCollection'/>.</para>
        /// </devdoc>
        public virtual void Add(string?name, string?value)
        {
            if (IsReadOnly)
            {
                throw new NotSupportedException(SR.CollectionReadOnly);
            }

            InvalidateCachedArrays();

            ArrayList?values = (ArrayList?)BaseGet(name);

            if (values == null)
            {
                // new key - add new key with single value
                values = new ArrayList(1);
                if (value != null)
                {
                    values.Add(value);
                }
                BaseAdd(name, values);
            }
            else
            {
                // old key -- append value to the list of values
                if (value != null)
                {
                    values.Add(value);
                }
            }
        }
Example #6
0
        private void GetSites()
        {
            NativeComInterfaces.IAdsPathname?pathCracker = null;
            pathCracker = (NativeComInterfaces.IAdsPathname) new NativeComInterfaces.Pathname();
            ArrayList propertyList = new ArrayList();

            // need to turn off the escaping for name
            pathCracker.EscapedMode = NativeComInterfaces.ADS_ESCAPEDMODE_OFF_EX;
            string propertyName = "siteList";

            propertyList.Add(propertyName);
            Hashtable values    = Utils.GetValuesWithRangeRetrieval(cachedEntry, "(objectClass=*)", propertyList, SearchScope.Base);
            ArrayList?siteLists = (ArrayList?)values[propertyName.ToLowerInvariant()];

            // somehow no site list
            if (siteLists == null)
            {
                return;
            }

            for (int i = 0; i < siteLists.Count; i++)
            {
                string dn = (string)siteLists[i] !;

                // escaping manipulation
                pathCracker.Set(dn, NativeComInterfaces.ADS_SETTYPE_DN);
                string rdn = pathCracker.Retrieve(NativeComInterfaces.ADS_FORMAT_LEAF);
                Debug.Assert(rdn != null && Utils.Compare(rdn, 0, 3, "CN=", 0, 3) == 0);
                rdn = rdn.Substring(3);
                ActiveDirectorySite site = new ActiveDirectorySite(context, rdn, true);

                // add to the collection
                _sites.Add(site);
            }
        }
Example #7
0
 public Key(XmlQualifiedName name, int matchkey, int usekey)
 {
     _name     = name;
     _matchKey = matchkey;
     _useKey   = usekey;
     _keyNodes = null;
 }
Example #8
0
        private void UpdateRegexList(bool canThrow)
        {
            Regex[]? regexBypassList = null;
            ArrayList?bypassList = _bypassList;

            try
            {
                if (bypassList != null && bypassList.Count > 0)
                {
                    regexBypassList = new Regex[bypassList.Count];
                    for (int i = 0; i < bypassList.Count; i++)
                    {
                        regexBypassList[i] = new Regex((string)bypassList[i] !, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                    }
                }
            }
            catch
            {
                if (!canThrow)
                {
                    _regexBypassList = null;
                    return;
                }
                throw;
            }

            // Update field here, as it could throw earlier in the loop
            _regexBypassList = regexBypassList;
        }
Example #9
0
 public void AddKey(XPathNavigator root, Hashtable table)
 {
     if (_keyNodes == null)
     {
         _keyNodes = new ArrayList();
     }
     _keyNodes.Add(new DocumentKeyList(root, table));
 }
Example #10
0
        private void CacheRecord(RecordBuilder record)
        {
            if (_outputCache == null)
            {
                _outputCache = new ArrayList();
            }

            _outputCache.Add(record.MainNode.Clone());
        }
Example #11
0
 internal void AddAction(Action?action)
 {
     if (this.containedActions == null)
     {
         this.containedActions = new ArrayList();
     }
     this.containedActions.Add(action);
     lastCopyCodeAction = null;
 }
Example #12
0
        /// <summary>
        ///  This method checks to see if it is necessary to
        ///  scavenge keys, and if it is it performs a scan
        ///  of all keys to see which ones are no longer valid.
        ///  To determine if we need to scavenge keys we need to
        ///  try to track the current GC memory.  Our rule of
        ///  thumb is that if GC memory is decreasing and our
        ///  key count is constant we need to scavenge.  We
        ///  will need to see if this is too often for extreme
        ///  use cases like the CompactFramework (they add
        ///  custom type data for every object at design time).
        /// </summary>
        private void ScavengeKeys()
        {
            int hashCount = Count;

            if (hashCount == 0)
            {
                return;
            }

            if (_lastHashCount == 0)
            {
                _lastHashCount = hashCount;
                return;
            }

            long globalMem = GC.GetTotalMemory(false);

            if (_lastGlobalMem == 0)
            {
                _lastGlobalMem = globalMem;
                return;
            }

            float memDelta  = (float)(globalMem - _lastGlobalMem) / (float)_lastGlobalMem;
            float hashDelta = (float)(hashCount - _lastHashCount) / (float)_lastHashCount;

            if (memDelta < 0 && hashDelta >= 0)
            {
                // Perform a scavenge through our keys, looking
                // for dead references.
                //
                ArrayList?cleanupList = null;
                foreach (object o in Keys)
                {
                    if (o is WeakReference wr && !wr.IsAlive)
                    {
                        if (cleanupList is null)
                        {
                            cleanupList = new ArrayList();
                        }

                        cleanupList.Add(wr);
                    }
                }

                if (cleanupList != null)
                {
                    foreach (object o in cleanupList)
                    {
                        Remove(o);
                    }
                }
            }

            _lastGlobalMem = globalMem;
            _lastHashCount = hashCount;
        }
        private OrderedDictionary(OrderedDictionary dictionary)
        {
            Debug.Assert(dictionary != null);

            _readOnly        = true;
            _objectsArray    = dictionary._objectsArray;
            _objectsTable    = dictionary._objectsTable;
            _comparer        = dictionary._comparer;
            _initialCapacity = dictionary._initialCapacity;
        }
 internal DomainCollection(ArrayList?values)
 {
     if (values != null)
     {
         for (int i = 0; i < values.Count; i++)
         {
             Add((Domain)values[i] !);
         }
     }
 }
Example #15
0
        private void MirgeAttributeSets(Stylesheet stylesheet)
        {
            // mirge stylesheet.AttributeSetTable to this.AttributeSetTable

            if (stylesheet.AttributeSetTable != null)
            {
                foreach (AttributeSetAction srcAttSet in stylesheet.AttributeSetTable.Values)
                {
                    ArrayList?         srcAttList = srcAttSet.containedActions;
                    AttributeSetAction?dstAttSet  = (AttributeSetAction?)_attributeSetTable[srcAttSet.Name !];
Example #16
0
 public WebProxy(Uri?Address, bool BypassOnLocal, string[]?BypassList, ICredentials?Credentials)
 {
     this.Address            = Address;
     this.Credentials        = Credentials;
     this.BypassProxyOnLocal = BypassOnLocal;
     if (BypassList != null)
     {
         _bypassList = new ArrayList(BypassList);
         UpdateRegexList(true);
     }
 }
Example #17
0
 public WebProxy(Uri?Address, bool BypassOnLocal, [StringSyntax(StringSyntaxAttribute.Regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)] string[]?BypassList, ICredentials?Credentials)
 {
     this.Address            = Address;
     this.Credentials        = Credentials;
     this.BypassProxyOnLocal = BypassOnLocal;
     if (BypassList != null)
     {
         _bypassList = new ArrayList(BypassList);
         UpdateRegexList(true);
     }
 }
Example #18
0
 internal void InitSortArray()
 {
     if (_sortArray == null)
     {
         _sortArray = new ArrayList();
     }
     else
     {
         _sortArray.Clear();
     }
 }
Example #19
0
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlQualifiedName[] ToArray()
        {
            ArrayList?namespaceList = NamespaceList;

            if (namespaceList == null)
            {
                return(Array.Empty <XmlQualifiedName>());
            }
            var array = new XmlQualifiedName[namespaceList.Count];

            namespaceList.CopyTo(array);
            return(array);
        }
Example #20
0
        /// <summary>
        /// Appends an object to the end of the stack, rather than pushing it
        /// onto the top of the stack. This method allows a serializer to communicate
        /// with other serializers by adding contextual data that does not have to
        /// be popped in order. There is no way to remove an object that was
        /// appended to the end of the stack without popping all other objects.
        /// </summary>
        public void Append(object context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (_contextStack == null)
            {
                _contextStack = new ArrayList();
            }
            _contextStack.Insert(0, context);
        }
Example #21
0
        /// <summary>
        /// Pushes the given object onto the stack.
        /// </summary>
        public void Push(object context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (_contextStack == null)
            {
                _contextStack = new ArrayList();
            }
            _contextStack.Add(context);
        }
Example #22
0
        private static string[]? GetAsStringArray(ArrayList?list)
        {
            int n = (list != null) ? list.Count : 0;

            if (n == 0)
            {
                return(null);
            }

            string[] array = new string[n];
            list !.CopyTo(0, array, 0, n);
            return(array);
        }
Example #23
0
        public void AddChild(SecurityElement child)
        {
            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            if (_children == null)
            {
                _children = new ArrayList(ChildrenTypical);
            }

            _children.Add(child);
        }
Example #24
0
        internal void AddTemplate(TemplateAction template)
        {
            Debug.Assert(template != null);
            Debug.Assert(
                ((object)_mode == (object?)template.Mode) ||
                (template.Mode == null && _mode.Equals(XmlQualifiedName.Empty)) ||
                _mode.Equals(template.Mode)
                );

            if (this.templates == null)
            {
                this.templates = new ArrayList();
            }

            this.templates.Add(template);
        }
Example #25
0
        private void OutputCachedRecords()
        {
            if (_outputCache == null)
            {
                return;
            }

            for (int record = 0; record < _outputCache.Count; record++)
            {
                Debug.Assert(_outputCache[record] is BuilderInfo);
                BuilderInfo info = (BuilderInfo)_outputCache[record] !;

                OutputRecord(info);
            }

            _outputCache = null;
        }
Example #26
0
 private ArrayList GetDependencies(XmlSchemaObject o, ArrayList deps, Hashtable refs)
 {
     if (refs[o] == null)
     {
         refs[o] = o;
         deps.Add(o);
         ArrayList?list = Graph[o] as ArrayList;
         if (list != null)
         {
             for (int i = 0; i < list.Count; i++)
             {
                 GetDependencies((XmlSchemaObject)list[i] !, deps, refs);
             }
         }
     }
     return(deps);
 }
Example #27
0
        internal XmlSchemaObject?AddItem(XmlSchemaObject?item, XmlQualifiedName?qname, XmlSchemas schemas)
        {
            if (item == null)
            {
                return(null);
            }
            if (qname == null || qname.IsEmpty)
            {
                return(null);
            }

            string    key  = $"{item.GetType().Name}:{qname}";
            ArrayList?list = (ArrayList?)ObjectCache[key];

            if (list == null)
            {
                list             = new ArrayList();
                ObjectCache[key] = list;
            }

            for (int i = 0; i < list.Count; i++)
            {
                XmlSchemaObject cachedItem = (XmlSchemaObject)list[i] !;
                if (cachedItem == item)
                {
                    return(cachedItem);
                }

                if (Match(cachedItem, item, true))
                {
                    return(cachedItem);
                }
                else
                {
                    Warnings.Add(SR.Format(SR.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace));
                    Warnings.Add($"DEBUG:Cached item key:\r\n{(string?)looks[cachedItem]}\r\nnew item key:\r\n{(string?)looks[item]}");
                }
            }
            // no match found we need to insert the new type in the cache
            list.Add(item);
            return(item);
        }
Example #28
0
            internal void Read(SmtpReplyReader caller)
            {
                // if we've already found the delimitter, then return 0 indicating
                // end of stream.
                if (_parent._currentReader != caller || _parent._readState == ReadState.Done)
                {
                    InvokeCallback();
                    return;
                }

                if (_parent._byteBuffer == null)
                {
                    _parent._byteBuffer = new byte[SmtpReplyReaderFactory.DefaultBufferSize];
                }

                System.Diagnostics.Debug.Assert(_parent._readState == ReadState.Status0);

                _builder = new StringBuilder();
                _lines   = new ArrayList();

                Read();
            }
Example #29
0
        internal void LoadDiffGram(DataTable dt, XmlReader dataTextReader)
        {
            XmlReader reader = DataTextReader.CreateReader(dataTextReader);

            _dataTable = dt;
            _tables    = new ArrayList();
            _tables.Add(dt);
            CreateTablesHierarchy(dt);

            while (reader.LocalName == Keywords.SQL_BEFORE && reader.NamespaceURI == Keywords.DFFNS)
            {
                ProcessDiffs(_tables, reader);
                reader.Read(); // now the reader points to the error section
            }

            while (reader.LocalName == Keywords.MSD_ERRORS && reader.NamespaceURI == Keywords.DFFNS)
            {
                ProcessErrors(_tables, reader);
                Debug.Assert(reader.LocalName == Keywords.MSD_ERRORS && reader.NamespaceURI == Keywords.DFFNS, "something fishy");
                reader.Read(); // pass the end of errors tag
            }
        }
Example #30
0
        private void ValidateAttributes(XElement e)
        {
            XAttribute?  a       = e.lastAttr;
            IXmlLineInfo orginal = SaveLineInfo(a);

            if (a != null)
            {
                do
                {
                    a = a.next !;
                    if (!a.IsNamespaceDeclaration)
                    {
                        ValidateAttribute(a);
                    }
                } while (a != e.lastAttr);
                source = e;
            }
            if (addSchemaInfo)
            {
                if (defaultAttributes == null)
                {
                    defaultAttributes = new ArrayList();
                }
                else
                {
                    defaultAttributes.Clear();
                }
                validator !.GetUnspecifiedDefaultAttributes(defaultAttributes);
                foreach (XmlSchemaAttribute sa in defaultAttributes)
                {
                    a = new XAttribute(XNamespace.Get(sa.QualifiedName.Namespace).GetName(sa.QualifiedName.Name), GetDefaultValue(sa) !);
                    ReplaceSchemaInfo(a, GetDefaultAttributeSchemaInfo(sa));
                    e.Add(a);
                }
            }
            RestoreLineInfo(orginal);
        }