Exemple #1
0
        private void SetOutputPath()
        {
            if (string.IsNullOrWhiteSpace(OutputPath))
            {
                var currentDateTime = DateTime.Now;
                OutputPath     = $@"Results\{currentDateTime:yyyyMdhhmmss}\Mutation_Report_{Constants.SourceClassPlaceholder}";
                HtmlOutputPath = $"{OutputPath}.html";
                JsonOutputPath = $"{OutputPath}.json";

                return;
            }

            if (OutputPath.EndsWith(JsonExtension))
            {
                JsonOutputPath = OutputPath;
                HtmlOutputPath = OutputPath.Replace(JsonExtension, HtmlExtension);
                return;
            }

            if (OutputPath.EndsWith(HtmlExtension))
            {
                HtmlOutputPath = OutputPath;
                HtmlOutputPath = OutputPath.Replace(HtmlExtension, JsonExtension);
                return;
            }

            throw new MuTestInputException("Output Path is invalid", CliOptions.OutputPath.ArgumentDescription);
        }
        private void _GuessNamespace()
        {
            if (OutputPath.EndsWith(".Entities"))
            {
                // Likely in an RA component, try to grab namespace from CSPROJ
                var projectFiles = Directory.GetFiles(OutputPath, "*.Entities.csproj");
                if (projectFiles.Length == 1)
                {
                    XDocument docment = XDocument.Load(projectFiles[0]);
                    var       projectDefaultNamespace = docment.Descendants().SingleOrDefault(element => element.Name.LocalName.EndsWith("RootNamespace"));
                    if (projectDefaultNamespace != null)
                    {
                        Namespace = projectDefaultNamespace.Value;
                    }
                }
            }
            else if (OutputPath.Contains("XXX.Dal"))
            {
                // Derive namespace from folders

                var pathParts     = OutputPath.Split('\\');
                var namespacePart = pathParts.Last();
                if (namespacePart == "Entities")
                {
                    namespacePart = pathParts.Reverse().Skip(1).First();
                }

                Namespace = "XXX." + namespacePart;
            }
            else if (OutputPath.Contains("XXX.Models"))
            {
                MessageBox.Show("Entities should NEVER be placed in XXX.Models.",
                                "ENTITIES NEVER GO IN MODELS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #3
0
 public void UpdateOutputPath(string subdir)
 {
     OutputPath = Path.Combine(BasePath, subdir);
     if (OutputPath.EndsWith(@"\"))
     {
         OutputPath.Substring(0, OutputPath.Length - 1);
     }
 }
Exemple #4
0
        protected override bool OnValidateArguments(IEnumerable <string> extras)
        {
            var hasError = false;

            AssemblyName ??= "Merged";

            if (string.IsNullOrWhiteSpace(OutputPath))
            {
                OutputPath = AssemblyName + ".dll";
            }
            else
            {
                if (OutputPath.EndsWith("/") || OutputPath.EndsWith("\\") || Directory.Exists(OutputPath))
                {
                    OutputPath = Path.Combine(OutputPath, AssemblyName + ".dll");
                }

                var dir = Path.GetDirectoryName(OutputPath);
                if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }

            var assemblies = extras.Where(p => !string.IsNullOrEmpty(p)).ToArray();

            foreach (var assemblyOrDir in assemblies.ToArray())
            {
                if (Directory.Exists(assemblyOrDir))
                {
                    Assemblies.AddRange(Directory.GetFiles(assemblyOrDir, "*.dll"));
                }
                else if (File.Exists(assemblyOrDir))
                {
                    Assemblies.Add(assemblyOrDir);
                }
                else
                {
                    Console.Error.WriteLine($"{Program.Name}: File does not exist: `{assemblyOrDir}`.");
                    hasError = true;
                }
            }

            if (Assemblies.Count == 0)
            {
                Console.Error.WriteLine($"{Program.Name}: At least one assembly is required `--assembly=PATH`.");
                hasError = true;
            }

            if (hasError)
            {
                Console.Error.WriteLine($"{Program.Name}: Use `{Program.Name} help {Name}` for details.");
            }

            return(!hasError);
        }
Exemple #5
0
        private void CreateOutputPath()
        {
            OutputPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("D"));
            if (!OutputPath.EndsWith("\\"))
            {
                OutputPath += "\\";
            }

            Directory.CreateDirectory(OutputPath);
        }
        protected bool ValidateOutputFolder()
        {
            if (string.IsNullOrEmpty(OutputPath))
            {
                //throw new ArgumentException("Missing value for 'StaticWeb:OutputFolder'", "StaticWeb:OutputFolder");
                return(false);
            }

            if (!OutputPath.EndsWith("\\"))
            {
                // Make sure it can be combined with _resourcePath
                OutputPath += "\\";
            }


            if (!Directory.Exists(OutputPath))
            {
                //throw new ArgumentException("Folder specified in 'StaticWeb:OutputFolder' doesn't exist", "StaticWeb:OutputFolder");
                return(false);
            }

            try
            {
                var directory     = new DirectoryInfo(OutputPath);
                var directoryName = directory.FullName;

                var fileName = directoryName + Path.DirectorySeparatorChar + ".staticweb-access-test";

                // verifying write access
                File.WriteAllText(fileName, "Verifying write access to folder");
                // verify modify access
                File.WriteAllText(fileName, "Verifying modify access to folder");
                // verify delete access
                File.Delete(fileName);
            }
            catch (UnauthorizedAccessException)
            {
                //throw new ArgumentException("Not sufficient permissions for folder specified in 'StaticWeb:OutputFolder'. Require read, write and modify permissions", "StaticWeb:OutputFolder");
                return(false);
            }
            catch (Exception)
            {
                //throw new ArgumentException("Unknown error when testing write, edit and remove access to folder specified in 'StaticWeb:OutputFolder'", "StaticWeb:OutputFolder");
                return(false);
            }
            return(true);
        }
        public bool EnsurePathExists(string uri, bool doCreate = true)
        {
            bool retVal = true;

            logger.Trace("EnsurePathExists Create paths: {0}. Full path: {1}", doCreate, OutputPath);
            if (!OutputPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                OutputPath += Path.DirectorySeparatorChar.ToString();
            }
            string fullPath = OutputPath + uri;

            string[] pathParts = fullPath.Split(Path.DirectorySeparatorChar);

            // extract file
            string file = pathParts.Last();

            pathParts[pathParts.Length - 1] = "";

            string currentPath = "";

            foreach (var item in pathParts.Where(s => s.Length > 0))
            {
                currentPath += item + Path.DirectorySeparatorChar.ToString();
                if (!FilePath.DirectoryExists(currentPath))
                {
                    if (doCreate)
                    {
                        logger.Trace("Create subdirectory {0}", currentPath);
                        FilePath.CreateDirectory(currentPath);
                    }
                    else
                    {
                        logger.Trace("Subdirectory {0} does not exist, but will not be created.", currentPath);
                        retVal = false;
                        break;
                    }
                }
            }

            FullPath = Path.Combine(currentPath, file);

            return(retVal);
        }
        public ArgsModel(string[] args)
        {
            for (int i = 0; i < args.Length - 1; i++)
            {
                var arg = args[i].ToLower().Substring(1);;
                if (arg == nameof(Mode).ToLower())
                {
                    i++;
                    Mode temp;
                    var  temparg = args[i].Substring(0, 1).ToUpper() + args[i].Substring(1);
                    var  result  = Enum.TryParse <Mode>(temparg, out temp);
                    if (result)
                    {
                        Mode = temp;
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(ConsoleHelper.Format.Error, nameof(Mode));
                        break;
                    }
                }
                else if (arg == nameof(LoadMode).ToLower())
                {
                    i++;
                    LoadMode temp;
                    var      temparg = args[i].Substring(0, 1).ToUpper() + args[i].Substring(1);
                    var      result  = Enum.TryParse(temparg, out temp);
                    if (result)
                    {
                        LoadMode = temp;
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(ConsoleHelper.Format.Error, nameof(LoadMode));
                        break;
                    }
                }
                else if (arg == nameof(Theme).ToLower())
                {
                    i++;
                    Theme = args[i];
                }
                else if (arg == nameof(Time).ToLower())
                {
                    i++;
                    double temp   = 0;
                    var    result = double.TryParse(args[i], out temp);
                    if (result)
                    {
                        if (Mode != Mode.Png && Time == 0)
                        {
                            Time = 5d;
                        }
                        else
                        {
                            Time = temp;
                        }
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(ConsoleHelper.Format.Error, nameof(Time));
                        break;
                    }
                }
                else if (arg == nameof(Content).ToLower())
                {
                    i++;
                    if (!string.IsNullOrWhiteSpace(args[i]))
                    {
                        Content = args[i];
                    }
                    else
                    {
                        ConsoleHelper.WriteLine(ConsoleHelper.Format.Error, nameof(Content));
                        break;
                    }
                }
                else if (arg == nameof(OutputPath).ToLower())
                {
                    i++;
                    OutputPath = args[i];
                    if (!System.IO.Directory.Exists(OutputPath))
                    {
                        ConsoleHelper.WriteLine(ConsoleHelper.Format.Error, "Output Path Error");
                    }
                    if (OutputPath.StartsWith("\""))
                    {
                        OutputPath = OutputPath.Substring(1, OutputPath.Length - 2);
                    }
                    if (!OutputPath.EndsWith("\\"))
                    {
                        OutputPath = OutputPath + "\\";
                    }
                    switch (Mode)
                    {
                    case Mode.Gif:
                        OutputPath += "output.gif";
                        break;

                    case Mode.Png:
                        OutputPath += "output.png";
                        break;

                    case Mode.Both:
                        OutputPath += "output";
                        break;
                    }
                }
                else if (arg == nameof(WaitKey).ToLower())
                {
                    i++;
                    if (args[i] == "1" || args[i].ToLower() == "true")
                    {
                        WaitKey = true;
                    }
                }
                else
                {
                    ConsoleHelper.WriteLine(ConsoleHelper.Format.Error, $"Unknown Args \"{args[i]}\"");
                    break;
                }
            }
            Result = true;
            if (string.IsNullOrWhiteSpace(Theme) || string.IsNullOrWhiteSpace(Content) || string.IsNullOrWhiteSpace(OutputPath))
            {
                Result = false;
            }
            else
            {
                Result = true;
            }
        }
Exemple #9
0
 private bool CanOpen()
 {
     return(!IsWorking && !string.IsNullOrWhiteSpace(OutputPath) && OutputPath.EndsWith(".xlsx") && _outputPath != null && _outputPath.Exists);
 }