示例#1
0
        public List <MefAddIns.Extensibility.mef_IBase> BuildListOfAddins()
        {
            if (CoreUtilities.Constants.BLANK == dataPath)
            {
                throw new Exception("No path defined for AddIns");
            }
            lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE, String.Format("Scanning {0} for addins", dataPath));

            var bootStrapper = new MefAddIns.Terminal.Bootstrapper();
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();

            //Adds all the parts found in same directory where the application is running!
            //var currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(MainForm)).Location);
            catalog.Catalogs.Add(new DirectoryCatalog(dataPath));

            //Create the CompositionContainer with the parts in the catalog
            var _container = new CompositionContainer(catalog);

            //Fill the imports of this object
            try {
                _container.ComposeParts(bootStrapper);
            } catch (CompositionException compositionException) {
                //CoreUtilities.lg.Instance.Line ("AddIns->BuildListOfAddIns", ProblemType.EXCEPTION, compositionException.ToString ());
                NewMessage.Show(compositionException.ToString());
            } catch (System.Reflection.ReflectionTypeLoadException) {
                CoreUtilities.lg.Instance.Line("AddIns->BuildListOfAddIns", ProblemType.EXCEPTION, "At least one AddIn does not implement the entirety of the needed Interface Contract");
                NewMessage.Show("At least one AddIn does not implement the entirety of the needed Interface Contract");
            }

            //Prints all the languages that were found into the application directory
            var i = 0;

            AddInsList = new List <MefAddIns.Extensibility.mef_IBase> ();

            //var bootStrapper = new MefAddIns.Terminal.Bootstrapper ();
            // May 2013 _ I was able to load in transactions but was still unable to get them to work properly, in all cases
            // hence Submission and Destination will need to remain in Transactions base class

//			foreach (var transaction in bootStrapper.tbase) {
//				NewMessage.Show (transaction.ToString());
//			}

            foreach (var language in bootStrapper.Base)
            {
                // We look to see if this is a copy of another addin loaded already
                mef_IBase AddInAlreadyIn = AddInsList.Find(mef_IBase => mef_IBase.CalledFrom.GUID == language.CalledFrom.GUID);
                if (null != AddInAlreadyIn)
                {
                    lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE, "This AddIn is already found. Adding as a copy");
                    language.SetGuid(language.CalledFrom.GUID + Loc.Instance.GetString(" (COPY) "));
                    language.IsCopy = true;
                }
                lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,
                                 String.Format("[{0}] {1} by {2}.\n\t{3}\n", language.Version, language.Name, language.Author, language.Description));

                i++;
                language.SetStorage(DatabaseName);
                AddInsList.Add(language);
            }

//			// added this back in, but as part of the "Consdensceing process", will remove again TO DO
//			foreach (var language in bootStrapper.Notes) {
//
//				// We look to see if this is a copy of another addin loaded already
//				mef_IBase AddInAlreadyIn = AddInsList.Find (mef_IBase => mef_IBase.CalledFrom.GUID == language.CalledFrom.GUID);
//				if (null != AddInAlreadyIn)
//				{
//					lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,"This AddIn is already found. Adding as a copy");
//					language.SetGuid(language.CalledFrom.GUID +  Loc.Instance.GetString(" (COPY) "));
//					language.IsCopy = true;
//
//				}
//				lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,
//				                 String.Format ("[{0}] {1} by {2}.\n\t{3}\n", language.Version, language.Name, language.Author, language.Description));
//
//				i++;
//				AddInsList.Add (language);
//
//
//
//			}

//			foreach (var form in bootStrapper.FormBasic) {
//
//				// We look to see if this is a copy of another addin loaded already
//				mef_IBase AddInAlreadyIn = AddInsList.Find (mef_IBase => mef_IBase.CalledFrom.GUID == form.CalledFrom.GUID);
//				if (null != AddInAlreadyIn)
//				{
//					lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,"This AddIn is already found. Adding as a copy");
//					form.SetGuid(form.CalledFrom.GUID +  Loc.Instance.GetString(" (COPY) "));
//					form.IsCopy = true;
//
//				}
//				lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,
//				                 String.Format ("[{0}] {1} by {2}.\n\t{3} {4}\n", form.Version, form.Name, form.Author, form.Description, form.IsCopy));
//
//				i++;
//				AddInsList.Add (form);
//
////				form.ShowWindow();
//			}

            /*
             * foreach (var note in bootStrapper.Notes) {
             *      Console.WriteLine ("[{0}] {1} by {2}.\n\t{3}\n", note.Version, note.Name, note.Author, note.Description);
             *      AddInsList.Add (note);
             *      //language.Boom ();
             *      //string result = language.Tester ("this is the string I passed in");
             *      //Console.WriteLine ("RESULT = " + result);
             *
             * //				note.RegisterType();
             * }
             */

            lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE, String.Format("AddIns Found: {0}.", i));

            return(AddInsList);

            //
        }
示例#2
0
        public List<MefAddIns.Extensibility.mef_IBase> BuildListOfAddins()
        {
            if (CoreUtilities.Constants.BLANK == dataPath) {
                throw new Exception ("No path defined for AddIns");
            }
            lg.Instance.Line ("AddIns.BuildListOfAddIns", ProblemType.MESSAGE, String.Format ("Scanning {0} for addins", dataPath));

            var bootStrapper = new MefAddIns.Terminal.Bootstrapper ();
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog ();
            //Adds all the parts found in same directory where the application is running!
            //var currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(MainForm)).Location);
            catalog.Catalogs.Add (new DirectoryCatalog (dataPath));

            //Create the CompositionContainer with the parts in the catalog
            var _container = new CompositionContainer (catalog);

            //Fill the imports of this object
            try {
                _container.ComposeParts (bootStrapper);
            } catch (CompositionException compositionException) {
                //CoreUtilities.lg.Instance.Line ("AddIns->BuildListOfAddIns", ProblemType.EXCEPTION, compositionException.ToString ());
                NewMessage.Show (compositionException.ToString ());
            } catch (System.Reflection.ReflectionTypeLoadException) {
                CoreUtilities.lg.Instance.Line ("AddIns->BuildListOfAddIns", ProblemType.EXCEPTION, "At least one AddIn does not implement the entirety of the needed Interface Contract");
                NewMessage.Show ("At least one AddIn does not implement the entirety of the needed Interface Contract");
            }

            //Prints all the languages that were found into the application directory
            var i = 0;

            AddInsList = new List<MefAddIns.Extensibility.mef_IBase> ();

            //var bootStrapper = new MefAddIns.Terminal.Bootstrapper ();
            // May 2013 _ I was able to load in transactions but was still unable to get them to work properly, in all cases
            // hence Submission and Destination will need to remain in Transactions base class

            //			foreach (var transaction in bootStrapper.tbase) {
            //				NewMessage.Show (transaction.ToString());
            //			}

            foreach (var language in bootStrapper.Base) {

                // We look to see if this is a copy of another addin loaded already
                mef_IBase AddInAlreadyIn = AddInsList.Find (mef_IBase => mef_IBase.CalledFrom.GUID == language.CalledFrom.GUID);
                if (null != AddInAlreadyIn)
                {
                    lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,"This AddIn is already found. Adding as a copy");
                    language.SetGuid(language.CalledFrom.GUID +  Loc.Instance.GetString(" (COPY) "));
                    language.IsCopy = true;

                }
                lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,
                                 String.Format ("[{0}] {1} by {2}.\n\t{3}\n", language.Version, language.Name, language.Author, language.Description));

                i++;
                language.SetStorage(DatabaseName);
                AddInsList.Add (language);

            }

            //			// added this back in, but as part of the "Consdensceing process", will remove again TO DO
            //			foreach (var language in bootStrapper.Notes) {
            //
            //				// We look to see if this is a copy of another addin loaded already
            //				mef_IBase AddInAlreadyIn = AddInsList.Find (mef_IBase => mef_IBase.CalledFrom.GUID == language.CalledFrom.GUID);
            //				if (null != AddInAlreadyIn)
            //				{
            //					lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,"This AddIn is already found. Adding as a copy");
            //					language.SetGuid(language.CalledFrom.GUID +  Loc.Instance.GetString(" (COPY) "));
            //					language.IsCopy = true;
            //
            //				}
            //				lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,
            //				                 String.Format ("[{0}] {1} by {2}.\n\t{3}\n", language.Version, language.Name, language.Author, language.Description));
            //
            //				i++;
            //				AddInsList.Add (language);
            //
            //
            //
            //			}

            //			foreach (var form in bootStrapper.FormBasic) {
            //
            //				// We look to see if this is a copy of another addin loaded already
            //				mef_IBase AddInAlreadyIn = AddInsList.Find (mef_IBase => mef_IBase.CalledFrom.GUID == form.CalledFrom.GUID);
            //				if (null != AddInAlreadyIn)
            //				{
            //					lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,"This AddIn is already found. Adding as a copy");
            //					form.SetGuid(form.CalledFrom.GUID +  Loc.Instance.GetString(" (COPY) "));
            //					form.IsCopy = true;
            //
            //				}
            //				lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE,
            //				                 String.Format ("[{0}] {1} by {2}.\n\t{3} {4}\n", form.Version, form.Name, form.Author, form.Description, form.IsCopy));
            //
            //				i++;
            //				AddInsList.Add (form);
            //
            ////				form.ShowWindow();
            //			}
            /*
            foreach (var note in bootStrapper.Notes) {
                Console.WriteLine ("[{0}] {1} by {2}.\n\t{3}\n", note.Version, note.Name, note.Author, note.Description);
                AddInsList.Add (note);
                //language.Boom ();
                //string result = language.Tester ("this is the string I passed in");
                //Console.WriteLine ("RESULT = " + result);

            //				note.RegisterType();
            }
            */

            lg.Instance.Line("AddIns.BuildListOfAddIns", ProblemType.MESSAGE, String.Format ("AddIns Found: {0}.", i));

            return AddInsList;

            //
        }