Пример #1
0
        public Manager()
        {
            FindFiles();
            JsonSerializer serializer = new JsonSerializer();           //(De)serializes JSON, a la JSON.parse() and JSON.stringify()
            TextReader     fileReader = new StreamReader(dataLocation); //C# class to read file text
            JsonReader     reader     = new JsonTextReader(fileReader); //Newtonsoft class to read JSON from files

            reader.SupportMultipleContent = true;

            //Basically JSON.parse() but with static typing. "reader" arg is the poem.js JSON
            ReadPoem scannedPoem = serializer.Deserialize <ReadPoem>(reader);

            if (scannedPoem != null) //If the JSON serializer correctly converts the input JSON to a ReadPoem obj
            {
                //Now read the sentiment file and add that data to the ReadPoem
                fileReader            = new StreamReader(sentimentLocation);
                reader                = new JsonTextReader(fileReader);
                scannedPoem.sentiment = serializer.Deserialize <NeuralNet>(reader);

                //Now read the urgency file and add that data to the ReadPoem
                fileReader          = new StreamReader(urgencyLocation);
                reader              = new JsonTextReader(fileReader);
                scannedPoem.urgency = serializer.Deserialize <NeuralNet>(reader);

                //Now make a new Poem that has the data of the ReadPoem
                Poem poem = new Poem(scannedPoem);
                SavePoem(poem); //Write poem to file
            }

            Environment.Exit(0);
        }
Пример #2
0
 private void SavePoem(Poem poem)
 {
     //JsonConvert.SerializeObject returns a string (in JSON) of an object, similar to JSON.stringify
     //Then write that string to outputFile
     File.WriteAllText(outputFile, JsonConvert.SerializeObject(poem, Formatting.Indented));
 }