Exemplo n.º 1
0
    public static async Task <VerifyResult> VerifyStreams(Stream stream, FilePair file)
    {
        stream.MoveToStart();

        try
        {
            await FileHelpers.WriteStream(file.Received, stream);

            var verifyResult = FileComparer.DoCompare(file.Received, file.Verified);

            if (verifyResult == VerifyResult.Equal)
            {
                File.Delete(file.Received);
                return(verifyResult);
            }

            return(verifyResult);
        }
        finally
        {
#if NETSTANDARD2_1
            await stream.DisposeAsync();
#else
            stream.Dispose();
#endif
        }
    }
Exemplo n.º 2
0
 public static Task <CompareResult> DefaultCompare(VerifySettings settings, FilePair filePair)
 {
     return(DoCompare(
                settings,
                (stream1, stream2, _) => StreamsAreEqual(stream1, stream2),
                filePair));
 }
        public override async Task <SyncActionType> GetActionOfBothFiles(FilePair pair)
        {
            SyncedItem last;

            Task <object> serverCompareValueTask = fileComparer.GetServerCompareValue(pair.ServerFullPath, api);
            Task <object> localCompareValueTask  = fileComparer.GetLocalCompareValue(pair.LocalFile);

            pair.ServerCompareValue = await serverCompareValueTask;
            pair.LocalCompareValue  = await localCompareValueTask;

            if (fileComparer.Equals(pair.ServerCompareValue, pair.LocalCompareValue))
            {
                return(SyncActionType.Equal);
            }
            else if (lastResult.TryGetValue(pair.RelativePath, out last))
            {
                if (fileComparer.Equals(last.ServerCompareValue, pair.ServerCompareValue))
                {
                    return(SyncActionType.CopyToServer);
                }
                else if (fileComparer.Equals(last.LocalCompareValue, pair.LocalCompareValue))
                {
                    return(SyncActionType.CopyToLocal);
                }
            }

            return(SolveConflict(pair));
        }
Exemplo n.º 4
0
        async Task <Result> InnerAddItemAsync(
            CancellationToken token,
            Func <CancellationToken, Task <Stream> > httpContentFunc,
            MetaData meta,
            Timestamp timestamp)
        {
            var tempFile = FilePair.GetTemp();

            try
            {
#if NET5_0
                await using var httpStream = await httpContentFunc(token);

                await using (var contentFileStream = FileEx.OpenWrite(tempFile.Content))
                    await using (var metaFileStream = FileEx.OpenWrite(tempFile.Meta))
                    {
#else
                using var httpStream = await httpContentFunc(token);

                using (var contentFileStream = FileEx.OpenWrite(tempFile.Content))
                    using (var metaFileStream = FileEx.OpenWrite(tempFile.Meta))
                    {
#endif
                        await JsonSerializer.SerializeAsync(metaFileStream, meta, cancellationToken : token);

                        await httpStream.CopyToAsync(contentFileStream, token);
                    }

                return(BuildResult(timestamp, tempFile));
            }
            finally
            {
                tempFile.Delete();
            }
        }
Exemplo n.º 5
0
        Result AddItem(HttpResponseMessage response, Uri uri, CancellationToken token)
        {
            var timestamp = Timestamp.FromResponse(uri, response);

#if NET5_0
            var meta = MetaData.FromEnumerables(response.Headers, response.Content.Headers, response.TrailingHeaders);
#else
            var meta = MetaData.FromEnumerables(response.Headers, response.Content.Headers);
#endif
            var tempFile = FilePair.GetTemp();
            try
            {
                using var httpStream = response.Content.ReadAsStream(token);
                using (var contentFileStream = FileEx.OpenWrite(tempFile.Content))
                    using (var metaFileStream = FileEx.OpenWrite(tempFile.Meta))
                        using (var writer = new Utf8JsonWriter(metaFileStream))
                        {
                            JsonSerializer.Serialize(writer, meta);
                            httpStream.CopyTo(contentFileStream);
                        }

                return(BuildResult(timestamp, tempFile));
            }
            finally
            {
                tempFile.Delete();
            }
        }
        public override async Task <SyncActionType> GetActionOfSingleFiles(FilePair pair)
        {
            SyncedItem last;

            if (pair.ServerFileExists)
            {
                pair.ServerCompareValue = await fileComparer.GetServerCompareValue(pair.ServerFullPath, api);

                if (lastResult.TryGetValue(pair.RelativePath, out last) &&
                    fileComparer.Equals(last.ServerCompareValue, pair.ServerCompareValue))
                {
                    return(SyncActionType.DeleteFromServer);
                }
                else
                {
                    return(SyncActionType.CopyToLocal);
                }
            }
            else if (pair.LocalFile != null)
            {
                pair.LocalCompareValue = await fileComparer.GetLocalCompareValue(pair.LocalFile);

                if (lastResult.TryGetValue(pair.RelativePath, out last) &&
                    fileComparer.Equals(last.LocalCompareValue, pair.LocalCompareValue))
                {
                    return(SyncActionType.DeleteFromLocal);
                }
                else
                {
                    return(SyncActionType.CopyToServer);
                }
            }

            throw new InvalidOperationException("Server or local file must exist");
        }
Exemplo n.º 7
0
    public static async Task <(Equality equality, string?message)> Text(FilePair file, string scrubbedInput, VerifySettings settings)
    {
        scrubbedInput = Scrub(scrubbedInput, settings.ignoreTrailingWhitespace);
        FileHelpers.DeleteIfEmpty(file.Verified);
        if (!File.Exists(file.Verified))
        {
            await FileHelpers.WriteText(file.Received, scrubbedInput);

            return(Equality.MissingVerified, null);
        }

        var verifiedText = await FileHelpers.ReadText(file.Verified);

        verifiedText = Scrub(verifiedText, settings.ignoreTrailingWhitespace);

        var result = await CompareStrings(scrubbedInput, verifiedText, settings);

        if (result.IsEqual)
        {
            return(Equality.Equal, null);
        }

        await FileHelpers.WriteText(file.Received, scrubbedInput);

        return(Equality.NotEqual, result.Message);
    }
Exemplo n.º 8
0
    static bool FilesAreSameSize(FilePair file)
    {
        var first  = new FileInfo(file.Received);
        var second = new FileInfo(file.Verified);

        return(first.Length == second.Length);
    }
Exemplo n.º 9
0
 public Result(FilePair file, bool revalidated, bool stored)
 {
     File        = file;
     Revalidated = revalidated;
     Stored      = stored;
     FromDisk    = true;
     Response    = null;
 }
Exemplo n.º 10
0
        private static void WriteDuplicate(FilePair filePair)
        {
            Console.WriteLine(filePair.FullPathLeft);
            Console.WriteLine(filePair.FullPathRight);

            Console.WriteLine($"{filePair.Size} ({filePair.Size.ToString(DataSizeUnit.Byte)})");
            Console.WriteLine();
        }
Exemplo n.º 11
0
 /// <inheritdoc/>
 public virtual void Purge()
 {
     foreach (var file in Directory.EnumerateFiles(directory))
     {
         var pair = FilePair.FromContentFile(file);
         pair.PurgeItem();
     }
 }
Exemplo n.º 12
0
        public override async Task <SyncActionType> GetActionOfBothFiles(FilePair pair)
        {
            Task <object> serverCompareValueTask = fileComparer.GetServerCompareValue(pair.ServerFullPath, api);
            Task <object> localCompareValueTask  = fileComparer.GetLocalCompareValue(pair.LocalFile);

            pair.ServerCompareValue = await serverCompareValueTask;
            pair.LocalCompareValue  = await localCompareValueTask;

            return(fileComparer.Equals(pair.ServerCompareValue, pair.LocalCompareValue) ?
                   SyncActionType.Equal : SyncActionType.CopyToServer);
        }
Exemplo n.º 13
0
    static async Task <CompareResult> GetResult(VerifySettings settings, FilePair file, Stream stream)
    {
        if (Extensions.IsText(file.Extension))
        {
            var readAsString = await stream.ReadAsString();

            var scrubbedInput = ScrubInput(readAsString, settings);
            return(await Comparer.Text(file, scrubbedInput));
        }

        return(await Comparer.Streams(settings, stream, file));
    }
Exemplo n.º 14
0
 static void Copy(FilePair fp)
 {
     try
     {
         Console.Write("copy {0} - ", fp.Fi1.FullName.Substring(BasePath.Length));
         File.Copy(fp.Fi1.FullName, fp.Fi2.FullName, _f);
         Console.WriteLine("OK");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemplo n.º 15
0
    async Task ReVerify(Func <object> target, VerifySettings settings, FilePair pair)
    {
        var command = BuildCommand(pair);

        ProcessCleanup.Refresh();
        await Verify(target(), settings);

        ProcessCleanup.Refresh();
        AssertProcessNotRunning(command);

        AssertNotExists(pair.Received);
        AssertExists(pair.Verified);
    }
Exemplo n.º 16
0
    async Task RunSplitTest(
        TypeToSplit initialTarget,
        TypeToSplit secondTarget,
        bool hasMatchingDiffTool,
        bool hasExistingReceived,
        bool autoVerify)
    {
        var settings = new VerifySettings();

        if (autoVerify)
        {
            settings.AutoVerify();
        }

        var prefix       = Path.Combine(SourceDirectory, $"{Context.UniqueTestName}.");
        var danglingFile = $"{prefix}03.verified.txt";
        var info         = new FilePair("txt", $"{prefix}info");
        var file1        = new FilePair("txt", $"{prefix}00");
        var file2        = new FilePair("txt", $"{prefix}01");

        DeleteAll(danglingFile, info.Received, info.Verified, file1.Verified, file1.Received, file2.Verified, file2.Received);
        File.WriteAllText(danglingFile, "");

        if (hasExistingReceived)
        {
            File.WriteAllText(info.Received, "");
            File.WriteAllText(file1.Received, "");
            File.WriteAllText(file2.Received, "");
        }


        await InitialVerifySplit(initialTarget, hasMatchingDiffTool, settings, info, file1, file2);

        if (!autoVerify)
        {
            RunClipboardCommand();
        }

        AssertNotExists(danglingFile);

        await ReVerifySplit(initialTarget, settings, info, file1, file2);

        await InitialVerifySplit(secondTarget, hasMatchingDiffTool, settings, info, file1, file2);

        if (!autoVerify)
        {
            RunClipboardCommand();
        }

        await ReVerifySplit(secondTarget, settings, info, file1, file2);
    }
Exemplo n.º 17
0
    public async Task Split(
        bool hasExistingReceived,
        bool autoVerify)
    {
        var initialTarget = new TypeToSplit("info1", "value1", "value2");
        var secondTarget  = new TypeToSplit("info2", "value1.1", "value2.1");
        var settings      = new VerifySettings();

        if (autoVerify)
        {
            settings.AutoVerify();
        }
        var uniqueTestName = TestNameBuilder.GetUniqueTestName("Tests_Split", Info.OfMethod <Tests>("Split"), new object[] { hasExistingReceived, autoVerify });

        settings.UseParameters(hasExistingReceived, autoVerify);
        var prefix       = Path.Combine(SourceDirectory, $"{uniqueTestName}.");
        var danglingFile = $"{prefix}03.verified.txt";
        var info         = new FilePair("txt", $"{prefix}info");
        var file1        = new FilePair("txt", $"{prefix}00");
        var file2        = new FilePair("txt", $"{prefix}01");

        DeleteAll(danglingFile, info.Received, info.Verified, file1.Verified, file1.Received, file2.Verified, file2.Received);
        File.WriteAllText(danglingFile, "");

        if (hasExistingReceived)
        {
            File.WriteAllText(info.Received, "");
            File.WriteAllText(file1.Received, "");
            File.WriteAllText(file2.Received, "");
        }

        await InitialVerifySplit(initialTarget, true, settings, info, file1, file2);

        if (!autoVerify)
        {
            RunClipboardCommand();
        }

        AssertNotExists(danglingFile);

        await ReVerifySplit(initialTarget, settings, info, file1, file2);

        await InitialVerifySplit(secondTarget, true, settings, info, file1, file2);

        if (!autoVerify)
        {
            RunClipboardCommand();
        }

        await ReVerifySplit(secondTarget, settings, info, file1, file2);
    }
Exemplo n.º 18
0
    static Task <CompareResult> FilesEqual(VerifySettings settings, FilePair file)
    {
        if (settings.TryFindComparer(out var compare))
        {
            return(DoCompare(settings, file.Received, file.Verified, compare !));
        }

        if (!FilesAreSameSize(file))
        {
            return(Task.FromResult(CompareResult.NotEqual()));
        }

        return(DefaultCompare(settings, file.Received, file.Verified));
    }
Exemplo n.º 19
0
    static Task <CompareResult> FilesEqual(VerifySettings settings, FilePair filePair)
    {
        if (settings.TryFindStreamComparer(filePair.Extension, out var compare))
        {
            return(DoCompare(settings, compare !, filePair));
        }

        if (FilesAreSameSize(filePair))
        {
            return(DefaultCompare(settings, filePair));
        }

        return(Task.FromResult(CompareResult.NotEqual()));
    }
Exemplo n.º 20
0
    async Task RunTest(
        string extension,
        Func <object> initialTarget,
        Func <object> secondTarget,
        bool hasMatchingDiffTool,
        bool hasExistingReceived,
        bool autoVerify)
    {
        var settings = new VerifySettings();

        settings.UseExtension(extension);
        if (autoVerify)
        {
            settings.AutoVerify();
        }

        var prefix       = Path.Combine(SourceDirectory, $"{Context.UniqueTestName}");
        var danglingFile = Path.Combine(SourceDirectory, $"{prefix}.01.verified.{extension}");
        var file         = new FilePair(extension, prefix);

        DeleteAll(danglingFile, file.Verified, file.Received);
        File.WriteAllText(danglingFile, "");

        if (hasExistingReceived)
        {
            File.WriteAllText(file.Received, "");
        }

        await InitialVerify(initialTarget, hasMatchingDiffTool, settings, file);

        if (!autoVerify)
        {
            RunClipboardCommand();
        }

        AssertNotExists(danglingFile);

        await ReVerify(initialTarget, settings, file);

        await InitialVerify(secondTarget, hasMatchingDiffTool, settings, file);

        if (!autoVerify)
        {
            RunClipboardCommand();
        }

        await ReVerify(secondTarget, settings, file);
    }
Exemplo n.º 21
0
    public static async Task <EqualityResult> Streams(
        VerifySettings settings,
        Stream stream,
        FilePair file)
    {
        await FileHelpers.WriteStream(file.Received, stream);

        var result = await FileComparer.DoCompare(settings, file);

        if (result.Equality == Equality.Equal)
        {
            File.Delete(file.Received);
        }

        return(result);
    }
Exemplo n.º 22
0
        protected SyncActionType SolveConflict(FilePair pair)
        {
            switch (conflictHandlingType)
            {
            case SyncConflictHandlingType.PreferServer:
                return(SyncActionType.CopyToServerByConflict);

            case SyncConflictHandlingType.PreferLocal:
                return(SyncActionType.CopyToLocalByConflict);

            case SyncConflictHandlingType.Igonre:
                return(SyncActionType.Ignore);
            }

            throw new ArgumentException("Value not Implemented:" + conflictHandlingType, nameof(conflictHandlingType));
        }
Exemplo n.º 23
0
        FilePair?FindContentFileForUri(Uri uri)
        {
            var hash          = Hash.Compute(uri.AbsoluteUri);
            var directoryInfo = new DirectoryInfo(directory);
            var fileInfo      = directoryInfo
                                .GetFiles($"{hash}_*.bin")
                                .OrderBy(x => x.LastWriteTime)
                                .FirstOrDefault();

            if (fileInfo == null)
            {
                return(null);
            }

            return(FilePair.FromContentFile(fileInfo));
        }
Exemplo n.º 24
0
        public virtual void SetUp()
        {
            _fileInfo1         = new FileInfo("some file path");
            _basePathToExclude = @"c:\BASEPATH\HERE";
            _fileItem1         = new FileItem(_fileInfo1, _basePathToExclude);

            _fileInfo2          = new FileInfo("some file path");
            _basePathToExclude2 = @"c:\BASEPATH\HERE";
            _fileItem2          = new FileItem(_fileInfo2, _basePathToExclude2);

            _filePair = new FilePair(_fileItem1, _fileItem2);

            _testFilePairs = new List <FilePair> {
                _filePair
            };
        }
Exemplo n.º 25
0
        public FilePair AddPath(string path)
        {
            var self = $"data/out/wn_prefix_{path}_wn.zip";

            ZipHelper.CreateFromDirectory(
                $"data/out/{path}",
                $"data/out/wn_prefix_{path}_wn.zip", CompressionLevel.Fastest, false, Encoding.UTF8,
                path => path != self);
            var ret = new FilePair()
            {
                filename = path + ".zip",
                file     = new FileBytes(File.ReadAllBytes($"data/out/wn_prefix_{path}_wn.zip"), true)
            };

            return(ret);
        }
Exemplo n.º 26
0
    public void HandleCompareResult(CompareResult compareResult, FilePair file)
    {
        switch (compareResult)
        {
        case CompareResult.MissingVerified:
            AddMissing(file);
            break;

        case CompareResult.NotEqual:
            AddNotEquals(file);
            break;

        case CompareResult.Equal:
            AddEquals(file);
            break;
        }
    }
Exemplo n.º 27
0
    public static Task <bool> FilesEqual(VerifySettings settings, FilePair file)
    {
        if (settings.comparer != null)
        {
            return(DoCompare(settings, file.Received, file.Verified, settings.comparer));
        }
        if (SharedVerifySettings.TryGetComparer(file.Extension, out var comparer))
        {
            return(DoCompare(settings, file.Received, file.Verified, comparer));
        }

        if (!FilesAreSameSize(file))
        {
            return(Task.FromResult(false));
        }

        return(DefaultCompare(settings, file.Received, file.Verified));
    }
Exemplo n.º 28
0
    public static async Task <CompareResult> DoCompare(VerifySettings settings, FilePair file)
    {
        if (!File.Exists(file.Verified))
        {
            return(CompareResult.MissingVerified);
        }

        if (AllFiles.IsEmptyFile(file.Verified))
        {
            return(CompareResult.NotEqual);
        }

        if (!await FilesEqual(settings, file))
        {
            return(CompareResult.NotEqual);
        }

        return(CompareResult.Equal);
    }
Exemplo n.º 29
0
        public static FilePair GetFilePair(string UrlName)
        {
            FilePair filePair;
            string   fileName = String.Empty;

            if (Constants.FillNameDatabase.Pairs.All(x => x.UrlName != UrlName))
            {
                string url = $"https://api.warframe.market/v1/items/{UrlName}";
                string iteminfo;
                using (WebClient c = new WebClient())
                {
                    iteminfo = c.DownloadString(url);
                }
                var thisItem = JsonConvert.DeserializeObject <Payloads.Items.ItemPayload>(iteminfo)
                               .Payload.Item.ItemsInSet.FirstOrDefault(x => x.UrlName == UrlName);

                if (!String.IsNullOrEmpty(thisItem.SubIcon))
                {
                    fileName = thisItem.SubIcon;
                }
                else if (!String.IsNullOrEmpty(thisItem.Icon))
                {
                    fileName = thisItem.Icon;
                }

                var hasRanks = thisItem.ModMaxRank.HasValue;
                filePair = new FilePair
                {
                    FileName     = fileName,
                    UrlName      = UrlName,
                    ItemHasRanks = hasRanks
                };
                Constants.FillNameDatabase.Pairs.Add(filePair);
                SaveDB();
            }
            else
            {
                filePair = Constants.FillNameDatabase.Pairs.FirstOrDefault(x => x.UrlName == UrlName);
            }
            GetImageIfNotCached(filePair.FileName);
            return(filePair);
        }
Exemplo n.º 30
0
    static async Task <EqualityResult> GetResult(VerifySettings settings, FilePair file, Stream stream)
    {
#if NETSTANDARD2_1
        await using (stream)
#else
        using (stream)
#endif
        {
            stream.MoveToStart();
            if (!Extensions.IsText(file.Extension))
            {
                return(await Comparer.Streams(settings, stream, file));
            }

            var builder = await stream.ReadAsString();

            ApplyScrubbers.Apply(builder, settings.instanceScrubbers);
            return(await Comparer.Text(file, builder, settings));
        }
    }
		static bool NeedsBuilding (FilePair fp)
		{
			return fp.NeedsBuilding ();
		}
		protected override BuildResult Compile (IProgressMonitor monitor, SolutionEntityItem item, BuildData buildData)
		{
			IPhoneProject proj = item as IPhoneProject;
			if (proj == null || proj.CompileTarget != CompileTarget.Exe)
				return base.Compile (monitor, item, buildData);
			
			var cfg = (IPhoneProjectConfiguration) buildData.Configuration;
			
			//make sure the codebehind files are updated before building
			monitor.BeginTask (GettextCatalog.GetString ("Updating CodeBehind files"), 0);	
			var cbWriter = MonoDevelop.DesignerSupport.CodeBehindWriter.CreateForProject (monitor, proj);
			BuildResult result = null;
			if (cbWriter.SupportsPartialTypes) {
				bool forceRegen = !Directory.Exists (cfg.AppDirectory);
				result = CodeBehind.UpdateXibCodebehind (cbWriter, proj, buildData.Items.OfType<ProjectFile> (), forceRegen);
				cbWriter.WriteOpenFiles ();
				if (cbWriter.WrittenCount > 0)
					monitor.Log.WriteLine (GettextCatalog.GetString ("Updated {0} CodeBehind files", cbWriter.WrittenCount));
			} else {
				monitor.ReportWarning ("Cannot generate designer code, because CodeDom " +
					"provider does not support partial classes.");
			}
			monitor.EndTask ();
			
			if (base.GetNeedsBuilding (item, buildData.ConfigurationSelector)) {
				result = base.Compile (monitor, item, buildData).Append (result);
				if (result.ErrorCount > 0)
					return result;
			}
			
			string appDir = ((IPhoneProjectConfiguration)buildData.Configuration).AppDirectory;
			
			var ibfiles = GetIBFilePairs (buildData.Items.OfType<ProjectFile> (), appDir).Where (NeedsBuilding).ToList ();
			
			if (ibfiles.Count > 0) {
				monitor.BeginTask (GettextCatalog.GetString ("Compiling interface definitions"), 0);	
				foreach (var file in ibfiles) {
					file.EnsureOutputDirectory ();
					var psi = new ProcessStartInfo ("ibtool",
						String.Format ("\"{0}\" --compile \"{1}\"", file.Input, file.Output)
					);
					monitor.Log.WriteLine (psi.FileName + " " + psi.Arguments);
					psi.WorkingDirectory = cfg.OutputDirectory;
					string errorOutput;
					int code;
					try {
					code = ExecuteCommand (monitor, psi, out errorOutput);
					} catch (System.ComponentModel.Win32Exception ex) {
						LoggingService.LogError ("Error running ibtool", ex);
						result.AddError (null, 0, 0, null, "ibtool not found. Please ensure the Apple SDK is installed.");
						return result;
					}
					if (code != 0) {
						//FIXME: parse the plist that ibtool returns
						result.AddError (null, 0, 0, null, "ibtool returned error code " + code);
					}
				}
				monitor.EndTask ();
			}
			
			var contentFiles = GetContentFilePairs (buildData.Items.OfType<ProjectFile> (), appDir)
				.Where (NeedsBuilding).ToList ();
			
			if (!proj.BundleIcon.IsNullOrEmpty) {
				FilePair icon = new FilePair (proj.BundleIcon, cfg.AppDirectory.Combine (proj.BundleIcon.FileName));
				if (!File.Exists (proj.BundleIcon)) {
					result.AddError (null, 0, 0, null, String.Format ("Application icon '{0}' is missing.", proj.BundleIcon));
					return result;
				} else if (icon.NeedsBuilding ()) {
					contentFiles.Add (icon);
				}
			}
			
			if (contentFiles.Count > 0) {
				monitor.BeginTask (GettextCatalog.GetString ("Copying content files"), contentFiles.Count);	
				foreach (var file in contentFiles) {
					file.EnsureOutputDirectory ();
					monitor.Log.WriteLine (GettextCatalog.GetString ("Copying '{0}' to '{1}'", file.Input, file.Output));
					File.Copy (file.Input, file.Output, true);
					monitor.Step (1);
				}
				monitor.EndTask ();
			}
			return result;
		}
Exemplo n.º 33
0
 public void Add(FilePair filter)
 {
     this.InnerList.Add(filter);
 }