예제 #1
0
        protected override void ExecuteInternal(string filePath, OrganizationServiceContext ctx, bool backupFiles)
        {
            _trace.WriteLine("Searching for plugin classes in '{0}'", filePath);
            var targetFolder = new DirectoryInfo(filePath);
            var matches      = DirectoryEx.Search(filePath, "*.cs", null);

            if (matches == null)
            {
                return;
            }

            var pluginRegistration = new PluginRegistraton(_service, ctx, _trace);
            int codeFilesUpdated   = 0;

            foreach (var codeFile in matches)
            {
                try
                {
                    // Find if it contains any IPlugin files
                    CodeParser parser = new CodeParser(new Uri(codeFile));

                    if (parser.PluginCount > 0)
                    {
                        // Backup
                        if (backupFiles)
                        {
                            File.WriteAllText(parser.FilePath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak", parser.Code);
                        }

                        foreach (var pluginType in parser.ClassNames)
                        {
                            // Remove existing attributes
                            parser.RemoveExistingAttributes();

                            if (parser.IsPlugin(pluginType))
                            {
                                AddPluginAttributes(ctx, parser, pluginType);
                            }
                            else if (parser.IsWorkflowActivity(pluginType))
                            {
                                AddWorkflowActivityAttributes(ctx, parser, pluginType);
                            }
                            else
                            {
                                _trace.WriteLine("Cannot find Plugin Type Registration {0}", pluginType);
                            }
                        }
                        // Update
                        File.WriteAllText(parser.FilePath, parser.Code);
                        codeFilesUpdated++;
                    }
                }

                catch (ReflectionTypeLoadException ex)
                {
                    throw new Exception(ex.LoaderExceptions.First().Message);
                }
            }
            _trace.WriteLine("{0} plugins decorated with deployment attributes!", codeFilesUpdated);
        }
예제 #2
0
        private void DeployPlugins(OrganizationServiceContext ctx, ConfigFile config)
        {
            var plugins = config.GetPluginsConfig(this.Profile);

            foreach (var plugin in plugins)
            {
                List <string> assemblies = ConfigFile.GetAssemblies(config, plugin);

                var pluginRegistration = new PluginRegistraton(_service, ctx, _trace);

                if (!string.IsNullOrEmpty(plugin.solution))
                {
                    pluginRegistration.SolutionUniqueName = plugin.solution;
                }

                foreach (var assemblyFilePath in assemblies)
                {
                    try
                    {
                        pluginRegistration.RegisterPlugin(assemblyFilePath);
                    }

                    catch (ReflectionTypeLoadException ex)
                    {
                        throw new Exception(ex.LoaderExceptions.First().Message);
                    }
                }
            }
        }
예제 #3
0
        private void DeployWorkflowActivities(OrganizationServiceContext ctx, ConfigFile config)
        {
            var plugins = config.GetPluginsConfig(this.Profile);

            foreach (var plugin in plugins)
            {
                List<string> assemblies = ConfigFile.GetAssemblies(config, plugin);

                var pluginRegistration = new PluginRegistraton(_service, ctx, _trace);

                foreach (var assemblyFilePath in assemblies)
                {
                    try
                    {
                        pluginRegistration.RegisterWorkflowActivities(assemblyFilePath);
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        throw new Exception(ex.LoaderExceptions.First().Message);
                    }
                }
            }
        }
        protected override void ExecuteInternal(string filePath, OrganizationServiceContext ctx)
        {
            _trace.WriteLine("Searching for classes in '{0}'", filePath);
            var targetFolder = new DirectoryInfo(filePath);
            var matches      = ServiceLocator.DirectoryService.Search(filePath, "*.cs");

            if (matches == null)
            {
                return;
            }

            var pluginRegistration = new PluginRegistraton(_service, ctx, _trace);
            int codeFilesUpdated   = 0;

            // Create a spkl.json file here (or load an existing one)
            var files = ServiceLocator.ConfigFileFactory.FindConfig(filePath, false);
            var file  = files[0];

            foreach (var codeFile in matches)
            {
                try
                {
                    string customClassRegex = null;
                    // Support for custom base class regex
                    var profile = file.GetPluginsConfig(this.Profile);
                    if (profile != null && profile.Length > 0 && !String.IsNullOrEmpty(profile[0].classRegex))
                    {
                        customClassRegex = profile[0].classRegex;
                    }

                    // Find if it contains any plugin/workflow classes
                    CodeParser parser = new CodeParser(new Uri(codeFile), customClassRegex);

                    if (parser.PluginCount > 0)
                    {
                        // Backup
                        File.WriteAllText(parser.FilePath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak", parser.Code);
                        foreach (var pluginType in parser.ClassNames)
                        {
                            // Remove existing attributes
                            parser.RemoveExistingAttributes();

                            if (parser.IsPlugin(pluginType))
                            {
                                AddPluginAttributes(ctx, parser, pluginType);
                            }
                            else if (parser.IsWorkflowActivity(pluginType))
                            {
                                AddWorkflowActivityAttributes(ctx, parser, pluginType);
                            }
                            else
                            {
                                _trace.WriteLine("Cannot find Type Registration {0}", pluginType);
                            }
                        }
                        // Update
                        File.WriteAllText(parser.FilePath, parser.Code);
                        codeFilesUpdated++;
                    }
                }

                catch (ReflectionTypeLoadException ex)
                {
                    throw new Exception(ex.LoaderExceptions.First().Message);
                }
            }
            _trace.WriteLine("{0} classes decorated with deployment attributes!", codeFilesUpdated);


            if (file.plugins == null)
            {
                file.plugins = new List <PluginDeployConfig>();
            }

            if (file.plugins.Where(a => a.assemblypath == @"bin\Debug").FirstOrDefault() == null)
            {
                file.plugins.Add(new PluginDeployConfig()
                {
                    assemblypath = @"bin\Debug"
                });
            }

            file.filePath = filePath;
            file.Save();
        }
        protected override void ExecuteInternal(string filePath, OrganizationServiceContext ctx)
        {
            _trace.WriteLine("Searching for plugin classes in '{0}'", filePath);
            var targetFolder = new DirectoryInfo(filePath);
            var matches      = DirectoryEx.Search(filePath, "*.cs", null);

            if (matches == null)
            {
                return;
            }

            var pluginRegistration = new PluginRegistraton(_service, ctx, _trace);
            int codeFilesUpdated   = 0;

            foreach (var codeFile in matches)
            {
                try
                {
                    // Find if it contains any IPlugin files
                    CodeParser parser = new CodeParser(new Uri(codeFile));

                    if (parser.PluginCount > 0)
                    {
                        // Backup
                        File.WriteAllText(parser.FilePath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak", parser.Code);
                        foreach (var pluginType in parser.ClassNames)
                        {
                            // Remove existing attributes
                            parser.RemoveExistingAttributes();

                            if (parser.IsPlugin(pluginType))
                            {
                                AddPluginAttributes(ctx, parser, pluginType);
                            }
                            else if (parser.IsWorkflowActivity(pluginType))
                            {
                                AddWorkflowActivityAttributes(ctx, parser, pluginType);
                            }
                            else
                            {
                                _trace.WriteLine("Cannot find Plugin Type Registration {0}", pluginType);
                            }
                        }
                        // Update
                        File.WriteAllText(parser.FilePath, parser.Code);
                        codeFilesUpdated++;
                    }
                }

                catch (ReflectionTypeLoadException ex)
                {
                    throw new Exception(ex.LoaderExceptions.First().Message);
                }
            }
            _trace.WriteLine("{0} plugins decorated with deployment attributes!", codeFilesUpdated);

            //TODO: remove backup files

            //// Create a spkl.json file here
            //var files = ConfigFile.FindConfig(filePath,false);
            //var file = files[0];

            //if (file.plugins == null)
            //{
            //    file.plugins = new List<PluginDeployConfig>();
            //}

            //if (file.plugins.Where(a=>a.assemblypath == @"bin\Debug").FirstOrDefault()==null)
            //{
            //    file.plugins.Add(new PluginDeployConfig()
            //    {
            //        assemblypath = @"bin\Debug"
            //    });
            //}

            //file.filePath = filePath;
            //file.Save();
        }