Ejemplo n.º 1
0
        public byte[] GetFileData(int id, BlobFactory.Container blobContainer)
        {
            var res  = GetFile(id);
            var blob = BlobFactory.GetBlobStorage(res.ResourceId, blobContainer);

            return(blob.Content);
        }
Ejemplo n.º 2
0
        public ResourceFile GetFile(int id, BlobFactory.Container blobContainer = BlobFactory.Container.Resources)
        {
            var res = Ctx.Resources.OfType <ResourceFile>().FirstOrDefault(r => r.Id == id);

            if (res != null)
            {
                var blob = BlobFactory.GetBlobStorage(res.ResourceId, blobContainer);
                res.Metadata = blob.MetaData;
            }
            return(res);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// deletes the record specifed based on id and resource id
 /// </summary>
 /// <param name="guid">Resource ID</param>
 /// <param name="resId">record ID</param>
 /// <param name="removeEmptyFolder"></param>
 /// <param name="resourcesDir"></param>
 /// <returns>Deletes the selected record</returns>
 public bool Delete(Guid guid, int resId, bool removeEmptyFolder, BlobFactory.Container resourcesDir = BlobFactory.Container.Resources)
 {
     try {
         var res = Ctx.Resources.FirstOrDefault(e => e.ResourceId == guid && e.Id == resId);
         if (res == null)
         {
             return(false);
         }
         // do not remove any deployed files
         if (Ctx.Published.Any(p => p.ResourceFiles.Any(r => r.ResourceId == guid && r.Id == resId)))
         {
             return(false);
         }
         if (res.HasChildren())
         {
             // TODO: delete children in recursive order
         }
         else
         {
             // keep ref to current parent
             var parent = res.Parent;
             var blob   = BlobFactory.GetBlobStorage(res.ResourceId, resourcesDir);
             // if already in trash, remove
             if (res.TypesOfResource == TypeOfResource.Trash)
             {
                 Ctx.Resources.Remove(res);
                 blob.Remove();
             }
             else
             {
                 // Move to trash, de-parent because trash is flat
                 var p = Ctx.Projects.Find(res.Project.Id);
                 res.TypesOfResource = TypeOfResource.Trash;
                 res.Deleted         = true;
                 res.Parent          = Ctx.Resources.OfType <ResourceFolder>().FirstOrDefault(r => r.Parent == null && r.TypesOfResource == TypeOfResource.Trash && r.Project.Id == p.Id);
                 res.Project         = p;
             }
             SaveChanges();
             // remove folder if there is no file in it (this is due to the relatively flat structure in file explorer)
             if (removeEmptyFolder && !parent.Children.Any())
             {
                 Ctx.Resources.Remove(parent);
                 SaveChanges();
             }
         }
         return(true);
     } catch (Exception ex) {
         Debug.WriteLine(ex.Message);
         return(false);
     }
 }
Ejemplo n.º 4
0
 public bool Delete(Guid guid, bool removeEmptyFolder = false, BlobFactory.Container resourcesDir = BlobFactory.Container.Resources)
 {
     try {
         var res = Ctx.Resources.FirstOrDefault(e => e.ResourceId == guid);
         if (res == null)
         {
             return(false);
         }
         // do not remove any deployed files
         if (Ctx.Published.Any(p => p.ResourceFiles.Any(r => r.ResourceId == guid)))
         {
             return(false);
         }
         if (res.HasChildren())
         {
             // delete children in recursive order
         }
         else
         {
             var blob = BlobFactory.GetBlobStorage(res.ResourceId, resourcesDir);
             // if already in trash, remove
             if (res.TypesOfResource == TypeOfResource.Trash)
             {
                 Ctx.Resources.Remove(res);
                 blob.Remove();
             }
             else
             {
                 // Move to trash, de-parent because trash is flat
                 var p = Ctx.Projects.Find(res.Project.Id);
                 res.TypesOfResource = TypeOfResource.Trash;
                 res.Deleted         = true;
                 res.Parent          = Ctx.Resources.OfType <ResourceFolder>().FirstOrDefault(r => r.Parent == null && r.TypesOfResource == TypeOfResource.Trash && r.Project.Id == p.Id);
                 res.Project         = p;
             }
         }
         SaveChanges();
         return(true);
     } catch (Exception ex) {
         Debug.WriteLine(ex.Message);
         return(false);
     }
 }