public TemporaryFile()
        {
            ApplicationSettings = new TemporaryFileApplicationSettings();

            Random Rnd = new Random();
            int    XID = Rnd.Next(100000, 999999);

            ApplicationSettings.Name = $"Iris{XID}.tmp";
        }
        /// <summary>
        /// Create a new temporary file with optional name and settings. Returns a FileStream that can be used for opening things.
        /// </summary>
        /// <param name="FileName"></param>
        /// <param name="TFS"></param>
        /// <returns></returns>
        public FileStream CreateNewFile(TemporaryFileApplicationSettings TFS = null)
        {
            TemporaryFile TF = new TemporaryFile();

            if (TFS != null)
            {
                TF.ApplicationSettings = TFS;
            }

            return(TF.Create());
        }
Exemple #3
0
        public static void LogFile(string Text, bool IsNew = false)
        {
            try
            {
                FileName = $"Iris-Log-{DateTime.Now.ToString("yyyyMMdd-HHmmss")}.txt";

                TemporaryFileApplicationSettings TFS = new TemporaryFileApplicationSettings();
                TFS.TemporaryFileLocation = ".";
                TFS.Name = FileName;

                if (ApplicationSettings.ClearLogs)
                {
                    TFS.DelayClearUntilNextStart = true;
                }
                else
                {
                    TFS.Persistent = true;
                }

                if (IsNew)
                {
                    // Crippling this as we're integrating it with the track maker.


                    FileStream XF = GlobalState.TFM.CreateNewFile(TFS);
                    using (StreamWriter SW = new StreamWriter(XF))
                    {
                        SW.BaseStream.Seek(0, SeekOrigin.End);
                        SW.WriteLine($@"{LogHeader} [{DateTime.Now}] - {Text}");
                    }
                }
                else
                {
                    FileStream XF = GlobalState.TFM.CreateNewFile(TFS);
                    using (StreamWriter SW = new StreamWriter(XF)) // OpenOrCreate just in case
                    {
                        SW.BaseStream.Seek(0, SeekOrigin.End);
                        SW.WriteLine($@"{LogHeader} [{DateTime.Now}] - {Text}");
                    }
                }
                // create the file
            }
            catch (FileNotFoundException err)
            {
#if DEBUG
                MessageBox.Show($"Error 301 (an error occurred writing to the log - Log not found)\n\n{err}", "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
#else
                MessageBox.Show($"Error 301 (an error occurred writing to the log - Log not found", "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
#endif
            }
        }