コード例 #1
0
        private async Task ProcessFile()
        {
            var file = SelectedFile;

            if (file == null)
            {
                return;
            }

            IsProcessing = true;
            try
            {
                Message = "Calculating File Hash...";

                var sw = Stopwatch.StartNew();

                using (var service = new FileUploadServiceClient())
                {
                    var result = await service.ProcessFileAsync(file.File.BlobFileId);

                    MessageBox.Show(result, "RESULT");
                }

                Message = string.Format("Elapsed: {0} seconds", sw.Elapsed.TotalSeconds);
            }
            catch (Exception e)
            {
                Message = "Error";
                MessageBox.Show(e.Message, "Error");
            }
            finally
            {
                IsProcessing = false;
            }
        }
コード例 #2
0
        private async Task DeleteFile()
        {
            var file = SelectedFile;

            if (file == null)
            {
                return;
            }

            IsProcessing = true;
            try
            {
                Message = "Deleting File...";

                var sw = Stopwatch.StartNew();

                using (var service = new FileUploadServiceClient())
                    await service.DeleteBlobFileAsync(file.File.BlobFileId);

                await RefreshData();

                Message = string.Format("Elapsed: {0} seconds", sw.Elapsed.TotalSeconds);
            }
            catch (Exception e)
            {
                Message = "Error";
                MessageBox.Show(e.Message, "Error");
            }
            finally
            {
                IsProcessing = false;
            }
        }
コード例 #3
0
        public virtual FileUploadServiceClient GetFileUploadWebService(TblFileServers fileServer)
        {
            var binding = new BasicHttpBinding()
            {
                Security =
                {
                    Mode    = BasicHttpSecurityMode.TransportWithMessageCredential,
                    Message =
                    {
                        ClientCredentialType = BasicHttpMessageCredentialType.UserName,
                        AlgorithmSuite       = SecurityAlgorithmSuite.Default
                    }
                },
                AllowCookies           = true,
                MaxReceivedMessageSize = 100000000,
                MaxBufferPoolSize      = 100000000,
                MessageEncoding        = WSMessageEncoding.Mtom,
                ReaderQuotas           = { MaxArrayLength = 100000000, MaxStringContentLength = 100000000, MaxDepth = 32 }
            };

            binding.OpenTimeout      = binding.ReceiveTimeout =
                binding.CloseTimeout = binding.SendTimeout = TimeSpan.FromSeconds(25);

            var endPoint =
                new EndpointAddress(fileServer.FileUploadServerUrl);
            var uploadWebService = new FileUploadServiceClient(binding, endPoint);

            if (uploadWebService.ClientCredentials != null)
            {
                uploadWebService.ClientCredentials.UserName.UserName = fileServer.ServiceUserName;
                uploadWebService.ClientCredentials.UserName.Password = fileServer.ServicePassword;
            }

            return(uploadWebService);
        }
コード例 #4
0
        private async Task SaveAsFile()
        {
            var file = SelectedFile;

            if (file == null)
            {
                return;
            }

            IsProcessing = true;
            try
            {
                Message = "Saving File...";

                var dlg = new Microsoft.Win32.SaveFileDialog
                {
                    Title    = "Select Destination File",
                    FileName = file.File.Name,
                    Filter   = "All Files|*.*"
                };

                if (dlg.ShowDialog() != true)
                {
                    return;
                }
                var fileName = dlg.FileName;
                if (string.IsNullOrEmpty(fileName))
                {
                    return;
                }

                var sw = Stopwatch.StartNew();

                using (var service = new FileUploadServiceClient())
                {
                    await service.SaveFileAsAsync(file.File.BlobFileId, fileName);
                }

                Message = string.Format("Elapsed: {0} seconds", sw.Elapsed.TotalSeconds);
            }
            catch (Exception e)
            {
                Message = "Error";
                MessageBox.Show(e.Message, "Error");
            }
            finally
            {
                IsProcessing = false;
            }
        }
コード例 #5
0
ファイル: ViewsManager.cs プロジェクト: ewin66/ToolsManager
        public static bool DownloadTaskFile(string machineTarget, TaskInfo task, out string targetZipFile, string sharedPath)
        {
            Logger.AddTrace("Downloading Shared Task");

            targetZipFile = string.Empty;

            if (string.IsNullOrEmpty(sharedPath))
            {
                return(false);
            }

            FileUploadServiceClient fileServices = new FileUploadServiceClient();

            string fileName = string.Format("{0}.{1}.{2}", machineTarget, task.Id.ToString(), ZipFiles.FILE_EXTENSION);

            if (!fileServices.FileExists(fileName))
            {
                Logger.AddWarning(string.Format("The file {0} can't be downloaded from server", fileName));
                return(false);
            }

            Stream stream = null;

            try
            {
                stream = fileServices.DownloadFile(fileName);

                targetZipFile = Path.Combine(Path.GetTempPath(), fileName);

                FileUtilities.SaveFile(stream, targetZipFile);

                fileServices.DeleteFile(fileName);

                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }

                fileServices.Close();
            }
        }
コード例 #6
0
ファイル: ViewsManager.cs プロジェクト: ewin66/ToolsManager
        private void UploadTaskFile(string machineTarget, TaskInfo task, string sharedPath)
        {
            if (string.IsNullOrEmpty(sharedPath))
            {
                return;
            }

            FileUploadServiceClient fileServices = new FileUploadServiceClient();

            var fileName = string.Format("{0}.{1}.{2}", machineTarget, task.Id.ToString(), ZipFiles.FILE_EXTENSION);

            var stream = ZipFiles.Compress(sharedPath);

            if (stream == null)
            {
                return;
            }

            fileServices.UploadFile(fileName, stream);
        }
コード例 #7
0
        private async Task RefreshData()
        {
            IsProcessing = true;
            try
            {
                Message = "Refreshing...";
                using (var service = new FileUploadServiceClient())
                {
                    var data = await service.GetBlobFilesAsync();

                    Data = new ObservableCollection <FileViewModel>(data.Select(x => new FileViewModel(x)));
                }
                Message = "Data Refreshed";
            }
            catch (Exception e)
            {
                Message = "Error";
                MessageBox.Show(e.Message, "Error");
            }
            finally
            {
                IsProcessing = false;
            }
        }
コード例 #8
0
        private async Task AddFile()
        {
            const int chunkSize = 2 * 1024 * 1024; // 2MB

            IsProcessing = true;
            try
            {
                Message = "Uploading File...";

                var dlg = new Microsoft.Win32.OpenFileDialog {
                    Title = "Select File to Upload"
                };

                if (dlg.ShowDialog() != true)
                {
                    return;
                }
                var fileName = dlg.FileName;
                if (string.IsNullOrEmpty(fileName))
                {
                    return;
                }

                var sw = Stopwatch.StartNew();

                using (var service = new FileUploadServiceClient())
                {
                    var fileId = await service.CreateBlobFileAsync(Path.GetFileName(fileName),
                                                                   fileName, new FileInfo(fileName).Length, Environment.UserName);

                    using (var stream = File.OpenRead(fileName))
                    {
                        var edb = new ExecutionDataflowBlockOptions {
                            BoundedCapacity = 5, MaxDegreeOfParallelism = 5
                        };

                        var ab = new ActionBlock <Tuple <byte[], int> >(x => service.AddBlobFileChunkAsync(fileId, x.Item2, x.Item1), edb);

                        foreach (var item in stream.GetByteChunks(chunkSize).Select((x, i) => Tuple.Create(x, i)))
                        {
                            await ab.SendAsync(item);
                        }

                        ab.Complete();

                        await ab.Completion;
                    }
                }

                await RefreshData();

                Message = string.Format("Elapsed: {0} seconds", sw.Elapsed.TotalSeconds);
            }
            catch (Exception e)
            {
                Message = "Error";
                MessageBox.Show(e.Message, "Error");
            }
            finally
            {
                IsProcessing = false;
            }
        }