Exemplo n.º 1
0
 public object GetGatherer(string scriptName, ToffeeWriter writer, TdlFile file)
 {
     if (ScriptName2Gatherer.ContainsKey(scriptName))
     {
         return(Activator.CreateInstance(ScriptName2Gatherer[scriptName], writer, file));
     }
     return(null);
 }
Exemplo n.º 2
0
        public ClientAgentServer(ClientAgentConfiguration configuration, TdlFile file, LoggerCategory category)
            : base(configuration, category)
        {
            Configuration = configuration;
            NetworkFile   = file;

            // Create the internal connection
            InternalClient = new ToffeeInternalClient(configuration.Internal, "ClientAgent", category);
        }
Exemplo n.º 3
0
        public bool Configure(object config, Logger logger = null)
        {
            try
            {
                // Get the configuration
                JObject jConfig = (JObject)config;
                ClientAgentConfiguration configuration = jConfig.ToObject <ClientAgentConfiguration>();

                // Load the network files
                TdlFile networkFile = new TdlFile(configuration.Network.Namespace, false);
                foreach (string file in configuration.Network.Files)
                {
                    if (!networkFile.ParseFile(file))
                    {
                        Console.WriteLine("Could not find: {0}", file);
                        return(false);
                    }
                }

                // Create the logger category
                LoggerCategory category =
                    logger?.MakeCategory(string.Format("ClientAgent-{0}", UniqueClientAgentIndex)) ?? null;

                // Sanity checks
                if (configuration.Internal.ChannelCount != 0)
                {
                    category.Warning("Internal channel count should not be set manually. Resetting value to maximum connections.");
                    configuration.Internal.ChannelCount = configuration.MaximumConnections;
                }

                // Create the server
                Server = new ClientAgentServer(configuration, networkFile, category);
                return(true);
            }
            catch (JsonException e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Exemplo n.º 4
0
 public CSharpDataGatherer(ToffeeWriter writer, TdlFile file) : base(writer, file)
 {
     AllObjects           = file.AllObjects;
     CurrentObjectIndex   = 0;
     CurrentPropertyIndex = 0;
 }
Exemplo n.º 5
0
        private static bool BeginApplication()
        {
            // Let's try to load the script file specified
            Console.WriteLine("Loading generator...");
            string scriptFilepath = string.Format("{0}/Scripts/{1}.tofc",
                                                  AppDomain.CurrentDomain.BaseDirectory, Arguments.GeneratorScript);

            try
            {
                Generator = new ToffeeGenerator(scriptFilepath, Arguments.Verbose || Arguments.VerboseGenerator);
            }
            catch (ToffeeGeneratorException e)
            {
                Console.WriteLine("An error occurred while creating the generator:");
                Console.WriteLine("ToffeeGeneratorException: {0}", e.Message);
            }

            // We've successfully loaded the script file, let's make the writer!
            Writer = new ToffeeWriter(Generator, Arguments.Verbose || Arguments.VerboseWriter);

            // Now, let's load the toffee file
            Console.WriteLine("Loading input file...");
            if (Path.GetExtension(Arguments.InputFile) != ".tdl")
            {
                Console.WriteLine("Input file must have '.tdl' extension.");
                return(false);
            }
            TdlFile file = new TdlFile(Arguments.BaseNamespace, Arguments.Verbose || Arguments.VerboseParser);

            try
            {
                if (!file.ParseFile(Path.GetFullPath(Arguments.InputFile)))
                {
                    Console.WriteLine("Could not find the input file.");
                    return(false);
                }
            }
            catch (TdlParserException e)
            {
                Console.WriteLine("An error occurred while parsing.");
                Console.WriteLine(e.Message);
                return(false);
            }
            Console.WriteLine("Hash: {0}", file.Hash);

            // Finally, let's output!
            Console.WriteLine("Generating...");
            try
            {
                object gatherer = ToffeeDataGatherers.Instance.GetGatherer(
                    Path.GetFileNameWithoutExtension(Arguments.GeneratorScript), Writer, file);
                if (gatherer == null)
                {
                    Console.WriteLine("An error occurred while generating.");
                    Console.WriteLine("Couldn't find gatherer for specified script.");
                    return(false);
                }
                Writer.Gatherer = gatherer;
                if (Arguments.OutputDirectory != "")
                {
                    Writer.Generate(Path.GetFullPath(Arguments.OutputDirectory));
                }
                else
                {
                    Writer.Generate(Arguments.OutputDirectory);
                }
            }
            catch (ToffeeWriterException e)
            {
                Console.WriteLine("An error occurred while generating.");
                Console.WriteLine(e.Message);
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
 public ToffeeDataGatherer(ToffeeWriter writer, TdlFile file)
 {
     Writer = writer;
     File   = file;
 }