// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { Marshal.FinalReleaseComObject(addon); addon = null; } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_BEGIN) { isXMLImportInProgress = true; } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_END) { isXMLImportInProgress = false; } //else if (@event == globalevent_enum.GLOBALEVENT_COMMIT_TRANSACTION) //{ // isProjectInTransation = true; //} //else if (@event == globalevent_enum.GLOBALEVENT_DESTROY_TERRITORY) //{ // isProjectInTransation = false; //} if (!componentEnabled) { return; } // TODO: Handle global events // MessageBox.Show(@event.ToString()); }
public void GlobalEvent(globalevent_enum @event) { if (GMEConsole != null) { if (!loggedActiveMessage) { GMEConsole.Info.WriteLine("Changes to this component will be saved to {0} when the file is saved", acmFilename); loggedActiveMessage = true; } } if (@event == globalevent_enum.GLOBALEVENT_SAVE_PROJECT) { if (GMEConsole != null) { GMEConsole.Info.WriteLine("Saving to {0}...", acmFilename); } CyPhyComponentExporter.CyPhyComponentExporterInterpreter.ExportToFile(ISIS.GME.Dsml.CyPhyML.Classes.Component.Cast(component), acmFilename); if (GMEConsole != null) { GMEConsole.Info.WriteLine("Saved {0}", acmFilename); } } if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { GMEConsole = null; addon = null; } }
// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { addon.Destroy(); Marshal.FinalReleaseComObject(addon); addon = null; } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_BEGIN) { isXMLImportInProgress = true; } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_END) { isXMLImportInProgress = false; } //else if (@event == globalevent_enum.GLOBALEVENT_COMMIT_TRANSACTION) //{ // isProjectInTransation = true; //} //else if (@event == globalevent_enum.GLOBALEVENT_DESTROY_TERRITORY) //{ // isProjectInTransation = false; //} if (!componentEnabled) { return; } // TODO: Handle global events // MessageBox.Show(@event.ToString()); }
public void Dispose() { if (addon != null) { addon.Destroy(); addon = null; } }
// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { //control.Dispose(); Marshal.FinalReleaseComObject(addon); addon = null; } if (!componentEnabled) { return; } if (@event == globalevent_enum.GLOBALEVENT_OPEN_PROJECT) { if (Environment.Is64BitProcess) { MessageBox.Show("You're running GME (64 bit). Many CyPhyML components do not work with GME (64 bit). Please start GME instead."); } } if (@event == (globalevent_enum)11 /* GLOBALEVENT_OPEN_PROJECT_FINISHED */) { // Store all library path names that will be attached // Nothing will be attached for these projects based on http://escher.isis.vanderbilt.edu/JIRA/browse/META-1559 // Don't attach QUDT or PortLib to themselves foreach (var libInfo in libInfos) { libraryPaths.Add(Path.Combine(metaPath, libInfo.MgaName + ".mga")); } TriggerQudtRefreshIfNeeded(); } if (@event == globalevent_enum.GLOBALEVENT_COMMIT_TRANSACTION) { CollapseFoldersWithSameNames(); if (addon != null && firstTime) { foreach (var info in libInfos) { info.Go(); } } } if (@event == globalevent_enum.APPEVENT_XML_IMPORT_END) { // System.Diagnostics.Trace.WriteLine("XML import end event"); needFolderCollapse = true; CollapseFoldersWithSameNames(); } // System.Diagnostics.Trace.WriteLine(@event.ToString()); // TODO: Handle global events // MessageBox.Show(@event.ToString()); }
// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { Marshal.FinalReleaseComObject(addon); addon = null; } if (!componentEnabled) { return; } //TODO: Handle global events //MessageBox.Show(@event.ToString()); }
// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (@event == globalevent_enum.GLOBALEVENT_OPEN_PROJECT) { GetMetaRefs(this.addon.Project); } if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { if (Logger != null) { Logger.Dispose(); Logger = null; } Marshal.FinalReleaseComObject(addon); addon = null; } if (@event == globalevent_enum.APPEVENT_XML_IMPORT_BEGIN) { xmeImportInProgress = true; addon.EventMask = unchecked ((uint)objectevent_enum.OBJEVENT_CREATED); } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } xmeImportInProgress = false; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_BEGIN) { addon.EventMask = 0; handleEvents = false; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } handleEvents = true; } if (!componentEnabled) { return; } // TODO: Handle global events // MessageBox.Show(@event.ToString()); }
// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (@event == globalevent_enum.GLOBALEVENT_OPEN_PROJECT) { GetMetaRefs(this.addon.Project); } if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { if (Logger != null) { Logger.Dispose(); Logger = null; } Marshal.FinalReleaseComObject(addon); addon = null; } if (@event == globalevent_enum.APPEVENT_XML_IMPORT_BEGIN) { xmeImportInProgress = true; addon.EventMask = unchecked((uint)objectevent_enum.OBJEVENT_CREATED); } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } xmeImportInProgress = false; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_BEGIN) { addon.EventMask = 0; handleEvents = false; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } handleEvents = true; } if (!componentEnabled) { return; } // TODO: Handle global events // MessageBox.Show(@event.ToString()); }
// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { if (GMEConsole != null) { if (GMEConsole.gme != null) { Marshal.FinalReleaseComObject(GMEConsole.gme); } GMEConsole = null; } addon.Destroy(); Marshal.FinalReleaseComObject(addon); addon = null; } if (@event == globalevent_enum.APPEVENT_XML_IMPORT_BEGIN) { handleEvents = false; addon.EventMask = 0; } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } handleEvents = true; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_BEGIN) { addon.EventMask = 0; handleEvents = false; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } handleEvents = true; } if (!componentEnabled) { return; } // TODO: Handle global events // MessageBox.Show(@event.ToString()); }
// Event handlers for addons #region MgaEventSink members public void GlobalEvent(globalevent_enum @event) { if (GMEConsole == null || GMEConsole.gme == null) { GMEConsole = GMEConsole.CreateFromProject(this.project); } if (@event == globalevent_enum.GLOBALEVENT_SAVE_PROJECT) { // update the list of models to be re-opened modelsToReOpen = new List <string>(openModels); #if (DEBUG) // notify open models on console GMEConsole.Info.Write(String.Format("Models Open: {0}", openModels.Count)); foreach (string model in openModels) { GMEConsole.Out.Write(model); } #endif } if (@event == globalevent_enum.GLOBALEVENT_CLOSE_PROJECT) { #if (DEBUG) // notify close project if (GMEConsole != null) { GMEConsole.Info.WriteLine("Closed project: {0}", project.ProjectConnStr.Split('\\').Last()); } #endif //if (GMEConsole != null) //{ // if (GMEConsole.gme != null) // { // Marshal.FinalReleaseComObject(GMEConsole.gme); // } // GMEConsole = null; //} addon.Destroy(); Marshal.FinalReleaseComObject(addon); addon = null; hiddenWindow.BeginInvoke((System.Action) delegate { hiddenWindow.Dispose(); hiddenWindow = null; }); } if (@event == globalevent_enum.GLOBALEVENT_OPEN_PROJECT_FINISHED) { if (hiddenWindow == null) { hiddenWindow = new System.Windows.Forms.Control(); IntPtr handle = hiddenWindow.Handle; // If the handle has not yet been created, referencing this property will force the handle to be created. } #if (DEBUG) // notify open project if (getGMEConsole()) { GMEConsole.Info.WriteLine("Opened project: {0}", project.ProjectConnStr.Split('\\').Last()); } #endif // Re-opening a project, re-open the previously open models if (project != null && mgaFile == project.ProjectConnStr) { var modelsToReOpenFcos = modelsToReOpen.Select(path => project.ObjectByPath[path]).Where(fco => fco != null).ToList(); if (modelsToReOpenFcos.Count > 0) { hiddenWindow.BeginInvoke((System.Action) delegate { foreach (MgaObject obj in modelsToReOpenFcos) { try { GMEConsole.gme.ShowFCO((MgaFCO)obj, false); } catch (Exception e) { //throw e; GMEConsole.Error.Write(e.ToString()); } } }); } } modelsToReOpen.Clear(); // update the open mga file name mgaFile = GMEConsole.gme.MgaProject.ProjectConnStr; if (thread != null) { if ((bool)abortOK) { thread.Abort(); } if (namedPipeServer != null) { namedPipeClient = new NamedPipeClientStream(".", pipeFile, PipeDirection.InOut); namedPipeClient.Connect(); namedPipeClient.Close(); namedPipeClient = null; } //if (namedPipeServer != null) //{ // if (namedPipeServer.IsConnected) // { // namedPipeServer.Disconnect(); // } // namedPipeServer.Close(); // namedPipeServer = null; //} Thread.Sleep(2000); thread.Join(); } thread = new Thread(() => { try { abortOK = true; pipeFile = String.Format("\\{0}\\{1}", Process.GetCurrentProcess().Id, mgaFile.Split('\\').Last()); PipeSecurity ps = new PipeSecurity(); ps.AddAccessRule(new PipeAccessRule(@"NT AUTHORITY\Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); namedPipeServer = new NamedPipeServerStream(pipeFile, PipeDirection.InOut, 1, PipeTransmissionMode.Message, PipeOptions.None, BUFFER_SIZE, BUFFER_SIZE, ps); #if (DEBUG) GMEConsole.Info.Write(String.Format("Opened Pipe File: {0}", pipeFile)); #endif namedPipeServer.WaitForConnection(); byte[] buffer = new byte[BUFFER_SIZE]; int nread = namedPipeServer.Read(buffer, 0, BUFFER_SIZE); string line = Encoding.UTF8.GetString(buffer, 0, nread); Actions act = (Actions)Enum.Parse(typeof(Actions), line, true); if (act != Actions.CLOSE) { throw new Exception(String.Format("Expected action: CLOSE, received action: {0}", act)); } GMEConsole.gme.SaveProject(); GMEConsole.gme.CloseProject(false); using (BinaryWriter writer = new BinaryWriter(new MemoryStream())) { writer.Write("closed"); namedPipeServer.Write(((MemoryStream)writer.BaseStream).ToArray(), 0, ((MemoryStream)writer.BaseStream).ToArray().Length); } nread = namedPipeServer.Read(buffer, 0, BUFFER_SIZE); line = Encoding.UTF8.GetString(buffer, 0, nread); act = (Actions)Enum.Parse(typeof(Actions), line, true); if (act != Actions.OPEN) { throw new Exception(String.Format("Expected action: OPEN, received action: {0}", act)); } namedPipeServer.Disconnect(); namedPipeServer.Close(); namedPipeServer = null; abortOK = false; new Thread(() => GMEConsole.gme.OpenProject(mgaFile)).Start(); } catch (ThreadAbortException e) { } catch (Exception e) { Console.WriteLine(String.Format("Inner Exception: {0}\nMessage: {1}\nSource: {2}\nStack Trace: {3}", e.InnerException, e.Message, e.Source, e.StackTrace)); GMEConsole.Error.WriteLine(String.Format("Inner Exception: {0}\nMessage: {1}\nSource: {2}\nStack Trace: {3}", e.InnerException, e.Message, e.Source, e.StackTrace)); } finally { if (namedPipeServer != null) { if (namedPipeServer.IsConnected) { namedPipeServer.Disconnect(); } namedPipeServer.Close(); namedPipeServer = null; } abortOK = true; } }); thread.Start(); } #region Other EventHandlers if (@event == globalevent_enum.APPEVENT_XML_IMPORT_BEGIN) { handleEvents = false; addon.EventMask = 0; } else if (@event == globalevent_enum.APPEVENT_XML_IMPORT_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } handleEvents = true; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_BEGIN) { addon.EventMask = 0; handleEvents = false; } else if (@event == globalevent_enum.APPEVENT_LIB_ATTACH_END) { unchecked { addon.EventMask = (uint)ComponentConfig.eventMask; } handleEvents = true; } #endregion if (!componentEnabled) { return; } // TODO: Handle global events // MessageBox.Show(@event.ToString()); }