Ejemplo n.º 1
0
 public async Task <bool> SaveAndExtractZip(PluginUploadViewModel model)
 {
     try
     {
         string uploadedZip = Path.Combine("Zips", $"{model.PluginName}.zip");
         using (var stream = new FileStream(uploadedZip, FileMode.Create))
         {
             await model.PluginZip.CopyToAsync(stream);
         }
         string zipDestDir = Path.Combine("Plugins", $"{model.PluginName}");
         ZipFile.ExtractToDirectory(uploadedZip, zipDestDir, true);
         File.Delete(uploadedZip);
         return(true);
     }
     catch { throw; }
 }
Ejemplo n.º 2
0
 public async Task <IActionResult> Add(PluginUploadViewModel model)
 {
     if (model.PluginZip.Length > 0)
     {
         try
         {
             if (await _pluginService.SaveAndExtractZip(model))
             {
                 if (_pluginService.LoadPlugin(model.PluginName))
                 {
                     PluginActionDescriptorChangeProvider.Instance.HasChanged = true;
                     PluginActionDescriptorChangeProvider.Instance.TokenSource.Cancel();
                     return(Ok());
                 }
             }
         }
         catch (Exception ex) when(ex is UnauthorizedAccessException || ex is ArgumentException || ex is IOException)
         {
             return(StatusCode(500));
         }
     }
     return(BadRequest());
 }