public DialogImport(string file, CircuitProject target) { this.FileName = file; this.DataContext = this; this.InitializeComponent(); Mainframe mainframe = App.Mainframe; Thread thread = new Thread(new ThreadStart(() => { try { CircuitProject import = CircuitProject.Create(file); List <CircuitInfo> list = new List <CircuitInfo>(); foreach (LogicalCircuit circuit in import.LogicalCircuitSet) { list.Add(new CircuitInfo(circuit, target.LogicalCircuitSet.FindByLogicalCircuitId(circuit.LogicalCircuitId) == null)); } list.Sort(CircuitDescriptorComparer.Comparer); this.List = list; this.NotifyPropertyChanged(nameof(this.List)); } catch (SnapStoreException snapStoreException) { Tracer.Report("DialogImport.Load", snapStoreException); mainframe.ErrorMessage(Properties.Resources.ErrorFileCorrupted(file), snapStoreException); mainframe.Dispatcher.BeginInvoke(new Action(() => { this.Close(); })); } catch (Exception exception) { Tracer.Report("DialogImport.Load", exception); mainframe.ReportException(exception); mainframe.Dispatcher.BeginInvoke(new Action(() => { this.Close(); })); } })); //TextNote validation will instantiate FlowDocument that in some cases required to happened only on STA. thread.SetApartmentState(ApartmentState.STA); thread.IsBackground = true; thread.Name = "ImportLoader"; thread.Priority = ThreadPriority.AboveNormal; thread.Start(); }
private static void InitPrimitive() { CircuitProject project = CircuitProject.Create(null); List <IDescriptor> list = new List <IDescriptor>(32); project.StartTransaction(); list.Add(new TextNoteDescriptor(project)); list.Add(new PinDescriptor(project, PinType.Input)); list.Add(new PinDescriptor(project, PinType.Output)); list.Add(new ButtonDescriptor(project)); list.Add(new ConstantDescriptor(project)); list.Add(new SensorDescriptor(project)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.Clock, 0, false), Properties.Resources.ToolTipDescriptorClock)); list.Add(new SplitterDescriptor(project)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.Led, 1, false), null)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.Led, 8, false), null)); list.Add(new LedMatrixDescriptor(project)); list.Add(new GraphicsArrayDescriptor(project)); list.Add(new SoundDescriptor(project)); list.Add(new ProbeDescriptor(project)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.Not, 1, true), null)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.TriState2, 2, false), Properties.Resources.ToolTipDescriptorTriState)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.TriState1, 2, false), Properties.Resources.ToolTipDescriptorTriState)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.And, 2, false), null)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.And, 2, true), null)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.Or, 2, false), null)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.Or, 2, true), null)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.Xor, 2, false), null)); list.Add(new GateDescriptor(project.GateSet.Gate(GateType.Xor, 2, true), null)); list.Add(new MemoryDescriptor(project, false)); list.Add(new MemoryDescriptor(project, true)); project.Commit(); CircuitDescriptorList.primitiveList = list; }
private static CircuitProject Create(Mainframe mainframe, string file) { bool useAutoSaveFile = false; string autoSaveFile = Mainframe.AutoSaveFile(file); if (Mainframe.IsFileExists(autoSaveFile)) { App.Dispatch(() => { MessageBoxResult result = DialogMessage.Show( mainframe, Properties.Resources.TitleApplication, Properties.Resources.MessageLoadAutoSavedFile(file), null, MessageBoxImage.Question, MessageBoxButton.YesNo ); if (result == MessageBoxResult.Yes) { useAutoSaveFile = true; } }); if (!useAutoSaveFile) { Mainframe.DeleteFile(autoSaveFile); } } if (!useAutoSaveFile) { autoSaveFile = file; } CircuitProject project = CircuitProject.Create(autoSaveFile); if (useAutoSaveFile) { project.InOmitTransaction(() => {}); } return(project); }