Пример #1
0
 /// <summary>
 /// Exports the Petri Net to a PNML document.
 /// </summary>
 /// <param name="petriNet">An instance of Petri Net to export.</param>
 /// <returns>An instance of PnmlDocument representing the persisted Petri Net.</returns>
 public PersistentDocument Export(PetriNet petriNet)
 {
     var xmlDocument = BuildPetriNetXmlDocument(petriNet);
     var result = new PnmlDocument();
     result.Load(xmlDocument);
     return result;
 }
Пример #2
0
        public static void ExecutePetriNet(string fileName)
        {
            var document = new PnmlDocument();
            document.Load(File.ReadAllText(fileName));
            var petriNet = new PnmlPersister().Import(document);

            var runtimeHost = new EmbeddedRuntimeHost(typeof(PetrifierRuntime));
            var handle = runtimeHost.ExecutePetriNetModule(new PetriNetModule(petriNet));
            runtimeHost.WaitForEnd(handle);
        }
Пример #3
0
        private void btnImportPnmlIntoEditor_Click(object sender, EventArgs e)
        {
            if (dlgOpenPnml.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string fileName = dlgOpenPnml.FileName;
            var document = new PnmlDocument();
            document.Load(File.ReadAllText(fileName));
            var petriNet = new PnmlPersister().Import(document);

            petriNetEditor.LoadPetriNet(petriNet);
        }
Пример #4
0
        /// <summary>
        /// Loads the file content into the textbox
        /// </summary>
        /// <param name="pszFilename">Pointer to the full path name of the file to load</param>
        /// <param name="grfMode">file format mode</param>
        /// <param name="fReadOnly">determines if teh file should be opened as read only</param>
        /// <returns>S_OK if the method succeeds</returns>
        int IPersistFileFormat.Load(string pszFilename, uint grfMode, int fReadOnly)
        {
            if (pszFilename == null)
            {
                return VSConstants.E_INVALIDARG;
            }

            loading = true;
            int hr = VSConstants.S_OK;
            try
            {
                // Show the wait cursor while loading the file
                IVsUIShell VsUiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                if (VsUiShell != null)
                {
                    // Note: we don't want to throw or exit if this call fails, so
                    // don't check the return code.
                    hr = VsUiShell.SetWaitCursor();
                }

                string content = File.ReadAllText(pszFilename);
                
                PnmlDocument document = new PnmlDocument();
                document.Load(content);

                PnmlPersister persister = new PnmlPersister();
                PetriNet petriNet = persister.Import(document);

                editorControl.Editor.LoadPetriNet(petriNet);

                isDirty = false;

                //Determine if the file is read only on the file system
                FileAttributes fileAttrs = File.GetAttributes(pszFilename);

                int isReadOnly = (int)fileAttrs & (int)FileAttributes.ReadOnly;

                //Set readonly if either the file is readonly for the user or on the file system
                if (0 == isReadOnly && 0 == fReadOnly)
                    SetReadOnly(false);
                else
                    SetReadOnly(true);


                // Notify to the property window that some of the selected objects are changed
                ITrackSelection track = TrackSelection;
                if (null != track)
                {
                    hr = track.OnSelectChange((ISelectionContainer)selContainer);
                    if (ErrorHandler.Failed(hr))
                        return hr;
                }

                // Hook up to file change notifications
                if (String.IsNullOrEmpty(fileName) || 0 != String.Compare(fileName, pszFilename, true, CultureInfo.CurrentCulture))
                {
                    fileName = pszFilename;
                    SetFileChangeNotification(pszFilename, true);

                    // Notify the load or reload
                    NotifyDocChanged();
                }
            }
            finally
            {
                loading = false;
            }
            return VSConstants.S_OK;
        }