private int ParseLinkCollection(int i, string recordString, OLinkCollection linkCollection)
        {
            // move to the start of pageSize value
            i += 15;

            int index = recordString.IndexOf(',', i);

            linkCollection.PageSize = int.Parse(recordString.Substring(i, index - i));

            // move to root value
            i     = index + 6;
            index = recordString.IndexOf(',', i);

            linkCollection.Root = new ORID(recordString.Substring(i, index - i));

            // move to keySize value
            i     = index + 9;
            index = recordString.IndexOf(')', i);

            linkCollection.KeySize = int.Parse(recordString.Substring(i, index - i));

            // move past close bracket of link collection
            i++;

            return(i);
        }
        private int ParseEmbeddedDocument(int i, string recordString, ODocument document, string fieldName)
        {
            // move to the inside of embedded document (go past starting bracket character)
            i++;


            if ((i < 15) && (recordString.Length > 15) && (recordString.Substring(i, 15).Equals("ORIDs@pageSize:")))
            {
                OLinkCollection linkCollection = new OLinkCollection();
                i = ParseLinkCollection(i, recordString, linkCollection);
                document[fieldName] = linkCollection;
            }
            else
            {
                var embeddedDocument = new ODocument();

                // We should not try to read the classname after the embedded document (represented by ')', or '}'), or the first property value (':')
                var maximumAtIndex = recordString.IndexOfAny(new[] { ')', '}', ':' }, i);
                var atIndex        = recordString.IndexOf('@', i, maximumAtIndex - i);
                if (atIndex > 0)
                {
                    // If there is an '@' we set the class name.
                    var documentClassName = recordString.Substring(i, atIndex - i);
                    embeddedDocument.OClassName = documentClassName;
                }

                // assign embedded object
                if (document[fieldName] == null)
                {
                    document[fieldName] = embeddedDocument;
                }
                else if (document[fieldName] is HashSet <object> )
                {
                    ((HashSet <object>)document[fieldName]).Add(embeddedDocument);
                }
                else
                {
                    ((List <object>)document[fieldName]).Add(embeddedDocument);
                }

                // start parsing field names until the closing bracket of embedded document is reached

                while (recordString[i] != ')' && recordString[i] != '}')
                {
                    i = ParseFieldName(i, recordString, embeddedDocument);
                }
            }

            // move past close bracket of embedded document
            i++;

            return(i);
        }
        private int ParseEmbeddedDocument(int i, string recordString, ODocument document, string fieldName)
        {
            // move to the inside of embedded document (go past starting bracket character)
            i++;


            if ((i < 15) && (recordString.Length > 15) && (recordString.Substring(i, 15).Equals("ORIDs@pageSize:")))
            {
                OLinkCollection linkCollection = new OLinkCollection();
                i = ParseLinkCollection(i, recordString, linkCollection);
                document[fieldName] = linkCollection;
            }
            else
            {
                // create new dictionary which would hold K/V pairs of embedded document
                ODocument embeddedDocument = new ODocument();

                // assign embedded object
                if (document[fieldName] == null)
                {
                    document[fieldName] = embeddedDocument;
                }
                else if (document[fieldName] is HashSet <object> )
                {
                    ((HashSet <object>)document[fieldName]).Add(embeddedDocument);
                }
                else
                {
                    ((List <object>)document[fieldName]).Add(embeddedDocument);
                }

                // start parsing field names until the closing bracket of embedded document is reached

                while (recordString[i] != ')' && recordString[i] != '}')
                {
                    i = ParseFieldName(i, recordString, embeddedDocument);
                }
            }

            // move past close bracket of embedded document
            i++;

            return(i);
        }
        private int ParseEmbeddedDocument(int index, string recordString, IDictionary <string, object> waterBucket, string fieldName)
        {
            // move to the inside of embedded document (go past starting bracket character)
            index++;


            if ((index < 15) && (recordString.Length > 15) && (recordString.Substring(index, 15).Equals("ORIDs@pageSize:")))
            {
                OLinkCollection linkCollection = new OLinkCollection();
                index = ParseLinkCollection(index, recordString, linkCollection);
                waterBucket[fieldName] = linkCollection;
            }
            else
            {
                // create new dictionary which would hold K/V pairs of embedded document
                IDictionary <string, object> embeddedDocument = new Dictionary <string, object>();

                // assign embedded object
                if (!embeddedDocument.ContainsKey(fieldName))
                {
                    waterBucket[fieldName] = embeddedDocument;
                }
                else if (waterBucket[fieldName] is HashSet <object> )
                {
                    ((HashSet <object>)waterBucket[fieldName]).Add(embeddedDocument);
                }
                else
                {
                    ((List <object>)waterBucket[fieldName]).Add(embeddedDocument);
                }

                // start parsing field names until the closing bracket of embedded document is reached

                while (recordString[index] != ')' && recordString[index] != '}')
                {
                    index = ParseFieldName(index, recordString, embeddedDocument);
                }
            }

            // move past close bracket of embedded document
            index++;

            return(index);
        }
Ejemplo n.º 5
0
        private static int ParseEmbeddedDocument(int i, string recordString, ODocument document, string fieldName)
        {
            // move to the inside of embedded document (go past starting bracket character)
            i++;

            if ((i < 15) && (recordString.Length > 15) && (recordString.Substring(i, 15).Equals("ORIDs@pageSize:")))
            {
                OLinkCollection linkCollection = new OLinkCollection();
                i = ParseLinkCollection(i, recordString, linkCollection);
                document[fieldName] = linkCollection;
            }
            else
            {
                // create new dictionary which would hold K/V pairs of embedded document
                ODocument embeddedDocument = new ODocument();

                // assign embedded object
                if (document[fieldName] == null)
                {
                    document[fieldName] = embeddedDocument;
                }
                else if (document[fieldName] is HashSet<object>)
                {
                    ((HashSet<object>)document[fieldName]).Add(embeddedDocument);
                }
                else
                {
                    ((List<object>)document[fieldName]).Add(embeddedDocument);
                }

                // start parsing field names until the closing bracket of embedded document is reached
                while (recordString[i] != ')')
                {
                    i = ParseFieldName(i, recordString, embeddedDocument);
                }
            }

            // move past close bracket of embedded document
            i++;

            return i;
        }
        private static int ParseLinkCollection(int i, string recordString, OLinkCollection linkCollection)
        {
            // move to the start of pageSize value
            i += 15;

            int index = recordString.IndexOf(',', i);

            linkCollection.PageSize = int.Parse(recordString.Substring(i, index - i));

            // move to root value
            i = index + 6;
            index = recordString.IndexOf(',', i);
            
            linkCollection.Root = new ORID(recordString.Substring(i, index - i));

            // move to keySize value
            i = index + 9;
            index = recordString.IndexOf(')', i);

            linkCollection.KeySize = int.Parse(recordString.Substring(i, index - i));

            // move past close bracket of link collection
            i++;

            return i;
        }