예제 #1
0
        private static Document CreateDocument(string lowerKey, RavenJObject metadata)
        {
            var doc = new Document();

            doc.Add(new Field("__key", lowerKey, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));

            var fileName = Path.GetFileName(lowerKey);

            Debug.Assert(fileName != null);
            doc.Add(new Field("__fileName", fileName, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
            // the reversed version of the file name is used to allow searches that start with wildcards
            char[] revFileName = fileName.ToCharArray();
            Array.Reverse(revFileName);
            doc.Add(new Field("__rfileName", new string(revFileName), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));

            int level         = 0;
            var directoryName = RavenFileNameHelper.RavenDirectory(Path.GetDirectoryName(lowerKey));


            doc.Add(new Field("__directory", directoryName, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
            // the reversed version of the directory is used to allow searches that start with wildcards
            char[] revDirectory = directoryName.ToCharArray();
            Array.Reverse(revDirectory);
            doc.Add(new Field("__rdirectory", new string(revDirectory), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));

            do
            {
                level += 1;

                directoryName = RavenFileNameHelper.RavenDirectory(directoryName);

                doc.Add(new Field("__directoryName", directoryName, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
                // the reversed version of the directory is used to allow searches that start with wildcards
                char[] revDirectoryName = directoryName.ToCharArray();
                Array.Reverse(revDirectoryName);
                doc.Add(new Field("__rdirectoryName", new string(revDirectoryName), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));

                directoryName = Path.GetDirectoryName(directoryName);
            }while (directoryName != null);

            doc.Add(new Field("__modified", DateTime.UtcNow.ToString(DateIndexFormat, CultureInfo.InvariantCulture), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
            doc.Add(new Field("__level", level.ToString(CultureInfo.InvariantCulture), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));

            RavenJToken contentLen;

            if (metadata.TryGetValue("Content-Length", out contentLen))
            {
                long len;
                if (long.TryParse(contentLen.Value <string>(), out len))
                {
                    doc.Add(new Field("__size", len.ToString("D20"), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
                    doc.Add(new NumericField("__size_numeric", Field.Store.NO, true).SetLongValue(len));
                }
            }

            return(doc);
        }
예제 #2
0
        public static FileVersioningConfiguration GetVersioningConfiguration(this IStorageActionsAccessor accessor, string filePath)
        {
            FileVersioningConfiguration fileVersioningConfiguration;
            var directoryName = RavenFileNameHelper.RavenDirectory(Path.GetDirectoryName(filePath));

            while (string.IsNullOrEmpty(directoryName) == false && directoryName != "/")
            {
                var configurationName = "Raven/Versioning/" + directoryName.TrimStart('/');

                if (TryGetDeserializedConfig(accessor, configurationName, out fileVersioningConfiguration))
                {
                    return(fileVersioningConfiguration);
                }

                directoryName = RavenFileNameHelper.RavenDirectory(Path.GetDirectoryName(directoryName));
            }

            if (TryGetDeserializedConfig(accessor, DefaultConfigurationName, out fileVersioningConfiguration))
            {
                return(fileVersioningConfiguration);
            }

            return(null);
        }