예제 #1
0
 public static void CopyFolder(NPath fromPath, NPath toPath)
 {
     Logger.Trace("CopyFolder fromPath: {0} toPath:{1}", fromPath.ToString(), toPath.ToString());
     toPath.DeleteIfExists();
     toPath.EnsureParentDirectoryExists();
     fromPath.Move(toPath);
 }
예제 #2
0
        public static void Copy(NPath fromPath, NPath toPath)
        {
            Logger.Trace("Copying from " + fromPath + " to " + toPath + ".");

            try
            {
                CopyFolder(fromPath, toPath);
            }
            catch (Exception ex1)
            {
                Logger.Warning(ex1, "Error copying.");

                try
                {
                    CopyFolderContents(fromPath, toPath);
                }
                catch (Exception ex2)
                {
                    Logger.Error(ex1, "Error copying contents.");
                    throw;
                }
            }
            finally
            {
                fromPath.DeleteIfExists();
            }
        }
예제 #3
0
        public UsageStore Load(string userId)
        {
            UsageStore result = null;
            string     json   = null;

            if (path.FileExists())
            {
                try
                {
                    json   = path.ReadAllText(Encoding.UTF8);
                    result = json?.FromJson <UsageStore>(lowerCase: true);
                }
                catch (Exception ex)
                {
                    LogHelper.Instance.Warning(ex, "Error Loading Usage: {0}; Deleting File", path);
                    try
                    {
                        path.DeleteIfExists();
                    }
                    catch { }
                }
            }

            if (result == null)
            {
                result = new UsageStore();
            }

            if (String.IsNullOrEmpty(result.Model.Guid))
            {
                result.Model.Guid = userId;
            }

            return(result);
        }
예제 #4
0
        protected override void Run(bool success)
        {
            base.Run(success);

            Logger.Trace("Unzip File: {0} to Path: {1}", archiveFilePath, extractedPath);

            try
            {
                zipHelper.Extract(archiveFilePath, extractedPath, Token, zipFileProgress, estimatedDurationProgress);
            }
            catch (Exception ex)
            {
                var message = "Error Unzipping file";

                Logger.Error(ex, message);
                throw new UnzipTaskException(message);
            }

            if (expectedMD5 != null)
            {
                var calculatedMD5 = fileSystem.CalculateFolderMD5(extractedPath);
                if (!calculatedMD5.Equals(expectedMD5, StringComparison.InvariantCultureIgnoreCase))
                {
                    extractedPath.DeleteIfExists();

                    var message = $"Extracted MD5: {calculatedMD5} Does not match expected: {expectedMD5}";
                    Logger.Error(message);

                    throw new UnzipTaskException(message);
                }
            }

            Logger.Trace("Completed Unzip");
        }
예제 #5
0
        private UsageStore LoadUsage()
        {
            UsageStore result = null;
            string     json   = null;

            if (storePath.FileExists())
            {
                Logger.Trace("LoadUsage: \"{0}\"", storePath);

                try
                {
                    json = storePath.ReadAllText(Encoding.UTF8);
                    if (json != null)
                    {
                        result = SimpleJson.DeserializeObject <UsageStore>(json);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Warning(ex, "Error Loading Usage: {0}; Deleting File", storePath);

                    try
                    {
                        storePath.DeleteIfExists();
                    }
                    catch {}
                }
            }

            if (result == null)
            {
                result = new UsageStore();
            }

            if (String.IsNullOrEmpty(result.Model.Guid))
            {
                result.Model.Guid = guid;
            }

            return(result);
        }
예제 #6
0
        public async Task <bool> SetupIfNeeded(IProgress <float> zipFileProgress = null, IProgress <long> estimatedDurationProgress = null)
        {
            logger.Trace("SetupIfNeeded");

            cancellationToken.ThrowIfCancellationRequested();

            NPath tempPath = null;

            try
            {
                tempPath = NPath.CreateTempDirectory(TempPathPrefix);

                cancellationToken.ThrowIfCancellationRequested();

                var ret = await SetupGitIfNeeded(tempPath, zipFileProgress, estimatedDurationProgress);

                cancellationToken.ThrowIfCancellationRequested();

                ret &= await SetupGitLfsIfNeeded(tempPath, zipFileProgress, estimatedDurationProgress);

                tempPath.Delete();
                return(ret);
            }
            catch (Exception ex)
            {
                logger.Trace(ex);
                return(false);
            }
            finally
            {
                try
                {
                    if (tempPath != null)
                    {
                        tempPath.DeleteIfExists();
                    }
                }
                catch {}
            }
        }
예제 #7
0
        private NPath MoveGitAndLfs(NPath gitExtractPath, NPath gitLfsExtractPath, NPath tempZipExtractPath)
        {
            var targetGitLfsExecPath = installDetails.GetGitLfsExecutablePath(gitExtractPath);
            var extractGitLfsExePath = gitLfsExtractPath.Combine(installDetails.GitLfsExecutable);

            Logger.Trace($"Moving Git LFS Exe:'{extractGitLfsExePath}' to target in tempDirectory:'{targetGitLfsExecPath}'");

            extractGitLfsExePath.Move(targetGitLfsExecPath);

            Logger.Trace($"Moving tempDirectory:'{gitExtractPath}' to extractTarget:'{installDetails.GitInstallationPath}'");

            installDetails.GitInstallationPath.EnsureParentDirectoryExists();
            gitExtractPath.Move(installDetails.GitInstallationPath);

            Logger.Trace($"Deleting targetGitLfsExecPath:'{targetGitLfsExecPath}'");

            targetGitLfsExecPath.DeleteIfExists();

            Logger.Trace($"Deleting tempZipPath:'{tempZipExtractPath}'");
            tempZipExtractPath.DeleteIfExists();
            return(installDetails.GitExecutablePath);
        }
예제 #8
0
 protected override void RaiseOnEnd()
 {
     tempFile.DeleteIfExists();
     base.RaiseOnEnd();
 }