예제 #1
0
 private void AssertCreateFolderResult(CreateFolderResult createFolderResult)
 {
     Assert.NotNull(createFolderResult);
     Assert.IsTrue(createFolderResult.Success, createFolderResult.Error?.Message);
     Assert.NotNull(createFolderResult.Name);
     Assert.NotNull(createFolderResult.Path);
 }
예제 #2
0
        private async Task <CreateFolderResult> CreateFolder(DropboxClient client, string path)
        {
            var folder = new CreateFolderResult();

            try
            {
                Console.WriteLine("--- Creating Folder ---");
                var folderArg = new CreateFolderArg(path);
                folder = await client.Files.CreateFolderV2Async(folderArg);

                Console.WriteLine("Folder: " + path + " created!");
                //MessageBox.Show(path + "を作成しました",
                //"メッセージ",
                //MessageBoxButton.OK,
                //MessageBoxImage.Information);
                log_box.Items.Add("フォルダ" + path + "を作成しました");
            }
            catch (ApiException <CreateFolderError> ex)
            {
                string a = ex.Message;
                log_box.Items.Add(path + "の作成に問題が発生しました。すでにフォルダが存在している可能性があります\n\n理由:" + a);

                /*
                 * log_box.ScrollIntoView(path + "の作成に問題が発生しました。すでにフォルダが存在している可能性があります");
                 * MessageBox.Show(path + "の作成に問題が発生しました\n\nすでにフォルダが存在している可能性があります",
                 * "エラー",
                 * MessageBoxButton.OK,
                 * MessageBoxImage.Error);
                 */
            }
            return(folder);
        }
        public async Task <bool> CreateFolder(DropboxClient client, string folder, string fileName)
        {
            if (client == null)
            {
                return(false);
            }

            string newPath = "";

            if (string.IsNullOrEmpty(folder))
            {
                newPath = "/" + fileName;
            }
            else
            {
                newPath = folder + "/" + fileName;
            }
            try
            {
                CreateFolderResult createFolderResult = await client.Files.CreateFolderV2Async(newPath);
            }catch (Exception ex)
            {
                Debug.WriteLine("Create folder on Dropbox:" + ex.ToString());
                return(false);
            }


            return(true);
        }
예제 #4
0
        /// <summary>
        /// The operation to create a folder in the document library of the current Document Workspace site.
        /// </summary>
        /// <param name="folderUrl">Site-relative URL with the full path for the new folder.</param>
        /// <param name="error">An error indication.</param>
        public void CreateFolder(string folderUrl, out Error error)
        {
            string respString = this.dwsService.CreateFolder(folderUrl);

            // Decode response standalone xml string.
            string respXmlString = AdapterHelper.GenRespXmlString("CreateFolderResult", respString);

            // Validate response xml schema and capture the related requirements.
            this.ValidateCreateFolderResponseSchema(respXmlString);

            // Capture protocol transport related requirements.
            this.ValidateProtocolTransport();

            // Capture SOAP version related requirements.
            this.ValidateSoapVersion();

            // Deserialize response xml string to CanCreateDwsUrlResponse object.
            CreateFolderResult resp = AdapterHelper.XmlDeserialize <CreateFolderResult>(respXmlString);

            error = resp.Item as Error;
            if (error == null)
            {
                Site.Assert.AreEqual(
                    string.Empty,
                    resp.Item,
                    "An empty Result element (\"<Result/>\") should be returned if the call is successful, the actual returned Result element is '{0}'.",
                    resp.Item);

                this.ValidateCreateFolderResultResult();
            }
        }
예제 #5
0
 internal WsFolder(CreateFolderResult newFolder, bool isPrivate, WsApiClient apiClient)
 {
     Ident        = newFolder.Ident;
     PathInternal = newFolder.Path;
     Created      = DateTime.Now;
     State        = "ready";
     Init(apiClient, isPrivate);
 }
예제 #6
0
 public static CreateFolderResult ToCreateFolderResult(this CreateFolderRequest.Result data)
 {
     var res = new CreateFolderResult
     {
         IsSuccess = data.status == 200,
         Path = data.body
     };
     return res;
 }
예제 #7
0
        public static CreateFolderResult ToCreateFolderResult(this CommonOperationResult <string> data)
        {
            var res = new CreateFolderResult
            {
                IsSuccess = data.Status == 200,
                Path      = data.Body
            };

            return(res);
        }
예제 #8
0
        public static CreateFolderResult ToCreateFolderResult(this YadCreateFolderRequestParams data)
        {
            var res = new CreateFolderResult
            {
                IsSuccess = true,
                Path      = data.Id.Remove(0, "/disk".Length)
            };

            return(res);
        }
예제 #9
0
        public static CreateFolderResult ToCreateFolderResult(this CreateFolderRequest.Result data)
        {
            var res = new CreateFolderResult
            {
                IsSuccess = data.OperationResult == OperationResult.Ok,
                Path      = data.Path
            };

            return(res);
        }
예제 #10
0
        public static MailRuCloud.PathResult ToPathResult(this CreateFolderResult data)
        {
            var res = new MailRuCloud.PathResult
            {
                IsSuccess = data.status == 200,
                Path      = data.body
            };

            return(res);
        }
예제 #11
0
        public async Task <IActionResult> CreateFolder(CreateFolderViewModel folder)
        {
            CreateFolderResult result = await _mediatr.Send(new CreateFolderCommand(folder.FolderName, folder.ParentFolder.Id));

            if (result.State == OperationState.Success)
            {
                return(Created($"{BaseUrl}/folder={result.Folder.Id}", result.Folder));
            }
            else
            {
                return(HandleResult(result));
            }
        }
예제 #12
0
        public static async Task <FolderMetadata> CreateFolder(DropboxClient client, string path)
        {
            try
            {
                CreateFolderResult result = await client.Files.CreateFolderV2Async(path);

                return(result.Metadata);
            }
            catch
            {
                //TODO: Add error handling
                return(null);
            }
        }
예제 #13
0
        public async Task <WsFolder> CreateFolder(string folderPath, bool isPrivate)
        {
            CheckConnected();
            CreateFolderResult newFolderResult = await PostFormDataWithLoginRetry(() =>
            {
                FormUrlEncodedContent formContent = CreateFormContent(new[]
                {
                    new KeyValuePair <string, string>("path", folderPath),
                    new KeyValuePair <string, string>("private", isPrivate ? "1" : "0")
                });
                return(_httpClient.PostFormData <CreateFolderResult>(API_CREATE_FOLDER_URI, formContent));
            });

            return(new WsFolder(newFolderResult, isPrivate, this));
        }
예제 #14
0
        public async Task <Result <CreateFolderResult> > CreateFolderAsync(Guid id, CreateFolderInput input, User user)
        {
            if (user == null)
            {
                return(new Result <CreateFolderResult>(false, null, "Unauthorized", ErrorType.Unauthorized));
            }

            if (input is null || id == Guid.Empty)
            {
                return(new Result <CreateFolderResult>(false, null, "Data is not received", ErrorType.BadRequest));
            }


            var folder = await _context
                         .Folders
                         .Include(x => x.Folders)
                         .FirstOrDefaultAsync(x => x.Id == id);

            var disk = await _context
                       .Disks
                       .Include(x => x.Owner)
                       .FirstOrDefaultAsync(x => x.OwnerId == user.Id && x.Id == folder.DiskHintId);

            if (folder == null)
            {
                return(new Result <CreateFolderResult>(false, null, "Parent folder not found", ErrorType.BadRequest));
            }

            if (disk == null)
            {
                return(new Result <CreateFolderResult>(false, null, "Disk not found", ErrorType.BadRequest));
            }

            var newFolder = new Folder(folder, user.Id, disk.Id, input.Name);

            await _context.AddAsync(newFolder);

            await _context.SaveChangesAsync();

            var result = new CreateFolderResult {
                Id = newFolder.Id, Name = newFolder.Name
            };

            return(new Result <CreateFolderResult>(true, result));
        }
예제 #15
0
        /// <summary>
        /// Create remote folder
        /// </summary>
        /// <returns></returns>
        public static async Task <bool> CreateDropboxFolder()
        {
            await Task.Delay(App.DropboxDeltaTimeout);

            Metadata meta = await App.DropboxClient.Files.GetMetadataAsync("/" + App.ApplicationId);

            CreateFolderResult response = null;

            if (!meta.IsFolder)
            {
                response = await App.DropboxClient.Files.CreateFolderV2Async("/" + App.ApplicationId);

                return(response.Metadata.IsFolder);
            }
            else
            {
                return(true);
            }
        }
예제 #16
0
        private async Task <CreateFolderResult> CreateFolder(DropboxClient client, string path)
        {
            var folder = new CreateFolderResult();

            try
            {
                Console.WriteLine("--- Creating Folder ---");
                var folderArg = new CreateFolderArg(path);
                folder = await client.Files.CreateFolderV2Async(folderArg);

                Console.WriteLine("Folder: " + path + " created!");
                log_box.Items.Add("フォルダ" + path + "を作成しました");
            }
            catch (ApiException <CreateFolderError> ex)
            {
                string a = ex.Message;
                log_box.Items.Add(path + "の作成に問題が発生しました。すでにフォルダが存在している可能性があります\n\n理由:" + a);
            }
            return(folder);
        }
예제 #17
0
        private static eFolderCreateStatus ParseResult(CreateFolderResult folderResult)
        {
            switch (folderResult)
            {
            case CreateFolderResult.Success:
                return(eFolderCreateStatus.Success);

            case CreateFolderResult.FolderAlreadyExist:
                return(eFolderCreateStatus.FolderAlreadyExist);

            case CreateFolderResult.SystemFolder:
                return(eFolderCreateStatus.SystemFolder);

            case CreateFolderResult.ParentNotFound:
                return(eFolderCreateStatus.ParentNotFound);

            case CreateFolderResult.ServerError:
                return(eFolderCreateStatus.ServerError);

            default:
                throw new StatusParseException("CreateFolderResult: " + folderResult);
            }
        }
예제 #18
0
 /// <summary>
 /// Create folder on Filesanywhere
 /// </summary>
 /// <param name="MainForlder"></param>
 /// <param name="Subfolder"></param>
 /// <returns></returns>
 private static bool CreateFolders(string MainForlder, string Subfolder)
 {
     try
     {
         // Get Root Folder on which we are trying to load all files
         string Root                      = ConfigurationSettings.AppSettings["FARootFolder"].ToString();
         FAWAPI.FAWAPIv2Soap obj          = new FAWAPIv2SoapClient();
         CreateFolderResult  folderResult = obj.CreateFolder(objAccount.GetLogintoken(), Root + "/" + MainForlder, Subfolder);
         if (folderResult.FolderCreated == false)
         {
             if (folderResult.ErrorMessage.StartsWith("e2937:"))
             {
                 Console.WriteLine(Subfolder + " folder already exsist on FA. Please use othe folder name.");
             }
         }
         return(folderResult.FolderCreated);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error occurs in Creating Folder on FA (might be because of Mainfolder " + MainForlder + " doesnot exists) :- " + ex.Message);
         throw ex;
     }
 }
예제 #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Generating format...");

            #region Params

            var p_copy = new CopyParam
            {
                CurrentFolderPath    = "/",
                SourceDirectory      = "/",
                DestinationDirectory = "/",
                Overwrite            = false,
                Targets = new System.Collections.Generic.List <BaseActionTarget>
                {
                    new BaseActionTarget
                    {
                        IsFile = true,
                        Name   = "sample.txt"
                    }
                }
            };

            var p_move = new MoveParam
            {
                CurrentFolderPath    = "/",
                SourceDirectory      = "/",
                DestinationDirectory = "/",
                Overwrite            = false,
                Targets = new System.Collections.Generic.List <BaseActionTarget>
                {
                    new BaseActionTarget
                    {
                        IsFile = true,
                        Name   = "sample.txt"
                    }
                }
            };

            var p_createFolder = new CreateFolderParam
            {
                CurrentFolderPath = "/",
                Name = "new folder name"
            };

            var p_delete = new DeleteParam
            {
                CurrentFolderPath = "/",
                Targets           = new System.Collections.Generic.List <string>
                {
                    "itemNameToDelete"
                }
            };

            var p_folderStruct = new FolderStructParam
            {
                CurrentFolderPath = "/",
                FileExtensions    = new string[] { ".txt" }
            };

            var p_rename = new RenameParam
            {
                CurrentFolderPath = "/",
                Targets           = new System.Collections.Generic.List <RenameActionTarget>
                {
                    new RenameActionTarget
                    {
                        IsFile  = true,
                        Name    = "new name",
                        OldName = "old name"
                    }
                }
            };

            #endregion

            #region Results

            var r_copy = new CopyResult
            {
                Errors = new System.Collections.Generic.List <string>
                {
                    "Error message."
                }
            };

            var r_move = new MoveResult
            {
                Errors = new System.Collections.Generic.List <string>
                {
                    "Error message."
                }
            };

            var r_createFolder = new CreateFolderResult
            {
                Errors = new System.Collections.Generic.List <string>
                {
                    "Error message."
                }
            };

            var r_delete = new DeleteResult
            {
                Affected = 0,
                Errors   = new System.Collections.Generic.List <string>
                {
                    "Error message."
                }
            };

            var r_folderStruct = new FolderStructResult
            {
                Errors = new System.Collections.Generic.List <string>
                {
                    "Error message."
                },
                Files = new System.Collections.Generic.List <FileInfoProxy>
                {
                    new FileInfoProxy
                    {
                        Name       = "file.name",
                        Properties = new System.Collections.Generic.Dictionary <string, string>
                        {
                            { "Property", "Value" }
                        }
                    }
                },
                Folders = new System.Collections.Generic.List <FileInfoProxy>
                {
                    new FileInfoProxy
                    {
                        Name       = "folder name",
                        Properties = new System.Collections.Generic.Dictionary <string, string>
                        {
                            { "Property", "Value" }
                        }
                    }
                }
            };

            var r_rename = new RenameResult
            {
                Affected = 0,
                Errors   = new System.Collections.Generic.List <string>
                {
                    "Error message."
                },
                RenamedObjects = new System.Collections.Generic.List <RenameActionTarget>()
                {
                    new RenameActionTarget
                    {
                        IsFile  = true,
                        Name    = "new name",
                        OldName = "old name"
                    }
                }
            };

            #endregion

            SaveFormat("p_copy.json", p_copy);
            SaveFormat("p_move.json", p_move);
            SaveFormat("p_createFolder.json", p_createFolder);
            SaveFormat("p_delete.json", p_delete);
            SaveFormat("p_folderStruct.json", p_folderStruct);
            SaveFormat("p_rename.json", p_rename);

            SaveFormat("r_copy.json", r_copy);
            SaveFormat("r_move.json", r_move);
            SaveFormat("r_createFolder.json", r_createFolder);
            SaveFormat("r_delete.json", r_delete);
            SaveFormat("r_folderStruct.json", r_folderStruct);
            SaveFormat("r_rename.json", r_rename);
        }
예제 #20
0
        public async Task <Uri> AddDocument(Meeting meeting, Document document, string path = "")
        {
            DropboxCertHelper.InitializeCertPinning();

            if (string.IsNullOrEmpty(accessToken))
            {
                throw new ArgumentException("accessToken");
            }

            // Specify socket level timeout which decides maximum waiting time when no bytes are
            // received by the socket.
            var httpClient = new HttpClient()
            {
                // Specify request level timeout which decides maximum time that can be spent on
                // download/upload files.
                Timeout = TimeSpan.FromMinutes(20)
            };

            var config = new DropboxClientConfig("OpenGovAlerts")
            {
                HttpClient = httpClient
            };

            var client = new DropboxClient(accessToken, config);

            if (string.IsNullOrEmpty(path))
            {
                path = Path.Combine(baseFolder, meeting.Source.Name, meeting.Title, meeting.Date.ToString("yyyy-MM-dd") + "-" + meeting.BoardName);
            }

            var filename = new string(document.Title.Select(ch => invalidFileNameChars.Contains(ch) ? '_' : ch).ToArray());

            try
            {
                CreateFolderResult result = await client.Files.CreateFolderV2Async(path, false);
            }
            catch (ApiException <CreateFolderError> ex)
            {
                if (ex.ErrorResponse.AsPath.Value.IsConflict)
                {
                    // The folder already exists. Fine. I feel like I need to shower now.
                }
                else
                {
                    // F**k it, I'm not looking at any of those other properties.
                    throw new ApplicationException(string.Format("Could not create/verify Dropbox folder {1} for document {0} because of error {2}", document.Url, path, ex.Message));
                }
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("Could not create/verify Dropbox folder {1} for document {0} because of error {2}", document.Url, path, e.Message));
            }

            string filePath = Path.Combine(path, filename);

            try
            {
                Stream input = await httpClient.GetStreamAsync(document.Url);

                FileMetadata file = await client.Files.UploadAsync(filePath, body : input);

                SharedLinkMetadata link = await client.Sharing.CreateSharedLinkWithSettingsAsync(new CreateSharedLinkWithSettingsArg(file.PathLower));

                return(new Uri(link.Url));
            }
            catch (ApiException <UploadError> ex)
            {
                throw new ApplicationException(string.Format("Could not upload document {0} to path {1} because of error {2}", document.Url, filePath, ex.Message));
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("Could not upload document {0} to path {1} because of error {2}", document.Url, filePath, e.Message));
            }
        }