Exemplo n.º 1
0
    private void WriteHeader()
    {
        string reelStr    = "";
        string isFixedStr = "";

        if (_userResult.Machine.MachineConfig.BasicConfig.ReelCount == CoreDefine.Reel3)
        {
            reelStr    = "Reel1,Reel2,Reel3,";
            isFixedStr = "IsFixed1,IsFixed2,IsFixed3,";
        }
        else if (_userResult.Machine.MachineConfig.BasicConfig.ReelCount == CoreDefine.Reel4)
        {
            reelStr    = "Reel1,Reel2,Reel3,Reel4,";
            isFixedStr = "IsFixed1,IsFixed2,IsFixed3,IsFixed4,";
        }
        else if (_userResult.Machine.MachineConfig.BasicConfig.ReelCount == CoreDefine.Reel5)
        {
            reelStr    = "Reel1,Reel2,Reel3,Reel4,Reel5,";
            isFixedStr = "IsFixed1,IsFixed2,IsFixed3,IsFixed4,IsFixed5,";
        }
        else
        {
            Debug.Assert(false);
        }

        string s = "ID," + reelStr + "ResultType,ResultId,Lucky,CurrentCredit," +
                   "Bet,Amount,CreditChange,RemainCredit,LuckyChange,RemainLucky,IsRespin,"
                   + isFixedStr + "IsTriggerIndieGame,IndieGameWinAmount,IndieGameCustomData";

        FileStreamUtility.WriteFile(_streamWriter, s);
    }
    public void WriteResult(string dir)
    {
        string fileName = "";

        if (_mode == MachineTestAnalysisMode.User)
        {
            int userId = _userResult.UserIndex + 1;
            fileName = dir + "analysis_" + _userResult.Machine.Name + "_" + userId.ToString() + ".txt";
        }
        else if (_mode == MachineTestAnalysisMode.Machine)
        {
            fileName = dir + "analysis_" + _machineResult.MachineName + ".txt";
        }
        else
        {
            Debug.Assert(false);
        }

        _streamWriter = FileStreamUtility.CreateFileStream(fileName);

        WriteConfig();
        WriteContent();

        FileStreamUtility.CloseFile(_streamWriter);
    }
Exemplo n.º 3
0
    public void WriteResult(string dir, MachineTestPrintFileNameMode mode)
    {
        string postfix = "";

        if (mode == MachineTestPrintFileNameMode.UserId)
        {
            int userId = _userResult.UserIndex + 1;
            postfix = userId.ToString();
        }
        else if (mode == MachineTestPrintFileNameMode.Seed)
        {
            postfix = _userResult.StartSeed.ToString();
        }
        else
        {
            Debug.Assert(false);
        }

        string fileName = dir + _userResult.Machine.Name + "_" + postfix + ".csv";

        _streamWriter = FileStreamUtility.CreateFileStream(fileName);

        WriteHeader();
        WriteContent();

        FileStreamUtility.CloseFile(_streamWriter);
    }
Exemplo n.º 4
0
        /// <nodoc />
        internal static async Task <DedupNode> GetDedupNodeFromFileAsync(HashType hashType, string path)
        {
            var contentHasher = (DedupContentHasher <DedupNodeOrChunkHashAlgorithm>)ContentHashers.Get(hashType);

            using (var stream = FileStreamUtility.OpenFileStreamForAsync(path, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete))
            {
                return(await contentHasher.HashContentAndGetDedupNodeAsync(stream));
            }
        }
Exemplo n.º 5
0
 private void WriteContent()
 {
     for (int i = 0; i < _userResult.RoundResults.Count; i++)
     {
         int id = i + 1;
         MachineTestRoundResult roundResult = _userResult.RoundResults[i];
         string s = ConstructResult(id, roundResult._input, roundResult._output);
         FileStreamUtility.WriteFile(_streamWriter, s);
     }
 }
Exemplo n.º 6
0
 public void CanReadAndWriteStream()
 {
     // Arrange
     using (var stream = FileStreamUtility.GetTemporaryFile())
         using (var reader = new StreamReader(stream))
             using (var writer = new StreamWriter(stream))
             {
                 // Act & Assert
                 writer.Write(FileContent);
                 writer.Flush();
                 stream.Position = 0;
                 var actualContent = reader.ReadToEnd();
                 Assert.Equal(FileContent, actualContent);
             }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Extracts the debug entry for a javascript sourcemap file.
        /// It will try to extract the client key from the sourcemap, so that
        /// the tool that writes the sourcemap has control over they key.
        /// It will fall back to the sha256 of the sourcemap as the client key
        /// when it can't be found.
        /// </summary>
        internal static async Task <DebugEntryData[]> GetJsMapDebugEntryAsync(FileInfo file, bool calculateBlobId = false)
        {
            var    fileName  = file.FullName;
            string clientKey = TryGetSymbolClientKeyFromJsMap(fileName);

            if (clientKey == null)
            {
                // If the .js.map file file does not contain the proper info, use content hash as a fallback
                try
                {
                    using (var fileStream = FileStreamUtility.OpenFileStreamForAsync(fileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete))
                    {
                        var hash = await HashInfoLookup.GetContentHasher(HashType.SHA256).GetContentHashAsync(fileStream);

                        var clientId = hash.ToHex().ToLowerInvariant();
                        clientKey = CreateClientKey(clientId, Path.GetFileName(fileName));
                    }
                }
                catch (IOException)
                {
                    return(new DebugEntryData[0]);
                }
                catch (UnauthorizedAccessException)
                {
                    return(new DebugEntryData[0]);
                }
            }

            BlobIdentifier blobId = null;

            if (calculateBlobId)
            {
                var blobDescriptor = await FileBlobDescriptor.CalculateAsync(file.DirectoryName, chunkDedup : false, file.Name, FileBlobType.File, CancellationToken.None);

                blobId = blobDescriptor.BlobIdentifier;
            }

            return(new[] {
                new DebugEntryData()
                {
                    BlobIdentifier = blobId,
                    ClientKey = clientKey,
                    InformationLevel = DebugInformationLevel.Private
                }
            });
        }
Exemplo n.º 8
0
            public void ReturnsFileStreamThatDeletesOnDispose()
            {
                // Arrange
                string fileName;

                using (var stream = FileStreamUtility.GetTemporaryFile())
                    using (var writer = new StreamWriter(stream))
                    {
                        fileName = stream.Name;
                        writer.WriteLine(FileContent);
                        writer.Flush();

                        // Act & Assert
                        Assert.True(File.Exists(fileName), "The file should still exist.");
                    }

                Assert.False(File.Exists(fileName), "The file should no longer exist.");
            }
Exemplo n.º 9
0
    void OutputMachineSeeds(MachineSeedGenConfig genConfig, List <uint> seedList)
    {
        if (genConfig._isOutputSeeds)
        {
            string[] seedArray = new string[seedList.Count];
            for (int i = 0; i < seedList.Count; i++)
            {
                seedArray[i] = seedList[i].ToString();
            }

            string content = string.Join(MachineSeedConfig.SeedFileDelimitor.ToString(), seedArray);

            string fileName = MachineSeedConfig.GetSeedFileName(genConfig._machineName, true);
            string filePath = Path.Combine(_outputSeedsDir, fileName);

            FileStreamUtility.DeleteFile(filePath);
            StreamWriter writer = FileStreamUtility.CreateFileStream(filePath);
            FileStreamUtility.WriteFile(writer, content);
            FileStreamUtility.CloseFile(writer);
        }
    }
Exemplo n.º 10
0
    void PrintData(List <MultiLineExportData> dataList)
    {
        if (File.Exists(_exportDataFilePath))
        {
            File.Delete(_exportDataFilePath);
        }

        StreamWriter writer = FileStreamUtility.CreateFileStream(_exportDataFilePath);

        FileStreamUtility.WriteFile(writer, "PayoutReward,NearHitReward,Reel1,Reel2,Reel3");

        for (int i = 0; i < dataList.Count; i++)
        {
            MultiLineExportData data = dataList[i];
            string s = string.Format("{0},{1},{2},{3},{4}", data._payoutReward, data._nearHitReward,
                                     data._stopIndexes[0], data._stopIndexes[1], data._stopIndexes[2]);

            FileStreamUtility.WriteFile(writer, s);
        }

        FileStreamUtility.CloseFile(writer);
    }
 private void Write(string s)
 {
     FileStreamUtility.WriteFile(_streamWriter, s);
 }
Exemplo n.º 12
0
        private async Task <SignatureValidatorResult> StripRepositorySignaturesAsync(Context context)
        {
            Stream packageStreamToDispose = null;

            try
            {
                packageStreamToDispose = FileStreamUtility.GetTemporaryFile();

                var stopwatch = Stopwatch.StartNew();

                var changed = await SignedPackageArchiveUtility.RemoveRepositorySignaturesAsync(
                    context.PackageStream,
                    packageStreamToDispose,
                    context.CancellationToken);

                _telemetryService.TrackDurationToStripRepositorySignatures(
                    stopwatch.Elapsed,
                    context.Message.PackageId,
                    context.Message.PackageVersion,
                    context.Message.ValidationId,
                    changed);

                if (changed)
                {
                    _logger.LogInformation(
                        "Repository signatures were removed from package {PackageId} {PackageVersion} for validation {ValidationId}.",
                        context.Message.PackageId,
                        context.Message.PackageVersion,
                        context.Message.ValidationId);

                    // The input stream and the input signed package reader are no longer useful since they contain
                    // the removed repository signatures. We need to initialize the new signed package archive
                    // reader and signature.
                    context.PackageReader.Dispose();
                    context.PackageStream.Dispose();

                    context.PackageStream  = packageStreamToDispose;
                    context.Changed        = true;
                    packageStreamToDispose = null;
                    context.PackageReader  = new SignedPackageArchive(context.PackageStream, packageWriteStream: Stream.Null);

                    var initialSignature = context.Signature;

                    if (await context.PackageReader.IsSignedAsync(context.CancellationToken))
                    {
                        _logger.LogInformation(
                            "The package {PackageId} {PackageVersion} for validation {ValidationId} is still signed.",
                            context.Message.PackageId,
                            context.Message.PackageVersion,
                            context.Message.ValidationId);

                        context.Signature = await context.PackageReader.GetPrimarySignatureAsync(context.CancellationToken);

                        _telemetryService.TrackStrippedRepositorySignatures(
                            context.Message.PackageId,
                            context.Message.PackageVersion,
                            context.Message.ValidationId,
                            initialSignature,
                            context.Signature);
                    }
                    else
                    {
                        _logger.LogInformation(
                            "The package {PackageId} {PackageVersion} for validation {ValidationId} is no longer signed.",
                            context.Message.PackageId,
                            context.Message.PackageVersion,
                            context.Message.ValidationId);

                        // The package is now unsigned. This would happen if the primary signature was a repository
                        // signature that was removed.
                        context.Signature = null;

                        _telemetryService.TrackStrippedRepositorySignatures(
                            context.Message.PackageId,
                            context.Message.PackageVersion,
                            context.Message.ValidationId,
                            initialSignature,
                            outputSignature: null);

                        return(await HandleUnsignedPackageAsync(context));
                    }
                }
                else
                {
                    _logger.LogInformation(
                        "No repository signatures were removed from package {PackageId} {PackageVersion} for validation {ValidationId}.",
                        context.Message.PackageId,
                        context.Message.PackageVersion,
                        context.Message.ValidationId);
                }
            }
            finally
            {
                packageStreamToDispose?.Dispose();
            }

            return(null);
        }