示例#1
0
        public SelectManyQuery(IDocumentSchema schema, IQueryableDocument mapping, QueryModel query, int index)
        {
            Index = index;

            _schema = schema;
            _query  = query;

            _from = query.BodyClauses[index - 1].As <AdditionalFromClause>();

            var members = FindMembers.Determine(_from.FromExpression);

            _field = mapping.FieldFor(members);

            IsDistinct = query.HasOperator <DistinctResultOperator>();

            var next = query.BodyClauses.Skip(index + 1).FirstOrDefault(x => x is AdditionalFromClause);

            if (next != null)
            {
                throw new NotSupportedException("Not yet supporting SelectMany().SelectMany()");
            }
            else
            {
                _take = _query.BodyClauses.Count - index;
            }


            _tableAlias   = "sub" + Index;
            _documentType = _field.MemberType.GetElementType();
            _document     = _schema.StoreOptions.GetChildDocument(_tableAlias + ".x", _documentType);
        }
示例#2
0
        public SelectManyQuery(DocumentStore store, IQueryableDocument mapping, QueryModel query, int index)
        {
            Index = index;

            _store = store;
            _query = query;

            _from = query.BodyClauses[index - 1].As <AdditionalFromClause>();

            _field = mapping.FieldFor(_from.FromExpression);

            IsDistinct = query.HasOperator <DistinctResultOperator>();

            var next = query.BodyClauses.Skip(index + 1).FirstOrDefault(x => x is AdditionalFromClause);

            if (next != null)
            {
                throw new NotSupportedException("Not yet supporting SelectMany().SelectMany()");
            }
            _take = _query.BodyClauses.Count - index;

            _tableAlias   = "sub" + Index;
            _documentType = _field.FieldType.DeriveElementType();
            _document     = _store.Options.GetChildDocument(_tableAlias + ".x", _documentType);
        }
示例#3
0
        private string toOrderClause(ChildDocument document, Ordering clause)
        {
            var locator = document.JsonLocator(clause.Expression);

            return(clause.OrderingDirection == OrderingDirection.Asc
                ? locator
                : locator + " desc");
        }
示例#4
0
        private string determineOrderClause(ChildDocument document)
        {
            var orders = bodyClauses().OfType <OrderByClause>().SelectMany(x => x.Orderings).ToArray();

            if (!orders.Any())
            {
                return(string.Empty);
            }

            return(" order by " + orders.Select(x => toOrderClause(document, x)).Join(", "));
        }
示例#5
0
        private IWhereFragment buildWhereFragment(ChildDocument document)
        {
            var wheres = findOperators <WhereClause>().ToArray();

            if (!wheres.Any())
            {
                return(null);
            }

            return(wheres.Length == 1
                ? _schema.Parser.ParseWhereFragment(document, wheres.Single().Predicate)
                : new CompoundWhereFragment(_schema.Parser, document, "and", wheres));
        }
示例#6
0
        public void Repository_Supports_Inheritance()
        {
            MyDocument newDoc1 = new MyDocument()
            {
                MyProperty = "Test!"
            };
            MyDocument newDoc2 = new ChildDocument()
            {
                MyProperty = "Child", ChildProperty = "some extra string"
            };

            _repository.Insert(newDoc1);
            _repository.Insert(newDoc2);

            MyDocument[] fromDatabase = _repository.OrderBy(x => x.MyProperty).ToArray();
            AssertState(newDoc2, fromDatabase[0]);
            AssertState(newDoc1, fromDatabase[1]);
        }
        /// <summary>
        /// Solid archive item requests a stream to write extracted item's data.
        /// </summary>
        /// <param name="index">The zero-offset archive child item index.</param>
        /// <param name="stream">The stream to be provided for extracted data.</param>
        private void ItemGetStreamCallback(int index, out Stream stream)
        {
            // This delegate requests a stream to which to extract the archive item. It can be a MemoryStream or FileStream depending
            // on your needs, however, pay attention to the extracted size of the item (ChildDocument.Size) to determine if you want to
            // or even can extract to a MemoryStream:
            ChildDocument childDoc = null;

            try
            {
                stream   = null;
                childDoc = _archiveContent.ChildDocuments[index];

                if (string.IsNullOrWhiteSpace(childDoc.Name))
                {
                    // Give the item a name based on index if it does not have one:
                    childDoc.Name = string.Format("item_{0}", childDoc.Index);
                }

                var filePath = Path.Combine(_rootOutputFolder, childDoc.ContainerRelativePath, childDoc.Name);

                //
                // Check for duplicate file paths and if found rename filename with like Windows does for duplicate files, e.g., "filename (2).ext"
                // Some archive types can have duplicate named files in same directory, so this is a check for that:
                //
                FileSystemHelper.CheckForAndCorrectDuplicateItemFilePaths(_itemFilenameByCountDict, childDoc, ref filePath);

                // Return an open file stream:
                stream = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite);
            }
            catch
            {
                stream = null;
                if (childDoc != null)
                {
                    childDoc.FormatId = DocumentIdentifier.ContainerUnextractableResult;
                }
            }
        }
 /// <summary>
 /// Checks for potential duplicate container item names in extracted path. Ideally, we would want to check for
 /// illegal characters in the filename/file path and also long file paths. That will be left up to the user to
 /// implement for production level code.
 /// </summary>
 /// <remarks>
 /// Some archive formats allow duplicate named files in same archive path - how this happens is by adding the same
 /// named file at a later date/time as an update. This method is an attempt to rename duplicate files like Windows
 /// does ("filename (##).ext", where (##) = 2,3,...,Number-of-duplicates).
 /// </remarks>
 /// <param name="itemFilenameByCountDict">A dictionary that stores item path as key and the count of total times this item path was used as value.</param>
 /// <param name="childDoc">The <see cref="ChildDocument"/> whose item name will be used as part of full item path.</param>
 /// <param name="itemFullPath">The folder path that this item will be eventually saved to.</param>
 public static void CheckForAndCorrectDuplicateItemFilePaths(Dictionary <string, int> itemFilenameByCountDict, ChildDocument childDoc, ref string itemFullPath)
 {
     if (itemFilenameByCountDict.TryGetValue(itemFullPath, out var count))
     {
         var folder        = Path.GetDirectoryName(itemFullPath);
         var extension     = Path.GetExtension(childDoc.Name);
         var nameWithNoExt = Path.GetFileNameWithoutExtension(childDoc.Name);
         itemFullPath = Path.Combine(folder, string.Format("{0} ({1}){2}", nameWithNoExt, count, extension));
         itemFilenameByCountDict[itemFullPath] = ++count;
     }
     else
     {
         itemFilenameByCountDict[itemFullPath] = 1;
     }
 }