/// <summary>
        /// Helper method to write the <paramref name="conversation"/> as JSON to outputFilePath in <paramref name="configuration"/>.
        /// </summary>
        /// <param name="conversation">
        /// The conversation.
        /// </param>
        /// <param name="configuration">
        /// The export configuration.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Thrown when there is a problem with the <paramref name="outputFilePath"/>.
        /// </exception>
        /// <exception cref="Exception">
        /// Thrown when something else bad happens.
        /// </exception>
        public void WriteConversation(Conversation conversation, ConversationExporterConfiguration configuration)
        {
            try
            {
                var writer = new StreamWriter(new FileStream(configuration.outputFilePath, FileMode.Create, FileAccess.ReadWrite));

                var serialized = JsonConvert.SerializeObject(conversation, Formatting.Indented);

                writer.Write(serialized);

                writer.Flush();

                writer.Close();
            }
            catch (SecurityException)
            {
                Console.WriteLine("No permission to file.");
                configuration.outputFilePath = PromptUserForInput("Please give new file path for output");
                WriteConversation(conversation, configuration);
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("Path invalid.");
                configuration.outputFilePath = PromptUserForInput("Please give new file path for output");
                WriteConversation(conversation, configuration);
            }
            catch (Exception)
            {
                Console.WriteLine("Something went wrong in the IO.");
                configuration.outputFilePath = PromptUserForInput("Please give new file path for output ");
                WriteConversation(conversation, configuration);
            }
        }
Пример #2
0
 public virtual void ApplyFilter(Conversation conversation)
 {
 }