Exemplo n.º 1
0
 public override async Task <bool> Apply(object?value)
 {
     try
     {
         if (fileManager.Exists(root))
         {
             if (FilesValue.TryFromObject(value, out var filesValue))
             {
                 var pathsToRemove = new HashSet <string>(expandedFilenames);
                 foreach (var fileValue in filesValue.Files)
                 {
                     var path = Path.Combine(root, fileValue.RelativePath);
                     pathsToRemove.Remove(path);
                     var dirname = Path.GetDirectoryName(path) !;
                     if (!fileManager.Exists(dirname))
                     {
                         fileManager.CreateDirectory(dirname);
                     }
                     await fileManager.WriteAllBytes(path, fileValue.Contents);
                 }
                 foreach (var path in pathsToRemove)
                 {
                     await fileManager.Delete(path);
                 }
                 return(true);
             }
         }
     }
     catch (Exception e)
     {
         logger.LogError(e, "Failed to apply files");
     }
     return(false);
 }
Exemplo n.º 2
0
        public override async Task <CaptureResult> Capture()
        {
            var result = new CaptureResult();

            try
            {
                if (fileManager.Exists(root))
                {
                    var files = new List <FileValue>();
                    foreach (var path in expandedFilenames)
                    {
                        if (fileManager.Exists(path))
                        {
                            var file = new FileValue();
                            file.RelativePath = Path.GetRelativePath(root, path);
                            file.Contents     = await fileManager.ReadAllBytes(path);

                            files.Add(file);
                        }
                    }
                    FilesValue value = new FilesValue();
                    value.Files    = files.ToArray();
                    result.Value   = value.ToDictionary();
                    result.Success = true;
                }
            }
            catch (Exception e)
            {
                logger.LogError(e, "Failed to capture files");
            }
            return(result);
        }
 public static bool TryFromObject(object?value, out FilesValue result)
 {
     if (value is Dictionary <string, object> dictionaryValue)
     {
         var files = new List <FileValue>();
         if (dictionaryValue.TryGetValue("files", out var dictionaryFileValues))
         {
             if (dictionaryFileValues is object?[] dictionaryFileValuesArray)