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); } }
public Writer(RelationSchemaLoaderResult rslr, String Title, String CopyrightText) { this.Schema = rslr.Schema; this.Title = Title; this.CopyrightText = CopyrightText; TypeInfoDict = new Dictionary <String, TypeInfo>(StringComparer.OrdinalIgnoreCase); String Root = ""; if (rslr.Positions.Count > 0) { Func <String, String, String> GetCommonHead = (a, b) => { var lc = new List <Char>(); var k = 0; while (true) { if (k >= a.Length || k >= b.Length) { break; } if (a[k] != b[k]) { break; } lc.Add(a[k]); k += 1; } return(new String(lc.ToArray())); }; Root = rslr.Positions.Select(p => FileNameHandling.GetDirectoryPathWithTailingSeparator(FileNameHandling.GetFileDirectory(p.Value.Text.Path))).Aggregate((a, b) => GetCommonHead(a, b)); if (Root != FileNameHandling.GetDirectoryPathWithTailingSeparator(Root)) { Root = FileNameHandling.GetFileDirectory(Root); } } var Map = Schema.GetMap().ToDictionary(p => p.Key, p => p.Value); foreach (var t in Schema.Types) { if (t.OnQueryList) { continue; } var Name = t.Name(); var Path = "Default.tree"; if (rslr.Positions.ContainsKey(t)) { Path = FileNameHandling.GetRelativePath(rslr.Positions[t].Text.Path, Root); } var PathWithoutExt = FileNameHandling.GetPath(FileNameHandling.GetFileDirectory(Path), FileNameHandling.GetMainFileName(Path)); var DocFilePath = PathWithoutExt.Replace(@"\", @"_").Replace(@"/", @"_").Replace(@".", "_").Replace(@":", @"_").Replace(@"#", @"_") + @".html"; var tli = new TypeInfo { Def = Map[Name], FriendlyPath = PathWithoutExt.Replace(@"\", @"/"), DocFilePath = DocFilePath, DocPath = String.Format("{0}#{1}", DocFilePath, Name) }; TypeInfoDict.Add(Name, tli); } }
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); } }
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 { } } } } } } } }