예제 #1
0
파일: Connect.cs 프로젝트: zi-yu/midgard
        /// <summary>
        /// Called when Visio loads the add-in.
        /// </summary>
        /// <param name="application">Reference to the Visio Application object.</param>
        /// <param name="connectMode">Describes how the add-in is started.</param>
        /// <param name="addInInst">Reference to the add-in.</param>
        /// <param name="custom">Array of additional parameters for the add-in.</param>
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            try
            {
                if (_visioApplication == null)
                {
                    _visioApplication = (VisioApplication)application;

                    /*
                     * Check visio version.
                     */
                    int majorVersion = (int)Convert.ToDouble(_visioApplication.Version, CultureInfo.InvariantCulture);

                    if ((majorVersion == 0) ||
                        (majorVersion < VisioUtils.MinVisioVersion))
                    {
                        return;
                    }


                    /*
                     * Start listening to the desired events.
                     */
                    _eventSink = new EventSink(Application);
                    EventSink.AddAdvise();
                    EventSink.CreateCommandBar();
                    EventSink.Activate();
                }
            }
            catch (Exception ex)
            {
                ESIMessageBox.ShowError(ex);
            }
        }
예제 #2
0
파일: Resources.cs 프로젝트: zi-yu/midgard
        /// <summary>This method creates a picture object from the contents
        /// of the passed in bitmap file.</summary>
        /// <remark>Note: The bitmap file is embedded as a resource in the
        /// executable. The file is temporarily copied out to the client
        /// file system by this function, since the OleLoadPictureFile
        /// function requires the file to reside in the file system.</remark>
        ///	<param name="resourceName">File name of the bitmap embedded as
        /// a resource in the executable</param>
        /// <returns>stdole.IPictureDisp object created from the contents
        /// of the file.</returns>
        public static IPictureDisp GetPicture(string resourceName)
        {
            int    loadPictureResult;
            Object picture = null;

            try
            {
                string temporaryFile = Path.GetTempFileName();

                // Get an input stream of the bitmap file embedded
                // in the executable.
                Stream inStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(BasePath + resourceName);

                // Create a BinaryReader from the input stream.
                BinaryReader inReader = new BinaryReader(inStream);

                // Create the output stream for the temporary file.
                FileStream outStream = new FileStream(temporaryFile, FileMode.Create);

                // Create a BinaryWriter from the output stream.
                BinaryWriter outWriter = new BinaryWriter(outStream);

                byte[] buffer    = new byte[1000];
                int    bytesRead = inReader.Read(buffer, 0, buffer.Length);

                while (bytesRead > 0)
                {
                    outWriter.Write(buffer, 0, bytesRead);
                    bytesRead = inReader.Read(buffer, 0, buffer.Length);
                }

                inReader.Close();
                outWriter.Close();

                // Load the bitmap from the temporary file.
                loadPictureResult = OleLoadPictureFile(temporaryFile, out picture);

                // Delete the temporary file.
                File.Delete(temporaryFile);

                if (loadPictureResult != 0)
                {
                    throw new COMException("OleLoadPictureFailed", loadPictureResult);
                }
            }
            catch (COMException ex)
            {
                ESIMessageBox.ShowError(ex);
            }

            return((IPictureDisp)picture);
        }
예제 #3
0
파일: Connect.cs 프로젝트: zi-yu/midgard
 /// <summary>
 /// This method is called when the add-in is about to be unloaded. The
 /// add-in will be unloaded when Visio is shutting down or when a user
 /// has removed or deselected the add-in from the "COM Add-Ins" dialog.
 /// </summary>
 /// <param name="removeMode">Tells the add-in why Visio is disconnecting.</param>
 /// <param name="custom">Array of additional parameters for the add-in, not used in this case.</param>
 public void OnDisconnection(ext_DisconnectMode removeMode, ref Array custom)
 {
     try
     {
         if (_eventSink != null)
         {
             _eventSink.Dispose();
         }
     }
     catch (Exception ex)
     {
         ESIMessageBox.ShowError(ex);
     }
 }
예제 #4
0
 public static void SaveMode(string mode)
 {
     try
     {
         //ESITracer.Current.LogDebug("Save Mode");
         SetMode(mode);
         RegistryKey regKeyAppRoot = Registry.CurrentUser.CreateSubKey("Software\\Classes\\ProcessModel.Connect");
         regKeyAppRoot.SetValue("Mode", _mode);
         //ESITracer.Current.LogDebug("Set mode:done");
     }
     catch (Exception e)
     {
         ESIMessageBox.ShowError(e.StackTrace.ToString());
     }
 }
예제 #5
0
 public static void SavePath(string path)
 {
     try
     {
         //ESITracer.Current.LogDebug("Save settings");
         SetPath(path);
         //ESITracer.Current.LogDebug("Set registry");
         RegistryKey regKeyAppRoot = Registry.CurrentUser.CreateSubKey("Software\\Classes\\ProcessModel.Connect");
         regKeyAppRoot.SetValue("ExportPath", _path);
         //ESITracer.Current.LogDebug("Set registry:done");
     }
     catch (Exception e)
     {
         ESIMessageBox.ShowError(e.StackTrace.ToString());
     }
 }
예제 #6
0
        private void validateTransition_Click(CommandBarButton sender, ref bool CancelDefault)
        {
            _forceFormChange = false;
            if (Application.ActivePage == null)
            {
                return;
            }

            try
            {
                Midgard.Interop.Export.UiProcessExporter exporter = new Midgard.Interop.Export.UiProcessExporter();
                exporter.ValidatePage(Application.ActivePage);
            }
            catch (Exception ex)
            {
                ESIMessageBox.ShowError(ex);
            }
        }
예제 #7
0
        /// <summary>
        /// Event handler for subscribed events.
        /// </summary>
        /// <param name="eventCode">Code of the captured event.</param>
        /// <param name="source">Source object. In this case, it will always be the Visio application.</param>
        /// <param name="eventID">?</param>
        /// <param name="eventSequenceNumber">?</param>
        /// <param name="subject">The object which caused the event. This parameter is not set for marker events (which are raised by Visio).</param>
        /// <param name="moreInfo">?</param>
        /// <returns>Always null.</returns>
        public object VisEventProc(short eventCode, object source, int eventID, int eventSequenceNumber, object subject, object moreInfo)
        {
            VisioApplication visioApplication = null;

            try
            {
                visioApplication = (VisioApplication)source;

                if (_active == false)
                {
                    return(null);
                }

                if (visioApplication.IsUndoingOrRedoing == true)
                {
                    return(null);
                }

                /*
                 * Test eventCode.
                 * Yes, it's _so_ retarded to have to use if/else, but we can't switch
                 * since VisioEvent.* aren't constants. :/
                 */


                /*
                 * Called whenever one shape connects to another. Filter out
                 * connects which are not raised by QuartzProcess shapes.
                 */
                #region Shape Connect

                if (eventCode == VisioEvent.ShapeConnect)
                {
                    Connects connects = (Connects)subject;
                    HandleShapeConnect(connects);
                }

                #endregion


                /*
                 * Called whenever a shape is disconnected from another. Filter
                 * out disconnects which are not raised by QuartzProcess shapes.
                 */
                #region Shape Disconnect

                else if (eventCode == VisioEvent.ShapeDisconnect)
                {
                    Connects connects = (Connects)subject;
                    HandleShapeDisconnect(connects);
                }

                #endregion


                /*
                 * Called whenever a QueueMarkerEvent command is executed from
                 * the shape. Filter out events which are not raised by
                 * QuartzProcess app.
                 */
                #region Marker Events

                else if (eventCode == VisioEvent.ShapeEventMarker)
                {
                    string context = visioApplication.get_EventInfo(VisioEvent.IdMostRecent);

                    if (context == null)
                    {
                        return(null);
                    }

                    NameValueCollection nvc = VisioUtils.ParseContext(context);

                    HandleMarkerEvent(nvc);
                }

                #endregion
            }
            catch (Exception ex)
            {
                ESIMessageBox.ShowError(ex);
            }

            return(null);
        }