Esempio n. 1
0
        public static IEnumerable <DocumentToken> GetTokens(DocumentSource source, object sourceData)
        {
            var visit      = ContentFactory.Default.CreateFrom(sourceData).Visit();
            var visitWhere = ContentFactory.Default.CreateFrom(sourceData).Visit().Where(p => p.Value is IContentPrimitive);

            var pairs = ContentFactory.Default.CreateFrom(sourceData).Visit()
                        .Where(p => p.Value is IContentPrimitive)
                        .Select(p => new ContentPathValue(
                                    ContentPath.Root
                                    .Append(p.Path
                                            .Select(n =>
                                                    n is ContentPath.ListIndex ? ContentPath.AnyIndex : n)), p.Value));
            ContentPath lastPath = null;
            var         offset   = 0;
            // filter pairs
            var filteredPairs = NullFilter(TokenFilter(TokenizePairs(pairs)))
                                // order by path
                                .OrderBy(p => p.Path.ToString());

            // build tokens from pairs
            foreach (var pair in filteredPairs)
            {
                // assign incremental offsets for similar paths
                offset = pair.Path.Equals(lastPath) ? offset + 1 : 0;
                var path = new DocumentSourcePath(pair.Path, offset);
                lastPath = pair.Path;
                yield return(new DocumentToken(source, sourceData, path, pair.Value, pair.Value));
            }
        }
Esempio n. 2
0
 public DocumentToken(
     DocumentSource source,
     object sourceData,
     DocumentSourcePath sourcePath,
     IContentNode raw,
     IContentNode normalized,
     CultureInfo locale = null)
 {
     Source     = source ?? throw new ArgumentNullException(nameof(source));
     SourcePath = sourcePath ?? throw new ArgumentNullException(nameof(sourcePath));
     SourceData = sourceData ?? throw new ArgumentNullException(nameof(sourceData));
     Raw        = raw ?? throw new ArgumentNullException(nameof(raw));
     Normalized = normalized ?? throw new ArgumentNullException(nameof(normalized));
     Locale     = locale;
 }
Esempio n. 3
0
        public DropIndexCommand CreateDropCommandByType(object key, Type objectType)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (objectType == null)
            {
                throw new ArgumentNullException(nameof(objectType));
            }

            var docType   = new DocumentType(objectType);
            var docSource = new DocumentSource(docType, ContentFactory.Default.CreateFrom(key));

            return(new DropIndexCommand(docSource));
        }
Esempio n. 4
0
        public UpdateIndexCommand CreateUpdateCommand(object key, object source)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var docType   = new DocumentType(source.GetType());
            var docSource = new DocumentSource(docType, ContentFactory.Default.CreateFrom(key));

            return(new UpdateIndexCommand(docSource, source));
        }