diff --git a/TVRename#/Exporter/Exporter.cs b/TVRename#/Exporter/Exporter.cs index 6146fffb1..97ecaa69f 100644 --- a/TVRename#/Exporter/Exporter.cs +++ b/TVRename#/Exporter/Exporter.cs @@ -1,15 +1,15 @@ -using System; +using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; -using System.Text; namespace TVRename { abstract class Exporter { public abstract bool Active(); - public abstract string Location(); - protected static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); + protected abstract string Location(); + protected static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); } @@ -21,12 +21,12 @@ abstract class ShowsExporter : Exporter abstract class MissingExporter : Exporter { - public abstract void Run(ItemList TheActionList); + public abstract void Run(ItemList theActionList); } abstract class UpcomingExporter : Exporter { - protected TVDoc mDoc; + protected readonly TVDoc mDoc; public UpcomingExporter(TVDoc doc) @@ -34,7 +34,7 @@ public UpcomingExporter(TVDoc doc) this.mDoc = doc; } - public string produce() + private string Produce() { try { @@ -46,32 +46,50 @@ public string produce() MemoryStream ms = new MemoryStream(); //duplicated the IF statement one for RSS and one for XML so that both can be generated. List lpe = mDoc.NextNShows(TVSettings.Instance.ExportRSSMaxShows, TVSettings.Instance.ExportRSSDaysPast, TVSettings.Instance.ExportRSSMaxDays); if (lpe != null) - if (this.generate(ms,lpe )) + if (this.Generate(ms,lpe )) { return System.Text.Encoding.ASCII.GetString(ms.ToArray()); } } - catch + catch (Exception e) { + Logger.Error(e, "Failed to produce records to put into Export file at: {0}", Location()); } return ""; } public void Run() { - if (this.Active()) + if (Active()) { - StreamWriter file = new StreamWriter(Location()); - String contents = produce(); - file.Write(contents); - file.Close(); - logger.Info("Output File to :{0}", Location()); - logger.Trace("contents of File are :{0}", contents); + try + { + + //Create the directory if needed + Directory.CreateDirectory(Path.GetDirectoryName(Location()) ??""); + + //Write Contents to file + StreamWriter file = new StreamWriter(Location()); + String contents = Produce(); + file.Write(contents); + file.Close(); + + Logger.Info("Output File to :{0}", Location()); + Logger.Trace("contents of File are :{0}", contents); + } + catch (Exception e) + { + Logger.Error(e,"Failed to Output File to :{0}", Location()); + } + } + else + { + Logger.Trace("SKipped (Disabled) Output File to :{0}", Location()); } } - protected abstract bool generate(Stream str, List elist); + protected abstract bool Generate(Stream str, List elist); } } diff --git a/TVRename#/Exporter/MissingXML.cs b/TVRename#/Exporter/MissingXML.cs index b74eeae52..e7b1e6d9e 100644 --- a/TVRename#/Exporter/MissingXML.cs +++ b/TVRename#/Exporter/MissingXML.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.IO; using System.Text; using System.Xml; @@ -8,7 +9,7 @@ namespace TVRename class MissingXML : MissingExporter { public override bool Active() =>TVSettings.Instance.ExportMissingXML; - public override string Location() =>TVSettings.Instance.ExportMissingXMLTo; + protected override string Location() =>TVSettings.Instance.ExportMissingXMLTo; public override void Run(ItemList TheActionList) { diff --git a/TVRename#/Exporter/ShowsTXT.cs b/TVRename#/Exporter/ShowsTXT.cs index 9bbc45b7e..e83bd2840 100644 --- a/TVRename#/Exporter/ShowsTXT.cs +++ b/TVRename#/Exporter/ShowsTXT.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; @@ -8,7 +9,7 @@ namespace TVRename class ShowsTXT : ShowsExporter { public override bool Active() =>TVSettings.Instance.ExportShowsTXT; - public override string Location() =>TVSettings.Instance.ExportShowsTXTTo; + protected override string Location() =>TVSettings.Instance.ExportShowsTXTTo; public override void Run(List shows) { @@ -27,7 +28,7 @@ public override void Run(List shows) } catch (Exception e) { - logger.Error(e); + Logger.Error(e); } } } diff --git a/TVRename#/Exporter/UpcomingRSS.cs b/TVRename#/Exporter/UpcomingRSS.cs index e5a6ad722..a6f53296e 100644 --- a/TVRename#/Exporter/UpcomingRSS.cs +++ b/TVRename#/Exporter/UpcomingRSS.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.IO; using System.Text; using System.Xml; @@ -9,9 +10,9 @@ class UpcomingRSS :UpcomingExporter { public UpcomingRSS(TVDoc i) : base(i) { } public override bool Active() =>TVSettings.Instance.ExportWTWRSS; - public override string Location() => TVSettings.Instance.ExportWTWRSSTo; + protected override string Location() => TVSettings.Instance.ExportWTWRSSTo; - protected override bool generate(System.IO.Stream str, List elist) + protected override bool Generate(System.IO.Stream str, List elist) { if (elist == null) return false; @@ -61,7 +62,7 @@ protected override bool generate(System.IO.Stream str, List el } // try catch (Exception e) { - logger.Error(e); + Logger.Error(e); return false; } diff --git a/TVRename#/Exporter/UpcomingXML.cs b/TVRename#/Exporter/UpcomingXML.cs index 862b5f5f0..b30c60618 100644 --- a/TVRename#/Exporter/UpcomingXML.cs +++ b/TVRename#/Exporter/UpcomingXML.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Generic; +using System.IO; using System.Text; using System.Xml; using System.Windows.Forms; @@ -12,9 +13,9 @@ class UpcomingXML : UpcomingExporter public UpcomingXML(TVDoc i) : base(i) { } public override bool Active()=> TVSettings.Instance.ExportWTWXML; - public override string Location() => TVSettings.Instance.ExportWTWXMLTo; + protected override string Location() => TVSettings.Instance.ExportWTWXMLTo; - protected override bool generate(System.IO.Stream str, List elist) + protected override bool Generate(System.IO.Stream str, List elist) { DirFilesCache dfc = new DirFilesCache(); try @@ -74,7 +75,7 @@ protected override bool generate(System.IO.Stream str, List e catch (Exception e) { if ((!this.mDoc.Args.Unattended) && (!this.mDoc.Args.Hide)) MessageBox.Show(e.Message); - logger.Error(e); + Logger.Error(e); return false; }