Example #1
0
        private static void ExecutePrintJsonSchemaCommand(string fileName)
        {
            JSONSchemaExtractor schemaExtractor;

            if (!File.Exists(fileName))
            {
                Console.WriteLine("File '{0}' not found!", fileName);
                return;
            }

            schemaExtractor = new JSONSchemaExtractor();
            try
            {
                Console.WriteLine(schemaExtractor.GetSchemaAsText(fileName));
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception during getting schema from the file: {0}", fileName);
                Console.WriteLine(e.Message);
            }
        }
Example #2
0
        private static void ExecuteSchemasComparisonCommand(string fileNameLeft, string fileNameRight)
        {
            if (!File.Exists(fileNameLeft))
            {
                Console.WriteLine("File '{0}' not found!", fileNameLeft);
                return;
            }

            if (!File.Exists(fileNameRight))
            {
                Console.WriteLine("File '{0}' not found!", fileNameRight);
                return;
            }

            JSONSchemaExtractor      extractor = new JSONSchemaExtractor();
            JSchema                  schemaLeft, schemaRight;
            List <CompareResultItem> compareResults;

            try
            {
                schemaLeft = extractor.GetSchemaAsObject(fileNameLeft);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception during schema extraction for the file: {0}", fileNameLeft);
                Console.WriteLine(e.Message);
                return;
            }

            try
            {
                schemaRight = extractor.GetSchemaAsObject(fileNameRight);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception during schema extraction for the file: {0}", fileNameRight);
                Console.WriteLine(e.Message);
                return;
            }

            try
            {
                // Try to compare
                compareResults = new List <CompareResultItem>();
                JsonSchemaComparator.Compare(schemaLeft, schemaRight, compareResults);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception during schema comparison");
                Console.WriteLine(e.Message);
                return;
            }

            Console.WriteLine("Comparing the following files: \n");
            // Write wich file is left and which is right
            Console.WriteLine("Left file: {0}", fileNameLeft);
            Console.WriteLine("Right file: {0}\n", fileNameRight);

            if (compareResults.Count == 0)
            {
                Console.WriteLine("Files are identical.");
            }
            else
            {
                // Compare results output
                ShowCompareResults(compareResults);
            }
        }