예제 #1
0
        public static void GenerateCSharp(String InputDirectory, String OutputDirectory)
        {
            var Files = new Dictionary <String, FileParserResult>();

            foreach (var FilePath in Directory.EnumerateFiles(InputDirectory, "*.tree", SearchOption.AllDirectories))
            {
                var AbsolutePath = FileNameHandling.GetAbsolutePath(FilePath, System.Environment.CurrentDirectory);
                var FileContent  = Txt.ReadFile(FilePath);
                var Text         = TokenParser.BuildText(FileContent, AbsolutePath);
                var Result       = FileParser.ParseFile(Text);
                Files.Add(AbsolutePath, Result);
            }

            foreach (var p in Files)
            {
                var RelativePath = FileNameHandling.GetRelativePath(p.Key, FileNameHandling.GetAbsolutePath(InputDirectory, System.Environment.CurrentDirectory));
                var FileName     = FileNameHandling.GetFileName(p.Key);
                var ecsg         = new EmbeddedCSharpGenerator();
                var Content      = String.Join("\r\n", ecsg.Generate(p.Value.File).Select(Line => Line.TrimEnd(' ')));
                var OutputPath   = FileNameHandling.GetPath(FileNameHandling.GetPath(OutputDirectory, FileNameHandling.GetFileDirectory(RelativePath)), FileNameHandling.GetMainFileName(FileName) + ".cs");
                var OutputDir    = FileNameHandling.GetFileDirectory(OutputPath);
                if (!Directory.Exists(OutputDir))
                {
                    Directory.CreateDirectory(OutputDir);
                }
                WriteToFileIfChanged(OutputPath, Content);
            }
        }
예제 #2
0
        public static void DumpSyntaxResult(String InputDirectory, String OutputDirectory)
        {
            var Files = new Dictionary <String, FileParserResult>();

            foreach (var FilePath in Directory.EnumerateFiles(InputDirectory, "*.tree", SearchOption.AllDirectories))
            {
                var AbsolutePath = FileNameHandling.GetAbsolutePath(FilePath, System.Environment.CurrentDirectory);
                var FileContent  = Txt.ReadFile(FilePath);
                var Text         = TokenParser.BuildText(FileContent, AbsolutePath);
                var Result       = FileParser.ParseFile(Text);
                Files.Add(AbsolutePath, Result);
            }

            //var arr = AmbiguousRemover.Reduce(Files, new List<String> { }, new TypeProvider());
            //if (arr.UnresolvableAmbiguousOrErrors.Count > 0)
            //{
            //    var l = new List<String> { };
            //    foreach (var p in arr.UnresolvableAmbiguousOrErrors)
            //    {
            //        var ErrorMessage = p.Key;
            //        var ErrorRange = p.Value;
            //        l.Add(p.Key + ": " + ErrorRange.Text.Path + (ErrorRange.Range.OnSome ? ": " + ErrorRange.Range.Value.ToString() : ""));
            //    }
            //    var OutputPath = FileNameHandling.GetPath(OutputDirectory, "Error.txt");
            //    var OutputDir = FileNameHandling.GetFileDirectory(OutputPath);
            //    if (!Directory.Exists(OutputDir)) { Directory.CreateDirectory(OutputDir); }
            //    Txt.WriteFile(OutputPath, String.Join("\r\n", l) + "\r\n");
            //    return;
            //}
            //Files = arr.Files;

            foreach (var p in Files)
            {
                var RelativePath = FileNameHandling.GetRelativePath(p.Key, FileNameHandling.GetAbsolutePath(InputDirectory, System.Environment.CurrentDirectory));
                var FileName     = FileNameHandling.GetFileName(p.Key);
                var fd           = new FileDumper();
                var Comment
                    = "==========================================================================" + "\r\n"
                      + "\r\n"
                      + "  SourceFile:  " + FileName + "\r\n"
                      + "\r\n"
                      + "==========================================================================";
                var f          = fd.Dump(p.Value, Comment);
                var OutputPath = FileNameHandling.GetPath(FileNameHandling.GetPath(OutputDirectory, FileNameHandling.GetFileDirectory(RelativePath)), FileNameHandling.GetMainFileName(FileName) + ".syn.tree");
                var OutputDir  = FileNameHandling.GetFileDirectory(OutputPath);
                if (!Directory.Exists(OutputDir))
                {
                    Directory.CreateDirectory(OutputDir);
                }
                TreeFile.WriteRaw(OutputPath, f);
            }
        }
예제 #3
0
 public void SaveAll()
 {
     lock (SaveLockee)
     {
         var InstancesSnapshot = new List <Lazy <InstanceInfo> >();
         lock (Instances)
         {
             InstancesSnapshot = Instances.Values.ToList();
         }
         foreach (var p in InstancesSnapshot)
         {
             var      i = p.Value;
             DateTime Time;
             Version  Version;
             using (var da = new KrustallosDataAccess(i.Instance, i.Data, IsolationLevel.Snapshot, (ITransactionLock)(null)))
             {
                 Version = da.GetReaderVersion();
                 Time    = DateTime.UtcNow;
                 var Dir = FileNameHandling.GetFileDirectory(i.FilePath);
                 if (!Directory.Exists(Dir))
                 {
                     Directory.CreateDirectory(Dir);
                 }
                 using (var s = new ReliableFileWriteStream(i.FilePath))
                 {
                     da.Save(i.sbs, i.bs, s, i.Schema);
                 }
             }
             if (i.BackupDir != "")
             {
                 if (!Directory.Exists(i.BackupDir))
                 {
                     Directory.CreateDirectory(i.BackupDir);
                 }
                 var FileName = FileNameHandling.GetFileName(i.FilePath);
                 var FilePath = FileNameHandling.GetPath(i.BackupDir, FileNameHandling.GetMainFileName(FileName) + Time.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture) + "-" + Version.ToString() + "." + FileNameHandling.GetExtendedFileName(FileName));
                 if (!File.Exists(FilePath))
                 {
                     File.Copy(i.FilePath, FilePath + ".new", true);
                     File.Move(FilePath + ".new", FilePath);
                 }
                 if (i.MaxBackupCount.OnSome)
                 {
                     var MaxBackupCount = i.MaxBackupCount.Value;
                     var FilesToDelete  = new List <String>();
                     var FilePaths      = new SortedSet <String>(StringComparer.OrdinalIgnoreCase);
                     foreach (var f in Directory.EnumerateFiles(i.BackupDir, "*", SearchOption.TopDirectoryOnly))
                     {
                         FilePaths.Add(f);
                         while (FilePaths.Count > MaxBackupCount)
                         {
                             var First = FilePaths.First();
                             FilePaths.Remove(First);
                             FilesToDelete.Add(First);
                         }
                     }
                     foreach (var f in FilesToDelete)
                     {
                         if (File.Exists(f))
                         {
                             try
                             {
                                 File.Delete(f);
                             }
                             catch
                             {
                             }
                         }
                     }
                 }
             }
         }
     }
 }