Write generated data mapping models to files

This commit is contained in:
Yoshi Askharoun
2022-06-12 23:42:00 -05:00
parent c0095896f1
commit df4764307b
2 changed files with 21 additions and 1 deletions
+20
View File
@@ -60,12 +60,32 @@ namespace ZuneHost.Wpf
}
}
Microsoft.Iris.Application.DebugSettings.GenerateDataMappingModels = true;
Microsoft.Iris.Application.DebugSettings.DataMappingModels.CollectionChanged += DataMappingModels_CollectionChanged;
IntPtr hWnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
Thread zuneThread = new Thread(new ThreadStart(() =>
Microsoft.Zune.Shell.ZuneApplication.Launch(strArgs, hWnd)));
zuneThread.Start();
}
private void DataMappingModels_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
string destDir = Path.Combine(Environment.CurrentDirectory, "DataMappings");
Directory.CreateDirectory(destDir);
foreach (var item in e.NewItems.Cast<Microsoft.Iris.Debug.DataMappingModel>())
{
FileInfo file = new(Path.Combine(destDir, $"{item.Provider}_{item.Type}.cs"));
if (file.Exists) file.Delete();
using var stream = file.Open(FileMode.Create);
using var writer = new StreamWriter(stream);
writer.Write(item.GeneratedCode);
writer.Flush();
}
}
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
// Check if the target directory exists