Exemple #1
0
        protected override void ExecuteInternal(string filePath, OrganizationServiceContext ctx, bool backupFiles, string customClassRegex)
        {
            _trace.WriteLine("Searching for 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 plugin/workflow classes
                    CodeParser parser = new CodeParser(new Uri(codeFile), customClassRegex);

                    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 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);
        }
Exemple #2
0
        public static List <ConfigFile> FindConfig(string folder, bool raiseErrorIfNotFound = true)
        {
            // search for the config file
            var configfilePath = DirectoryEx.Search(folder, "spkl.json", null);

            if (raiseErrorIfNotFound && (configfilePath == null || configfilePath.Count == 0))
            {
                throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.CONFIG_NOTFOUND, String.Format("Cannot find spkl.json in at '{0}' - make sure it is in the same folder or sub-folder as spkl.exe or provide a [path]", folder));
            }

            var results = new List <ConfigFile>();

            foreach (var configPath in configfilePath)
            {
                if (configPath != null)
                {
                    var config = Newtonsoft.Json.JsonConvert.DeserializeObject <ConfigFile>(File.ReadAllText(configPath));
                    config.filePath = Path.GetDirectoryName(configPath);
                    results.Add(config);
                }
            }

            if (results.Count == 0)
            {
                results.Add(new ConfigFile
                {
                    filePath = folder
                });
            }

            return(results);
        }
Exemple #3
0
        public static List <string> GetAssemblies(ConfigFile config, PluginDeployConfig plugin)
        {
            var           assemblyPath = Path.Combine(config.filePath, plugin.assemblypath);
            List <string> assemblies;
            var           extension = Path.GetExtension(assemblyPath);

            if (extension == "")
            {
                assemblyPath = Path.Combine(assemblyPath, "*.dll");
            }

            var path = Path.GetDirectoryName(assemblyPath);
            var file = Path.GetFileName(assemblyPath);

            assemblies = DirectoryEx.Search(path, file, null);
            return(assemblies);
        }
Exemple #4
0
        public static List <ConfigFile> FindConfig(string folder, bool raiseErrorIfNotFound = true)
        {
            List <string> configfilePath = null;

            // search for the config file - using path or absolute location
            if (folder.EndsWith("spkl.json") && File.Exists(folder))
            {
                configfilePath = new List <string> {
                    folder
                };
            }
            else
            {
                configfilePath = DirectoryEx.Search(folder, "spkl.json", null);
            }

            if (raiseErrorIfNotFound && (configfilePath == null || configfilePath.Count == 0))
            {
                throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.CONFIG_NOTFOUND, String.Format("Cannot find spkl.json in at '{0}' - make sure it is in the same folder or sub-folder as spkl.exe or provide a [path]", folder));
            }

            var results = new List <ConfigFile>();

            foreach (var configPath in configfilePath)
            {
                // Check valid path and this is not the nuget package folder
                if (configPath != null && !Regex.IsMatch(configPath, @"packages\\spkl[0-9|.]*\\tools"))
                {
                    var config = Newtonsoft.Json.JsonConvert.DeserializeObject <ConfigFile>(File.ReadAllText(configPath));
                    config.filePath = Path.GetDirectoryName(configPath);
                    results.Add(config);
                }
            }

            if (results.Count == 0)
            {
                results.Add(new ConfigFile
                {
                    filePath = folder
                });
            }

            return(results);
        }