public TwoDARowTypeDescriptor(DataRow row) { if (row == null) { throw new ArgumentNullException("row"); } this.row = row; doc = (TwoDADocument)row.Table.ExtendedProperties[typeof(TwoDADocument)]; var properties = new List <PropertyDescriptor>(); foreach (DataColumn column in row.Table.Columns) { TwoDASchema.Column schemaColumn = null; if (doc.Schema != null) { schemaColumn = doc.Schema.Columns.FirstOrDefault(sc => sc.Name == column.ColumnName); } var property = new ColumnPropertyDescriptor(column, schemaColumn); properties.Add(property); } this.properties = new PropertyDescriptorCollection(properties.ToArray(), true); }
public TlkDocument GetReferencedTlkDocument(TwoDADocument referringDocument, bool alternate) { string docFileName = (from dw in MdiChildren.OfType <TwoDADocumentWindow>() where dw.Document == referringDocument select dw.FileName ).FirstOrDefault(); if (docFileName == null) { return(null); } var matchingWindows = (from dw in MdiChildren.OfType <TlkDocumentWindow>() let fileName = Path.GetFileName(dw.FileName) let std = "dialog.tlk".Equals(fileName, StringComparison.OrdinalIgnoreCase) || "dialogf.tlk".Equals(fileName, StringComparison.OrdinalIgnoreCase) where std ^ alternate select dw ).ToArray(); if (matchingWindows.Length == 0) { return(null); } if (matchingWindows.Length > 1) { var docDirName = Path.GetDirectoryName(docFileName); var sameDirWindow = matchingWindows.FirstOrDefault(dw => Path.GetDirectoryName(dw.FileName) == docDirName); if (sameDirWindow != null) { return(sameDirWindow.Document); } var stdDirName = Path.GetFullPath(Settings.Default.TlkPath); var stdDirWindow = matchingWindows.FirstOrDefault(dw => Path.GetDirectoryName(dw.FileName) == stdDirName); if (stdDirWindow != null) { return(stdDirWindow.Document); } } return(matchingWindows.First().Document); }
public TwoDADocument GetReferencedTwoDADocument(TwoDADocument referringDocument, string rowSource) { var twoDAWindows = MdiChildren.OfType <TwoDADocumentWindow>(); string docFileName = (from dw in twoDAWindows where dw.Document == referringDocument select dw.FileName ).FirstOrDefault(); if (docFileName == null) { return(null); } var matchingWindows = (from dw in twoDAWindows where Path.GetFileName(dw.FileName) == rowSource select dw ).ToArray(); if (matchingWindows.Length == 0) { return(null); } if (matchingWindows.Length > 1) { var docDirName = Path.GetDirectoryName(docFileName); var sameDirWindow = matchingWindows.FirstOrDefault(dw => Path.GetDirectoryName(dw.FileName) == docDirName); if (sameDirWindow != null) { return(sameDirWindow.Document); } var stdDirName = Path.GetFullPath(Settings.Default.TwoDAPath); var stdDirWindow = matchingWindows.FirstOrDefault(dw => Path.GetDirectoryName(dw.FileName) == stdDirName); if (stdDirWindow != null) { return(stdDirWindow.Document); } } return(matchingWindows.First().Document); }
private TwoDADocument LoadTwoDADocument(string fileName) { var schema = TwoDASchemaRegistry.GetMatchingSchema(Path.GetFileName(fileName)); int lineCount = 0; var buffer = new MemoryStream(); using (var reader = new StreamReader(fileName)) { var writer = new StreamWriter(buffer); string line; while ((line = reader.ReadLine()) != null) { writer.WriteLine(line); ++lineCount; } writer.Flush(); } buffer.Position = 0; using (var reader = new StreamReader(buffer)) { var doc = new TwoDADocument(schema); doc.Load( reader, lineNumber => { if (lineNumber % 100 == 0) { openFilesBackgroundWorker.ReportProgress( (int)Math.Round(lineNumber * 100m / lineCount), new OpenFileProgressState { FileName = fileName, Document = null }); } }); return(doc); } }