private async Task ResolveFileAsync(UpgradeInfo info)
        {
            using (var tempPath = new TempDirectory(Path.Combine(AcceleriderFolders.Temp, $"{Name}-{Path.GetRandomFileName()}")))
            {
                var zipFilePath = Path.Combine(tempPath.Path, Path.GetRandomFileName());

                // 1. Download the module
                var downloader = FileTransferService
                                 .GetDownloaderBuilder()
                                 .UseDefaultConfigure()
                                 .From(info.Url)
                                 .To(zipFilePath)
                                 .Build();

                downloader.Run();

                await downloader;

                // 2. Unzip the module
                ZipFile.ExtractToDirectory(zipFilePath, tempPath.Path);

                Logger.Info($"[UNZIP] From {zipFilePath} to {tempPath.Path}");

                // 3. Move file to target path.
                var targetPath   = GetInstallPath(info.Version);
                var subDirectory = Directory.GetDirectories(tempPath.Path).FirstOrDefault();
                if (tempPath.MoveTo(targetPath, subDirectory))
                {
                    Logger.Info($"[MOVE FILE] From {subDirectory} to {targetPath}");
                }
            }
        }
Esempio n. 2
0
        private void FilterCommandExecute(string tag)
        {
            AllTasks.Clear();
            var transferTasks = FileTransferService.GetAllTransferTask();

            switch (tag)
            {
            case null:
                transferTasks.ForEach(item =>
                {
                    AllTasks.Add(item);
                });
                break;

            case "download":
                transferTasks.ForEach(item =>
                {
                    if (item.TransferType == TransferType.Download)
                    {
                        AllTasks.Add(item);
                    }
                });
                break;

            case "upload":
                transferTasks.ForEach(item =>
                {
                    if (item.TransferType == TransferType.Upload)
                    {
                        AllTasks.Add(item);
                    }
                });
                break;
            }
        }
Esempio n. 3
0
        protected ResultDownloadFileRequest InternalGetReport(RequestsCounterData requestsCounter)
        {
            //var jobs = BulkDataService.GetJobs();

            //BulkDataService.DeleteRecurringJob( ReportType );

            ResultInfoJobRequest jobRez = BulkDataService.DownloadJob(ReportType);
            var reportTypeString        = ReportType.ToString();

            requestsCounter.IncrementRequests("DownloadJob", reportTypeString);
            if (jobRez.HasError)
            {
                return(new ResultDownloadFileRequest(jobRez.Errors, jobRez.SubmittedDate));
            }

            var fileReferenceId = jobRez.FileReferenceId;
            var jobId           = jobRez.JobId;

            if (string.IsNullOrEmpty(fileReferenceId))
            {
                JobProfile job = BulkDataService.GetJob(jobId);
                requestsCounter.IncrementRequests("GetJob", reportTypeString);
                fileReferenceId = job.fileReferenceId;
            }
            var rez = FileTransferService.DownloadFile(jobId, fileReferenceId);

            requestsCounter.IncrementRequests("DownloadFile", reportTypeString);
            return(new ResultDownloadFileRequest(rez));
        }
Esempio n. 4
0
            public void Start()
            {
                var Products = ordersServiseWorker.dataAccess.Products.GetAllObj();
                List <ProductsToClient>    products      = ordersServiseWorker.ModelChangeToClient(Products);
                Creator <ProductsToClient> xml_xsdCreate = new Creator <ProductsToClient>(products);
                FileTransferService        transfer      = new FileTransferService(settings.SourceDirectory);

                transfer.FileTransfer(xml_xsdCreate.CreateXML(), xml_xsdCreate.CreateXSD());
            }
Esempio n. 5
0
        public void Initialize()
        {
            var transferTasks = FileTransferService.GetAllTransferTask();

            transferTasks.ForEach(item =>
            {
                AllTasks.Add(item);
            });
        }
Esempio n. 6
0
 public static IEnumerable <IDownloader> ToDownloaders(this IEnumerable <RemoteRef> @this)
 {
     return(@this.Select(item => FileTransferService
                         .GetDownloaderBuilder()
                         .UseDefaultConfigure()
                         .From(item.RemotePath)
                         .To(item.LocalPath)
                         .Build()));
 }
        public override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            // Register for container
            containerRegistry.RegisterInstance(FileTransferService.GetDownloaderManager("net-disk"));

            // Register for region
            _regionManager.RegisterViewWithRegion(RegionNames.MainTabRegion, typeof(FileBrowserComponent));
            _regionManager.RegisterViewWithRegion(RegionNames.MainTabRegion, typeof(TransportationComponent));
            _regionManager.RegisterViewWithRegion(RegionNames.SettingsTabRegion, typeof(TaskSettingsTabItem));
        }
Esempio n. 8
0
 /// <summary>
 /// Gets FileTransferService
 /// </summary>
 public FileTransferService GetFileTransferService()
 {
     if (fileTransferService == null)
     {
         fileTransferService = new FileTransferService();
         fileTransferService.ResourcePath = AdministrationResourcePath.FILE_TRANSFER_RESOURCE_PATH;
         configureService(fileTransferService);
     }
     return(fileTransferService);
 }
Esempio n. 9
0
        // -------------------------------------------------------------------------------------
        public static IReadOnlyList <TransferItem> GetDownloadItems(this IAcceleriderUser @this)
        {
            Guards.ThrowIfNull(@this);

            return(FileTransferService
                   .GetDownloaderManager()
                   .Transporters
                   .OfType <TransferItem>()
                   .ToList()
                   .AsReadOnly());
        }
Esempio n. 10
0
        public static IDownloadingFile ToDownloadingFile(this string jsonText, Action <IDownloaderBuilder> configure, INetDiskUser owner)
        {
            var data = jsonText.ToObject <SerializedData>();

            var file    = data.File;
            var builder = FileTransferService.GetDownloaderBuilder();

            configure(builder);
            var downloader = builder.Build(data.DownloadInfo.ToString());

            return(DownloadingFile.Create(owner, file, downloader));
        }
Esempio n. 11
0
        private TransferItem MockDownload(INetDiskFile file, FileLocator to)
        {
            var downloader = FileTransferService
                             .GetDownloaderBuilder()
                             .UseSixCloudConfigure()
                             .From(file.Path)
                             .To(to)
                             .Build();

            return(new TransferItem(downloader)
            {
                File = file,
                Owner = this
            });
        }
Esempio n. 12
0
        public override IDownloadingFile Download(INetDiskFile from, FileLocator to)
        {
            var downloader = FileTransferService
                             .GetDownloaderBuilder()
                             .UseSixCloudConfigure()
                             .Configure(localPath => localPath.GetUniqueLocalPath(path => File.Exists(path) || File.Exists($"{path}{ArddFileExtension}")))
                             .From(new RemotePathProvider(this, from.Path))
                             .To(Path.Combine(to, from.Path.FileName))
                             .Build();

            var result = DownloadingFile.Create(this, from, downloader);

            SaveDownloadingFile(result);

            return(result);
        }
        public override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            // Register for container
            containerRegistry.RegisterInstance(FileTransferService.GetDownloaderManager("any-drive"));

            AcceleriderUserExtensions.Initialize(containerRegistry.GetContainer());

            // Register for region
            _regionManager.RegisterViewWithRegion(RegionNames.MainTabRegion, typeof(FileBrowserComponent));
            _regionManager.RegisterViewWithRegion(RegionNames.MainTabRegion, typeof(TransportationComponent));
            _regionManager.RegisterViewWithRegion(RegionNames.SettingsTabRegion, typeof(TaskSettingsTabItem));

            _regionManager.RegisterViewWithRegion(Constants.NetDiskAuthenticationViewRegion, typeof(NetDiskList));
            _regionManager.RegisterViewWithRegion(Constants.NetDiskAuthenticationViewRegion, typeof(BaiduCloud));
            _regionManager.RegisterViewWithRegion(Constants.NetDiskAuthenticationViewRegion, typeof(OneDrive));
            _regionManager.RegisterViewWithRegion(Constants.NetDiskAuthenticationViewRegion, typeof(SixCloud));
        }
Esempio n. 14
0
        //加载菜单
        public object LoadMenuSetting(HttpContext context)
        {
            ExecuteBcfMethodResult result = new ExecuteBcfMethodResult();

            string data = context.Request["data"];
            MDictionary <string, string> dic = new MDictionary <string, string>();

            if (!string.IsNullOrEmpty(data))
            {
                dic = JsonConvert.DeserializeObject <MDictionary <string, string> >(data);
            }

            FileTransferService service = new FileTransferService();
            string handle = dic["Handle"];

            result.Result = service.LoadMenuSetting(handle);
            return(result);
        }
Esempio n. 15
0
        public object UpLoadFile(HttpContext context)
        {
            string data = context.Request["data"];
            MDictionary <string, string> dic = new MDictionary <string, string>();

            if (!string.IsNullOrEmpty(data))
            {
                dic = JsonConvert.DeserializeObject <MDictionary <string, string> >(data);
            }
            string progId = dic["ProgId"];

            HttpFileCollection postedFile = context.Request.Files;

            FileTransferService service = new FileTransferService();

            for (int i = 0; i < postedFile.Count; i++)
            {
                UpLoadFileResult ret = service.UpLoadFile1(postedFile[i], progId);
                return(new { uploaded = 1, fileName = ret.FileName, url = ret.FileName, });
            }

            return(null);
        }
Esempio n. 16
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            _coreTitleBar.ExtendViewIntoTitleBar = true;
            Window.Current.SetTitleBar(TitleBarBackgroundElement);

            //notification
            NotificationService.Initialize(AppNotification);

            //main page datacontext
            var dataContext = new MainPageViewModel();

            DataContext = dataContext;

            //NaviagtionService Initialize
            NavigationService.MainFrame = ContentFrame;
            NavigationService.RegisterPageType("setting", typeof(SettingPage));
            NavigationService.RegisterPageType("files", typeof(FileListPage));
            NavigationService.RegisterPageType("create", typeof(CreateBucketPage));
            NavigationService.RegisterPageType("transfer", typeof(FileTransferPage));

            //Start File Transfer Service
            FileTransferService.Start();

            //load data
            var setting = AppSettingService.GetSetting();

            if (string.IsNullOrEmpty(setting.Ak) || string.IsNullOrEmpty(setting.Sk))
            {
                NavigationService.NaviageTo("setting");
            }
            else
            {
                QiniuService.Initialize(setting.Ak, setting.Sk);
                await dataContext.BucketListViewModel.Initialize();
            }
        }
        public bool Execute(ISessionContext context)
        {
            var _logger  = context.GetLogger();
            var _options = context.Options;


            try
            {
                var searchPath = _options.Get("searchPath", "");
                if (String.IsNullOrEmpty(searchPath))
                {
                    throw new ArgumentNullException("searchPath");
                }

                var destinationPath = _options.Get("destinationPath", "");
                if (String.IsNullOrEmpty(destinationPath))
                {
                    throw new ArgumentNullException("destinationPath");
                }

                var deleteSourceFile = _options.Get <bool> ("deleteSourceFile", false);

                maxFilesCount = _options.Get("maxFileCount", maxFilesCount);
                if (maxFilesCount <= 0)
                {
                    maxFilesCount = Int32.MaxValue;
                }

                var defaultEncoding = Encoding.GetEncoding(_options.Get("encoding", "ISO-8859-1"));

                // prepare paths
                var parsedInput = FileTransferService.Create(searchPath, _options);
                if (!parsedInput.HasConnectionString)
                {
                    throw new Exception("Invalid searchPath: " + searchPath);
                }
                var parsedOutput = FileTransferService.Create(destinationPath, _options);
                if (!parsedOutput.HasConnectionString)
                {
                    throw new Exception("Invalid destinationPath: " + destinationPath);
                }

                var parsedBackupLocation = FileTransferService.Create(_options.Get("backupLocation", ""), _options);
                parsedErrorLocation.Parse(_options.Get("errorLocation", ""), _options);

                // open connection
                Layout layout = new Layout();
                input  = parsedInput.OpenConnection();
                output = parsedOutput.OpenConnection();

                // try get files
                foreach (var f in input.GetFileStreams())
                {
                    lastFile = f.FileName;
                    _logger.Info("File found: " + lastFile);
                    filesCount++;

                    // upload file
                    var fileName = parsedOutput.GetDestinationPath(f.FileName);
                    output.SendFile(f.FileStream, fileName, true);

                    context.Emit(layout.Create()
                                 .Set("FileName", fileName)
                                 .Set("FileCount", filesCount)
                                 .Set("FilePath", destinationPath)
                                 .Set("SourcePath", searchPath)
                                 .Set("SourceFileName", f.FileName));

                    // If backup folder exists, move file
                    if (parsedBackupLocation.HasConnectionString)
                    {
                        // TODO: implement move operation if location are the same!
                        var destName = parsedBackupLocation.GetDestinationPath(f.FileName);
                        using (var backup = parsedBackupLocation.OpenConnection())
                            backup.SendFile(input.GetFileStream(f.FileName).FileStream, destName, true);
                    }

                    // If DeleSource is set
                    if (deleteSourceFile)
                    {
                        input.RemoveFile(f.FileName);
                    }

                    // limit
                    if (filesCount >= maxFilesCount)
                    {
                        break;
                    }
                }

                if (filesCount > 0)
                {
                    _logger.Success("Done");
                    return(true);
                }
                else
                {
                    _logger.Debug("No Files Found on: " + searchPath);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                context.Error = ex.Message;
                _logger.Error(ex);
                try
                {
                    if (lastFile != null && input != null && parsedErrorLocation.HasConnectionString)
                    { // move files
                        var destName = parsedErrorLocation.GetDestinationPath(lastFile);
                        using (var backup = parsedErrorLocation.OpenConnection())
                            backup.SendFile(input.GetFileStream(lastFile).FileStream, destName, true);
                    }
                }
                catch { }
                return(false);
            }
            finally
            {
                if (output != null)
                {
                    output.Dispose();
                }
                if (input != null)
                {
                    input.Dispose();
                }
            }
        }
 public FileTransferServiceTests()
 {
     _target  = new FileTransferService();
     testData = new FileTransferServiceTestData();
 }
        static void Main(string[] args)
        {
            Log.InitLogger("FileTransferServiceLog");



            var hostName = Dns.GetHostName();

            Console.WriteLine($"Host: {hostName}");

            var hostUri = Dns.GetHostEntry(hostName).AddressList
                          .Where(x => x.AddressFamily == AddressFamily.InterNetwork)
                          .Select(hostIp => new Uri($"net.tcp://{hostIp}/ImageService"))
                          .First();

            Console.WriteLine($"Service endpoint: {hostUri}");

            // Dmitry Belkin TODO: In config
            string connectionString =
                @"Data Source=mkr0009;Initial Catalog=Media; User ID=db_user;Password=Qwerty_123; Integrated Security=False";

            string connectionMongoString =
                @"mongodb://mkr0007:27017/PhotoStore";

            Log.Instance.LogAsInfo($"{nameof(FileTransferServiceConsoleHost)}.{nameof(Program)}.{nameof(Main)}: Creating {nameof(FileTransferService)}");
            var service = new FileTransferService(
                new ImageDbFileSource(
                    new UnitOfWorkPhotoStorageMongo(connectionMongoString),
                    new UnitOfWorkPhotoStorageSQL(connectionString)));

            Log.Instance.LogAsInfo($"{nameof(FileTransferServiceConsoleHost)}.{nameof(Program)}.{nameof(Main)}: Creating {nameof(FileTransferService)} is ended");

            Log.Instance.LogAsInfo($"{nameof(FileTransferServiceConsoleHost)}.{nameof(Program)}.{nameof(Main)}: Creating {nameof(FileTransferService)}");
            var serviceHost = new ServiceHost(service, hostUri);

            Log.Instance.LogAsInfo($"{nameof(FileTransferServiceConsoleHost)}.{nameof(Program)}.{nameof(Main)}: Creating {nameof(FileTransferService)} is ended");

            serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior());

            serviceHost.Description.Behaviors.Find <ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;


            serviceHost.AddServiceEndpoint(typeof(IMetadataExchange),
                                           MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
            //serviceHost.CloseTimeout = TimeSpan.MaxValue;
            //serviceHost.OpenTimeout = TimeSpan.MaxValue;


            var httpb = new NetTcpBinding()
            {
                TransferMode           = TransferMode.Streamed,
                MaxReceivedMessageSize = 2147483647,//4294967295,//2147483647,
                MaxBufferSize          = 2147483647,
                SendTimeout            = new TimeSpan(4, 01, 0),
                CloseTimeout           = new TimeSpan(4, 01, 0),
                OpenTimeout            = new TimeSpan(4, 01, 0),
                ReceiveTimeout         = new TimeSpan(4, 01, 0),
                ReaderQuotas           = new System.Xml.XmlDictionaryReaderQuotas()
                {
                    MaxDepth = 2147483647,
                    MaxStringContentLength = 2147483647,
                    MaxArrayLength         = 2147483647,
                    MaxNameTableCharCount  = 2147483647,
                    MaxBytesPerRead        = 2147483647
                }
            };

            var tcpb2 = new NetTcpBinding()
            {
                ReceiveTimeout = TimeSpan.MaxValue
            };

            serviceHost.AddServiceEndpoint(typeof(IFileTransferService), httpb, "ImageService");
            serviceHost.AddServiceEndpoint(typeof(IFileTransferServiceV2), tcpb2, "ImageService2");
            Console.WriteLine("Initialization complete");

            Console.WriteLine("Open service");
            using (serviceHost)
            {
                Log.Instance.LogAsInfo($"{nameof(FileTransferServiceConsoleHost)}.{nameof(Program)}.{nameof(Main)}: Open ServiceHost...");
                serviceHost.Open();

                string cmd;
                do
                {
                    Console.Write('>');
                    cmd = Console.ReadLine();
                    if (cmd == "copy")
                    {
                        Clipboard.SetText(hostUri.ToString());
                    }
                    else if (cmd == "client")
                    {
                        System.Diagnostics.Process.Start("C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\IDE\\wcftestclient.exe");
                    }
                } while (cmd != "exit");

                serviceHost.Close();
                Console.WriteLine("Service closed");
                Log.Instance.LogAsInfo($"{nameof(FileTransferServiceConsoleHost)}.{nameof(Program)}.{nameof(Main)}: ServiceHost is closed.");
            }

            //  Log.Instance.ExceptionInfo(e).LogAsError($"{nameof(FileTransferServiceConsoleHost)}.{nameof(Program)}.{nameof(Main)}: Open ServiceHost");
            // Console.WriteLine(e);
        }