Example #1
0
        public bool Validate(string filePathToValidate, string fileNameToValidateAgainst)
        {
            AppioLogger.Info(string.Format(LoggingText.ValidatingModel, filePathToValidate, fileNameToValidateAgainst));
            var xsdToValidateAgainst = _fileSystem.LoadTemplateFile(fileNameToValidateAgainst);
            var anyErrors            = true;

            var schema = XmlSchema.Read(new StringReader(xsdToValidateAgainst), null); // ValidationEventHandler == null, because xsd is provided by APPIO, so parsing it can't go wrong

            var schemaSet = new XmlSchemaSet();

            schemaSet.Add(schema);

            var streamToValidate = _fileSystem.ReadFile(filePathToValidate);
            var xmlReader        = XmlReader.Create(streamToValidate);
            var xDocument        = XDocument.Load(xmlReader);

            xDocument.Validate(schemaSet, (o, e) =>
            {
                AppioLogger.Error(string.Format(LoggingText.ValidationError, e.Message), e.Exception);
                anyErrors = false;
            });

            streamToValidate.Close();
            streamToValidate.Dispose();

            return(anyErrors);
        }
Example #2
0
 public void CopyFile(string source, string target)
 {
     try
     {
         File.Copy(source, target, true);
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #3
0
 public void CreateDirectory(string directoryName)
 {
     try
     {
         Directory.CreateDirectory(directoryName);
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #4
0
 public void DeleteFile(string name)
 {
     try
     {
         File.Delete(name);
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #5
0
 public Stream ReadFile(string path)
 {
     try
     {
         return(File.Open(path, FileMode.OpenOrCreate));
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #6
0
 public string[] GetFilesByExtension(string path, string extension)
 {
     try
     {
         return(Directory.GetFiles(path, "*" + extension));
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #7
0
 public void WriteFile(string path, IEnumerable <string> content)
 {
     try
     {
         File.WriteAllLines(path, content, System.Text.Encoding.Default);
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #8
0
 public string CombinePaths(params string[] paths)
 {
     try
     {
         return(Path.Combine(paths));
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #9
0
 public string GetFileNameWithoutExtension(string path)
 {
     try
     {
         return(Path.GetFileNameWithoutExtension(path));
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #10
0
 public void CreateFile(string filePath, string fileContent)
 {
     try
     {
         File.WriteAllText(filePath, fileContent);
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #11
0
 public void ExtractFromZip(string source, string target, string resourceFullName)
 {
     try
     {
         if (WriteResourceToFile(resourceFullName, source))
         {
             ZipFile.ExtractToDirectory(source, target);
         }
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #12
0
 private bool WriteResourceToFile(string resourceName, string fileName)
 {
     try
     {
         using (var resource = GetResourceAssembly().GetManifestResourceStream(resourceName))
         {
             using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
             {
                 resource.CopyTo(file);
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         AppioLogger.Error(LoggingText.ExceptionOccured, ex);
         throw;
     }
 }
Example #13
0
        public string LoadTemplateFile(string fileName)
        {
            try
            {
                var assembly     = typeof(Resources.Resources).Assembly;
                var resourceName = fileName;

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        return(reader.ReadToEnd());
                    }
            }
            catch (Exception ex)
            {
                AppioLogger.Error(LoggingText.ExceptionOccured, ex);
                throw;
            }
        }
Example #14
0
        public bool CallExecutable(string name, string workingDirectory, string args)
        {
            try
            {
                var info = new ProcessStartInfo(name, args)
                {
                    WorkingDirectory = workingDirectory,
                };

                var process = Process.Start(info);
                process?.WaitForExit();

                return(process?.ExitCode == 0);
            }
            catch (Exception ex)
            {
                AppioLogger.Error(LoggingText.ExceptionOccured, ex);
                return(false);
            }
        }
Example #15
0
        public CommandResult ExecuteCommand(IEnumerable <string> inputParams)
        {
            if (inputParams == null)
            {
                try
                {
                    throw new ArgumentNullException(nameof(inputParams));
                }
                catch (Exception ex)
                {
                    AppioLogger.Error(LoggingText.NullInputParams_Msg, ex);
                    throw;
                }
            }

            var inputParamsArray = inputParams.ToArray();
            var strategy         = _commandStrategyFactory.GetCommand(inputParamsArray.FirstOrDefault());

            return(strategy.Execute(inputParamsArray.Skip(1)));
        }
Example #16
0
 public void DeleteDirectory(string name)
 {
     try
     {
         Directory.Delete(name, true);
     }
     catch (DirectoryNotFoundException ex)
     {
         AppioLogger.Error(LoggingText.DirectoryNotFoundException, ex);
         throw;
     }
     catch (PathTooLongException ex)
     {
         AppioLogger.Error(LoggingText.PathTooLongException, ex);
         throw;
     }
     catch (IOException ex)
     {
         AppioLogger.Error(LoggingText.DirectoryIOException, ex);
         throw;
     }
 }