public static bool RegistrationDetailsPresent(string assemblyPath, bool isWorkflow)
        {
            var assemblyBytes = File.ReadAllBytes(assemblyPath);

            AssemblyContainer container = AssemblyContainer.LoadAssembly(assemblyBytes, isWorkflow, true);

            return(container.PluginDatas.First().CrmPluginRegistrationAttributes.Count > 0);
        }
Ejemplo n.º 2
0
    static void Main(string[] args)
    {
        var assemblyBytes = File.ReadAllBytes(@"C:\dev\Newtonsoft.Json.dll");

        // load an unload the same assembly 5 times
        for (int i = 0; i < 5; i++)
        {
            var assemblyContainer = AssemblyContainer.LoadAssembly(assemblyBytes, true);
            var assemblyName      = assemblyContainer.AssemblyName;
            assemblyContainer.Unload();
        }

        Console.ReadKey();
    }
Ejemplo n.º 3
0
        public Guid RegisterWorkflowActivities(string file, string solutionName)
        {
            SolutionUniqueName = solutionName;
            var assemblyFilePath = new FileInfo(file);

            if (_ignoredAssemblies.Contains(assemblyFilePath.Name))
            {
                return(Guid.Empty);
            }

            AssemblyContainer assemblyContainer = null;

            try
            {
                //Load the assembly in its own AppDomain to prevent load errors & file locking
                var assemblyBytes = File.ReadAllBytes(file);
                assemblyContainer = AssemblyContainer.LoadAssembly(assemblyBytes, true, true);
                List <PluginData> pluginDatas = assemblyContainer.PluginDatas;

                if (pluginDatas.Count <= 0)
                {
                    return(Guid.Empty);
                }

                var plugin = RegisterAssembly(assemblyFilePath, pluginDatas.First().AssemblyName, pluginDatas.First().CrmPluginRegistrationAttributes);

                if (plugin == null)
                {
                    return(plugin.Id);
                }

                foreach (PluginData pluginData in pluginDatas)
                {
                    RegisterActivities(pluginData.CrmPluginRegistrationAttributes, plugin, pluginData.AssemblyFullName);
                }

                _ctx.SaveChanges();

                return(plugin.Id);
            }
            finally
            {
                assemblyContainer?.Unload();
            }
        }
Ejemplo n.º 4
0
        private static bool RegistrationDetailsPresent(string assemblyPath, bool isWorkflow)
        {
            AssemblyContainer container = null;

            try
            {
                var assemblyBytes = File.ReadAllBytes(assemblyPath);

                string assemblyFolderPath = Path.GetDirectoryName(assemblyPath);

                container = AssemblyContainer.LoadAssembly(assemblyBytes, isWorkflow, assemblyFolderPath, true);

                return(container.PluginDatas.First().CrmPluginRegistrationAttributes.Count > 0);
            }
            finally
            {
                container?.Unload();
            }
        }
Ejemplo n.º 5
0
        public static string AssemblyFullName(string assemblyPath, bool isWorkflow)
        {
            AssemblyContainer assemblyContainer = null;

            try
            {
                string assemblyFolderPath = Path.GetDirectoryName(assemblyPath);

                assemblyContainer = AssemblyContainer.LoadAssembly(File.ReadAllBytes(assemblyPath), isWorkflow, assemblyFolderPath, true);

                List <PluginData> pluginDatas = assemblyContainer.PluginDatas;

                return(pluginDatas.First().AssemblyFullName);
            }
            finally
            {
                assemblyContainer?.Unload();
            }
        }
Ejemplo n.º 6
0
        public static string[] AssemblyProperties(string assemblyPath, bool isWorkflow)
        {
            AssemblyContainer assemblyContainer = null;

            try
            {
                string assemblyFolderPath = Path.GetDirectoryName(assemblyPath);

                assemblyContainer = AssemblyContainer.LoadAssembly(File.ReadAllBytes(assemblyPath), isWorkflow, assemblyFolderPath, true);

                List <PluginData> pluginDatas = assemblyContainer.PluginDatas;

                AssemblyName assemblyName = pluginDatas.First().AssemblyName;

                var assemblyProperties = assemblyName.FullName.Split(",= ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                return(assemblyProperties);
            }
            finally
            {
                assemblyContainer?.Unload();
            }
        }
Ejemplo n.º 7
0
        public void RegisterPlugin(string file)
        {
            var assemblyFilePath = new FileInfo(file);
            AssemblyContainer assemblyContainer = null;

            try
            {
                //Load the assembly in its own AppDomain to prevent load errors & file locking
                var assemblyBytes = File.ReadAllBytes(file);
                assemblyContainer = AssemblyContainer.LoadAssembly(assemblyBytes, false, true);
                List <PluginData> pluginDatas = assemblyContainer.PluginDatas;

                if (pluginDatas.Count <= 0)
                {
                    return;
                }

                var plugin = RegisterAssembly(assemblyFilePath, pluginDatas.First().AssemblyName, pluginDatas.First().CrmPluginRegistrationAttributes);

                if (plugin == null)
                {
                    return;
                }

                foreach (PluginData pluginData in pluginDatas)
                {
                    RegisterPluginSteps(pluginData.CrmPluginRegistrationAttributes, plugin, pluginData.AssemblyFullName);
                }

                _ctx.SaveChanges();
            }
            finally
            {
                assemblyContainer?.Unload();
            }
        }
Ejemplo n.º 8
0
        public void RegisterWorkflowActivities(string file)
        {
            var assemblyFilePath = new FileInfo(file);

            if (_ignoredAssemblies.Contains(assemblyFilePath.Name))
            {
                return;
            }

            AssemblyContainer assemblyContainer = null;

            try
            {
                //Load the assembly in its own AppDomain to prevent load errors & file locking
                var assemblyBytes = File.ReadAllBytes(file);
                assemblyContainer = AssemblyContainer.LoadAssembly(assemblyBytes, true, true);
                List <PluginData> pluginDatas = assemblyContainer.PluginDatas;

                if (pluginDatas.Count <= 0)
                {
                    return;
                }

                var plugin = RegisterAssembly(assemblyFilePath, pluginDatas.First().AssemblyName, pluginDatas.First().CrmPluginRegistrationAttributes);

                if (plugin == null)
                {
                    return;
                }

                foreach (PluginData pluginData in pluginDatas)
                {
                    RegisterActivities(pluginData.CrmPluginRegistrationAttributes, plugin, pluginData.AssemblyFullName);
                }

                _ctx.SaveChanges();
            }
            finally
            {
                assemblyContainer?.Unload();
            }

            //var assemblyFilePath = new FileInfo(path);
            //if (_ignoredAssemblies.Contains(assemblyFilePath.Name))
            //    return;
            //// Load each assembly
            //Assembly assembly = Reflection.ReflectionOnlyLoadAssembly(assemblyFilePath.FullName);

            //if (assembly == null)
            //    return;

            //// Search for any types that interhit from IPlugin
            //IEnumerable<Type> pluginTypes = Reflection.GetTypesInheritingFrom(assembly, typeof(System.Activities.CodeActivity));

            //if (pluginTypes.Count() > 0)
            //{
            //    //var plugin = RegisterAssembly(assemblyFilePath, assembly, pluginTypes);
            //    var plugin = RegisterAssembly(assemblyFilePath, assembly, pluginTypes);

            //    if (plugin != null)
            //    {
            //        RegisterActivities(pluginTypes, plugin);
            //    }
            //}
        }