Esempio n. 1
0
        public void Test_Issue4()
        {
            var strings = new [] { "hello", "there" };
            var hron    = HRONSerializer.ObjectAsString(strings);

            List <string> resultsStrings;

            HRONObjectParseError[] errors;

            var result = HRONSerializer.TryParseObject(
                100,
                hron.ReadLines(),
                out resultsStrings,
                out errors
                );

            TestFor.Equality(true, result, "TryParseObject should succeed");
            if (TestFor.Equality(strings.Length, resultsStrings.Count, "The length of expected and result sets should be the same"))
            {
                for (var iter = 0; iter < strings.Length; ++iter)
                {
                    TestFor.Equality(strings[iter], resultsStrings[iter], "The result set should have the same value as the expected set: {0}".FormatWith(iter));
                }
            }
        }
Esempio n. 2
0
        public void Test_ObjectAsString()
        {
            var dic = new Dictionary <string, object>
            {
                { "A", "AA" },
                { "B", "BB" },
                { "C",
                  new Dictionary <string, object>
                  {
                      { "AAA", "AAAA" },
                      { "BBB", "BBBB" },
                  } },
            };

            var value = HRONSerializer.ObjectAsString(dic);

            const string testCase = @"=A
	AA
=B
	BB
@C
	=AAA
		AAAA
	=BBB
		BBBB"        ;

            TestFor.Equality(testCase, value, "Serialized dictionary should have the expected value");
        }
Esempio n. 3
0
        public static TableVersion GetTargetVersion(
            this SqlConnection conn,
            string tableName,
            out string targetStatePath
            )
        {
            if (!SyncStateDirectory.Exists)
            {
                SyncStateDirectory.Create();
            }

            targetStatePath = Path.Combine(
                SyncStateDirectory.FullName,
                Uri.EscapeDataString(
                    string.Concat(
                        conn.DataSource,
                        "_",
                        conn.Database,
                        "_",
                        tableName,
                        ".hron"
                        )
                    )
                );


            TableVersion targetVersion;

            HRONObjectParseError[] errors;
            if (
                File.Exists(targetStatePath) &&
                HRONSerializer.TryParseObject(
                    0,
                    File.ReadAllText(targetStatePath, Encoding.UTF8).ReadLines(),
                    out targetVersion,
                    out errors
                    ))
            {
                return(targetVersion);
            }

            var tableVersion = new TableVersion
            {
                CurrentVersion  = -1,
                MinValidVersion = -1
            };

            File.WriteAllText(
                targetStatePath,
                HRONSerializer.ObjectAsString(
                    tableVersion
                    ),
                Encoding.UTF8
                );
            return(tableVersion);
        }
Esempio n. 4
0
 public void Save(string jobPath)
 {
     File.WriteAllText(
         jobPath,
         HRONSerializer.ObjectAsString(
             this
             ),
         Encoding.UTF8
         );
 }
Esempio n. 5
0
 public static void PersistsSourceTargetVersionState(this TableSchema tableSchema)
 {
     File.WriteAllText(
         tableSchema.TargetStatePath,
         HRONSerializer.ObjectAsString(
             tableSchema.SourceVersion
             ),
         Encoding.UTF8
         );
 }
Esempio n. 6
0
        public void Test_NameValueCollection()
        {
            var nvc = new NameValueCollection
            {
                { "Key1", "Value1" },
                { "Key1", "Value2" },
                { "Key1", "Value3" }
            };

            var value = HRONSerializer.ObjectAsString(nvc);

            // This test case is just to test that NameValueCollection doesn't crash the serializer
        }
Esempio n. 7
0
 public static bool TryLoad(string jobPath, out SyncJob syncJob)
 {
     syncJob = null;
     HRONObjectParseError[] errors;
     return(
         File.Exists(jobPath) &&
         HRONSerializer.TryParseObject(
             0,
             File.ReadAllText(jobPath, Encoding.UTF8).ReadLines(),
             out syncJob,
             out errors
             )
         );
 }
Esempio n. 8
0
        public void Test_Parse()
        {
            var visitor = new HRONWriterVisitor();
            var lines   = s_test_hron.ReadLines().ToArray();

            HRONSerializer.Parse(
                int.MaxValue,
                lines,
                visitor
                );

            TestFor.Equality(
                s_test_hron,
                visitor.Value,
                "HRON after deserialize/serialize should be identical to test case"
                );
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            // Basic sanity check to see if functionality that are supposed to work
            // on .NET2 compiles

            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;

            var hron = File.ReadAllText("Test.hron");

            var visitor = new HRONWriterVisitor();

            HRONSerializer.Parse(
                int.MaxValue,
                hron.ReadLines(),
                visitor);

            Console.WriteLine(visitor.Value);
        }
Esempio n. 10
0
        public void Test_TryParseObject()
        {
            var    lines = s_test2_hron.ReadLines().ToArray();
            Config config;

            HRONObjectParseError[] errors;
            var result = HRONSerializer.TryParseObject(int.MaxValue, lines, out config, out errors);

            if (TestFor.Equality(true, result, "HRON should be parsed successfully"))
            {
                var value = HRONSerializer.ObjectAsString(config);

                TestFor.Equality(
                    s_test2_hron,
                    value,
                    "HRON after deserialize/serialize to object should be identical to test case"
                    );
            }
        }
Esempio n. 11
0
        public void Test_TryParseDynamic()
        {
            var     lines = s_test2_hron.ReadLines().ToArray();
            dynamic dyn;

            HRONDynamicParseError[] errors;
            var result = HRONSerializer.TryParseDynamic(int.MaxValue, lines, out dyn, out errors);

            if (TestFor.Equality(true, result, "HRON should be parsed successfully"))
            {
                MyFlag myFlag        = dyn.Common.MyFlag;
                MyFlag myMissingFlag = dyn.Common.MyMissingFlag;
                TestFor.Equality((int)MyFlag.MyFlagValue, (int)myFlag, "Expects MyFlagValue");
                TestFor.Equality((int)MyFlag.MyDefaultValue, (int)myMissingFlag, "Expects the default MyFlag");

                dynamic connections = dyn.DataBaseConnection;
                if (TestFor.Equality(2, connections.GetCount(), "Expects two database connections"))
                {
                    {
                        var connection = connections[0];

                        string name             = connection.Name;
                        string connectionString = connection.ConnectionString;
                        string timeOut          = connection.TimeOut;
                        int    parsedTimeOut    = connection.TimeOut;
                        int?   optParsedTimeOut = connection.TimeOut;
                        int[]  arrParsedTimeOut = connection.TimeOut;
                        TestFor.Equality(
                            "CustomerDB",
                            name,
                            "Expects CustomerDB name"
                            );
                        TestFor.Equality(
                            @"Data Source=.\SQLEXPRESS;Initial Catalog=Customers",
                            connectionString,
                            "Expects CustomerDB connection"
                            );
                        TestFor.Equality(
                            @"10",
                            timeOut,
                            "Expects CustomerDB timeout"
                            );
                        TestFor.Equality(
                            10,
                            parsedTimeOut,
                            "Expects parsed CustomerDB timeout"
                            );
                        if (TestFor.Equality(
                                true,
                                optParsedTimeOut.HasValue,
                                "Expects parsed CustomerDB timeout"
                                ))
                        {
                            TestFor.Equality(
                                10,
                                optParsedTimeOut.Value,
                                "Expects parsed CustomerDB timeout"
                                );
                        }
                        if (TestFor.Equality(
                                1,
                                arrParsedTimeOut.Length,
                                "Expects parsed CustomerDB timeout"
                                ))
                        {
                            TestFor.Equality(
                                10,
                                arrParsedTimeOut[0],
                                "Expects parsed CustomerDB timeout"
                                );
                        }
                    }
                    {
                        var connection = connections[1];

                        string name             = connection.Name;
                        string connectionString = connection.ConnectionString;
                        string timeOut          = connection.TimeOut;
                        int    parsedTimeOut    = connection.TimeOut;
                        int?   optParsedTimeOut = connection.TimeOut;
                        int[]  arrParsedTimeOut = connection.TimeOut;

                        TestFor.Equality(
                            "PartnerDB",
                            name,
                            "Expects PartnerDB name"
                            );
                        TestFor.Equality(
                            @"Data Source=.\SQLEXPRESS;Initial Catalog=Partners",
                            connectionString,
                            "Expects PartnerDB connection"
                            );
                        TestFor.Equality(
                            "",
                            timeOut,
                            "Expects no PartnerDB timeout"
                            );
                        TestFor.Equality(
                            0,
                            parsedTimeOut,
                            "Expects no parsed CustomerDB timeout"
                            );
                        TestFor.Equality(
                            false,
                            optParsedTimeOut.HasValue,
                            "Expects no parsed CustomerDB timeout"
                            );
                        TestFor.Equality(
                            0,
                            arrParsedTimeOut.Length,
                            "Expects no parsed CustomerDB timeout"
                            );
                    }
                }
                var value = HRONSerializer.DynamicAsString(dyn);

                TestFor.Equality(
                    s_test2_hron,
                    value,
                    "HRON after deserialize/serialize to object should be identical to test case"
                    );
            }
        }
Esempio n. 12
0
        public static void Run(string[] args)
        {
            Partial_ConsoleAppStarts();
            try
            {
                Log.HighLight("{0} is starting...", s_consoleName);
                Thread.CurrentThread.CurrentCulture = Config.DefaultCulture;
                Environment.CurrentDirectory        = AppDomain.CurrentDomain.BaseDirectory;

                object config;
                var    configFile = "{0}.ini".FormatWith(s_consoleName);
                if (File.Exists(configFile))
                {
                    Log.Info("Loading config file: {0}", configFile);
                    using (var streamReader = new StreamReader(configFile))
                    {
                        HRONDynamicParseError[] parserErrors;
                        if (!HRONSerializer.TryParseDynamic(
                                int.MaxValue,
                                streamReader.ReadLines().Select(x => x.ToSubString()),
                                out config,
                                out parserErrors
                                ))
                        {
                            throw new ExitCodeException(ExitCode.InvalidConfigFile);
                        }
                    }
                }
                else
                {
                    config = HRONObject.Empty;
                }

                Log.Info("Initial setup is done, executing main program");

                Partial_Run(args, config);

                Log.Success("{0} completed", s_consoleName);
            }
            catch (ExitCodeException exc)
            {
                Environment.ExitCode = (int)exc.ExitCode;
                Log.Exception(
                    "Terminated {0} {1}({2:000}), caught exception: {3}",
                    s_consoleName,
                    exc.ExitCode,
                    Environment.ExitCode,
                    exc
                    );
            }
            catch (Exception exc)
            {
                Environment.ExitCode = 999;
                Log.Exception(
                    "Terminated {0} Unknown({1:000}), caught exception: {2}",
                    s_consoleName,
                    Environment.ExitCode,
                    exc
                    );
            }
            finally
            {
                Partial_ConsoleAppStops();
            }
        }