Exemple #1
0
        private void DownloadFile(IFtpClient client, ILocalDirectory storageFolder, string fullRemotePath, IRemoteItem item, bool overwrite)
        {
            var file = storageFolder.TryGetItemAsync(item.Name).Result;

            if (file != null && !overwrite)
            {
                var downloadRemoteItem = DependencyService.Resolve <IDownloadRemoteItem>();
                downloadRemoteItem.Destination = storageFolder;
                downloadRemoteItem.Item        = item;

                FileConflicts.Add(downloadRemoteItem);
                return;
            }

            storageFolder.CreateFileAsync(item.Name, overwrite)
            .ContinueWith(fileStreamTask =>
            {
                var stream = fileStreamTask.Result.OpenStreamForWriteAsync().Result;

                using (var fileStream = stream)
                {
                    client.Download(fileStream, fullRemotePath);
                }
            }).Wait();
        }
 /// <summary>
 /// Initializes a new instance of <see cref="DisposableLocalDirectoryWrapper"/>
 /// </summary>
 /// <param name="directory">The local directory to wrao</param>
 public DisposableLocalDirectoryWrapper(ILocalDirectory directory)
 {
     if (directory == null)
     {
         throw new ArgumentNullException(nameof(directory));
     }
     Directory = directory;
 }
        public UninstallCommand(ILocalDirectory localData, ILocalMetaData localMetaData)
        {
            Checks.ArgumentNotNull(localData, "localData");
            Checks.ArgumentNotNull(localMetaData, "localMetaData");

            DebugLogger.LogConstructor();

            _localData     = localData;
            _localMetaData = localMetaData;
        }
        public CheckVersionIntegrityCommand(int versionId, AppContentSummary versionSummary, ILocalDirectory localDirectory, ILocalMetaData localMetaData)
        {
            Checks.ArgumentValidVersionId(versionId, "versionId");
            // TODO: Validate the content summary.
            Checks.ArgumentNotNull(localDirectory, "localDirectory");
            Checks.ArgumentNotNull(localMetaData, "localMetaData");


            DebugLogger.LogConstructor();
            DebugLogger.LogVariable(versionId, "versionId");

            _versionId      = versionId;
            _versionSummary = versionSummary;
            _localDirectory = localDirectory;
            _localMetaData  = localMetaData;
        }
        public CheckVersionIntegrityCommand(int versionId, AppContentSummary versionSummary,
                                            ILocalDirectory localDirectory, ILocalMetaData localMetaData, bool isCheckingHash, bool isCheckingSize)
        {
            Checks.ArgumentValidVersionId(versionId, "versionId");
            Checks.ArgumentNotNull(versionSummary, "versionSummary");
            Checks.ArgumentNotNull(localDirectory, "localDirectory");
            Checks.ArgumentNotNull(localMetaData, "localMetaData");

            DebugLogger.LogConstructor();
            DebugLogger.LogVariable(versionId, "versionId");

            _versionId      = versionId;
            _versionSummary = versionSummary;
            _localDirectory = localDirectory;
            _localMetaData  = localMetaData;
            _isCheckingSize = isCheckingSize;
            _isCheckingHash = isCheckingHash;
        }
Exemple #6
0
        public RepairFilesCommand(
            RemoteResource resource,
            Pack1Meta meta,
            Pack1Meta.FileEntry[] fileEntries,
            string destinationPackagePath,
            string packagePassword,
            ILocalDirectory localData)
        {
            _resource = resource;
            _meta     = meta;
            _entries  = fileEntries;

            _packagePath     = destinationPackagePath;
            _packagePassword = packagePassword;

            _localData = localData;

            _logger = PatcherLogManager.DefaultLogger;
        }
Exemple #7
0
        public App([NotNull] string appDataPath, [NotNull] ILocalDirectory localDirectory,
                   [NotNull] ILocalMetaData localMetaData,
                   [NotNull] IDownloadDirectory downloadDirectory, [NotNull] IRemoteData remoteData,
                   [NotNull] IRemoteMetaData remoteMetaData,
                   int overrideLatestVersionId)
        {
            if (string.IsNullOrEmpty(appDataPath))
            {
                throw new ArgumentException("Value cannot be null or empty.", "appDataPath");
            }

            if (localDirectory == null)
            {
                throw new ArgumentNullException("localDirectory");
            }

            if (localMetaData == null)
            {
                throw new ArgumentNullException("localMetaData");
            }

            if (downloadDirectory == null)
            {
                throw new ArgumentNullException("downloadDirectory");
            }

            if (remoteData == null)
            {
                throw new ArgumentNullException("remoteData");
            }

            if (remoteMetaData == null)
            {
                throw new ArgumentNullException("remoteMetaData");
            }

            LocalDirectory           = localDirectory;
            LocalMetaData            = localMetaData;
            DownloadDirectory        = downloadDirectory;
            RemoteData               = remoteData;
            RemoteMetaData           = remoteMetaData;
            _overrideLatestVersionId = overrideLatestVersionId;
        }
        public App(ILocalDirectory localDirectory, ILocalMetaData localMetaData, ITemporaryDirectory temporaryDirectory,
                   IDownloadDirectory downloadDirectory, IRemoteData remoteData, IRemoteMetaData remoteMetaData,
                   int overrideLatestVersionId)
        {
            Checks.ArgumentNotNull(localDirectory, "localData");
            Checks.ArgumentNotNull(localMetaData, "localMetaData");
            Checks.ArgumentNotNull(temporaryDirectory, "temporaryData");
            Checks.ArgumentNotNull(downloadDirectory, "downloadData");
            Checks.ArgumentNotNull(remoteData, "remoteData");
            Checks.ArgumentNotNull(remoteMetaData, "remoteMetaData");

            LocalDirectory           = localDirectory;
            LocalMetaData            = localMetaData;
            TemporaryDirectory       = temporaryDirectory;
            DownloadDirectory        = downloadDirectory;
            RemoteData               = remoteData;
            RemoteMetaData           = remoteMetaData;
            _overrideLatestVersionId = overrideLatestVersionId;
        }
Exemple #9
0
        public InstallDiffCommand(string packagePath, string packageMetaPath, string packagePassword, int versionId,
                                  AppDiffSummary versionDiffSummary, ILocalDirectory localData, ILocalMetaData localMetaData,
                                  ITemporaryDirectory temporaryData)
        {
            Checks.ArgumentValidVersionId(versionId, "versionId");
            // TODO: Check whether version diff summary is correct
            Checks.ArgumentNotNull(localData, "localData");
            Checks.ArgumentNotNull(localMetaData, "localMetaData");
            Checks.ArgumentNotNull(temporaryData, "temporaryData");

            _packagePath        = packagePath;
            _packageMetaPath    = packageMetaPath;
            _packagePassword    = packagePassword;
            _versionId          = versionId;
            _versionDiffSummary = versionDiffSummary;
            _localData          = localData;
            _localMetaData      = localMetaData;
            _temporaryData      = temporaryData;
        }
        public InstallContentCommand(string packagePath, string packageMetaPath, string packagePassword, int versionId,
                                     AppContentSummary versionContentSummary, ILocalDirectory localData, ILocalMetaData localMetaData)
        {
            Checks.ArgumentValidVersionId(versionId, "versionId");
            // TODO: Validate the content summary.
            Checks.ArgumentNotNull(localData, "localData");
            Checks.ArgumentNotNull(localMetaData, "localMetaData");

            DebugLogger.LogConstructor();
            DebugLogger.LogVariable(packagePath, "packagePath");
            DebugLogger.LogVariable(versionId, "versionId");

            _packagePath           = packagePath;
            _packageMetaPath       = packageMetaPath;
            _packagePassword       = packagePassword;
            _versionId             = versionId;
            _versionContentSummary = versionContentSummary;
            _localData             = localData;
            _localMetaData         = localMetaData;
        }
Exemple #11
0
        private Task DownloadDirectory(IFtpClient client, ILocalDirectory storageFolder, string remoteDirectoryPath)
        {
            return(Task.Run(() =>
            {
                var files = client.GetItems(remoteDirectoryPath);

                if (files.Any())
                {
                    foreach (var file in files.Where(w => w.Type == FileSystemItemType.File))
                    {
                        DownloadFile(client, storageFolder, file.FullName, file, false);
                    }
                    foreach (var folder in files.Where(w => w.Type == FileSystemItemType.Directory))
                    {
                        var newFolder = storageFolder.CreateFolderAsync(folder.Name).Result;
                        DownloadDirectory(client, newFolder, folder.FullName).Wait();
                    }
                }
                return files;
            }));
        }
Exemple #12
0
        public InstallDiffCommand([NotNull] string packagePath, string packageMetaPath, string packagePassword,
                                  int versionId,
                                  [NotNull] ILocalDirectory localData, [NotNull] ILocalMetaData localMetaData,
                                  [NotNull] IRemoteMetaData remoteMetaData)
        {
            if (packagePath == null)
            {
                throw new ArgumentNullException("packagePath");
            }

            if (versionId <= 0)
            {
                throw new ArgumentOutOfRangeException("versionId");
            }

            if (localData == null)
            {
                throw new ArgumentNullException("localData");
            }

            if (localMetaData == null)
            {
                throw new ArgumentNullException("localMetaData");
            }

            if (remoteMetaData == null)
            {
                throw new ArgumentNullException("remoteMetaData");
            }

            _logger          = PatcherLogManager.DefaultLogger;
            _packagePath     = packagePath;
            _packageMetaPath = packageMetaPath;
            _packagePassword = packagePassword;
            _versionId       = versionId;
            _localData       = localData;
            _localMetaData   = localMetaData;
            _remoteMetaData  = remoteMetaData;
        }
        private Task UploadDirectory(IFtpClient client, ILocalDirectory storagefolder, string remoteDirectoryPath)
        {
            return(Task.Run(() =>
            {
                return storagefolder.GetFilesAsync().Result;
            })
                   .ContinueWith(fileTask =>
            {
                var files = fileTask.Result;

                if (files != null && files.Any())
                {
                    foreach (var file in files)
                    {
                        UploadFile(client, file, remoteDirectoryPath, false).Wait();
                    }
                }
            }).ContinueWith(folderTask =>
            {
                return storagefolder.GetFoldersAsync().Result;
            })
                   .ContinueWith(folderTask =>
            {
                var folders = folderTask.Result;

                if (folders == null || !folders.Any())
                {
                    return;
                }

                foreach (var folder in folders)
                {
                    var newDirectoryPath = remoteDirectoryPath + "/" + folder.Name;
                    client.CreateDirectory(newDirectoryPath);
                    UploadDirectory(client, folder, newDirectoryPath).Wait();
                }
            }));
        }
Exemple #14
0
        public static List <ILocalDirectoryItemViewModel> CreatDirectoryItemViewModels(ILocalDirectory localDirectory)
        {
            var directoryItems = new List <ILocalDirectoryItemViewModel>();

            foreach (var file in localDirectory.GetFilesAsync().Result)
            {
                directoryItems.Add(CreateFileViewModel(file));
            }

            foreach (var folder in localDirectory.GetFoldersAsync().Result)
            {
                directoryItems.Add(CreateFileViewModel(folder));
            }

            return(directoryItems);
        }