예제 #1
0
 public XXLanguageXXFile(FileStatistics statistics, IPsiSourceFile psiSourceFile, XXLanguageXXProject project)
     : base(null)// TODO: add statistics
 {
     _psiSourceFile = psiSourceFile;
     _fullName      = psiSourceFile.GetLocation().FullPath;
     _project       = project;
 }
예제 #2
0
        public void StatTest()
        {
            DeviceData device = new DeviceData()
            {
                Serial = "169.254.109.177:5555",
                State  = DeviceState.Online
            };

            FileStatistics value = null;

            this.RunTest(
                OkResponses(2),
                NoResponseMessages,
                Requests("host:transport:169.254.109.177:5555", "sync:"),
                SyncRequests(SyncCommand.STAT, "/fstab.donatello"),
                new SyncCommand[] { SyncCommand.STAT },
                new byte[][] { new byte[] { 160, 129, 0, 0, 85, 2, 0, 0, 0, 0, 0, 0 } },
                null,
                () =>
            {
                using (SyncService service = new SyncService(this.Socket, device))
                {
                    value = service.Stat("/fstab.donatello");
                }
            });

            Assert.NotNull(value);
            Assert.Equal(UnixFileMode.Regular, value.FileMode & UnixFileMode.TypeMask);
            Assert.Equal(597, value.Size);
            Assert.Equal(DateTimeHelper.Epoch.ToLocalTime(), value.Time);
        }
예제 #3
0
        public static FileStatistics ConvertToUnixFile(FileInformation file)
        {
            FileStatistics s = new FileStatistics();

            s.Path = ConvertToUnixPath(file.FileName);
            return(s);
        }
예제 #4
0
        public TestVm(string testPath, int id, ITestTreeNode parent)
            : base(parent, testPath)
        {
            _testFolder = parent as TestFolderVm;
            TestPath    = testPath;
            TestSuite   = _testFolder == null ? (TestSuiteVm)parent : _testFolder.TestSuite;

            if (_testFolder != null)
            {
                Statistics     = null;
                FileStatistics = new FileStatistics(
                    _testFolder.ParsingStatistics.ReplaceSingleSubtask(Name),
                    _testFolder.ParseTreeStatistics.ReplaceSingleSubtask(Name),
                    _testFolder.AstStatistics.ReplaceSingleSubtask(Name),
                    _testFolder.DependPropsStatistics);
                _file = new TestFile(this, TestSuite.Language, id, _testFolder.Project, FileStatistics);
            }
            else
            {
                Statistics     = new StatisticsTask.Container("Total");
                FileStatistics = new FileStatistics(
                    Statistics.ReplaceSingleSubtask("Parsing"),
                    Statistics.ReplaceSingleSubtask("ParseTree"),
                    Statistics.ReplaceSingleSubtask("Ast", "AST Creation"),
                    Statistics.ReplaceContainerSubtask("DependProps", "Dependent properties"));
                var solution = new FsSolution <IAst>();
                var project  = new FsProject <IAst>(solution, Path.GetDirectoryName(testPath), TestSuite.Libs);
                _file = new TestFile(this, TestSuite.Language, id, project, FileStatistics);
            }

            if (TestSuite.TestState == TestState.Ignored)
            {
                TestState = TestState.Ignored;
            }
        }
예제 #5
0
파일: File.cs 프로젝트: derigel23/Nitra
 public XXLanguageXXFile(FileStatistics statistics, IPsiSourceFile psiSourceFile, XXLanguageXXProject project)
   : base(null)// TODO: add statistics
 {
   _psiSourceFile = psiSourceFile;
   _fullName      = psiSourceFile.GetLocation().FullPath;
   _project       = project;
 }
예제 #6
0
        private static void WriteStat(XmlWriter w, ObjectBTreeFile File, FileStatistics Stat)
        {
            w.WriteStartElement("Stat");

            if (!double.IsNaN(Stat.AverageBytesUsedPerBlock))
            {
                w.WriteAttributeString("avgBytesPerBlock", CommonTypes.Encode(Stat.AverageBytesUsedPerBlock));
            }

            if (!double.IsNaN(Stat.AverageObjectSize))
            {
                w.WriteAttributeString("avgObjSize", CommonTypes.Encode(Stat.AverageObjectSize));
            }

            if (!double.IsNaN(Stat.AverageObjectsPerBlock))
            {
                w.WriteAttributeString("avgObjPerBlock", CommonTypes.Encode(Stat.AverageObjectsPerBlock));
            }

            w.WriteAttributeString("hasComments", CommonTypes.Encode(Stat.HasComments));
            w.WriteAttributeString("isBalanced", CommonTypes.Encode(Stat.IsBalanced));
            w.WriteAttributeString("isCorrupt", CommonTypes.Encode(Stat.IsCorrupt));
            w.WriteAttributeString("maxBytesPerBlock", Stat.MaxBytesUsedPerBlock.ToString());
            w.WriteAttributeString("maxDepth", Stat.MaxDepth.ToString());
            w.WriteAttributeString("maxObjSize", Stat.MaxObjectSize.ToString());
            w.WriteAttributeString("maxObjPerBlock", Stat.MaxObjectsPerBlock.ToString());
            w.WriteAttributeString("minBytesPerBlock", Stat.MinBytesUsedPerBlock.ToString());
            w.WriteAttributeString("minDepth", Stat.MinDepth.ToString());
            w.WriteAttributeString("minObjSize", Stat.MinObjectSize.ToString());
            w.WriteAttributeString("minObjPerBlock", Stat.MinObjectsPerBlock.ToString());
            w.WriteAttributeString("nrBlobBlocks", Stat.NrBlobBlocks.ToString());
            w.WriteAttributeString("nrBlobBytes", Stat.NrBlobBytesTotal.ToString());
            w.WriteAttributeString("nrBlobBytesUnused", Stat.NrBlobBytesUnused.ToString());
            w.WriteAttributeString("nrBlobBytesUsed", Stat.NrBlobBytesUsed.ToString());
            w.WriteAttributeString("nrBlocks", Stat.NrBlocks.ToString());
            w.WriteAttributeString("nrBytes", Stat.NrBytesTotal.ToString());
            w.WriteAttributeString("nrBytesUnused", Stat.NrBytesUnused.ToString());
            w.WriteAttributeString("nrBytesUsed", Stat.NrBytesUsed.ToString());
            w.WriteAttributeString("nrObjects", Stat.NrObjects.ToString());
            w.WriteAttributeString("usage", CommonTypes.Encode(Stat.Usage));

            if (Stat.NrBlobBytesTotal > 0)
            {
                w.WriteAttributeString("blobUsage", CommonTypes.Encode((100.0 * Stat.NrBlobBytesUsed) / Stat.NrBlobBytesTotal));
            }

            if (Stat.HasComments)
            {
                foreach (string Comment in Stat.Comments)
                {
                    w.WriteElementString("Comment", Comment);
                }
            }

            w.WriteEndElement();
        }
예제 #7
0
        public async Task DBFiles_RetryLastTest_01_Retry_SaveNew()
        {
            FileStatistics StatBefore = (await this.file.ComputeStatistics()).Key;
            Simple         Obj        = this.LoadSimple();
            Guid           ObjectId   = await this.file.SaveNewObject(Obj);

            Assert.AreNotEqual(Guid.Empty, ObjectId);

            await DBFilesBTreeTests.AssertConsistent(this.file, this.provider, (int)(StatBefore.NrObjects + 1), null, true);
        }
예제 #8
0
        public void StatTest()
        {
            FileStatistics stats = new FileStatistics();

            var mock = new Mock<ISyncService>();
            mock.Setup(m => m.Stat("/test")).Returns(stats);

            Factories.SyncServiceFactory = (d) => mock.Object;

            var device = new DeviceData();

            Assert.AreEqual(stats, device.Stat("/test"));
        }
 /// <summary>
 ///     This method intentionally does the same thing as TextProcessor, but in different way, to make this test capable of
 ///     correctness validation.
 /// </summary>
 /// <param name="testFilePath">The test file path.</param>
 /// <returns></returns>
 private static FileStatistics GetTestFileStatistics(string testFilePath)
 {
     var input = File.ReadAllText(testFilePath);
     int words = Regex.Matches(input, @"[\S]+").Count;
     int lines = Regex.Matches(input, Environment.NewLine).Count;
     FileStatistics fileStatistics = new FileStatistics
     {
         LinesCount = lines,
         WordsCount = words,
         Filename = testFilePath
     };
     return fileStatistics;
 }
예제 #10
0
        private void m_RefreshStatistics(InterfaceFile file)
        {
            FileStatistics fstatistics = krnGateway.GetFileStatistics(file.strHash);

            labelSessionDownloadedRes.Text = eLePhantListView.SizeToString((uint)fstatistics.SessionDownload);
            labelSessionUploadedRes.Text   = eLePhantListView.SizeToString((uint)fstatistics.SessionUpload);
            labelSessionRequestsRes.Text   = fstatistics.SessionRequests.ToString();
            byte   rating  = 0;
            string comment = "";

            krnGateway.GetFileComment(file.strHash, ref comment, ref rating);
            this.textBoxComment.Text = comment;
        }
예제 #11
0
        public void StatTest()
        {
            FileStatistics stats = new FileStatistics();

            var mock = new Mock<ISyncService>();
            mock.Setup(m => m.Stat("/test")).Returns(stats);

            Factories.SyncServiceFactory = (d) => mock.Object;

            var device = new DeviceData();

            Assert.AreEqual(stats, device.Stat("/test"));
        }
예제 #12
0
        public void StatTest()
        {
            FileStatistics stats = new FileStatistics();

            var client = new Mock <IAdbClient>();
            var mock   = new Mock <ISyncService>();

            mock.Setup(m => m.Stat("/test")).Returns(stats);

            Factories.SyncServiceFactory = (c, d) => mock.Object;

            var device = new DeviceData();

            Assert.Equal(stats, client.Object.Stat(device, "/test"));
        }
예제 #13
0
        internal AdbEntry(AdbDevice device, FileStatistics fileStatistics, string path)
        {
            this.device         = device;
            this.fileStatistics = fileStatistics;
            this.path           = path == null ? fileStatistics.Path : UnixPath.Combine(path, fileStatistics.Path);

            if (fileStatistics.FileMode.HasFlag(UnixFileMode.SymbolicLink))
            {
                string str   = device.ExcecuteCommandResult($"ls -l {this.path}");
                Match  match = Regex.Match(str, @".*->(?<link>.+)");
                if (match.Success)
                {
                    this.link = match.Groups["link"].Value.Trim();
                }
            }
        }
예제 #14
0
        public async Task DBFiles_RetryLastTest_02_Retry_Delete()
        {
            FileStatistics StatBefore = (await this.file.ComputeStatistics()).Key;
            Guid           ObjectId   = this.LoadObjectId();

            try
            {
                await this.file.DeleteObject(ObjectId);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(await DBFilesBTreeTests.ExportXML(this.file, "Data\\BTreeError.xml"));
                ExceptionDispatchInfo.Capture(ex).Throw();
            }

            Console.Out.WriteLine(await DBFilesBTreeTests.ExportXML(this.file, "Data\\BTreeAfter.xml"));

            await DBFilesBTreeTests.AssertConsistent(this.file, this.provider, (int)(StatBefore.NrObjects - 1), null, true);
        }
예제 #15
0
 public void AddParse(FileStatistics fileStatistics)
 {
     lock (_addLock)
     {
         _parseTimes.Add(fileStatistics.ParseStatistics.ParseTime);
         if (fileStatistics.ParseStatistics.BytesAllocated > 0)
         {
             _parseAllocations.Add(fileStatistics.ParseStatistics.BytesAllocated);
         }
         if (fileStatistics.TokenStatistics is not null)
         {
             _tokenCounts.Add(fileStatistics.TokenStatistics.TokenCount);
         }
         if (fileStatistics.FeatureStatistics is not null)
         {
             _globalFeatureStatisticsBuilder.Merge(fileStatistics.FeatureStatistics);
         }
     }
 }
예제 #16
0
        public static FileInformation ConvertToWindowsFile(FileStatistics file)
        {
            FileInformation info = new FileInformation();

            info.FileName = ConvertToWindowsPath(file.Path);
            FileAttributes attributes = FileAttributes.Normal;

            if (file.Path.ToCharArray()[file.Path.LastIndexOf('/') + 1] == '.')
            {
                attributes |= FileAttributes.Hidden;
            }
            if (file.FileMode == UnixFileMode.Directory)
            {
                attributes |= FileAttributes.Directory;
            }
            else if (file.FileMode != UnixFileMode.Regular)
            {
                attributes |= FileAttributes.Device;
            }
            info.CreationTime = file.Time.DateTime;
            return(info);
        }
예제 #17
0
 public TestFile([NotNull] TestVm test, Language language, int id, FsProject <IAst> project, FileStatistics statistics)
     : base(test.TestPath, language, project, statistics)
 {
     _id = id;
     if (test == null)
     {
         throw new ArgumentNullException("test");
     }
     _test = test;
 }
예제 #18
0
        internal static async Task <FileStatistics> AssertConsistent(ObjectBTreeFile File, FilesProvider Provider, int?ExpectedNrObjects, object LastObjectAdded,
                                                                     bool WriteStat)
        {
            FileStatistics Statistics = await File.ComputeStatistics();

            if (WriteStat)
            {
                Console.Out.WriteLine("Block Size: " + Statistics.BlockSize.ToString());
                Console.Out.WriteLine("#Blocks: " + Statistics.NrBlocks.ToString());
                Console.Out.WriteLine("#BLOB Blocks: " + Statistics.NrBlobBlocks.ToString());
                Console.Out.WriteLine("#Bytes used: " + Statistics.NrBytesUsed.ToString());
                Console.Out.WriteLine("#Bytes unused: " + Statistics.NrBytesUnused.ToString());
                Console.Out.WriteLine("#Bytes total: " + Statistics.NrBytesTotal.ToString());
                Console.Out.WriteLine("#BLOB Bytes used: " + Statistics.NrBlobBytesUsed.ToString());
                Console.Out.WriteLine("#BLOB Bytes unused: " + Statistics.NrBlobBytesUnused.ToString());
                Console.Out.WriteLine("#BLOB Bytes total: " + Statistics.NrBlobBytesTotal.ToString());
                Console.Out.WriteLine("#Block loads: " + Statistics.NrBlockLoads.ToString());
                Console.Out.WriteLine("#Cache loads: " + Statistics.NrCacheLoads.ToString());
                Console.Out.WriteLine("#Block saves: " + Statistics.NrBlockSaves.ToString());
                Console.Out.WriteLine("#BLOB Block loads: " + Statistics.NrBlobBlockLoads.ToString());
                Console.Out.WriteLine("#BLOB Block saves: " + Statistics.NrBlobBlockSaves.ToString());
                Console.Out.WriteLine("#Objects: " + Statistics.NrObjects.ToString());
                Console.Out.WriteLine("Smallest object: " + Statistics.MinObjectSize.ToString());
                Console.Out.WriteLine("Largest object: " + Statistics.MaxObjectSize.ToString());
                Console.Out.WriteLine("Average object: " + Statistics.AverageObjectSize.ToString("F1"));
                Console.Out.WriteLine("Usage: " + Statistics.Usage.ToString("F2") + " %");
                Console.Out.WriteLine("Min(Depth): " + Statistics.MinDepth.ToString());
                Console.Out.WriteLine("Max(Depth): " + Statistics.MaxDepth.ToString());
                Console.Out.WriteLine("Min(Objects/Block): " + Statistics.MinObjectsPerBlock.ToString());
                Console.Out.WriteLine("Max(Objects/Block): " + Statistics.MaxObjectsPerBlock.ToString());
                Console.Out.WriteLine("Avg(Objects/Block): " + Statistics.AverageObjectsPerBlock.ToString("F1"));
                Console.Out.WriteLine("Min(Bytes Used/Block): " + Statistics.MinBytesUsedPerBlock.ToString());
                Console.Out.WriteLine("Max(Bytes Used/Block): " + Statistics.MaxBytesUsedPerBlock.ToString());
                Console.Out.WriteLine("Avg(Bytes Used/Block): " + Statistics.AverageBytesUsedPerBlock.ToString("F1"));
                Console.Out.WriteLine("Is Corrupt: " + Statistics.IsCorrupt.ToString());
                Console.Out.WriteLine("Is Balanced: " + Statistics.IsBalanced.ToString());
                Console.Out.WriteLine("Has Comments: " + Statistics.HasComments.ToString());
            }

            if (Statistics.HasComments)
            {
                Console.Out.WriteLine();
                foreach (string Comment in Statistics.Comments)
                {
                    Console.Out.WriteLine(Comment);
                }
            }

            try
            {
                if (Statistics.IsCorrupt || !Statistics.IsBalanced)
                {
                    Console.Out.WriteLine();
                    Console.Out.WriteLine(await ExportXML(File, "Data\\BTreeError.xml"));
                    Console.Out.WriteLine();

                    Assert.IsFalse(Statistics.IsCorrupt, "Database is corrupt.");
                    Assert.IsTrue(Statistics.IsBalanced, "Database is unbalanced.");
                }

                if (ExpectedNrObjects.HasValue)
                {
                    AssertEx.Same(ExpectedNrObjects.Value, Statistics.NrObjects);
                }
            }
            catch (Exception ex)
            {
                SaveLastObject(Provider, LastObjectAdded);

                ExceptionDispatchInfo.Capture(ex).Throw();
            }

            foreach (IndexBTreeFile Index in File.Indices)
            {
                await AssertConsistent(Index.IndexFile, Provider, ExpectedNrObjects, null, WriteStat);
            }

            return(Statistics);
        }
예제 #19
0
        private async Task DBFiles_BTree_Test_DeleteObjects(int c, bool CheckForEachObject)
        {
            Random Gen = new Random();

            Simple[] Objects = new Simple[c];
            Simple   Obj;
            int      i;

            for (i = 0; i < c; i++)
            {
                Objects[i] = Obj = CreateSimple(this.MaxStringLength);
                await this.file.SaveNewObject(Obj);
            }

            while (c > 0)
            {
                i = Gen.Next(0, c);

                Obj = Objects[i];
                c--;
                if (i < c)
                {
                    Array.Copy(Objects, i + 1, Objects, i, c - i);
                }

                if (CheckForEachObject)
                {
                    try
                    {
                        this.provider.CloseFile(this.file.CollectionName);
                        this.file = null;

                        File.Copy(FileName, FileName + ".bak", true);
                        File.Copy(BlobFileName, BlobFileName + ".bak", true);
                        File.Copy(NamesFileName, NamesFileName + ".bak", true);

                        this.file = await this.provider.GetFile(CollectionName);

                        if (File.Exists(ObjIdFileName))
                        {
                            File.Delete(ObjIdFileName);
                        }

                        File.WriteAllBytes(ObjIdFileName, Obj.ObjectId.ToByteArray());

                        if (File.Exists(BlockSizeFileName))
                        {
                            File.Delete(BlockSizeFileName);
                        }

                        File.WriteAllText(BlockSizeFileName, this.BlockSize.ToString());

                        Console.Out.WriteLine(await ExportXML(this.file, "Data\\BTreeBefore.xml"));
                        Console.Out.WriteLine(Obj.ObjectId);
                        await this.file.DeleteObject(Obj);

                        //Console.Out.WriteLine(await ExportXML(this.file, "Data\\BTreeAfter.xml"));
                        await AssertConsistent(this.file, this.provider, null, null, true);

                        for (i = 0; i < c; i++)
                        {
                            Obj = await this.file.LoadObject <Simple>(Objects[i].ObjectId);

                            DBFilesObjectSerializationTests.AssertEqual(Objects[i], Obj);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (this.file != null)
                        {
                            Console.Out.WriteLine(await ExportXML(this.file, "Data\\BTreeError.xml"));
                        }

                        ExceptionDispatchInfo.Capture(ex).Throw();
                    }
                }
                else
                {
                    await this.file.DeleteObject(Obj);
                }
            }

            FileStatistics Stat = await AssertConsistent(this.file, this.provider, null, null, true);

            AssertEx.Same(0, this.file.Count);
            AssertEx.Same(1, Stat.NrBlocks);
            AssertEx.Same(0, Stat.NrBlobBlocks);
        }
예제 #20
0
        public AmmyFile(int id, AmmyFileMeta meta, Nitra.Language language, string projectDir, FsProject <T> fsProject = null, FileStatistics statistics = null)
            : base(meta.Filename, language, fsProject, statistics)
        {
            Id   = id;
            Meta = meta;

            var filename = Path.ChangeExtension(Meta.Filename, ".xaml");

            if (Path.IsPathRooted(filename))
            {
                OutputFilename = filename;
            }
            else
            {
                OutputFilename = Path.Combine(projectDir, filename);
            }

            LastWriteTime = new FileInfo(FilePath).LastWriteTime;

            EvalPropertiesData = GetEvalPropertiesData();
        }
예제 #21
0
 public InputFile(int id, string filePath, Nitra.Language language, FsProject <Start> fsProject = null, FileStatistics statistics = null) : base(filePath, language, fsProject, statistics)
 {
     Id = id;
 }
예제 #22
0
        static int Main(string[] args)
        {
            try
            {
                Encoding Encoding          = Encoding.UTF8;
                string   ProgramDataFolder = null;
                string   OutputFileName    = null;
                string   XsltPath          = null;
                string   s;
                int      BlockSize     = 8192;
                int      BlobBlockSize = 8192;
                int      i             = 0;
                int      c             = args.Length;
                bool     Help          = false;
                bool     Encryption    = false;
                bool     Export        = false;

                while (i < c)
                {
                    s = args[i++].ToLower();

                    switch (s)
                    {
                    case "-d":
                        if (i >= c)
                        {
                            throw new Exception("Missing program data folder.");
                        }

                        if (string.IsNullOrEmpty(ProgramDataFolder))
                        {
                            ProgramDataFolder = args[i++];
                        }
                        else
                        {
                            throw new Exception("Only one program data folder allowed.");
                        }
                        break;

                    case "-o":
                        if (i >= c)
                        {
                            throw new Exception("Missing output file name.");
                        }

                        if (string.IsNullOrEmpty(OutputFileName))
                        {
                            OutputFileName = args[i++];
                        }
                        else
                        {
                            throw new Exception("Only one output file name allowed.");
                        }
                        break;

                    case "-bs":
                        if (i >= c)
                        {
                            throw new Exception("Block size missing.");
                        }

                        if (!int.TryParse(args[i++], out BlockSize))
                        {
                            throw new Exception("Invalid block size");
                        }

                        break;

                    case "-bbs":
                        if (i >= c)
                        {
                            throw new Exception("Blob Block size missing.");
                        }

                        if (!int.TryParse(args[i++], out BlobBlockSize))
                        {
                            throw new Exception("Invalid blob block size");
                        }

                        break;

                    case "-enc":
                        if (i >= c)
                        {
                            throw new Exception("Text encoding missing.");
                        }

                        Encoding = Encoding.GetEncoding(args[i++]);
                        break;

                    case "-t":
                        if (i >= c)
                        {
                            throw new Exception("XSLT transform missing.");
                        }

                        XsltPath = args[i++];
                        break;

                    case "-e":
                        Encryption = true;
                        break;

                    case "-x":
                        Export = true;
                        break;

                    case "-?":
                        Help = true;
                        break;

                    default:
                        throw new Exception("Unrecognized switch: " + s);
                    }
                }

                if (Help || c == 0)
                {
                    Console.Out.WriteLine("Analyzes an object database created by the Waher.Persistence.Files or");
                    Console.Out.WriteLine("Waher.Persistence.FilesLW libraries, such as the IoT Gateway database.");
                    Console.Out.WriteLine();
                    Console.Out.WriteLine("Command line switches:");
                    Console.Out.WriteLine();
                    Console.Out.WriteLine("-d APP_DATA_FOLDER    Points to the application data folder.");
                    Console.Out.WriteLine("-o OUTPUT_FILE        File name of report file.");
                    Console.Out.WriteLine("-e                    If encryption is used by the database.");
                    Console.Out.WriteLine("-bs BLOCK_SIZE        Block size, in bytes. Default=8192.");
                    Console.Out.WriteLine("-bbs BLOB_BLOCK_SIZE  BLOB block size, in bytes. Default=8192.");
                    Console.Out.WriteLine("-enc ENCODING         Text encoding. Default=UTF-8");
                    Console.Out.WriteLine("-t                    XSLT transform to use.");
                    Console.Out.WriteLine("-x                    Export contents of each collection.");
                    Console.Out.WriteLine("-?                    Help.");
                    return(0);
                }

                if (string.IsNullOrEmpty(ProgramDataFolder))
                {
                    throw new Exception("No program data folder set");
                }

                if (!Directory.Exists(ProgramDataFolder))
                {
                    throw new Exception("Program data folder does not exist.");
                }

                if (string.IsNullOrEmpty(OutputFileName))
                {
                    throw new Exception("No output filename specified.");
                }

                Types.Initialize(
                    typeof(Database).Assembly,
                    typeof(FilesProvider).Assembly);

                using (FilesProvider FilesProvider = new FilesProvider(ProgramDataFolder, "Default", BlockSize, 10000, BlobBlockSize, Encoding, 10000, Encryption, false))
                {
                    Database.Register(FilesProvider);

                    using (StreamWriter f = File.CreateText(OutputFileName))
                    {
                        XmlWriterSettings Settings = new XmlWriterSettings()
                        {
                            Encoding                = Encoding,
                            Indent                  = true,
                            IndentChars             = "\t",
                            NewLineChars            = Console.Out.NewLine,
                            OmitXmlDeclaration      = false,
                            WriteEndDocumentOnClose = true
                        };

                        using (XmlWriter w = XmlWriter.Create(f, Settings))
                        {
                            w.WriteStartDocument();

                            if (string.IsNullOrEmpty(XsltPath))
                            {
                                i = ProgramDataFolder.LastIndexOf(Path.DirectorySeparatorChar);
                                if (i > 0)
                                {
                                    s = Path.Combine(ProgramDataFolder.Substring(0, i), "Transforms", "DbStatXmlToHtml.xslt");
                                    if (File.Exists(s))
                                    {
                                        XsltPath = s;
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(XsltPath))
                            {
                                w.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"" + XML.Encode(XsltPath) + "\"");
                            }

                            w.WriteStartElement("DatabaseStatistics", "http://waher.se/Schema/Persistence/Statistics.xsd");

                            foreach (ObjectBTreeFile File in FilesProvider.Files)
                            {
                                w.WriteStartElement("File");
                                w.WriteAttributeString("id", File.Id.ToString());
                                w.WriteAttributeString("collectionName", File.CollectionName);
                                w.WriteAttributeString("fileName", Path.GetRelativePath(ProgramDataFolder, File.FileName));
                                w.WriteAttributeString("blockSize", File.BlockSize.ToString());
                                w.WriteAttributeString("blobFileName", Path.GetRelativePath(ProgramDataFolder, File.BlobFileName));
                                w.WriteAttributeString("blobBlockSize", File.BlobBlockSize.ToString());
                                w.WriteAttributeString("count", File.Count.ToString());
                                w.WriteAttributeString("encoding", File.Encoding.WebName);
                                w.WriteAttributeString("encrypted", CommonTypes.Encode(File.Encrypted));
                                w.WriteAttributeString("inlineObjectSizeLimit", File.InlineObjectSizeLimit.ToString());
                                w.WriteAttributeString("isReadOnly", CommonTypes.Encode(File.IsReadOnly));
                                w.WriteAttributeString("timeoutMs", File.TimeoutMilliseconds.ToString());

                                FileStatistics Stat = File.ComputeStatistics().Result;
                                WriteStat(w, File, Stat);

                                foreach (IndexBTreeFile Index in File.Indices)
                                {
                                    w.WriteStartElement("Index");
                                    w.WriteAttributeString("id", Index.IndexFile.Id.ToString());
                                    w.WriteAttributeString("fileName", Path.GetRelativePath(ProgramDataFolder, Index.IndexFile.FileName));
                                    w.WriteAttributeString("blockSize", Index.IndexFile.BlockSize.ToString());
                                    w.WriteAttributeString("blobFileName", Index.IndexFile.BlobFileName);
                                    w.WriteAttributeString("blobBlockSize", Index.IndexFile.BlobBlockSize.ToString());
                                    w.WriteAttributeString("count", Index.IndexFile.Count.ToString());
                                    w.WriteAttributeString("encoding", Index.IndexFile.Encoding.WebName);
                                    w.WriteAttributeString("encrypted", CommonTypes.Encode(Index.IndexFile.Encrypted));
                                    w.WriteAttributeString("inlineObjectSizeLimit", Index.IndexFile.InlineObjectSizeLimit.ToString());
                                    w.WriteAttributeString("isReadOnly", CommonTypes.Encode(Index.IndexFile.IsReadOnly));
                                    w.WriteAttributeString("timeoutMs", Index.IndexFile.TimeoutMilliseconds.ToString());

                                    foreach (string Field in Index.FieldNames)
                                    {
                                        w.WriteElementString("Field", Field);
                                    }

                                    Stat = Index.IndexFile.ComputeStatistics().Result;
                                    WriteStat(w, Index.IndexFile, Stat);

                                    w.WriteEndElement();
                                }

                                if (Export)
                                {
                                    File.ExportGraphXML(w, true).Wait();
                                }

                                w.WriteEndElement();
                            }

                            w.WriteEndElement();
                            w.WriteEndDocument();
                        }
                    }
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.Message);
                return(-1);
            }
        }
예제 #23
0
 public CSharpFile(int id, string filePath, Nitra.Language language, FsProject <CompilationUnit> fsProject = null, FileStatistics statistics = null) : base(filePath, language, fsProject, statistics)
 {
     Id = id;
 }