Exemple #1
0
        public string GetDirectory(string relativeDirectoryName)
        {
            var fullPath = Path.Combine(_rootDirectory, relativeDirectoryName);

            if (!_directoryService.Exists(fullPath))
            {
                _directoryService.Create(fullPath);
            }

            return(fullPath);
        }
Exemple #2
0
 private void CreateOutputDirectoryIfNeeded(string outputDirectory)
 {
     if (!_directoryService.CheckIfExists(outputDirectory))
     {
         _directoryService.Create(outputDirectory);
     }
 }
Exemple #3
0
        public AppDataService(ISaveFileService saveFileService,
                              IProcessService processService, IDirectoryService directoryService, IFileService fileService)
        {
            Argument.IsNotNull(() => saveFileService);
            Argument.IsNotNull(() => processService);
            Argument.IsNotNull(() => directoryService);
            Argument.IsNotNull(() => fileService);

            _saveFileService  = saveFileService;
            _processService   = processService;
            _directoryService = directoryService;
            _fileService      = fileService;

            ExclusionFilters = new List <string>(new []
            {
                "licenseinfo.xml",
                "*.log"
            });

            var applicationDataDirectory = Catel.IO.Path.GetApplicationDataDirectory();

            _directoryService.Create(applicationDataDirectory);

            ApplicationDataDirectory = applicationDataDirectory;
        }
        public async Task <IDisposableToken <IProgress <float> > > TrackDownloadOperationAsync(IPackageInstallationService packageInstallationService, SourcePackageDependencyInfo packageDependencyInfo)
        {
            Argument.IsNotNull(() => packageInstallationService);
            Argument.IsNotNull(() => packageDependencyInfo);

            try
            {
#pragma warning disable IDISP001 // Dispose created.
                var watcher = new FileSystemWatcher();
#pragma warning restore IDISP001 // Dispose created.
                var downloadPath          = packageInstallationService.InstallerPathResolver.GetPackageFilePath(packageDependencyInfo.Id, packageDependencyInfo.Version);
                var downloadDirectoryPath = Path.GetDirectoryName(downloadPath);

                // the download method creates directory itself, but we need to create it eager to start watching
                _directoryService.Create(downloadDirectoryPath);

                watcher.Path = Path.GetDirectoryName(downloadPath);

                // determine package size
                var packageByteSize = await packageInstallationService.MeasurePackageSizeFromRepositoryAsync(packageDependencyInfo, packageDependencyInfo.Source);

                var trackToken = new DownloadProgressTrackToken(_fileService, this, packageDependencyInfo, packageDependencyInfo.Source, watcher, OnProgressReportedCallback, packageByteSize ?? 0);

                return(trackToken);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(null);
            }
        }
        public override async Task SaveSnapshotsAsync(IEnumerable <ISnapshot> snapshots)
        {
            Argument.IsNotNull(() => snapshots);

            var directory = Directory;

            _directoryService.Create(directory);

            Log.Debug("Deleting previous snapshot files");

            var deleteCount = 0;

            var snapshotFileNames = snapshots.ToDictionary(x => GetSnapshotFileName(directory, x), x => x, StringComparer.OrdinalIgnoreCase);

            foreach (var snapshotFile in _directoryService.GetFiles(directory, $"*{SnapshotExtension}"))
            {
                try
                {
                    ISnapshot snapshot = null;
                    var       delete   = !snapshotFileNames.TryGetValue(snapshotFile, out snapshot);
                    if (!delete)
                    {
                        // Note: we cannot yet use this method because we add additional contents to the file
                        // when writing to disk. Therefore we must assume that snapshots will never change once
                        // written to disk.
                    }

                    if (delete)
                    {
                        _fileService.Delete(snapshotFile);
                        deleteCount++;
                    }
                    else
                    {
                        Log.Debug($"No need to delete '{snapshotFile}', snapshot is still in use");
                    }
                }
                catch (Exception ex)
                {
                    Log.Warning(ex, $"Failed to delete file '{snapshotFile}'");
                }
            }

            Log.Debug($"Deleted '{deleteCount}' snapshots, going to save new snapshots now");

            var saveCount = 0;

            foreach (var snapshot in snapshots)
            {
                var fileName = GetSnapshotFileName(directory, snapshot);
                if (!_fileService.Exists(fileName))
                {
                    await SaveSnapshotAsync(fileName, snapshot);

                    saveCount++;
                }
            }

            Log.Debug($"Saved '{saveCount}' of '{snapshots.Count()}' snapshots to disk");
        }
Exemple #6
0
        public AppDataService(IMessageService messageService, ISaveFileService saveFileService, 
            IProcessService processService, IDirectoryService directoryService, IFileService fileService)
        {
            Argument.IsNotNull(() => messageService);
            Argument.IsNotNull(() => saveFileService);
            Argument.IsNotNull(() => processService);
            Argument.IsNotNull(() => directoryService);
            Argument.IsNotNull(() => fileService);

            _messageService = messageService;
            _saveFileService = saveFileService;
            _processService = processService;
            _directoryService = directoryService;
            _fileService = fileService;

            ExclusionFilters = new List<string>(new []
            {
                "licenseinfo.xml",
                "*.log"
            });

            var applicationDataDirectory = Catel.IO.Path.GetApplicationDataDirectory();

            _directoryService.Create(applicationDataDirectory);

            ApplicationDataDirectory = applicationDataDirectory;
        }
Exemple #7
0
    private void CreateOutputDirectoryIfNeeded(string outputFilePath)
    {
        var outputDirectory = _pathService.GetParentDirectory(outputFilePath);

        if (!_directoryService.CheckIfExists(outputDirectory))
        {
            _directoryService.Create(outputDirectory);
        }
    }
Exemple #8
0
    public Task RunAsync(CancellationToken cancellationToken)
    {
        State = OperationState.InProgress;
        var creationResult = _directoryService.Create(_directoryToCreate);

        State = creationResult ? OperationState.Finished : OperationState.Failed;
        SetFinalProgress();

        return(Task.CompletedTask);
    }
Exemple #9
0
        public TemporaryFileSystemContext(IDirectoryService directoryService)
        {
            Argument.IsNotNull(() => directoryService);

            _directoryService = directoryService;

            var assembly = AssemblyHelper.GetEntryAssembly();

            _rootDirectory = Path.Combine(Path.GetTempPath(), assembly.Company(), assembly.Title(),
                                          "backup", DateTime.Now.ToString("yyyyMMdd_HHmmss"));

            _directoryService.Create(_rootDirectory);
        }
Exemple #10
0
        protected override async Task WriteMetaDataAsync(IDictionary <string, string> files, string trashCanLocation)
        {
            var infoTrashCanLocation = GetInfoTrashCanLocation(trashCanLocation);

            if (!_directoryService.CheckIfExists(infoTrashCanLocation))
            {
                _directoryService.Create(infoTrashCanLocation);
            }

            var deleteTime = _environmentService.Now;

            await files.Values.ForEachAsync(f => WriteMetaDataAsync(f, infoTrashCanLocation, deleteTime));
        }
 public IActionResult Create([FromBody] DirectoryCreate data)
 {
     try
     {
         var            userData = jwtService.ParseData(this.User);
         DirectoryIndex result   = dirService.Create(data, userData.UserId);
         return(Ok(result));
     }
     catch (ServiceException e)
     {
         return(BadRequest(e.Message));
     }
 }
Exemple #12
0
 private void CreateOutputDirectoryIfNeeded(string destinationFile)
 {
     try
     {
         var outputDirectory = _pathService.GetParentDirectory(destinationFile);
         if (!_directoryService.CheckIfExists(outputDirectory))
         {
             _directoryService.Create(outputDirectory);
         }
     }
     catch
     {
         // ignore
     }
 }
Exemple #13
0
        protected override async Task WriteMetaDataAsync(IReadOnlyDictionary <string, string> filePathsDictionary,
                                                         string trashCanLocation)
        {
            var infoTrashCanLocation = GetInfoTrashCanLocation(trashCanLocation);

            if (!_directoryService.CheckIfExists(infoTrashCanLocation))
            {
                _directoryService.Create(infoTrashCanLocation);
            }

            var deleteTime = _dateTimeProvider.Now;

            await filePathsDictionary.ForEachAsync(kvp =>
                                                   WriteMetaDataAsync(kvp.Key, kvp.Value, infoTrashCanLocation, deleteTime));
        }
        public void CreateDeleteme(string name, string path)
        {
            var fullPath      = GetDeletemePath(name, path);
            var directoryPath = Path.GetDirectoryName(fullPath);

            if (_fileService.Exists(fullPath))
            {
                return;
            }

            _directoryService.Create(directoryPath);

            using (_fileService.Create(fullPath))
            {
            }
        }
        public async Task SaveAsync(List <FeatureToggleValue> toggleValues)
        {
            var fileName = GetFileName();

            Log.Debug($"Saving feature toggle values to '{fileName}'");

            var directory = Path.GetDirectoryName(fileName);

            _directoryService.Create(directory);

            using (var stream = _fileService.Create(fileName))
            {
                var togglesValuesToSerialize = (from toggleValue in toggleValues
                                                where toggleValue.Value.HasValue
                                                select toggleValue).ToList();

                _xmlSerializer.Serialize(togglesValuesToSerialize, stream);
            }
        }
Exemple #16
0
        public SearchHistoryService(ISearchService searchService, IXmlSerializer xmlSerializer,
                                    IAppDataService appDataService, IDirectoryService directoryService)
        {
            Argument.IsNotNull(() => searchService);
            Argument.IsNotNull(() => xmlSerializer);
            Argument.IsNotNull(() => appDataService);
            Argument.IsNotNull(() => directoryService);

            _xmlSerializer          = xmlSerializer;
            _appDataService         = appDataService;
            _directoryService       = directoryService;
            searchService.Searched += OnSearchServiceSearched;

            var directory = Path.Combine(_appDataService.GetApplicationDataDirectory(Catel.IO.ApplicationDataTarget.UserRoaming), "search");

            _directoryService.Create(directory);

            _fileName = Path.Combine(directory, "history.xml");

            LoadSearchHistory();
        }
Exemple #17
0
        private string CreateTemporaryDirectory()
        {
            Log.Debug("Creating temporary directory");

            var tempDirectory = string.Empty;

            try
            {
                var assembly = AssemblyHelper.GetEntryAssembly();

                tempDirectory = Path.Combine(Path.GetTempPath(), assembly.Company(), assembly.Title(),
                                             "ExternalEditor", DateTime.Now.ToString("yyyyMMdd_HHmmss"));

                _directoryService.Create(tempDirectory);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to create temporary directory");
            }

            return(tempDirectory);
        }
Exemple #18
0
        private string GetSettingsFilePath(IControlTool tool, PropertyInfo settingsProperty)
        {
            var toolSettingsAttribute = Attribute.GetCustomAttribute(settingsProperty, typeof(ToolSettingsAttribute)) as ToolSettingsAttribute;
            var settingsStorage       = toolSettingsAttribute.Storage;
            var appDataDirectory      = Catel.IO.Path.GetApplicationDataDirectory();
            var fileName = settingsProperty.Name + ".xml";

            if (string.IsNullOrWhiteSpace(settingsStorage))
            {
                settingsStorage = Path.Combine(appDataDirectory, tool.Name);
            }
            else
            {
                var companyDirectory = Catel.IO.Path.GetParentDirectory(appDataDirectory);

                settingsStorage = Regex.Replace(settingsStorage, "%AppData%", appDataDirectory, RegexOptions.IgnoreCase);
                settingsStorage = Regex.Replace(settingsStorage, "%Company%", companyDirectory, RegexOptions.IgnoreCase);
                settingsStorage = Regex.Replace(settingsStorage, "%Name%", tool.Name, RegexOptions.IgnoreCase);
            }

            _directoryService.Create(settingsStorage);
            return(Path.Combine(settingsStorage, fileName));
        }
Exemple #19
0
        public async Task <IActionResult> Create([FromBody] CreateDirectoryModel model)
        {
            return(await ProcessAsync(async() =>
            {
                var user = await UserService.GetUserByPrincipal(User);

                if (await _directoryService.IsAuthorised(user, model.ParentId))
                {
                    var directory = new DirectoryModel
                    {
                        ParentId = model.ParentId,
                        Name = model.Name,
                        Private = model.Private,
                        StaffOnly = model.StaffOnly
                    };

                    await _directoryService.Create(directory);

                    return Ok("Directory created successfully.");
                }

                return Unauthorized("Access denied.");
            }));
        }
Exemple #20
0
 public void Create_Directory_NullArgument_Test()
 {
     directoryService.Create(null);
 }
Exemple #21
0
 public void TestDirectoryCreationFailed()
 {
     Assert.False(_directoryService.Create(null));
     Assert.False(_directoryService.Create(string.Empty));
     Assert.False(_directoryService.Create(" "));
 }
        public void CreateDirectory(string sourceDirectory, string directoryName)
        {
            var fullPath = _pathService.Combine(sourceDirectory, directoryName);

            _directoryService.Create(fullPath);
        }
 public IActionResult Create(int id, string name, int returnDirId)
 {
     directoryService.Create(id, name, User.Identity.Name);
     return(RedirectToAction(nameof(Index), new { id = returnDirId }));
 }