예제 #1
0
        public void Notify(FFIExecutionSession session)
        {
            Type[] appTypes = session.ExtensionAppTypes;
            foreach (var item in appTypes)
            {
                //If the specified key is not found then the HashTable returns null.
                IExtensionApplication app = mExtensionApps[item] as IExtensionApplication;
                if (null == app)
                {
                    continue;
                }

                switch (session.State)
                {
                case ProtoCore.ExecutionStateEventArgs.State.ExecutionBegin:
                    app.OnBeginExecution(session);
                    break;

                case ProtoCore.ExecutionStateEventArgs.State.ExecutionEnd:
                    app.OnEndExecution(session);
                    break;

                case ProtoCore.ExecutionStateEventArgs.State.ExecutionBreak:
                    app.OnSuspendExecution(session);
                    break;

                case ProtoCore.ExecutionStateEventArgs.State.ExecutionResume:
                    app.OnResumeExecution(session);
                    break;

                default:
                    break;
                }
            }
        }
예제 #2
0
        private void InitializeExtensionApp(Assembly assembly)
        {
            Type extensionAppType  = typeof(IExtensionApplication);
            Type assemblyAttribute = typeof(Autodesk.DesignScript.Runtime.ExtensionApplicationAttribute);

            System.Type appType = CLRDLLModule.GetImplemetationType(assembly, extensionAppType, assemblyAttribute, true);

            if (null == appType)
            {
                return;
            }

            IExtensionApplication extesionApp = null;

            lock (mAssemblies)
            {
                if (!mAssemblies.ContainsKey(assembly))
                {
                    extesionApp = (IExtensionApplication)Activator.CreateInstance(appType, true);
                    mExtensionApps.Add(appType, extesionApp);
                }
            }

            if (null != extesionApp)
            {
                extesionApp.StartUp();
            }
        }
예제 #3
0
 public void Initialize(IExtensionApplication application)
 {
     application.Initialize();
     if (_applications.FirstOrDefault(x => x == application) == null)
     {
         _applications.Add(application);
     }
 }
예제 #4
0
        /// <summary>
        /// For nunit-teardown
        /// </summary>
        internal void ForceShutDownAllApps()
        {
            IDictionaryEnumerator i = mExtensionApps.GetEnumerator();

            while (i.MoveNext())
            {
                IExtensionApplication app = i.Value as IExtensionApplication;
                if (null != app)
                {
                    app.ShutDown();
                }
            }
        }
예제 #5
0
        public static void PrepareServices(this IExtensionApplication app)
        {
            var startupType = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(x => x.Name == "Startup");

            //var services = new ServiceCollection();
            services.AddInstance(services);
            services.AddSingleton <IActivator, Injection.Activator>();
            var provider = services.BuildServiceProvider();
            var instance = ActivatorUtilities.CreateInstance(provider, startupType);

            foreach (var method in startupType.GetMethods(BindingFlags.Public | BindingFlags.Instance).OrderBy(x => x.Name))
            {
                method.Invoke(instance, method.GetParameters().Select(x => provider.GetService(x.ParameterType)).ToArray());
            }
        }
예제 #6
0
        /// <summary>
        /// For nunit-setup
        /// </summary>
        internal void ForceStartUpAllApps()
        {
            IDictionaryEnumerator i = mExtensionApps.GetEnumerator();

            while (i.MoveNext())
            {
                IExtensionApplication app = i.Value as IExtensionApplication;
                if (null != app)
                {
                    app.StartUp(new ExtensionStartupParams()
                    {
                        DisableADP = Dynamo.Logging.Analytics.DisableAnalytics
                    });
                }
            }
        }
예제 #7
0
        private object CreateInstance(Type type, string library)
        {
            Object returnValue           = null;
            Type   externalExtensionType = null;
            Type   extensionType         = typeof(IExtensionApplication);

            System.Diagnostics.Debug.Write("Trying to load assembly: " + library);
            Assembly assembly = Assembly.LoadFrom(library);

            Type[] types = assembly.GetExportedTypes();
            foreach (var item in types)
            {
                if (item.IsAbstract)
                {
                    continue;
                }

                if (type.IsAssignableFrom(item))
                {
                    returnValue = Activator.CreateInstance(item);
                }

                if (extensionType.IsAssignableFrom(item))
                {
                    externalExtensionType = item;
                }

                if (null != externalExtensionType && null != returnValue)
                {
                    break;
                }
            }

            //If the GeometryFactory instance or the persistent manager is created successfully, and the extension application in that module
            // has not yet been created, then create a extension application as well.
            if (null != returnValue && null != externalExtensionType && !mExtensionApplicationTypes.Contains(externalExtensionType))
            {
                IExtensionApplication extensionApplication = Activator.CreateInstance(externalExtensionType) as IExtensionApplication;
                if (null != extensionApplication)
                {
                    mExtensionApplicationTypes.Add(externalExtensionType);
                    mExtensionApplications.Add(extensionApplication);
                }
            }

            return(returnValue);
        }
        private void Terminate()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.AssemblyLoad    -= new AssemblyLoadEventHandler(OnAssemblyLoad);
            currentDomain.AssemblyResolve -= new ResolveEventHandler(OnAssemblyResolve);
            currentDomain.ProcessExit     -= new EventHandler(OnDomainUnload);

            IDictionaryEnumerator i = mExtensionApps.GetEnumerator();

            while (i.MoveNext())
            {
                IExtensionApplication app = i.Value as IExtensionApplication;
                if (null != app)
                {
                    app.ShutDown();
                }
            }
            mExtensionApps.Clear();
            mAssemblies.Clear();
        }