Example #1
0
        // additional method is required by Costura's assembly loading hack under Mono
        private static int MainImpl(string[] args)
        {
            var timer   = Stopwatch.StartNew();
            var options = new CommandLineOptions();

            try
            {
                var toolName = Assembly.GetExecutingAssembly().GetName();

                options.Parse(args);
                var isTestMode = options.IsTestMode;

                if (!isTestMode)
                {
                    Print($"{toolName.Name} v{toolName.Version}", ConsoleColor.Gray);
                }


                if (options.NeedHelp)
                {
                    options.PrintHelp(Console.Out);
                    return(0);
                }


                JsonGenerator.OnMessage += (message, importance) =>
                {
                    if (!isTestMode && importance >= options.LogLevel)
                    {
                        Print(message, ConsoleColor.DarkGray);
                    }
                };

                foreach (var ignoredOption in options.IgnoredOptions)
                {
                    PrintError($"File or option was ignored: {ignoredOption}");
                }

                var(tdls, refs) = (options.InputFiles.ToArray(), options.References.ToArray());
                var output = new Lazy <TextWriter>(() => new StreamWriter(options.OutputFile, false, Encoding.UTF8));
                CompilerMessageBag messages;

                if (options.Transformers.Count > 0)
                {
                    Print($"Using custom transformers", ConsoleColor.Magenta);
                    messages = new CompilerMessageBag();
                    foreach (var t in options.Transformers)
                    {
                        var transformatorFunc     = LoadTransformator(t.assembly, t.type, t.method);
                        var transformationContext = JsonGenerator.Generate(options.WorkingDirectory, tdls, refs, options.DeploymentScriptHeader, options.DeploymentToolPath,
                                                                           isMethodTypingEnabled: true, output: null, transformatorOutput: options.OutputFile, transformatorOpt: transformatorFunc, isTestMode: isTestMode,
                                                                           booleanMarshalMode: options.BooleanMarshalMode, jsonSchemaType: options.JsonSchemaType, diffFile: options.DiffFile,
                                                                           repositoryRoot: options.RepositoryPath, excludeTriggerPathScenarios: options.ExcludeTriggerPathScenarios,
                                                                           isSampleGeneration: options.SampleOutputFile != null);
                        messages.AddRange(transformationContext.Messages);

                        if (messages.HasErrors)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    var transformationContext = JsonGenerator.Generate(options.WorkingDirectory, tdls, refs, options.DeploymentScriptHeader, options.DeploymentToolPath,
                                                                       isMethodTypingEnabled: true, output: output, transformatorOutput: null, transformatorOpt: null, isTestMode: isTestMode,
                                                                       booleanMarshalMode: options.BooleanMarshalMode, jsonSchemaType: options.JsonSchemaType, diffFile: options.DiffFile,
                                                                       repositoryRoot: options.RepositoryPath, excludeTriggerPathScenarios: options.ExcludeTriggerPathScenarios,
                                                                       isSampleGeneration: options.SampleOutputFile != null);

                    if (isTestMode)
                    {
                        Debug.Assert(transformationContext.Comments != null);

                        if (!TestCompilerMessages(transformationContext, options))
                        {
                            return(-4);
                        }
                        if (output.IsValueCreated && options.SampleOutputFile != null)
                        {
                            var result = TestCompareWitSample(options, output);
                            if (result < 0)
                            {
                                return(result);
                            }
                        }

                        Print($"test passed.  Elapsed time: {timer.Elapsed}", ConsoleColor.Green);
                        return(0);
                    }

                    messages = transformationContext.Messages;
                }

                if (output.IsValueCreated)
                {
                    output.Value.Dispose();
                }

                ReportCompilerMessages(messages);

                if (output.IsValueCreated)
                {
                    Print($"JSON file was created successfully: '{options.OutputFile}'.", ConsoleColor.Green);
                }

                Print("Took: " + timer.Elapsed, ConsoleColor.DarkGray);

                return(messages.HasErrors ? -3 : 0);
            }
            catch (OptionException e)
            {
                PrintError(e.Message);
                return(-2);
            }
            catch (ConfigurationException e)
            {
                PrintError($"Configuration error: {e.Message}");
                return(-3);
            }
            catch (Exception e)
            {
                PrintError($"Unhandled exception: {e}");
                return(-3);
            }
            finally
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
        }
        public void TestSerializeNull()
        {
            var js = new JsonGenerator();

            Assert.ThrowsException <ArgumentNullException>(() => { js.GenerateJson(null, "null"); });
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void init()
        public virtual void Init()
        {
            _jsonCodec     = new Neo4jJsonCodec(Tptpmc);
            _jsonGenerator = mock(typeof(JsonGenerator));
        }