Advertisement
Guest User

SolidEdge add in source

a guest
Sep 24th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 60.09 KB | None | 0 0
  1. using SolidEdge.AddIn.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Runtime.InteropServices.ComTypes;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Reflection;
  10. using DevExpress.Xpo;
  11. using SolidEdge.Manageem.Addin.Utils;
  12. using System.IO;
  13. //using ME2DLL.DataStore;
  14. //using ME2DLL.DataStore.ViewModels;
  15. using DevExpress.Data.Filtering;
  16.  
  17. namespace SolidEdge.Manageem.Addin
  18. {
  19.     [Guid("1F47DA3A-B2CC-6A86-9031-C7813CD102E3")]
  20.     [ProgId("SolidEdge.Manageem.Addin")]
  21.     [ComVisible(true)]
  22.     [AddInInfo("ManageEm 2.6.2", "Connecting Solid Edge to ManageEm", true)]
  23.     [AddInEnvironmentCategory(CategoryIDs.CATID_SEApplication)]
  24.     [AddInEnvironmentCategory(CategoryIDs.CATID_SEAllDocumentEnvrionments)]
  25.     public class ManageEmAddIn
  26.         : SolidEdgeFramework.ISolidEdgeAddIn, SolidEdgeFramework.ISEAddInEvents
  27.     {
  28.  
  29.         #region Properties
  30.         public SolidEdgeFramework.Application Application { get { return _application; } }
  31.         public SolidEdgeFramework.ISEAddInEx AddIn { get { return _addInEx; } }        
  32.  
  33.         private enum FormType
  34.         {
  35.             WhereUsed = 0,
  36.             PrintList = 1,
  37.             OpenDraft = 2,
  38.             Search = 3,
  39.             CheckDrafts = 4,
  40.             CustomProperties = 5
  41.         };
  42.  
  43.         private SolidEdgeFramework.Application _application;
  44.         private SolidEdgeFramework.ISEAddInEx _addInEx;
  45.         private SolidEdgeFramework.DISEApplicationEvents_Event appEvents;    
  46.         private Dictionary<IConnectionPoint, int> _connectionPointDictionary = new Dictionary<IConnectionPoint, int>();
  47.         static Assembly _resourceAssembly;
  48.         string _ActiveFileName = string.Empty;
  49.         #endregion
  50.  
  51.         #region SolidEdgeFramework.ISolidEdgeAddIn
  52.         /// <summary>
  53.         /// Implementation of SolidEdgeFramework.ISolidEdgeAddIn.OnConnection().
  54.         /// </summary>
  55.         public void OnConnection(object Application, SolidEdgeFramework.SeConnectMode ConnectMode, SolidEdgeFramework.AddIn AddInInstance)
  56.         {            
  57.             _application = (SolidEdgeFramework.Application)Application;
  58.             _addInEx = (SolidEdgeFramework.ISEAddInEx)AddInInstance;
  59.             _addInEx.Description = String.Format("\n{0}", _addInEx.Description);
  60.             _resourceAssembly = Assembly.GetExecutingAssembly();
  61.             AddInInstance.GuiVersion = 1;
  62.            
  63.             HookEvents(_addInEx, typeof(SolidEdgeFramework.ISEAddInEvents).GUID);
  64.    
  65.             switch (ConnectMode)
  66.             {
  67.                 case SolidEdgeFramework.SeConnectMode.seConnectAtStartup:
  68.                     break;
  69.                 case SolidEdgeFramework.SeConnectMode.seConnectByUser:
  70.                     break;
  71.                 case SolidEdgeFramework.SeConnectMode.seConnectExternally:
  72.                     break;
  73.             }
  74.             appEvents = (SolidEdgeFramework.DISEApplicationEvents_Event)_application.ApplicationEvents;
  75.             appEvents.AfterDocumentSave += new SolidEdgeFramework.DISEApplicationEvents_AfterDocumentSaveEventHandler(appEvents_AfterDocumentSave);
  76.             appEvents.AfterActiveDocumentChange += new SolidEdgeFramework.DISEApplicationEvents_AfterActiveDocumentChangeEventHandler(appEvents_AfterActiveDocumentChange);
  77.             appEvents.AfterDocumentOpen += new SolidEdgeFramework.DISEApplicationEvents_AfterDocumentOpenEventHandler(appEvents_AfterDocumentOpen);
  78.        
  79.             StartThread(string.Empty, FormType.Search);
  80.         }
  81.  
  82.         /// <summary>
  83.         /// Implementation of SolidEdgeFramework.ISolidEdgeAddIn.OnDisconnection().
  84.         /// </summary>
  85.         public void OnDisconnection(SolidEdgeFramework.SeDisconnectMode DisconnectMode)
  86.         {
  87.             UnhookAllEvents();
  88.  
  89.             switch (DisconnectMode)
  90.             {
  91.                 case SolidEdgeFramework.SeDisconnectMode.seDisconnectAtShutdown:
  92.                     break;
  93.                 case SolidEdgeFramework.SeDisconnectMode.seDisconnectByUser:
  94.                     break;
  95.                 case SolidEdgeFramework.SeDisconnectMode.seDisconnectExternally:
  96.                     break;
  97.             }
  98.         }
  99.  
  100.         /// <summary>
  101.         /// Implementation of SolidEdgeFramework.ISolidEdgeAddIn.OnConnectToEnvironment().
  102.         /// </summary>
  103.         public void OnConnectToEnvironment(string EnvCatID, object pEnvironmentDispatch, bool bFirstTime)
  104.         {
  105.            bFirstTime = true;
  106.            try
  107.            {
  108.                 //uow = ManageEm.Business.Orm.XpoHelper.GetNewUnitOfWork();
  109.            }
  110.            catch (Exception e)
  111.            {
  112.                String x = e.Message;
  113.            }
  114.            if (!EnvCatID.Equals(CategoryIDs.CATID_SEApplication))
  115.            {
  116.  
  117.                Guid environmentGuid = new Guid(EnvCatID);
  118.                RibbonCommandInfo rci = null;
  119.                int commandId = 0;
  120.                string _knopName = "";
  121.  
  122.                //ASSISTANTS TAB
  123.                rci = new RibbonCommandInfo();
  124.                rci.RibbonTabName = "ManageEm";
  125.                rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icCustomProp;
  126.                rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icCustomProp;
  127.                rci.ResourceFilename = _resourceAssembly.Location;
  128.                rci.EnvironmentCatID = EnvCatID;
  129.  
  130.                _knopName = "Custom properties";
  131.                rci.RibbonCommands.Add(new RibbonCommand("Assistants", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandCustomProps)));
  132.  
  133.                RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  134.  
  135.                rci = new RibbonCommandInfo();
  136.                rci.RibbonTabName = "ManageEm";
  137.                rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icFindDraft;
  138.                rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icFindDraft;
  139.                rci.ResourceFilename = _resourceAssembly.Location;
  140.                rci.EnvironmentCatID = EnvCatID;
  141.  
  142.                _knopName = "Check Drafts";
  143.                rci.RibbonCommands.Add(new RibbonCommand("Assistants", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandCheckDrafts)));
  144.  
  145.                RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  146.  
  147.                rci = new RibbonCommandInfo();
  148.                rci.RibbonTabName = "ManageEm";
  149.                rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icRevisie2;
  150.                rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icRevisie2;
  151.                rci.ResourceFilename = _resourceAssembly.Location;
  152.                rci.EnvironmentCatID = EnvCatID;
  153.  
  154.                 #region nog niet gebruikt
  155.                 /*_knopName = "Revisie";
  156.                 rci.RibbonCommands.Add(new RibbonCommand("Assistants", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandRevisie)));
  157.  
  158.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  159.  
  160.                 rci = new RibbonCommandInfo();
  161.                 rci.RibbonTabName = "ManageEm";
  162.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icReleased2;
  163.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icReleased2;
  164.                 rci.ResourceFilename = _resourceAssembly.Location;
  165.                 rci.EnvironmentCatID = EnvCatID;
  166.  
  167.                 _knopName = "Release";
  168.                 rci.RibbonCommands.Add(new RibbonCommand("Assistants", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandRelease)));
  169.  
  170.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  171.  
  172.                 rci = new RibbonCommandInfo();
  173.                 rci.RibbonTabName = "ManageEm";
  174.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icCopy;
  175.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icCopy;
  176.                 rci.ResourceFilename = _resourceAssembly.Location;
  177.                 rci.EnvironmentCatID = EnvCatID;
  178.  
  179.                 _knopName = "Copy Project";
  180.                 rci.RibbonCommands.Add(new RibbonCommand("Assistants", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandCopyProject)));
  181.  
  182.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  183.  
  184.                 rci = new RibbonCommandInfo();
  185.                 rci.RibbonTabName = "ManageEm";
  186.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icDraftView2;
  187.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icDraftView2;
  188.                 rci.ResourceFilename = _resourceAssembly.Location;
  189.                 rci.EnvironmentCatID = EnvCatID;
  190.  
  191.                 _knopName = "Draft view";
  192.                 rci.RibbonCommands.Add(new RibbonCommand("Assistants", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandDraftView)));
  193.  
  194.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);*/
  195.  
  196.                 //EXPORT TAB
  197.  
  198.                 /* rci = new RibbonCommandInfo();
  199.                  rci.RibbonTabName = "ManageEm";
  200.                  rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icExport;
  201.                  rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icExport;
  202.                  rci.ResourceFilename = _resourceAssembly.Location;
  203.                  rci.EnvironmentCatID = EnvCatID;
  204.  
  205.                  _knopName = "FlattenEM Export";
  206.                  rci.RibbonCommands.Add(new RibbonCommand("Export", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandFlattenEmExport)));
  207.  
  208.                  RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);*/
  209.  
  210.                 //FAVORITES TAB
  211.  
  212.  
  213.                 /*rci = new RibbonCommandInfo();
  214.                 rci.RibbonTabName = "ManageEm";
  215.  
  216.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icMarkFavourite_32x32;
  217.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icMarkFavourite_32x32;
  218.                 rci.ResourceFilename = _resourceAssembly.Location;
  219.                 rci.EnvironmentCatID = EnvCatID;
  220.  
  221.                 _knopName = "Als favoriet opslaan";
  222.                 rci.RibbonCommands.Add(new RibbonCommand("Favorites", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandSaveFavourite)));
  223.  
  224.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  225.  
  226.                 rci = new RibbonCommandInfo();
  227.                 rci.RibbonTabName = "ManageEm";
  228.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icBookmarks;
  229.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icBookmarks;
  230.                 rci.ResourceFilename = _resourceAssembly.Location;
  231.                 rci.EnvironmentCatID = EnvCatID;
  232.  
  233.                 _knopName = "Opgeslagen favorieten openen";
  234.                 rci.RibbonCommands.Add(new RibbonCommand("Favorites", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandOpenFavourites)));
  235.  
  236.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);*/
  237.                 #endregion
  238.  
  239.                 //PRINT TAB
  240.                 rci = new RibbonCommandInfo();
  241.                rci.RibbonTabName = "ManageEm";
  242.                rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icPrintList;
  243.                rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icPrintList;
  244.                rci.ResourceFilename = _resourceAssembly.Location;
  245.                rci.EnvironmentCatID = EnvCatID;
  246.  
  247.                 _knopName = "Printlist";
  248.                 rci.RibbonCommands.Add(new RibbonCommand("Print", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandPrintList)));
  249.  
  250.                RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  251.                //SEARCH TAB
  252.                rci = new RibbonCommandInfo();
  253.                rci.RibbonTabName = "ManageEm";
  254.                rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icSearchText;
  255.                rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icSearchText;
  256.                rci.ResourceFilename = _resourceAssembly.Location;
  257.                rci.EnvironmentCatID = EnvCatID;
  258.  
  259.                 _knopName = "Zoeken op ingave";
  260.                 rci.RibbonCommands.Add(new RibbonCommand("Search", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandSearchOnInput)));
  261.  
  262.                RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  263.  
  264.                rci = new RibbonCommandInfo();
  265.                rci.RibbonTabName = "ManageEm";
  266.                rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icWhereUsed;
  267.                rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icWhereUsed;
  268.                rci.ResourceFilename = _resourceAssembly.Location;
  269.                rci.EnvironmentCatID = EnvCatID;
  270.  
  271.                _knopName = "Where used";
  272.                rci.RibbonCommands.Add(new RibbonCommand("Search", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandWhereUsed)));
  273.  
  274.                RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  275.  
  276.                rci = new RibbonCommandInfo();
  277.                rci.RibbonTabName = "ManageEm";
  278.                rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icOpendrag;
  279.                rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icOpendrag;
  280.                rci.ResourceFilename = _resourceAssembly.Location;
  281.                rci.EnvironmentCatID = EnvCatID;
  282.  
  283.                _knopName = "Open Drafts";
  284.                rci.RibbonCommands.Add(new RibbonCommand("Search", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandOpenDraft)));
  285.  
  286.                RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  287.  
  288.                 #region nog niet gebruikt
  289.                 /*rci = new RibbonCommandInfo();
  290.                 rci.RibbonTabName = "ManageEm";
  291.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icSearchActiveDocument;
  292.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icSearchActiveDocument;
  293.                 rci.ResourceFilename = _resourceAssembly.Location;
  294.                 rci.EnvironmentCatID = EnvCatID;
  295.  
  296.                 _knopName = "Zoeken op active document";
  297.                 rci.RibbonCommands.Add(new RibbonCommand("Search", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandSearchOnActiveDocument)));
  298.  
  299.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  300.  
  301.                 rci = new RibbonCommandInfo();
  302.                 rci.RibbonTabName = "ManageEm";
  303.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icSearch;
  304.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icSearch;
  305.                 rci.ResourceFilename = _resourceAssembly.Location;
  306.                 rci.EnvironmentCatID = EnvCatID;
  307.  
  308.                 _knopName = "Zoeken";
  309.                 rci.RibbonCommands.Add(new RibbonCommand("Search", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandSearch)));
  310.  
  311.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  312.  
  313.                 rci = new RibbonCommandInfo();
  314.                 rci.RibbonTabName = "ManageEm";
  315.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icSavedFilters;
  316.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icSavedFilters;
  317.                 rci.ResourceFilename = _resourceAssembly.Location;
  318.                 rci.EnvironmentCatID = EnvCatID;
  319.  
  320.                 _knopName = "Opgeslagen filters uitvoeren";
  321.                 rci.RibbonCommands.Add(new RibbonCommand("Search", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandRunSavedFilters)));
  322.  
  323.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);
  324.  
  325.                 rci = new RibbonCommandInfo();
  326.                 rci.RibbonTabName = "ManageEm";
  327.                 rci.IDColorBitmapLarge = Win32ResourceIDs.PNG.icCustomFilters;
  328.                 rci.IDColorBitmapMedium = Win32ResourceIDs.PNG.icCustomFilters;
  329.                 rci.ResourceFilename = _resourceAssembly.Location;
  330.                 rci.EnvironmentCatID = EnvCatID;
  331.  
  332.                 _knopName = "Custom Filters";
  333.                 rci.RibbonCommands.Add(new RibbonCommand("Search", commandId++, _knopName + commandId, _knopName, _knopName, _knopName, SolidEdgeFramework.SeButtonStyle.seButtonIconAndCaptionBelow, new RibbonCommandDelegate(this.OnMouseRibbonCommandCustomFilters)));
  334.  
  335.                 RibbonHelper.AddRibbonCommands(_addInEx, rci, bFirstTime);*/
  336.                 #endregion
  337.             }
  338.        
  339.         }
  340.         #endregion
  341.  
  342.         #region After Document save
  343.         void appEvents_AfterDocumentSave(object theDocument)
  344.         {
  345.            //save properties  
  346.             //SolidEdgeFramework.SolidEdgeDocument doc = (SolidEdgeFramework.SolidEdgeDocument)theDocument;
  347.             //processPropperties(doc);
  348.         }
  349.         /*void processPropperties(SolidEdgeFramework.SolidEdgeDocument d)
  350.         {
  351.  
  352.             try
  353.             {
  354.                 UnitOfWork uow = new UnitOfWork();
  355.              
  356.                 uow.ConnectionString = DataConnection.GetConnectionString();
  357.                 listDocumentStatus = new XPCollection<ME2DLL.DataStore.DocumentStatus>(uow);
  358.                 listDocumentType = new XPCollection<ME2DLL.DataStore.DocumentType>(uow);
  359.                 String x = d.FullName;
  360.                 if (File.Exists(d.FullName))
  361.                 {
  362.  
  363.  
  364.                     DocumentViewModel dv = _GetDocumentByName(d.FullName);
  365.                     Document doc = null;
  366.                     if (dv.List.Count > 0)
  367.                     {
  368.                         DocumentViewModel div = dv.List.First();
  369.                         doc = uow.GetObjectByKey<Document>(div.Oid);
  370.                         doc.Name = div.Name;
  371.  
  372.                         doc.Oid = div.Oid;
  373.                         doc.Path = div.Path;
  374.                         doc.FileName = div.FileName;
  375.                         doc.ModifiedDate = div.ModifiedDate;
  376.                         doc.ModifiedBy = div.ModifiedBy;
  377.                         doc.CreationDate = div.CreationDate;
  378.                         doc.CreatedBy = div.CreatedBy;
  379.                         // doc.DocType = div.DocType;
  380.                         //doc.DocStatus = div.DocStatus;
  381.                         doc.DocNumber = div.DocNumber;
  382.                         doc.Revision = div.Revision;
  383.                         doc.Material = div.Material;
  384.                         doc.Profile = div.Profile;
  385.                         doc.Category = div.Category;
  386.                         doc.Title = div.Title;
  387.                         doc.Subject = div.Subject;
  388.                         doc.Article = div.Article;
  389.                         doc.Manager = div.Manager;
  390.                         doc.Company = div.Company;
  391.                         doc.Keywords = div.Keywords;
  392.                         doc.Comments = div.Comments;
  393.                         doc.Template = div.Template;
  394.                         doc.Project = div.Project;
  395.                         doc.IsLibraryItem = div.IsLibraryItem;
  396.                         doc.RoutingCode = div.RoutingCode;
  397.                     }
  398.                     else
  399.                     {
  400.                         doc = new Document(uow);
  401.                     }
  402.  
  403.                     doc = ProccesSolidEdgePropperties(d, doc, uow);
  404.                     if (doc != null)
  405.                     {
  406.                         if (doc.DocStatus != null)
  407.                             doc.DocStatus = uow.GetObjectByKey<DocumentStatus>(doc.DocStatus.Oid);
  408.                         if (doc.DocType != null)
  409.                             doc.DocType = uow.GetObjectByKey<DocumentType>(doc.DocType.Oid);
  410.                         doc.Save();
  411.                         uow.CommitChanges();
  412.                        
  413.                     }
  414.                     else
  415.                     {
  416.                        
  417.                     }
  418.                 }
  419.                 else
  420.                 {
  421.                    
  422.                 }
  423.  
  424.             }
  425.             catch
  426.             {
  427.  
  428.             }
  429.  
  430.  
  431.         }
  432.         public static XPCollection<DocumentStatus> listDocumentStatus = null;
  433.         public static XPCollection<DocumentType> listDocumentType = null;
  434.         private DocumentViewModel _GetDocumentByName(String g)
  435.         {
  436.            
  437.          
  438.             UnitOfWork uow = new UnitOfWork();// XpoHelper.GetNewUnitOfWork();
  439.             uow.ConnectionString = DataConnection.GetConnectionString();
  440.             return new DocumentViewModel
  441.             {
  442.                 List = (from o in uow.Query<Document>().ToList()
  443.                         where o.Path != null && o.Path.ToLower() == g.ToLower()
  444.                         select new DocumentViewModel()
  445.                         {
  446.                             Name = o.Name,
  447.                             Oid = o.Oid,
  448.                             Path = o.Path,
  449.                             FileName = o.FileName,
  450.                             ModifiedDate = o.ModifiedDate,
  451.                             ModifiedBy = o.ModifiedBy,
  452.                             CreationDate = o.CreationDate,
  453.                             CreatedBy = o.CreatedBy,
  454.                             DocType = o.DocType,
  455.                             DocStatus = o.DocStatus,
  456.                             DocNumber = o.DocNumber,
  457.                             Revision = o.Revision,
  458.                             Material = o.Material,
  459.                             Profile = o.Profile,
  460.                             Category = o.Category,
  461.                             Title = o.Title,
  462.                             Subject = o.Subject,
  463.                             Article = o.Article,
  464.                             Manager = o.Manager,
  465.                             Company = o.Company,
  466.                             Keywords = o.Keywords,
  467.                             Comments = o.Comments,
  468.                             Template = o.Template,
  469.                             Project = o.Project,
  470.                             IsLibraryItem = o.IsLibraryItem,
  471.                             RoutingCode = o.RoutingCode,
  472.                         }).ToList()
  473.             };
  474.         }
  475.         public Document ProccesSolidEdgePropperties(SolidEdgeFramework.SolidEdgeDocument doc, Document d, UnitOfWork uow)
  476.         {
  477.  
  478.             SolidEdgeFramework.PropertySets propertySets = null;
  479.           //  SolidEdgeFramework.Properties properties = null;
  480.             //SolidEdgeFramework.Property property = null;
  481.             //propertySets = new SolidEdgeFileProperties.PropertySets();
  482.             //propertySets.Open(fileName, false);
  483.  
  484.             propertySets = doc.Properties as SolidEdgeFramework.PropertySets;
  485.  
  486.  
  487.             d.Path = doc.FullName;
  488.             d.FileName = Path.GetFileName(doc.FullName).ToLower();
  489.  
  490.  
  491.             foreach (DocumentType s in listDocumentType)
  492.             {
  493.                 if (s.Extension == Path.GetExtension(doc.FullName).ToLower())
  494.                 {
  495.                     d.DocType = uow.GetObjectByKey<DocumentType>(s.Oid);
  496.                 }
  497.             }
  498.  
  499.  
  500.             foreach(SolidEdgeFramework.Properties properties in propertySets)//for (int i = 0; i < propertySets.Count; i++)
  501.             {
  502.                 //properties = (SolidEdgeFileProperties.Properties)propertySets[i];
  503.  
  504.                 //---------------------------------------------------------------
  505.                 // ProjectInformation
  506.                 //---------------------------------------------------------------
  507.                 if (properties.Name == "ProjectInformation")
  508.                 {
  509.                   foreach(SolidEdgeFramework.Property property in properties)//  for (int j = 0; j < properties.Count; j++)
  510.                     {
  511.                         //property = (SolidEdgeFramework.Property)properties[j];
  512.  
  513.                         switch (property.Name)
  514.                         {
  515.                             case "Document Number":
  516.                                 if (property.get_Value() != null)
  517.                                     d.DocNumber = property.get_Value().ToString();//_DocNumber = property.get_Value().ToString();
  518.                                 break;
  519.                             case "Project Name":
  520.                                 if (property.get_Value() != null)
  521.                                 {
  522.                                     //##   d.Project = property.get_Value().ToString();
  523.                                 }
  524.                                 break;
  525.                             case "Revision":
  526.                                 if (property.get_Value() != null)
  527.                                     d.Revision = property.get_Value().ToString();
  528.                                 //else
  529.                                 //_Revision = ComposeRevisionNumber(_Revision);
  530.                                 break;
  531.                         }
  532.                     }
  533.                 }
  534.                 //---------------------------------------------------------------
  535.                 // SummaryInformation
  536.                 //---------------------------------------------------------------
  537.                 else if (properties.Name == "SummaryInformation")
  538.                 {
  539.                     foreach (SolidEdgeFramework.Property property in properties)// for (int j = 0; j < properties.Count; j++)
  540.                     {
  541.                        // property = (SolidEdgeFileProperties.Property)properties[j];
  542.  
  543.                         switch (property.Name)
  544.                         {
  545.                             case "Comments":
  546.                                 if (property.get_Value() != null)
  547.                                     d.Comments = property.get_Value().ToString();
  548.                                 break;
  549.                             case "Keywords":
  550.                                 if (property.get_Value() != null)
  551.                                     d.Keywords = property.get_Value().ToString();
  552.                                 break;
  553.                             case "Subject":
  554.                                 if (property.get_Value() != null)
  555.                                     d.Subject = property.get_Value().ToString();
  556.                                 break;
  557.                             case "Template":
  558.                                 if (property.get_Value() != null)
  559.                                     d.Template = property.get_Value().ToString();
  560.                                 break;
  561.                             case "Title":
  562.                                 if (property.get_Value() != null)
  563.                                     d.Title = property.get_Value().ToString();
  564.                                 break;
  565.                             case "Author":
  566.                                 if (property.get_Value() != null)
  567.                                     d.CreatedBy = property.get_Value().ToString();
  568.                                 break;
  569.                             case "Origination Date":
  570.                                 try
  571.                                 {
  572.                                     if (property.get_Value() != null)
  573.                                     {
  574.                                         DateTime temp = Convert.ToDateTime(property.get_Value());
  575.                                         if (temp > DateTime.MinValue.AddYears(1700))
  576.                                         {
  577.                                             d.CreationDate = temp;
  578.                                         }
  579.                                     }
  580.                                 }
  581.                                 catch { }
  582.                                 break;
  583.                             case "Last Author":
  584.                                 if (property.get_Value() != null)
  585.                                     d.ModifiedBy = property.get_Value().ToString();
  586.                                 break;
  587.                             case "Last Save Date":
  588.                                 try
  589.                                 {
  590.                                     if (property.get_Value() != null)
  591.                                     {
  592.                                         DateTime temp = Convert.ToDateTime(property.get_Value());
  593.                                         if (temp > DateTime.MinValue.AddYears(1700))
  594.                                         {
  595.                                             d.ModifiedDate = temp;
  596.                                         }
  597.                                     }
  598.  
  599.                                 }
  600.                                 catch { }
  601.                                 break;
  602.                         }
  603.                     }
  604.                 }
  605.                 //---------------------------------------------------------------
  606.                 // DocumentSummaryInformation
  607.                 //---------------------------------------------------------------
  608.                 else if (properties.Name == "DocumentSummaryInformation")
  609.                 {
  610.                     foreach (SolidEdgeFramework.Property property in properties) //for (int j = 0; j < properties.Count; j++)
  611.                     {
  612.                       //  property = (SolidEdgeFileProperties.Property)properties[j];
  613.  
  614.                         switch (property.Name)
  615.                         {
  616.                             case "Company":
  617.                                 if (property.get_Value() != null)
  618.                                     d.Company = property.get_Value().ToString();
  619.                                 break;
  620.                             case "Manager":
  621.                                 if (property.get_Value() != null)
  622.                                     d.Manager = property.get_Value().ToString();
  623.                                 break;
  624.                             case "Category":
  625.                                 if (property.get_Value() != null)
  626.                                 {
  627.                                     //##    d.Category = property.get_Value().ToString();
  628.                                 }
  629.                                 break;
  630.                         }
  631.                     }
  632.                 }
  633.                 //---------------------------------------------------------------
  634.                 // ExtendedSummaryInformation
  635.                 //-----------------------------------------------------------------------
  636.                 else if (properties.Name == "ExtendedSummaryInformation")
  637.                 {
  638.                     foreach (SolidEdgeFramework.Property property in properties)// for (int j = 0; j < properties.Count; j++)
  639.                     {
  640.                       //  property = (SolidEdgeFileProperties.Property)properties[j];
  641.  
  642.                         switch (property.Name)
  643.                         {
  644.                             case "Status":
  645.                                 if (property.get_Value() != null)
  646.                                 {
  647.                                     foreach (DocumentStatus s in listDocumentStatus)
  648.                                     {
  649.                                         if (Convert.ToInt32(s.SeStatus) == Convert.ToInt32(property.get_Value()))
  650.                                         {
  651.                                             d.DocStatus = uow.GetObjectByKey<DocumentStatus>(s.Oid);
  652.                                         }
  653.                                     }
  654.  
  655.  
  656.                                     //##  d.DocStatus = property.get_Value().ToString();
  657.                                 }
  658.                                 break;
  659.                         }
  660.                     }
  661.                 }
  662.                 //---------------------------------------------------------------
  663.                 // MechanicalModeling
  664.                 //---------------------------------------------------------------
  665.                 else if (properties.Name == "MechanicalModeling")
  666.                 {
  667.                     foreach (SolidEdgeFramework.Property property in properties)// for (int j = 0; j < properties.Count; j++)
  668.                     {
  669.                         //property = (SolidEdgeFileProperties.Property)properties[j];
  670.  
  671.                         switch (property.Name)
  672.                         {
  673.                             case "Material":
  674.                                 if (property.get_Value() != null)
  675.                                 {
  676.                                     //##  d.Material = property.get_Value().ToString();
  677.                                 }
  678.                                 break;
  679.                         }
  680.                     }
  681.                 }
  682.                 //---------------------------------------------------------------
  683.                 // Custom
  684.                 //---------------------------------------------------------------
  685.                 else if (properties.Name == "Custom")
  686.                 {
  687.                     // SePropertyMapReader sem = SePropertyMapReader.GetSeMapping();
  688.                     String CustomProppies = "";
  689.                     foreach (SolidEdgeFramework.Property property in properties) //for (int j = 0; j < properties.Count; j++)
  690.                     {
  691.                        // property = (SolidEdgeFileProperties.Property)properties[j];
  692.  
  693.                         String seFieldName = (property.Name);
  694.  
  695.                         if (seFieldName != "")
  696.                         {
  697.                             String value = "";
  698.                             if (property.get_Value() != null)
  699.                             {
  700.                                 value = property.get_Value().ToString();
  701.                                 value = value.Replace("'", "");
  702.                                 String Name = property.Name.Replace("'", "");
  703.                                 CustomProppies += "'" + Name + "':" + "'" + value + "';";
  704.  
  705.                             }
  706.  
  707.                          
  708.                             switch (seFieldName)
  709.                             {
  710.                                 //case "Custom1": Propys.Add("Custom1", value); break;//_Custom1 = value; break;
  711.                                 //case "Custom2": Propys.Add("Custom2", value); break;//_Custom2 = value; break;
  712.                                 //case "Custom3": Propys.Add("Custom3", value); break;//_Custom3 = value; break;
  713.                                 //case "Custom4": Propys.Add("Custom4", value); break;//_Custom4 = value; break;
  714.                                 //case "Custom5": Propys.Add("Custom5", value); break;//_Custom5 = value; break;
  715.                                 //case "Custom6": Propys.Add("Custom6", value); break;//_Custom6 = value; break;
  716.                                 //case "Custom7": Propys.Add("Custom7", value); break;//_Custom7 = value; break;
  717.                                 //case "Custom8": Propys.Add("Custom8", value); break;//_Custom8 = value; break;
  718.                                 //case "Custom9": Propys.Add("Custom9", value); break;//_Custom9 = value; break;
  719.                                 //case "Custom10": Propys.Add("Custom10", value); break;//_Custom10 = value; break;
  720.                                 //case "Custom11": Propys.Add("Custom11", value); break;//_Custom11 = value; break;
  721.                                 //case "Custom12": Propys.Add("Custom12", value); break;//_Custom12 = value; break;
  722.                                 //case "Custom13": Propys.Add("Custom13", value); break;//_Custom13 = value; break;
  723.                                 //case "Custom14": Propys.Add("Custom14", value); break;//_Custom14 = value; break;
  724.                                 //case "Custom15": Propys.Add("Custom15", value); break;//_Custom15 = value; break;
  725.                                 //case "Custom16": Propys.Add("Custom16", value); break;//_Custom16 = value; break;
  726.                                 //case "Custom17": Propys.Add("Custom17", value); break;//_Custom17 = value; break;
  727.                                 //case "Custom18": Propys.Add("Custom18", value); break;//_Custom18 = value; break;
  728.                                 //case "Custom19": Propys.Add("Custom19", value); break;//_Custom19 = value; break;
  729.                                 //case "Custom20": Propys.Add("Custom20", value); break;//_Custom20 = value; break;
  730.                             }
  731.                         }
  732.  
  733.                         if (property.Name == "ArticleNumber")
  734.                         {
  735.                             if (property.get_Value() != null)
  736.                             {
  737.                                 // d.ArticleNumber = property.get_Value().ToString();
  738.                             }
  739.                         }
  740.                         if (property.Name == "Profile")
  741.                         {
  742.                             if (property.get_Value() != null)
  743.                             {
  744.                                 //##   d.Profile = property.get_Value().ToString();
  745.                             }
  746.                         }
  747.  
  748.                         if (property.Name == "IsLibraryItem")
  749.                         {
  750.                             try
  751.                             {
  752.                                 if (property.get_Value() != null)
  753.                                     d.IsLibraryItem = Convert.ToBoolean(property.get_Value());
  754.                             }
  755.                             catch { }
  756.                         }
  757.                     }
  758.                     d.CustomProps = CustomProppies;
  759.                 }
  760.             }
  761.             //RF@ 30-04-2010
  762.           //  propertySets.Close();
  763.             return d;
  764.  
  765.             // retval = true;
  766.         }*/
  767.         #endregion
  768.  
  769.         #region AfterDocumentOpen
  770.         void appEvents_AfterDocumentOpen(object theDocument)
  771.         {
  772.             try
  773.             {
  774.                 if (_application.ActiveDocument != null)
  775.                 {
  776.                     SolidEdgeFramework.SolidEdgeDocument document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument;
  777.                     _ActiveFileName = document.FullName;
  778.                 }
  779.             }
  780.             catch { }
  781.         }
  782.         #endregion
  783.  
  784.         #region AfterActiveDocumentChange
  785.         void appEvents_AfterActiveDocumentChange(object theDocument)
  786.         {
  787.             if ((SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument != null)
  788.             {
  789.                 SolidEdgeFramework.SolidEdgeDocument document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument;
  790.                 String extension = Path.GetExtension(document.FullName);
  791.  
  792.                 if (_ActiveFileName == document.FullName)
  793.                 {
  794.                     DoOpenDraftForm(document.FullName, true);
  795.                     DoOpenWhereUsedForm(document.FullName, true);
  796.                 }
  797.                 else
  798.                 {
  799.                     if (extension.Equals(""))
  800.                     {
  801.                         DoOpenDraftForm(document.FullName, true);
  802.                         return;
  803.                     }
  804.  
  805.                     if (!extension.Equals(".asm"))
  806.                     {
  807.                         DoOpenDraftForm(document.FullName, true, true);
  808.                         return;
  809.                     }
  810.                     else
  811.                         DoOpenDraftForm(document.FullName, true);
  812.                 }
  813.  
  814.                 _ActiveFileName = document.FullName;
  815.             }
  816.         }
  817.         #endregion
  818.  
  819.         #region Open WhereUsed
  820.         void OnMouseRibbonCommandWhereUsed(RibbonCommand ribbonCommand)
  821.         {
  822.             SolidEdgeFramework.SolidEdgeDocument document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument;
  823.             StartThread(document.FullName, FormType.WhereUsed);
  824.         }
  825.         private void DoOpenWhereUsedForm(String DocumentName, bool bChange = false, bool bClose = false)
  826.         {
  827.             MessageHelper msg = new MessageHelper();
  828.             string s = string.Empty;
  829.             int result;
  830.  
  831.             String extension = Path.GetExtension(DocumentName);
  832.            
  833.             if (!IfApplicationWindowOpen("Where Used") && !bChange)
  834.                 System.Windows.Forms.Application.Run(new ME2DLL.MdiForms.frmWhereUsed() { HeaderText = string.Format("ManageEm - Where Used - {0}", DocumentName), FileName = DocumentName });  
  835.             else
  836.             {
  837.                 if (collectionIntPtr.Count > 0)
  838.                 {
  839.  
  840.                     if (bClose)
  841.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/closewhereused#{0}", DocumentName));
  842.                     else
  843.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/openwhereused#{0}", DocumentName));
  844.                 }
  845.             }
  846.      
  847.         }
  848.         #endregion
  849.  
  850.         #region OpenDraft
  851.         void OnMouseRibbonCommandOpenDraft(RibbonCommand ribbonCommand)
  852.         {
  853.             SolidEdgeFramework.SolidEdgeDocument document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument;
  854.             StartThread(document.FullName, FormType.OpenDraft);
  855.         }
  856.         private void DoOpenDraftForm(String DocumentName, bool bChange = false, bool bClose = false)
  857.         {
  858.             MessageHelper msg = new MessageHelper();
  859.             string s = string.Empty;
  860.             int result;
  861.  
  862.             String extension = Path.GetExtension(DocumentName);
  863.  
  864.             if(extension.Equals(".dft"))
  865.                 return;
  866.            
  867.             if (extension.Equals(".asm") || extension.Equals(""))
  868.             {
  869.                 if (!IfApplicationWindowOpen("Open Drafts") && !bChange)
  870.                     System.Windows.Forms.Application.Run(new ME2DLL.MdiForms.frmOpenDrafts() { HeaderText = string.Format("ManageEm - Open Drafts - {0}", DocumentName), FileName = DocumentName });
  871.                 else
  872.                 {
  873.                     if (collectionIntPtr.Count > 0)
  874.                     {                      
  875.  
  876.                         if (bClose)
  877.                             result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/closedrafts#{0}", DocumentName));
  878.                         else
  879.                             result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/opendrafts#{0}", DocumentName));
  880.                     }
  881.                 }
  882.             }
  883.             else
  884.             {
  885.                 if (bClose)
  886.                 {
  887.                     if ( IfApplicationWindowOpen("Open Drafts") && collectionIntPtr.Count > 0)
  888.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/closedrafts#{0}", DocumentName));
  889.                     else
  890.                         return;                    
  891.                 }
  892.                 else
  893.                 {
  894.                     UnitOfWork unitOfWork = new UnitOfWork();
  895.                     //unitOfWork.ConnectionString = DataConnection.GetConnection();
  896.                     //PopulateDraftDocuments(DocumentName, unitOfWork);
  897.                 }
  898.             }            
  899.         }
  900.        
  901.         private Int32 counter;        
  902.         /*private void PopulateDraftDocuments(String fileName, UnitOfWork unitOfWork)
  903.         {          
  904.  
  905.             String name = Path.GetFileName(fileName).ToLower();
  906.             String path = Path.GetDirectoryName(fileName).ToLower();          
  907.            
  908.              XPCollection docs = new XPCollection(unitOfWork, typeof(Document),
  909.                  CriteriaOperator.Parse("FileName = ? and Path = ? ", name, path));
  910.  
  911.             if (docs.Count > 0)
  912.             {
  913.                 //Check if there is draft, with this file linked to it.
  914.                 // If so add the draft ot the list.
  915.                 XPCollection draftLinks = new XPCollection(unitOfWork, typeof(DocumentLinks),
  916.                     CriteriaOperator.Parse(String.Format("BaseItem.DocType.Extension = '.dft' and LinkedItem = '{0}'", ((Document)docs[0]).Oid)));
  917.  
  918.                 if (draftLinks.Count > 0)
  919.                 {
  920.                     SolidEdgeFramework.Documents documents = (SolidEdgeFramework.Documents)_application.Documents;
  921.                     foreach (DocumentLinks item in draftLinks)
  922.                     {
  923.                         DocumentLinks link = (DocumentLinks)item;
  924.                         String FileName = link.BaseItem.Path + "\\" + link.BaseItem.FileName;
  925.  
  926.                         if (File.Exists(FileName))
  927.                             documents.Open(FileName, Missing.Value, Missing.Value, Missing.Value,
  928.                                                                         Missing.Value, Missing.Value);                      
  929.                     }
  930.                 }
  931.  
  932.                 DraftSubLoop(((Document)docs[0]).Oid, counter, unitOfWork);
  933.             }
  934.         }
  935.         private void DraftSubLoop(Int32 oId, Int32 parentId, UnitOfWork unitOfWork)
  936.         {
  937.             XPCollection links = new XPCollection(unitOfWork, typeof(DocumentLinks),
  938.                 CriteriaOperator.Parse(String.Format("BaseItem = '{0}'", oId)));
  939.  
  940.             int tmp = links.Count;
  941.             SolidEdgeFramework.Documents documents = (SolidEdgeFramework.Documents)_application.Documents;
  942.  
  943.             foreach (DocumentLinks item in links)
  944.             {
  945.  
  946.                 //Check if there is draft, with this file linked to it.
  947.                 // If so add the draft ot the list.
  948.                 XPCollection draftLinks = new XPCollection(unitOfWork, typeof(DocumentLinks),
  949.                     CriteriaOperator.Parse(String.Format("BaseItem.DocType.Extension = '.dft' and LinkedItem = '{0}'", item.LinkedItem.Oid)));
  950.  
  951.                 if (draftLinks.Count > 0)
  952.                 {
  953.                     DocumentLinks link = (DocumentLinks)draftLinks[0];
  954.                     String fileName = link.BaseItem.Path + "\\" + link.BaseItem.FileName;
  955.  
  956.                     if (File.Exists(fileName))
  957.                         documents.Open(fileName, Missing.Value, Missing.Value, Missing.Value,
  958.                                                                     Missing.Value, Missing.Value);                    
  959.                 }
  960.  
  961.                 // process the current document.
  962.                 DraftSubLoop(item.LinkedItem.Oid, counter, unitOfWork);
  963.             }
  964.         }*/
  965.         #endregion
  966.  
  967.         #region Search
  968.         void OnMouseRibbonCommandSearchOnInput(RibbonCommand ribbonCommand)
  969.         {
  970.             DoOpenSearchForm(string.Empty);
  971.         }
  972.  
  973.         private void DoOpenSearchForm(String DocumentName, bool bChange = false, bool bClose = false)
  974.         {
  975.             MessageHelper msg = new MessageHelper();
  976.             string s = string.Empty;
  977.             int result;
  978.            
  979.             if (!IfApplicationWindowOpen("Search") && !bChange)
  980.                 System.Windows.Forms.Application.Run(new ME2DLL.MdiForms.frmSearch() { HeaderText = "ManageEm - Search" });
  981.             else
  982.             {
  983.                 if (collectionIntPtr.Count > 0)
  984.                 {
  985.  
  986.                     if (bClose)
  987.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/closesearch#{0}", DocumentName));
  988.                     else
  989.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/opensearch#{0}", DocumentName));
  990.                 }
  991.             }
  992.         }
  993.         #endregion
  994.  
  995.         #region PrintList
  996.         void OnMouseRibbonCommandPrintList(RibbonCommand ribbonCommand)
  997.         {
  998.             SolidEdgeFramework.SolidEdgeDocument document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument;
  999.             StartThread(document.FullName, FormType.PrintList);
  1000.         }
  1001.         private void DoOpenPrintListForm(String DocumentName, bool bChange = false, bool bClose = false)
  1002.         {
  1003.             MessageHelper msg = new MessageHelper();
  1004.             string s = string.Empty;
  1005.             int result;
  1006.  
  1007.             String extension = Path.GetExtension(DocumentName);
  1008.  
  1009.             if (!IfApplicationWindowOpen("PrintList") && !bChange)
  1010.                 System.Windows.Forms.Application.Run(new ME2DLL.MdiForms.frmPrintList() { HeaderText = string.Format("ManageEm - PrintList - {0}", DocumentName), FileName = DocumentName });
  1011.             else
  1012.             {
  1013.                 if (collectionIntPtr.Count > 0)
  1014.                 {
  1015.  
  1016.                     if (bClose)
  1017.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/closeprintlist#{0}", DocumentName));
  1018.                     else
  1019.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/openprintlist#{0}", DocumentName));
  1020.                 }
  1021.             }
  1022.  
  1023.         }
  1024.         #endregion      
  1025.  
  1026.         #region CheckDrafts
  1027.         void OnMouseRibbonCommandCheckDrafts(RibbonCommand ribbonCommand)
  1028.         {
  1029.             SolidEdgeFramework.SolidEdgeDocument document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument;
  1030.             StartThread(document.FullName, FormType.CheckDrafts);
  1031.         }
  1032.  
  1033.         private void DoOpenCheckDraftsForm(String DocumentName, bool bChange = false, bool bClose = false)
  1034.         {
  1035.             MessageHelper msg = new MessageHelper();
  1036.             string s = string.Empty;
  1037.             int result;
  1038.  
  1039.             String extension = Path.GetExtension(DocumentName);
  1040.  
  1041.                 if (!IfApplicationWindowOpen("Check Drafts") && !bChange)
  1042.                     System.Windows.Forms.Application.Run(new ME2DLL.MdiForms.frmCheckDrafts() { HeaderText = string.Format("ManageEm - Check Drafts - {0}", DocumentName), FileName = DocumentName });
  1043.                 else
  1044.                 {
  1045.                     if (collectionIntPtr.Count > 0)
  1046.                     {
  1047.  
  1048.                         if (bClose)
  1049.                             result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/closeCheckdrafts#{0}", DocumentName));
  1050.                         else
  1051.                             result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/openCheckdrafts#{0}", DocumentName));
  1052.                     }
  1053.                 }
  1054.  
  1055.         }
  1056.  
  1057.         #endregion
  1058.  
  1059.         #region ManageEm Properties
  1060.         private void DoOpenCustomPropertiesForm(String DocumentName, bool bChange = false, bool bClose = false)
  1061.         {
  1062.             MessageHelper msg = new MessageHelper();
  1063.             string s = string.Empty;
  1064.             int result;
  1065.  
  1066.             String extension = Path.GetExtension(DocumentName);
  1067.  
  1068.             if (!IfApplicationWindowOpen("Custom Properties") && !bChange)
  1069.                 System.Windows.Forms.Application.Run(new ME2DLL.MdiForms.frmOpenProperties() { HeaderText = string.Format("ManageEm - Properties - {0}", DocumentName), FileName = DocumentName });
  1070.             else
  1071.             {
  1072.                 if (collectionIntPtr.Count > 0)
  1073.                 {
  1074.  
  1075.                     if (bClose)
  1076.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/closeCustomProperties#{0}", DocumentName));
  1077.                     else
  1078.                         result = msg.sendWindowsStringMessage((int)collectionIntPtr[0], 0, String.Format("/openCustomProperties#{0}", DocumentName));
  1079.                 }
  1080.             }
  1081.  
  1082.         }
  1083.        
  1084.         void OnMouseRibbonCommandCustomProps(RibbonCommand ribbonCommand)
  1085.         {
  1086.             SolidEdgeFramework.SolidEdgeDocument document = (SolidEdgeFramework.SolidEdgeDocument)_application.ActiveDocument;
  1087.             StartThread(document.FullName, FormType.CustomProperties);
  1088.         }
  1089.  
  1090.         #endregion
  1091.  
  1092.         #region Threading
  1093.         private void StartThread(String DocumentName, FormType Type)
  1094.         {
  1095.             var t = new System.Threading.Thread(() => RealStart(DocumentName, Type));
  1096.             t.SetApartmentState(System.Threading.ApartmentState.STA);
  1097.             t.IsBackground = false;
  1098.             t.Start();          
  1099.         }
  1100.  
  1101.         private void RealStart(String DocumentName, FormType Type)
  1102.         {
  1103.             System.Windows.Forms.Application.EnableVisualStyles();
  1104.             System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
  1105.  
  1106.             switch (Type)
  1107.             {
  1108.                 case FormType.Search:
  1109.                     DoOpenSearchForm(DocumentName);
  1110.                     break;
  1111.                 case FormType.WhereUsed:
  1112.                     DoOpenWhereUsedForm(DocumentName);                                        
  1113.                     break;
  1114.                 case FormType.OpenDraft:
  1115.                     DoOpenDraftForm(DocumentName);
  1116.                     break;
  1117.                 case FormType.PrintList:
  1118.                     DoOpenPrintListForm(DocumentName);
  1119.                     break;
  1120.                 case FormType.CheckDrafts:
  1121.                     DoOpenCheckDraftsForm(DocumentName);
  1122.                     break;
  1123.                 case FormType.CustomProperties:
  1124.                     DoOpenCustomPropertiesForm(DocumentName);
  1125.                     break;
  1126.  
  1127.             }
  1128.         }        
  1129.  
  1130.         private static List<IntPtr> collectionIntPtr = null;
  1131.         private static bool IfApplicationWindowOpen(string windowName)
  1132.         {
  1133.             List<string> collection = new List<string>();
  1134.             List<IntPtr> internCollectionIntPtr = new List<IntPtr>();
  1135.             collectionIntPtr = new List<IntPtr>();
  1136.             User32.EnumDelegate filter = delegate(IntPtr hWnd, int lParam)
  1137.             {
  1138.                 StringBuilder strbTitle = new StringBuilder(255);
  1139.                 int nLength = User32.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1);
  1140.                 string strTitle = strbTitle.ToString();
  1141.  
  1142.                 if (User32.IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false)
  1143.                 {
  1144.                     collection.Add(strTitle);
  1145.                     internCollectionIntPtr.Add(hWnd);
  1146.                 }
  1147.                 return true;
  1148.             };
  1149.  
  1150.             if (User32.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero))
  1151.             {
  1152.                 int iTeller = 0;
  1153.                 foreach (string item in collection)
  1154.                 {
  1155.                     if (item.ToString().Contains(windowName))
  1156.                     {
  1157.                         collectionIntPtr.Add(internCollectionIntPtr[iTeller]);
  1158.                         return true;
  1159.                     }
  1160.  
  1161.                     iTeller++;
  1162.                 }
  1163.             }
  1164.             return false;
  1165.         }
  1166.        
  1167.         #endregion
  1168.  
  1169.         #region IConnectionPoint helpers
  1170.  
  1171.         /// <summary>
  1172.         /// Attaches specified events to this object.
  1173.         /// </summary>
  1174.         private void HookEvents(object eventSource, Guid eventGuid)
  1175.         {
  1176.             IConnectionPointContainer container = null;
  1177.             IConnectionPoint connectionPoint = null;
  1178.             int cookie = 0;
  1179.  
  1180.             container = (IConnectionPointContainer)eventSource;
  1181.             container.FindConnectionPoint(eventGuid, out connectionPoint);
  1182.  
  1183.             if (connectionPoint != null)
  1184.             {
  1185.                 try
  1186.                 {
  1187.                     connectionPoint.Advise(this, out cookie);
  1188.                     _connectionPointDictionary.Add(connectionPoint, cookie);
  1189.                 }
  1190.                 catch (Exception ex) { MessageBox.Show(ex.Message); }
  1191.             }
  1192.         }
  1193.  
  1194.         /// <summary>
  1195.         /// Detaches specified events from this object.
  1196.         /// </summary>
  1197.         private void UnhookAllEvents()
  1198.         {
  1199.             Dictionary<IConnectionPoint, int>.Enumerator enumerator = _connectionPointDictionary.GetEnumerator();
  1200.             while (enumerator.MoveNext())
  1201.             {
  1202.                 enumerator.Current.Key.Unadvise(enumerator.Current.Value);
  1203.             }
  1204.  
  1205.             _connectionPointDictionary.Clear();
  1206.         }
  1207.  
  1208.         #endregion
  1209.  
  1210.         #region Command Bar commands
  1211.         public void OnCommand(int CommandID)
  1212.         {
  1213.             // Get the GUID of the active environment.
  1214.             Guid environmentGuid = _application.GetActiveEnvironmentGuid();
  1215.  
  1216.             // Lookup ribbon command by environment and command id.
  1217.             RibbonCommand ribbonCommand = RibbonHelper.LookupRibbonCommandByCommandId(environmentGuid, CommandID);
  1218.  
  1219.             if (ribbonCommand != null)
  1220.             {
  1221.                 if (ribbonCommand.Callback != null)
  1222.                 {
  1223.                     // Forward call to specified delegate.
  1224.                     ribbonCommand.Callback(ribbonCommand);
  1225.                 }
  1226.                 else
  1227.                 {
  1228.                     MessageBox.Show("No callback set for ribbon command!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1229.                 }
  1230.             }
  1231.             else
  1232.             {
  1233.                 MessageBox.Show("Lookup for ribbon command failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  1234.             }
  1235.         }
  1236.  
  1237.         public void OnCommandHelp(int hFrameWnd, int HelpCommandID, int CommandID)
  1238.         {
  1239.  
  1240.         }
  1241.  
  1242.         public void OnCommandUpdateUI(int CommandID, ref int CommandFlags, out string MenuItemText, ref int BitmapID)
  1243.         {
  1244.             MenuItemText = null;
  1245.  
  1246.             // Default to disabled state.
  1247.             CommandFlags = 0;
  1248.  
  1249.             // Get the GUID of the active environment.
  1250.             Guid environmentGuid = _application.GetActiveEnvironmentGuid();
  1251.  
  1252.             // Lookup the ribbon command by it's command id.
  1253.             RibbonCommand ribbonCommand = RibbonHelper.LookupRibbonCommandByCommandId(environmentGuid, CommandID);
  1254.  
  1255.             if (ribbonCommand != null)
  1256.             {
  1257.                 // Toggle button enabled state if necessary.
  1258.                 if (ribbonCommand.Enabled)
  1259.                 {
  1260.                     CommandFlags = (int)SolidEdgeConstants.SECommandActivation.seCmdActive_Enabled;
  1261.                 }
  1262.  
  1263.                 // Toggle button checked state if necessary.
  1264.                 if (ribbonCommand.Checked)
  1265.                 {
  1266.                     CommandFlags |= (int)SolidEdgeConstants.SECommandActivation.seCmdActive_Checked;
  1267.                 }
  1268.             }
  1269.         }
  1270.         #endregion
  1271.  
  1272.         #region regasm.exe
  1273.  
  1274.         /// <summary>
  1275.         /// Implementation of ComRegisterFunction.
  1276.         /// </summary>
  1277.         /// <remarks>
  1278.         /// This method gets called when regasm.exe is executed against the assembly.
  1279.         /// </remarks>
  1280.         [ComRegisterFunction]
  1281.         public static void Register(Type t)
  1282.         {
  1283.             RegistrationHelper.Register(t);
  1284.         }
  1285.  
  1286.         /// <summary>
  1287.         /// Implementation of ComUnregisterFunction.
  1288.         /// </summary>
  1289.         /// <remarks>
  1290.         /// This method gets called when regasm.exe is executed against the assembly.
  1291.         /// </remarks>
  1292.         [ComUnregisterFunction]
  1293.         public static void Unregister(Type t)
  1294.         {
  1295.             ManageEmAddIn.Unregister(t);
  1296.         }
  1297.  
  1298.         #endregion
  1299.     }
  1300. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement