Esempio n. 1
0
    public override void Deserialize(ByteArray stream)
    {
        base.Deserialize(stream);

        int retCodeCount = 0;

        while (stream.bytesAvailable > 0)
        {
            var tag = ReadUtils.ReadTag(stream);
            switch (tag.number)
            {
            case 0:
                throw new ProtobufException("Invalid field id: 0, wrong stream");

            case 1:
                this.retCode = ReadUtils.Read_TYPE_UINT32(stream);
                retCodeCount++;
                break;

            default:
                ReadUtils.Skip(stream, tag.wireType);
                break;
            }
        }

        if (retCodeCount == 0)
        {
            throw new ProtobufException("Required field retCode not readed");
        }
    }
Esempio n. 2
0
        public void WriteLayersDeep(int depth)
        {
            List <(string key, object value)> kvps;

            using (var writer = new ManagedBinaryWriter(_memoryStream, Symbols.EmptySymbolTablesArray))
            {
                writer.StepIn(IonType.Struct);
                for (var i = 0; i < depth - 1; i++)
                {
                    writer.SetFieldName($"layer{i}");
                    writer.StepIn(IonType.Struct);
                }

                kvps = WriteFlat(writer);

                for (var i = 0; i < depth; i++)
                {
                    writer.StepOut();
                }

                writer.Flush();
            }

            var reader = new UserBinaryReader(new MemoryStream(_memoryStream.GetWrittenBuffer()));

            for (var i = 0; i < depth - 1; i++)
            {
                Console.WriteLine(i);
                Assert.AreEqual(IonType.Struct, reader.MoveNext());
                Console.WriteLine(reader.CurrentFieldName);
                reader.StepIn();
            }

            ReadUtils.AssertFlatStruct(reader, kvps);
        }
Esempio n. 3
0
        public async Task ExecuteAsync(IPluginJobContext context)
        {
            if (!CliUtils.ParseArgs(_options, context.Args))
            {
                return;
            }

            if (_isHelp)
            {
                PrintUsage();
                return;
            }

            if (string.IsNullOrEmpty(_account))
            {
                _account = ReadUtils.GetString("Username:"******"Password:"******"you have successful logged in");
            }
            else
            {
                await WriteUtils.PrintErrorAsync(failureMessage);
            }
        }
Esempio n. 4
0
        public async Task ExecuteAsync(IPluginJobContext context)
        {
            if (!CliUtils.ParseArgs(_options, context.Args))
            {
                return;
            }

            if (_isHelp)
            {
                PrintUsage();
                return;
            }

            if (!await _configRepository.IsNeedInstallAsync())
            {
                await WriteUtils.PrintErrorAsync($"SS CMS has been installed in {_settingsManager.ContentRootPath}");

                return;
            }

            var userName = string.IsNullOrEmpty(_userName)
                ? ReadUtils.GetString("Super administrator username:"******"Super administrator password:"******"index.html"), Constants.Html5Empty);

            await WriteUtils.PrintSuccessAsync("Congratulations, SS CMS was installed successfully!");
        }
Esempio n. 5
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadWithSeparator("./Day8DataStar1.txt", ',').ConfigureAwait(false);

            var input = lines[0].ToArray().Select(e => int.Parse($"{e}")).ToArray();

            Assert.Equal("0110010001100101110010001\n0001100101110010001100101\n0101110010001100101000110\n0010001100101000110100100\n1100101000110100100101000\n1000110100100101000110000\n", Day8.Star2(input, 25, 6));
        }
Esempio n. 6
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadWithSeparator("./Day5DataStar1.txt", ',').ConfigureAwait(false);

            var input = lines.Select(e => int.Parse(e)).ToArray();

            Assert.Equal(13758663, Day5.Star1(input, 5).Last());
        }
Esempio n. 7
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day1Part1Input.txt").ConfigureAwait(false);

            var numbers = lines.Select(e => int.Parse(e)).ToArray();

            Assert.Equal(295086480, Day1.Star2(numbers));
        }
Esempio n. 8
0
        public async Task Test1()
        {
            var lines = await ReadUtils.ReadAllLines("./Day1Part1.txt").ConfigureAwait(false);

            var numbers = lines.Select(e => int.Parse(e)).ToArray();

            Assert.Equal(514579, Day1.Star1(numbers));
        }
Esempio n. 9
0
        public async Task Star1()
        {
            var lines = await ReadUtils.ReadWithSeparator("./Day2DataStar1.txt", ',');

            var input = lines.Select(e => int.Parse(e)).ToArray();

            input[1] = 12;
            input[2] = 2;
            Assert.Equal(4138687, Day2.Star1(input));
        }
Esempio n. 10
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day3Part1Input.txt").ConfigureAwait(false);

            Assert.Equal(1115775000, Day3.Star1(lines, 1, 1) *
                         Day3.Star1(lines, 3, 1) *
                         Day3.Star1(lines, 5, 1) *
                         Day3.Star1(lines, 7, 1) *
                         Day3.Star1(lines, 1, 2));
        }
Esempio n. 11
0
        public async Task Test2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day3Part1Test1.txt").ConfigureAwait(false);

            Assert.Equal(336, Day3.Star1(lines, 1, 1) *
                         Day3.Star1(lines, 3, 1) *
                         Day3.Star1(lines, 5, 1) *
                         Day3.Star1(lines, 7, 1) *
                         Day3.Star1(lines, 1, 2));
        }
Esempio n. 12
0
        public async Task Test2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day13Part1Test1.txt").ConfigureAwait(false);

            Assert.Equal(754018, Day13.Star2(new string[] { "1", "67,7,59,61" }));
            Assert.Equal(779210, Day13.Star2(new string[] { "1", "67,x,7,59,61" }));
            Assert.Equal(1261476, Day13.Star2(new string[] { "1", "67,7,x,59,61" }));
            Assert.Equal(1202161486, Day13.Star2(new string[] { "1", "1789,37,47,1889" }));
            Assert.Equal(1068781, Day13.Star2(lines));
        }
Esempio n. 13
0
        public async Task ExecuteAsync(IPluginJobContext context)
        {
            if (!CliUtils.ParseArgs(_options, context.Args))
            {
                return;
            }

            if (_isHelp)
            {
                PrintUsage();
                return;
            }

            var pluginsPath = CliUtils.IsSsCmsExists(_settingsManager.ContentRootPath)
                ? _pathManager.PluginsPath
                : _settingsManager.ContentRootPath;

            var(status, _) = await _apiService.GetStatusAsync();

            var publisher = status == null
                ? ReadUtils.GetString("What's the publisher of your plugin?")
                : status.UserName;

            if (status == null && !StringUtils.IsStrictName(publisher))
            {
                await WriteUtils.PrintErrorAsync(
                    $@"Invalid plugin publisher: ""{publisher}"", string does not match the pattern of ""{StringUtils.StrictNameRegex}""");

                return;
            }

            var name = ReadUtils.GetString("What's the name of your plugin?");

            if (!StringUtils.IsStrictName(name))
            {
                await WriteUtils.PrintErrorAsync(
                    $@"Invalid plugin name: ""{publisher}"", string does not match the pattern of ""{StringUtils.StrictNameRegex}""");

                return;
            }

            var pluginId   = PluginUtils.GetPluginId(publisher, name);
            var pluginPath = PathUtils.Combine(pluginsPath, pluginId);

            var dict = new Dictionary <string, object>
            {
                ["name"]      = name,
                ["publisher"] = publisher
            };
            var json = TranslateUtils.JsonSerialize(dict);
            await FileUtils.WriteTextAsync(PathUtils.Combine(pluginPath, Constants.PackageFileName), json);

            await WriteUtils.PrintSuccessAsync($@"The plugin ""{pluginId}"" was created successfully.");
        }
Esempio n. 14
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadWithSeparator("./Day7DataStar1.txt", ',').ConfigureAwait(false);

            var        input = lines.Select(e => int.Parse(e)).ToArray();
            List <int> seq   = new List <int>()
            {
                9, 8, 7, 6, 5
            };

            Assert.Equal(9246095, Permutate(seq, seq.Count).Select(e => Day7.Star2(input, e.ToArray()).Last()).Max());
        }
Esempio n. 15
0
        public async Task Star1()
        {
            var lines = await ReadUtils.ReadAllLines("./Day5Part1Input.txt").ConfigureAwait(false);

            var seats = lines.Select(e => Day5.Star1(e)).OrderBy(e => e).ToArray();

            for (int i = 1; i < seats.Length; i++)
            {
                if (seats[i - 1] + 2 == seats[i])
                {
                    Assert.Equal(623, seats[i] - 1);
                    return;
                }
            }
            Assert.False(true);
        }
Esempio n. 16
0
        public void WriteFlatStruct()
        {
            List <(string key, object value)> kvps;

            using (var writer = new ManagedBinaryWriter(_memoryStream, Symbols.EmptySymbolTablesArray))
            {
                writer.StepIn(IonType.Struct);

                kvps = WriteFlat(writer);

                writer.StepOut();
                writer.Flush();
            }

            var reader = new UserBinaryReader(new MemoryStream(_memoryStream.GetWrittenBuffer()));

            ReadUtils.AssertFlatStruct(reader, kvps);
        }
Esempio n. 17
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadWithSeparator("./Day2DataStar1.txt", ',');

            var input = lines.Select(e => int.Parse(e)).ToArray();

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    input[1] = i;
                    input[2] = j;
                    if (19690720 == Day2.Star1(input))
                    {
                        Assert.Equal(6635, 100 * i + j);
                    }
                }
            }
        }
Esempio n. 18
0
        public void WriteFlatStruct()
        {
            using (var stream = new MemoryStream())
            {
                List <(string key, object value)> kvps;
                IIonWriter writer;
                using (writer = new ManagedBinaryWriter(BinaryConstants.EmptySymbolTablesArray))
                {
                    writer.StepIn(IonType.Struct);

                    kvps = WriteFlat(writer);

                    writer.StepOut();
                    writer.Flush(stream);
                }

                var reader = new UserBinaryReader(new MemoryStream(stream.ToArray()));
                ReadUtils.AssertFlatStruct(reader, kvps);
            }
        }
Esempio n. 19
0
    public override void Deserialize(ByteArray stream)
    {
        base.Deserialize(stream);

        int usernameCount = 0;
        int passwordCount = 0;

        while (stream.bytesAvailable > 0)
        {
            var tag = ReadUtils.ReadTag(stream);
            switch (tag.number)
            {
            case 0:
                throw new ProtobufException("Invalid field id: 0, wrong stream");

            case 1:
                this.username = ReadUtils.Read_TYPE_STRING(stream);
                usernameCount++;
                break;

            case 2:
                this.password = ReadUtils.Read_TYPE_STRING(stream);
                passwordCount++;
                break;

            default:
                ReadUtils.Skip(stream, tag.wireType);
                break;
            }
        }

        if (usernameCount == 0)
        {
            throw new ProtobufException("Required field username not readed");
        }
        if (passwordCount == 0)
        {
            throw new ProtobufException("Required field password not readed");
        }
    }
Esempio n. 20
0
        public async Task Star1()
        {
            var lines = await ReadUtils.ReadAllLines("./Day14Part1Input.txt").ConfigureAwait(false);

            Assert.Equal(8332632930672, Day14.Star1(lines));
        }
Esempio n. 21
0
        public async Task Test1()
        {
            var lines = await ReadUtils.ReadAllLines("./Day14Part1Test1.txt").ConfigureAwait(false);

            Assert.Equal(165, Day14.Star1(lines));
        }
Esempio n. 22
0
        public async Task ExecuteAsync(IPluginJobContext context)
        {
            if (!CliUtils.ParseArgs(_options, context.Args))
            {
                return;
            }

            if (_isHelp)
            {
                PrintUsage();
                return;
            }

            var contentRootPath = _settingsManager.ContentRootPath;

            if (!CliUtils.IsSsCmsExists(contentRootPath))
            {
                var(success, result, failureMessage) = await _apiService.GetReleasesAsync(_settingsManager.Version, null);

                if (!success)
                {
                    await WriteUtils.PrintErrorAsync(failureMessage);

                    return;
                }

                var proceed = ReadUtils.GetYesNo($"Do you want to install SS CMS in {contentRootPath}?");
                if (!proceed)
                {
                    return;
                }

                Console.WriteLine($"Downloading SS CMS {result.Cms.Version}...");
                var directoryPath = CloudUtils.Dl.DownloadCms(_pathManager, _settingsManager.OSArchitecture, result.Cms.Version);

                await WriteUtils.PrintSuccessAsync($"{result.Cms.Version} download successfully!");

                DirectoryUtils.Copy(directoryPath, contentRootPath, true);
            }

            InstallUtils.Init(contentRootPath);

            if (!await _configRepository.IsNeedInstallAsync())
            {
                await WriteUtils.PrintErrorAsync($"SS CMS has been installed in {contentRootPath}");

                return;
            }

            var databaseTypeInput = ReadUtils.GetSelect("Database type", new List <string>
            {
                DatabaseType.MySql.GetValue().ToLower(),
                DatabaseType.SqlServer.GetValue().ToLower(),
                DatabaseType.PostgreSql.GetValue().ToLower(),
                DatabaseType.SQLite.GetValue().ToLower()
            });

            var databaseType          = TranslateUtils.ToEnum(databaseTypeInput, DatabaseType.MySql);
            var databaseName          = string.Empty;
            var databaseHost          = string.Empty;
            var isDatabaseDefaultPort = true;
            var databasePort          = 0;
            var databaseUserName      = string.Empty;
            var databasePassword      = string.Empty;

            if (databaseType != DatabaseType.SQLite)
            {
                databaseHost          = ReadUtils.GetString("Database hostname / IP:");
                isDatabaseDefaultPort = ReadUtils.GetYesNo("Use default port?");

                if (!isDatabaseDefaultPort)
                {
                    databasePort = ReadUtils.GetInt("Database port:");
                }
                databaseUserName = ReadUtils.GetString("Database userName:"******"Database password:"******"Database name", databaseNames);
            }

            var databaseConnectionString = InstallUtils.GetDatabaseConnectionString(databaseType, databaseHost, isDatabaseDefaultPort, databasePort, databaseUserName, databasePassword, databaseName);

            var isProtectData = ReadUtils.GetYesNo("Protect settings in sscms.json?");

            _settingsManager.SaveSettings(isProtectData, false, false, databaseType, databaseConnectionString, string.Empty, string.Empty, null, null);

            await WriteUtils.PrintSuccessAsync("SS CMS was download and ready for install, please run: sscms install database");
        }
Esempio n. 23
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day10Part1Input.txt").ConfigureAwait(false);

            Assert.Equal(3022415986688, Day10.Star2(lines.Select(e => int.Parse(e)).ToArray()));
        }
Esempio n. 24
0
        public async Task Test4()
        {
            var lines = await ReadUtils.ReadAllLines("./Day10Part1Test2.txt").ConfigureAwait(false);

            Assert.Equal(19208, Day10.Star2(lines.Select(e => int.Parse(e)).ToArray()));
        }
Esempio n. 25
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day6Part1Input.txt").ConfigureAwait(false);

            Assert.Equal(3358, Day6.Star2(lines));
        }
Esempio n. 26
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day14Part1Input.txt").ConfigureAwait(false);

            Assert.Equal(4753238784664, Day14.Star2(lines));
        }
Esempio n. 27
0
        public async Task Star1()
        {
            var lines = await ReadUtils.ReadAllLines("./Day13Part1Input.txt").ConfigureAwait(false);

            Assert.Equal(246, Day13.Star1(lines));
        }
Esempio n. 28
0
        public async Task Test2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day17Part1Test1.txt").ConfigureAwait(false);

            Assert.Equal(848, Day17.Star1(lines, true));
        }
Esempio n. 29
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day13Part1Input.txt").ConfigureAwait(false);

            Assert.Equal(939490236001473, Day13.Star2(lines));
        }
Esempio n. 30
0
        public async Task Star2()
        {
            var lines = await ReadUtils.ReadAllLines("./Day17Part1Input.txt").ConfigureAwait(false);

            Assert.Equal(2192, Day17.Star1(lines, true));
        }