private void Process(CrmPluginAssembly assembly, string mergedPluginAssemblyPath)
        {
            // ToDo: use DataFlow
            var currentAssembly    = AssemblyHelper.LoadAssemblyFromDB(assembly.Name);
            var createAssembly     = currentAssembly == null;
            var pluginsForRegister = new List <CrmPlugin>();
            var pluginsForRemove   = new List <CrmPlugin>();
            var pluginsForUpdate   = new List <(CrmPlugin plugin, CrmPlugin existed)>();

            if (createAssembly)
            {
                pluginsForRegister.AddRange(assembly.CrmPlugins);
            }
            else
            {
                CrmPlugin GetCorrelated(CrmPluginAssembly a, CrmPlugin plugin) => a.CrmPlugins.FirstOrDefault(p => p.TypeName == plugin.TypeName);

                pluginsForRegister.AddRange(
                    from plugin in assembly.CrmPlugins
                    where GetCorrelated(currentAssembly, plugin) == null
                    select plugin);

                pluginsForRemove.AddRange(
                    from plugin in currentAssembly.CrmPlugins
                    where GetCorrelated(assembly, plugin) == null
                    select plugin);

                pluginsForUpdate.AddRange(
                    from plugin in assembly.CrmPlugins
                    let existed = GetCorrelated(currentAssembly, plugin)
                                  where existed != null
                                  select(plugin, existed));
            }

            if (createAssembly)
            {
                try
                {
                    assembly.IsolationMode = CrmAssemblyIsolationMode.None;
                    assembly.AssemblyId    = AssemblyHelper.CreateAssemblyInDB(mergedPluginAssemblyPath, assembly);
                }
                catch (Exception ex)
                {
                    throw new Exception("ERROR: Error occurred while registering the plugin assembly", ex);
                }
            }
            else
            {
                UnregisterPlugins(pluginsForRemove);

                assembly.IsolationMode = currentAssembly.IsolationMode;
                assembly.AssemblyId    = currentAssembly.AssemblyId;

                var workflows =
                    (from plugin in currentAssembly.CrmPlugins
                     where plugin.PluginType == CrmPluginType.WorkflowActivity
                     select
                     new PluginType
                {
                    Id = plugin.Id,
                    WorkflowActivityGroupName = plugin.WorkflowActivityGroupName
                }).ToArray();

                AssemblyHelper.UpdateAssemblyInDB(mergedPluginAssemblyPath, assembly, workflows);
            }

            RegisterPlugins(pluginsForRegister);

            UpdatePlugins(pluginsForUpdate);
        }