public void CreateFolder(string subscriptionId, Folder folder)
        {
            if (folder == null)
            {
                throw Utility.ThrowResponseException(this.Request, System.Net.HttpStatusCode.BadRequest, ErrorMessages.FolderEmpty);
            }

            // Let us ensure that the same folder name is not repeated in same shares for same subscription.
            List<Folder> folders = DataProviderFactory.FolderInstance.GetFolders(subscriptionId);
            var existing = folders.FirstOrDefault(c => c.SubscriptionId == subscriptionId &&
                                                    c.FolderName.ToLower() == folder.FolderName.ToLower() &&
                                                    c.ShareId == folder.ShareId);
            if (existing != null)
            {
                throw Utility.ThrowResponseException(this.Request, System.Net.HttpStatusCode.BadRequest, ErrorMessages.FolderAlreadyExists);
            }

            // Invoke the provider so that data is presisted in store.
            DataProviderFactory.FolderInstance.CreateFolder(subscriptionId, folder);

            // Create the physical folder directory.
            // TODO: If this fails, then we need to rollback changes made to folder store DB.
            string dir = string.Format("{0}\\{1}\\{2}",
                            DataProviderFactory.ShareInstance.GetShares().First(l => l.ShareId == folder.ShareId).NetworkSharePath,
                            subscriptionId,
                            folder.FolderName);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileServerModel" /> class.
 /// </summary>
 /// <param name="ProductModel">The domain name from API.</param>
 public FolderModel(Folder folderFromApi)
 {
     this.FolderName = folderFromApi.FolderName;
     this.SubscriptionId = folderFromApi.SubscriptionId;
     this.ShareId = folderFromApi.ShareId;
     this.URL = folderFromApi.URL;
     this.FolderId = folderFromApi.FolderId;
     this.id = folderFromApi.FolderId;
     this.Type = "Folder";
 }
 void IFolderProvider.CreateFolder(string subscriptionId, Folder folder)
 {
     folders.Add(new Folder
     {
         FolderId = CurrentMaxFolderId++,
         ShareId = folder.ShareId,
         FolderName = folder.FolderName,
         SubscriptionId = subscriptionId,
         URL = string.Format("{0}\\{1}\\{2}",
                 InMemoryShareProvider.Instance.GetShares().First(l => l.ShareId == folder.ShareId).NetworkSharePath,
                 subscriptionId,
                 folder.FolderName)
     });
 }
        public void UpdateFolder(string subscriptionId, Folder folderToUpdate)
        {
            if (string.IsNullOrWhiteSpace(subscriptionId))
            {
                throw Utility.ThrowResponseException(this.Request, System.Net.HttpStatusCode.BadRequest, ErrorMessages.EmptySubscription);
            }

            if (folderToUpdate == null)
            {
                throw Utility.ThrowResponseException(this.Request, System.Net.HttpStatusCode.BadRequest, ErrorMessages.FolderEmpty);
            }

            List<Folder> folders = DataProviderFactory.FolderInstance.GetFolders(subscriptionId);
            var existing = folders.FirstOrDefault(c => c.SubscriptionId == subscriptionId && c.FolderId == folderToUpdate.FolderId);
            if (existing == null)
            {
                throw Utility.ThrowResponseException(this.Request, System.Net.HttpStatusCode.BadRequest, ErrorMessages.FolderNotFound);
            }

            DataProviderFactory.FolderInstance.UpdateFolder(subscriptionId, folderToUpdate);
        }
        void IFolderProvider.UpdateFolder(string subscriptionId, Folder folderToUpdate)
        {
            var existing = (from c in folders
                             where c.FolderId == folderToUpdate.FolderId && string.Equals(c.SubscriptionId, folderToUpdate.SubscriptionId, StringComparison.OrdinalIgnoreCase)
                             select c).First();

            // Actually, we will not allow any updates to the folder properties for now.
            ////existing.FolderName = folderToUpdate.FolderName;
            ////existing.ShareId = folderToUpdate.ShareId;
            ////existing.URL = folderToUpdate.URL;
        }