Exemplo n.º 1
0
        private void UploadFile(FileDestination fileUploaderType, Stream data)
        {
            FileUploader fileUploader = null;

            switch (fileUploaderType)
            {
                case FileDestination.FTP:
                    if (Engine.ConfigUI.ShowFTPSettingsBeforeUploading)
                    {
                        var ucf = new UploadersConfigForm(Engine.ConfigUploaders, Engine.ConfigUI.ApiKeysConfig);
                        ucf.Icon = Resources.zss_main;
                        ucf.tcUploaders.SelectedTab = ucf.tpFileUploaders;
                        ucf.tcFileUploaders.SelectedTab = ucf.tpFTP;
                        ucf.ShowDialog();
                    }
                    switch (Job1)
                    {
                        case EDataType.Text:
                            UploadToFTP(Engine.ConfigUploaders.FTPSelectedText, data);
                            break;
                        case EDataType.Image:
                            UploadToFTP(Engine.ConfigUploaders.FTPSelectedImage, data);
                            break;
                        default:
                        case EDataType.File:
                            UploadToFTP(Engine.ConfigUploaders.FTPSelectedFile, data);
                            break;
                    }
                    break;
                case FileDestination.Minus:
                    fileUploader = new Minus(Engine.ConfigUploaders.MinusConfig, new OAuthInfo(Engine.ConfigUI.ApiKeysConfig.MinusConsumerKey, Engine.ConfigUI.ApiKeysConfig.MinusConsumerSecret));
                    break;
                case FileDestination.Dropbox:
                    string uploadPath = new NameParser { IsFolderPath = true }.Convert(Dropbox.TidyUploadPath(Engine.ConfigUploaders.DropboxUploadPath));
                    fileUploader = new Dropbox(Engine.ConfigUploaders.DropboxOAuthInfo, uploadPath, Engine.ConfigUploaders.DropboxAccountInfo)
                    {
                        AutoCreateShareableLink = Engine.ConfigUploaders.DropboxAutoCreateShareableLink
                    };
                    break;
                case FileDestination.Box:
                    fileUploader = new Box(ZKeys.BoxKey)
                     {
                         AuthToken = Engine.ConfigUploaders.BoxAuthToken,
                         FolderID = Engine.ConfigUploaders.BoxFolderID,
                         Share = Engine.ConfigUploaders.BoxShare
                     };
                    break;
                case FileDestination.SendSpace:
                    fileUploader = new SendSpace(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey);
                    switch (Engine.ConfigUploaders.SendSpaceAccountType)
                    {
                        case AccountType.Anonymous:
                            SendSpaceManager.PrepareUploadInfo(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey);
                            break;
                        case AccountType.User:
                            SendSpaceManager.PrepareUploadInfo(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey, Engine.ConfigUploaders.SendSpaceUsername, Engine.ConfigUploaders.SendSpacePassword);
                            break;
                    }
                    break;
                case FileDestination.RapidShare:
                    fileUploader = new RapidShare(Engine.ConfigUploaders.RapidShareUsername, Engine.ConfigUploaders.RapidSharePassword,
                        Engine.ConfigUploaders.RapidShareFolderID);
                    break;
                case FileDestination.CustomUploader:
                    fileUploader = new CustomUploader(Engine.ConfigUploaders.CustomUploadersList[Engine.ConfigUploaders.CustomUploaderSelected]);
                    break;
            }

            if (fileUploader != null)
            {
                MyWorker.ReportProgress((int)ProgressType.UpdateProgressMax, TaskbarProgressBarState.Indeterminate);
                DestinationName = fileUploaderType.GetDescription();
                DebugHelper.WriteLine("Initialized " + DestinationName);
                fileUploader.ProgressChanged += UploadProgressChanged;
                UploadResult ur_remote_file = fileUploader.Upload(data, Info.FileName);
                if (ur_remote_file != null)
                {
                    ur_remote_file.Host = fileUploaderType.GetDescription();
                    ur_remote_file.LocalFilePath = Info.LocalFilePath;
                    AddUploadResult(ur_remote_file);
                }
                Errors = fileUploader.Errors;
            }
        }
        private void TestCustomUploader(CustomUploaderInfo cui)
        {
            UploadResult ur = null;

            AsyncHelper.AsyncJob(() =>
            {
                try
                {
                    using (Stream stream = Resources.ZScreen_256.GetStream())
                    {
                        CustomUploader cu = new CustomUploader(cui);
                        ur = cu.Upload(stream, "Test.png");
                        ur.Errors = cu.Errors;
                    }
                }
                catch { }
            },
            () =>
            {
                if (ur != null)
                {
                    if (!string.IsNullOrEmpty(ur.URL))
                    {
                        txtCustomUploaderLog.AppendText("URL: " + ur.URL + Environment.NewLine);
                    }
                    else if (ur.IsError)
                    {
                        txtCustomUploaderLog.AppendText("Error: " + ur.ErrorsToString() + Environment.NewLine);
                    }
                    else
                    {
                        txtCustomUploaderLog.AppendText("Error: Result is empty." + Environment.NewLine);
                    }

                    txtCustomUploaderLog.ScrollToCaret();
                }

                btnCustomUploaderTest.Enabled = true;
            });
        }