public bool Start(HostControl hostControl)
        {
            var path = _configuration.Folder;

            _directoryService.CreateDirectory(_configuration.SuccessFolder);
            _directoryService.CreateDirectory(_configuration.ErrorFolder);
            _directoryService.CreateDirectory(_configuration.ProcessingFolder);
            _directoryService.CreateDirectory(path);

            _fileProcessor.ProcessWaitingFiles(path, _rules.Where(r => r.GetType() != typeof(TimerRule)).ToList());

            InitializeWatcher(path);

            return(true);
        }
        public async Task <string> Create(string path, string directoryName)
        {
            var userName = await GetLoggedUserName();

            _directoryService.CreateDirectory(userName, path, directoryName);
            return("Created");
        }
Exemple #3
0
        public ActionResult CreateFolder(DirectoryViewModel directoryModel)
        {
            List <ExplorerViewModel> explorerObjects;

            if (directoryModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            string path = directoryModel.ParentDirectoryPath + directoryModel.Name;

            if (directoryService.IsExist(path))
            {
                return(Json(new { Status = "Exist" }, JsonRequestBehavior.AllowGet));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    directoryService.CreateDirectory(path);

                    var dirListModel =
                        directoryService.GetAllDirectories(directoryModel.ParentDirectoryPath).Select(d => d.ToExplorerObject());
                    var fileListModel = fileService.GetAllFiles(directoryModel.ParentDirectoryPath).Select(f => f.ToExplorerObject());

                    explorerObjects = new List <ExplorerViewModel>();

                    foreach (var obj in dirListModel)
                    {
                        explorerObjects.Add(obj);
                    }

                    foreach (var obj in fileListModel)
                    {
                        explorerObjects.Add(obj);
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    return(Json(new { Status = "NotAcceptable" }, JsonRequestBehavior.AllowGet));
                }

                path = directoryModel.ParentDirectoryPath.Remove(1, 1);

                if (path.Last() != '\\')
                {
                    path = path + "\\";
                }
                path = path.Replace("\\", "\\\\");

                ViewBag.LastPath = path;
                return(PartialView("GetExplorerTable", explorerObjects));
            }

            if (Request.IsAjaxRequest())
            {
                return(PartialView(directoryModel));
            }
            return(View(directoryModel));
        }
Exemple #4
0
        public IDirectory CopyTo(string destBasePath)
        {
            if (string.IsNullOrWhiteSpace(destBasePath))
            {
                throw new ArgumentException("destBasePath cannot be null or white space.");
            }

            var destPath = destBasePath + _directoryService.DirectorySeparator + Name;

            if (_directoryService.Exists(destPath))
            {
                throw new InvalidOperationException("Target directory " + destPath + " already exists.");
            }

            var destDir = _directoryService.CreateDirectory(destPath);

            var files = _directoryService.GetFiles(this);

            foreach (var filePath in files)
            {
                var sourceFile = _fileService.OpenFile(filePath);
                var destFile   = sourceFile.Copy(destDir.Path + _directoryService.DirectorySeparator + sourceFile.Name);

                if (sourceFile.GetCheckSum() == destFile.GetCheckSum())
                {
                    throw new InvalidOperationException("Source and destinatin file have different check sum.");
                }
            }

            return(destDir);
        }
        private void CreateTemporaryDirectory(string absPath)
        {
            var tmpDir = absPath + "\\tmp";

            if (!_directoryService.Exists(tmpDir))
            {
                _directoryService.CreateDirectory(tmpDir);
            }
        }
Exemple #6
0
        public override string CreateDirectory(string ownerName, string directoryName)
        {
            ID       id   = HashFunction.GenerateID(directoryName);
            FileNode node = FindSuccessor(id);

            if (node == null)
            {
                throw new ApplicationException("Cannot find server for directory: " + directoryName);
            }
            if (node == this)
            {
                return(directoryService.CreateDirectory(ownerName, directoryName));
            }
            else
            {
                return(node.CreateDirectory(ownerName, directoryName));
            }
        }
Exemple #7
0
        private void PersistUserId(string userId)
        {
            var directoryName = Path.GetDirectoryName(UserIdFilePath);

            if (!_directoryService.Exists(directoryName))
            {
                _directoryService.CreateDirectory(directoryName);
            }

            _fileService.WriteAllText(UserIdFilePath, userId);
        }
Exemple #8
0
        public void CreateDirectory_PathIsValid_ExpectedPositiveTest()
        {
            //Arrange
            IDirectoryService directoryService = mockDirectory.Object;

            //Act
            directoryService.CreateDirectory(@"D:\New Folder");

            //Assert
            mockDirectory.Verify(ds => ds.CreateDirectory(It.IsAny <string>()));
        }
        public ProjectFileService(IDirectoryService directoryService, [Inject(Key = "open")] IFileDialog openDialog, [Inject(Key = "save")] IFileDialog saveDialog, IProjectLoadSave loadSave, IDialogService dialogService)
        {
            _openFileDialog  = openDialog;
            _saveFileDialog  = saveDialog;
            _loadSave        = loadSave;
            _dialogService   = dialogService;
            ProjectDirectory = directoryService.GetCurrentDirectory() + "\\" + "Projects";

            if (!directoryService.Exists(ProjectDirectory))
            {
                directoryService.CreateDirectory(ProjectDirectory);
            }
        }
        public async Task <ActionResponse> ExecuteAsync(CreateSolutionModel model, Action <CreateSolutionModel, string> notifyAction)
        {
            // Clean working directory
            _directoryService.DeleteDirectory(_configuration.WorkingDirectory);
            var directory = _directoryService.CreateDirectory(_configuration.DownloadDirectory);
            // Clone template repository
            await _cloneSolutionTemplateCommand.ExecuteAsync(model, notifyAction);

            _directoryService.CopyDirectory(directory.FullName, _configuration.WorkingDirectory);
            await _updateSolutionFileNamespacesCommand.ExecuteAsync(model, notifyAction);

            // download template and unzip into location
            return(await _cloneSolutionTemplateCommand.ExecuteAsync(model, notifyAction));
        }
Exemple #11
0
        public async Task <bool> Execute(string tipoProjeto, string nomeProjeto)
        {
            try
            {
                foreach (var item in DirectoryService.GetDirectories(nomeProjeto))
                {
                    var newPath = item.Replace(Constante.GetIdentifier(), Constante.GetPathOutput());
                    DirectoryService.CreateDirectory(newPath);
                }

                foreach (var item in from files in DirectoryService.EnumerateFiles()
                         where files.Split('.').Last() != "suo"
                         select new { File = files }
                         )
                {
                    var newPath = item.File.Replace(
                        Constante.GetIdentifier(),
                        Constante.GetPathOutput()
                        ).Replace(
                        Constante.GetNameTemplate(),
                        nomeProjeto
                        );

                    File.Copy(item.File, newPath, false);
                    await File.WriteAllTextAsync(
                        newPath,
                        File.ReadAllText(newPath)
                        .Replace(
                            Constante.GetNameTemplate(),
                            nomeProjeto
                            )
                        );
                }

                DirectoryService.MoveDirectory(tipoProjeto, nomeProjeto);

                Process.Start(
                    $"_Config/open.bat",
                    $"{Constante.GetFullPath(tipoProjeto, nomeProjeto)}\\{Constante.GetIdentifier()}"
                    );

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Gerado Error: {ex.Message}", ConsoleColor.Red);
                return(false);
            }
        }
Exemple #12
0
 private void CreateOutputDirectoryIfNeeded(string destinationFile)
 {
     try
     {
         var outputDirectory = _pathService.GetParentDirectory(destinationFile);
         if (!_directoryService.CheckIfDirectoryExists(outputDirectory))
         {
             _directoryService.CreateDirectory(outputDirectory);
         }
     }
     catch
     {
         // ignore
     }
 }
        public void Setup()
        {
            Sut = Get <IDirectoryService>();
            var configuration = Get <IConfiguration>();

            _sourceDirectory      = configuration.DownloadDirectory;
            _destinationDirectory = configuration.WorkingDirectory;
            Sut.CreateDirectory(_sourceDirectory);

            var gitService = Get <IGitService>();
            var _repoUrl   = "https://github.com/Gary-Moore/SolutionTemplates.git";
            var task       = gitService.CloneProjectAsync(_repoUrl, s => { });

            task.Wait();
        }
Exemple #14
0
        public PluginLoader(
            Func <IProvideNodes> nodeProviderFactory,
            Func <IDirectoryService> directoryServiceFactory)
        {
            _nodeProvider     = nodeProviderFactory.Invoke();
            _directoryService = directoryServiceFactory.Invoke();
            _pluginDirectory  = _directoryService.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Plugins";
            RegisterPluginNodesFromAssembly(Assembly.Load(nameof(DiiagramrAPI)), new NodeLibrary());
            if (!_directoryService.Exists(_pluginDirectory))
            {
                _directoryService.CreateDirectory(_pluginDirectory);
            }

            LoadNonPluginDll();
            GetInstalledPlugins();
        }
Exemple #15
0
        public IKernel Load(IKernel kernel)
        {
            var executableLocation    = _assemblyService.GetEntryAssembly().Location;
            var additionalPluginsPath = _pathService.Combine(_pathService.GetDirectoryName(executableLocation), "Plugins");

            if (!_directoryService.Exists(additionalPluginsPath))
            {
                _directoryService.CreateDirectory(additionalPluginsPath);
            }

            kernel.Bind(x => x
                        .FromAssembliesInPath(additionalPluginsPath)
                        .SelectAllClasses()
                        .InheritedFrom <IPlugin>()
                        .BindDefaultInterfaces()
                        .Configure(y => y.InTransientScope()));

            return(kernel);
        }
Exemple #16
0
        public Task SerializeDataAsync(string destFolder)
        {
            return(Task.Run(() =>
            {
                using (var db = dbFactory.Create())
                {
                    foreach (var request in db.Requests)
                    {
                        var fileName = request.Date.ToString("yyyy-MM-dd") + ".xml";

                        if (!directory.Exists(destFolder))
                        {
                            directory.CreateDirectory(destFolder);
                        }

                        var fullPath = Path.Combine(destFolder, fileName);

                        if (file.Exists(fullPath))
                        {
                            file.Delete(fullPath);
                        }

                        using (var stream = file.Create(fullPath))
                        {
                            var xmlModel = new XmlRequestModel
                            {
                                Index = request.Index,
                                Content = new XmlRequestContentModel
                                {
                                    Date = request.Date,
                                    Name = request.Name,
                                    Visits = request.Visits
                                }
                            };

                            var serializer = new XmlSerializer(typeof(XmlRequestModel));
                            serializer.Serialize(stream, xmlModel);
                        }
                    }
                }
            }));
        }
Exemple #17
0
        public ActionResult CreateFolder(DirectoryViewModel directoryModel, string driveName = "", string path = "")
        {
            var uri      = new Uri(driveName + ":/" + path);
            var realPath = uri.LocalPath;

            if (Directory.Exists(realPath + directoryModel.Name))
            {
                ModelState.AddModelError("", "Such folder is already exists");
                return(View("_CreateFolder", directoryModel));
            }

            if (ModelState.IsValid)
            {
                directoryService.CreateDirectory(realPath + directoryModel.Name);

                var explorerModel = GetExplorerModel(realPath);
                return(PartialView("_GetDirectories", explorerModel));
            }
            return(PartialView("_CreateFolder", directoryModel));
        }
        private void bindAdditionalPlugins()
        {
            _assemblyService  = _kernel.Get <IAssemblyService>();
            _directoryService = _kernel.Get <IDirectoryService>();
            _pathService      = _kernel.Get <IPathService>();

            var executableLocation    = _assemblyService.GetEntryAssembly().Location;
            var additionalPluginsPath = _pathService.Combine(_pathService.GetDirectoryName(executableLocation), "Plugins");

            if (!_directoryService.Exists(additionalPluginsPath))
            {
                _directoryService.CreateDirectory(additionalPluginsPath);
            }

            _kernel.Bind(x => x
                         .FromAssembliesInPath(additionalPluginsPath)
                         .SelectAllClasses()
                         .InheritedFrom <IPlugin>()
                         .BindDefaultInterfaces()
                         .Configure(y => y.InTransientScope()));
        }
        /// <inheritdoc />
        public FileStream CreateOrGetCacheFile(string source, string cacheDirectory)
        {
            if (string.IsNullOrWhiteSpace(source))
            {
                throw new ArgumentException(string.Format(Strings.ArgumentException_Shared_ValueCannotBeNullWhitespaceOrAnEmptyString, nameof(source)));
            }

            if (string.IsNullOrWhiteSpace(cacheDirectory))
            {
                throw new ArgumentException(string.Format(Strings.ArgumentException_Shared_ValueCannotBeNullWhitespaceOrAnEmptyString, nameof(cacheDirectory)));
            }

            // Ensure that cache directory string is valid and that the directory exists
            try
            {
                _directoryService.CreateDirectory(cacheDirectory);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException(string.Format(Strings.InvalidOperationException_DiskCacheService_InvalidDiskCacheDirectory, cacheDirectory), exception);
            }

            string filePath = CreatePath(source, cacheDirectory);

            try
            {
                return(GetStream(filePath,
                                 FileMode.OpenOrCreate, // Create file if it doesn't already exist
                                 FileAccess.ReadWrite,  // Read and write access
                                 FileShare.None));      // Don't allow other threads to access the file while we write to it
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException(string.Format(Strings.InvalidOperationException_DiskCacheService_UnexpectedDiskCacheException, source, filePath), exception);
            }
        }
Exemple #20
0
 public void TestDirectoryCreationFailed()
 {
     Assert.False(_directoryService.CreateDirectory(null));
     Assert.False(_directoryService.CreateDirectory(string.Empty));
     Assert.False(_directoryService.CreateDirectory(" "));
 }
Exemple #21
0
        public void CreateDirectory(string sourceDirectory, string directoryName)
        {
            var fullPath = _pathService.Combine(sourceDirectory, directoryName);

            _directoryService.CreateDirectory(fullPath);
        }
        ///<inheritdoc/>
        public void Init(string workspace)
        {
            string initDirectoryPath = Path.Combine(workspace, RESERVED_DIRECTORY_NAME.INIT);

            if (!_directoryService.Exists(initDirectoryPath))
            {
                _directoryService.CreateDirectory(initDirectoryPath);
                _fileService.AppendAllText(Path.Combine(initDirectoryPath, RESERVED_FILE_NAME.README), @$ "# The `{RESERVED_DIRECTORY_NAME.INIT}` directory
Initialization scripts. Executed once. This is called the first time you do `yuniql run`.");
                _traceService.Info($"Created script directory {initDirectoryPath}");
            }

            string preDirectoryPath = Path.Combine(workspace, RESERVED_DIRECTORY_NAME.PRE);

            if (!_directoryService.Exists(preDirectoryPath))
            {
                _directoryService.CreateDirectory(preDirectoryPath);
                _fileService.AppendAllText(Path.Combine(preDirectoryPath, RESERVED_FILE_NAME.README), @$ "# The `{RESERVED_DIRECTORY_NAME.PRE}` directory
Pre migration scripts. Executed every time before any version. 
");
                _traceService.Info($"Created script directory {preDirectoryPath}");
            }

            string defaultVersionDirectoryPath = Path.Combine(workspace, RESERVED_DIRECTORY_NAME.BASELINE);

            if (!_directoryService.Exists(defaultVersionDirectoryPath))
            {
                _directoryService.CreateDirectory(defaultVersionDirectoryPath);
                _fileService.AppendAllText(Path.Combine(defaultVersionDirectoryPath, RESERVED_FILE_NAME.README), @"# The `v0.00` directory
Baseline scripts. Executed once. This is called when you do `yuniql run`.");
                _traceService.Info($"Created script directory {defaultVersionDirectoryPath}");
            }

            string draftDirectoryPath = Path.Combine(workspace, RESERVED_DIRECTORY_NAME.DRAFT);

            if (!_directoryService.Exists(draftDirectoryPath))
            {
                _directoryService.CreateDirectory(draftDirectoryPath);
                _fileService.AppendAllText(Path.Combine(draftDirectoryPath, RESERVED_FILE_NAME.README), $@"# The `{RESERVED_DIRECTORY_NAME.DRAFT}` directory
Scripts in progress. Scripts that you are currently working and have not moved to specific version directory yet. Executed every time after the latest version.");
                _traceService.Info($"Created script directory {draftDirectoryPath}");
            }

            string postDirectoryPath = Path.Combine(workspace, RESERVED_DIRECTORY_NAME.POST);

            if (!_directoryService.Exists(postDirectoryPath))
            {
                _directoryService.CreateDirectory(postDirectoryPath);
                _fileService.AppendAllText(Path.Combine(postDirectoryPath, RESERVED_FILE_NAME.README), $@"# The `{RESERVED_DIRECTORY_NAME.POST}` directory
Post migration scripts. Executed every time and always the last batch to run.");
                _traceService.Info($"Created script directory {postDirectoryPath}");
            }

            string eraseDirectoryPath = Path.Combine(workspace, RESERVED_DIRECTORY_NAME.ERASE);

            if (!_directoryService.Exists(eraseDirectoryPath))
            {
                _directoryService.CreateDirectory(eraseDirectoryPath);
                _fileService.AppendAllText(Path.Combine(eraseDirectoryPath, RESERVED_FILE_NAME.README), $@"# The `{RESERVED_DIRECTORY_NAME.ERASE}` directory
Database cleanup scripts. Executed once only when you do `yuniql erase`.");
                _traceService.Info($"Created script directory {eraseDirectoryPath}");
            }

            var readMeFile = Path.Combine(workspace, RESERVED_FILE_NAME.README);

            if (!_fileService.Exists(readMeFile))
            {
                var assembly          = typeof(WorkspaceService).Assembly;
                var embededReadMeFile = $"{assembly.GetName().Name}.TemplateReadMe.md";
                _fileService.AppendAllText(readMeFile, _fileService.ReadAllEmbeddedText(embededReadMeFile));
                _traceService.Info($"Created file {readMeFile}");
            }

            var dockerFile = Path.Combine(workspace, RESERVED_FILE_NAME.DOCKER_FILE);

            if (!_fileService.Exists(dockerFile))
            {
                _fileService.AppendAllText(dockerFile, @"FROM yuniql/yuniql:latest
COPY . ./db                
");
                _traceService.Info($"Created file {dockerFile}");
            }

            var gitIgnoreFile = Path.Combine(workspace, RESERVED_FILE_NAME.GIT_IGNORE_FILE);

            if (!_fileService.Exists(gitIgnoreFile))
            {
                _fileService.AppendAllText(gitIgnoreFile, @"
.plugins
yuniql.exe
yuniql.pdb
yuniqlx.exe
yuniql-log-*.txt
");
                _traceService.Info($"Created file {gitIgnoreFile}");
            }
        }
Exemple #23
0
 public IDirectoryInfo CreateFolderInCurrentDirectory()
 {
     return(directoryService.CreateDirectory(Guid.NewGuid().ToString()));
 }