Example #1
0
        public EntityPart UpdateEntityPart(string containerTitle, Guid entityId, string partName, string category)
        {
            var packagePath = GetEntityPackagePath(containerTitle, null, entityId);

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                return(entityPackage.UpdateEntityPart(partName, category));
            }
        }
Example #2
0
        public EntityPart UpdateEntityPartData(string containerTitle, Guid entityId, string partName, string eTag, string data)
        {
            var packagePath = GetEntityPackagePath(containerTitle, null, entityId);

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                return(entityPackage.UpdateEntityPartData(partName, eTag, data));
            }
        }
        public IList <EntityPart> ListEntityParts(string containerTitle, string path, Guid entityId)
        {
            var packagePath = GetEntityPackagePath(containerTitle, path, entityId);

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                return(entityPackage.ListEntityParts().ToList());
            }
        }
        /// <summary>
        /// Deletes the attachment.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns><c>true</c> if the attachment was deleted, <c>false</c> otherwise</returns>
        public bool DeleteAttachment(string containerTitle, Guid entityId, string fileName)
        {
            var packagePath = GetEntityPackagePath(containerTitle, null, entityId);

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                return(entityPackage.DeleteAttachment(fileName));
            }
        }
        public bool RenameEntityPart(string containerTitle, string path, Guid entityId, string partName, string newPartName)
        {
            var packagePath = GetEntityPackagePath(containerTitle, path, entityId);

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                return(entityPackage.RenameEntityPart(partName, newPartName));
            }
        }
        public EntityPart CreateEntityPart(string containerTitle, string path, Guid entityId, string partName,
                                           string category, string data)
        {
            var packagePath = GetEntityPackagePath(containerTitle, path, entityId);

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                return(entityPackage.CreateEntityPart(partName, category, data));
            }
        }
        public Entity UpdateEntity(string containerTitle, Guid entityId, string title, string description, string @namespace)
        {
            var packagePath = GetEntityPackagePath(containerTitle, null, entityId);

            using (var package = EntityPackage.Open(packagePath))
            {
                package.UpdateDefaultEntityPart(title, description, @namespace);

                return(package.MapEntityFromPackage(true));
            }
        }
        public Entity GetEntityLight(string containerTitle, Guid entityId, string path)
        {
            var packagePath = GetEntityPackagePath(containerTitle, path, entityId);

            using (var package = EntityPackage.Open(packagePath))
            {
                return(package == null
          ? null
          : package.MapEntityFromPackage(false));
            }
        }
        /// <summary>
        /// Lists the attachments.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <returns>IList{Attachment}.</returns>
        /// <exception cref="System.InvalidOperationException">An entity with the specified id does not exist.</exception>
        public IList <Attachment> ListAttachments(string containerTitle, Guid entityId)
        {
            var packagePath = GetEntityPackagePath(containerTitle, null, entityId);

            if (File.Exists(packagePath) == false)
            {
                throw new InvalidOperationException("An entity with the specified id does not exist.");
            }

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                return(entityPackage.ListAttachments().ToList());
            }
        }
        /// <summary>
        /// Downloads the attachment.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>Stream.</returns>
        /// <exception cref="System.InvalidOperationException">An entity with the specified id does not exist.</exception>
        public Stream DownloadAttachment(string containerTitle, Guid entityId, string fileName)
        {
            var packagePath = GetEntityPackagePath(containerTitle, null, entityId);

            if (File.Exists(packagePath) == false)
            {
                throw new InvalidOperationException("An entity with the specified id does not exist.");
            }

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                return(entityPackage.DownloadAttachmentStream(fileName));
            }
        }
        public Entity CreateEntity(string containerTitle, string path, string title, string @namespace, string data)
        {
            var newId = Guid.NewGuid();

            var packagePath = GetEntityPackagePath(containerTitle, path, newId);

            if (File.Exists(packagePath))
            {
                throw new InvalidOperationException("An entity with the specified id already exists.");
            }

            using (var package = EntityPackage.Create(packagePath, newId, @namespace, title, data))
            {
                return(package.MapEntityFromPackage(true));
            }
        }
        /// <summary>
        /// Uploads the attachment.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="attachment">The attachment.</param>
        /// <param name="category">The category.</param>
        /// <param name="path">The path.</param>
        /// <returns>Attachment.</returns>
        /// <exception cref="System.InvalidOperationException">An entity with the specified id does not exist.</exception>
        public Attachment UploadAttachment(string containerTitle, Guid entityId, string fileName, byte[] attachment, string category, string path)
        {
            var packagePath = GetEntityPackagePath(containerTitle, null, entityId);

            if (File.Exists(packagePath) == false)
            {
                throw new InvalidOperationException("An entity with the specified id does not exist.");
            }

            using (var entityPackage = EntityPackage.Open(packagePath))
            {
                using (var ms = new MemoryStream(attachment))
                {
                    return(entityPackage.CreateAttachment(fileName, category, path, ms));
                }
            }
        }
        public IList <Entity> ListEntities(string containerTitle, EntityFilterCriteria criteria)
        {
            var targetPath = GetContainerPath(containerTitle);

            if (criteria.Path.IsNullOrWhiteSpace() == false)
            {
                targetPath = Path.Combine(targetPath, criteria.Path);
            }

            var entities = new List <Entity>();

            foreach (var entityFileName in Directory.GetFiles(targetPath, "*.dse", SearchOption.AllDirectories))
            {
                using (var package = EntityPackage.Open(entityFileName))
                {
                    if (package == null)
                    {
                        continue;
                    }

                    var entity = package.MapEntityFromPackage(criteria.IncludeData);
                    entities.Add(entity);
                }
            }

            IEnumerable <Entity> result = entities;

            if (criteria.Top.HasValue)
            {
                result = result.Take((int)criteria.Top.Value);
            }

            if (criteria.Skip.HasValue)
            {
                result = result.Skip((int)criteria.Skip.Value);
            }

            return(result.ToList());
        }