Ejemplo n.º 1
0
 private void GenerateCodeClick(object sender, RoutedEventArgs e)
 {
     Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
     if (dlg.ShowDialog() == true)
     {
         System.IO.FileStream   fs   = new System.IO.FileStream(dlg.FileName, System.IO.FileMode.Create);
         System.IO.StreamWriter strm = new System.IO.StreamWriter(fs);
         strm.WriteIndent("// Copyright (c) Microsoft Corporation. All rights reserved.", 0);
         strm.WriteIndent("// Licensed under the MIT license.", 0);
         strm.WriteIndent("using System;", 0);
         strm.WriteIndent("using System.Collections.Generic;", 0);
         strm.WriteIndent("using System.ComponentModel;", 0);
         strm.WriteIndent("using System.IO;", 0);
         strm.WriteIndent("using Microsoft.Psi;", 0);
         strm.WriteIndent("using Microsoft.Psi.Imaging;", 0);
         strm.WriteIndent("using Microsoft.Psi.Visualization.Common;", 0);
         strm.WriteIndent("public partial class MainWindow : Window, INotifyPropertyChanged", 0);
         strm.WriteIndent("{", 0);
         strm.WriteIndent("private Pipeline pipeline;", 4);
         for (int i = 0; i < this.dispGraph.dispNodes.Count; i++)
         {
             this.dispGraph.dispNodes[i].GenerateVariableDefinitions(strm, 4);
         }
         strm.WriteIndent("", 0);
         strm.WriteIndent("public MainWindow()", 4);
         strm.WriteIndent("{", 4);
         strm.WriteIndent("    this.DataContext = this;", 4);
         strm.WriteIndent("    InitializeComponent();", 4);
         strm.WriteIndent("    SetupPsi();", 4);
         strm.WriteIndent("}", 4);
         strm.WriteIndent("", 0);
         strm.WriteIndent("public event PropertyChangedEventHandler PropertyChanged;", 4);
         strm.WriteIndent("public void RaisePropertyChanged(string propertyName)", 4);
         strm.WriteIndent("{", 4);
         strm.WriteIndent("    if (PropertyChanged != null)", 4);
         strm.WriteIndent("        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));", 4);
         strm.WriteIndent("}", 4);
         strm.WriteIndent("", 0);
         strm.WriteIndent("private void SetupPsi()", 4);
         strm.WriteIndent("{", 4);
         strm.WriteIndent("    this.pipeline = Microsoft.Psi.Pipeline.Create(\"PsiPipeline\", DeliveryPolicy.LatestMessage);", 4);
         for (int i = 0; i < this.dispGraph.dispNodes.Count; i++)
         {
             this.dispGraph.dispNodes[i].GenerateSetup(strm, 8);
         }
         strm.WriteIndent("    this.pipeline.RunAsync();", 4);
         strm.WriteIndent("}", 4);
         strm.WriteIndent("}", 0);
         strm.Flush();
         fs.Close();
     }
 }