Skip to content

Commit

Permalink
Merge pull request #284 from MarkSummerville/master
Browse files Browse the repository at this point in the history
Fix issue #273, improved error handling and slight refactor
  • Loading branch information
SirSparkles authored Jan 15, 2018
2 parents b01a9f7 + fea258c commit 4e4adf5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 30 deletions.
52 changes: 35 additions & 17 deletions TVRename#/Exporter/Exporter.cs
Original file line number Diff line number Diff line change
@@ -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();

}

Expand All @@ -21,20 +21,20 @@ 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)
{
this.mDoc = doc;
}

public string produce()
private string Produce()
{
try
{
Expand All @@ -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<ProcessedEpisode> 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<ProcessedEpisode> elist);
protected abstract bool Generate(Stream str, List<ProcessedEpisode> elist);
}

}
5 changes: 3 additions & 2 deletions TVRename#/Exporter/MissingXML.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;

Expand All @@ -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)
{
Expand Down
7 changes: 4 additions & 3 deletions TVRename#/Exporter/ShowsTXT.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

Expand All @@ -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<ShowItem> shows)
{
Expand All @@ -27,7 +28,7 @@ public override void Run(List<ShowItem> shows)
}
catch (Exception e)
{
logger.Error(e);
Logger.Error(e);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions TVRename#/Exporter/UpcomingRSS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;

Expand All @@ -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<ProcessedEpisode> elist)
protected override bool Generate(System.IO.Stream str, List<ProcessedEpisode> elist)
{
if (elist == null)
return false;
Expand Down Expand Up @@ -61,7 +62,7 @@ protected override bool generate(System.IO.Stream str, List<ProcessedEpisode> el
} // try
catch (Exception e)
{
logger.Error(e);
Logger.Error(e);
return false;
}

Expand Down
9 changes: 5 additions & 4 deletions TVRename#/Exporter/UpcomingXML.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ProcessedEpisode> elist)
protected override bool Generate(System.IO.Stream str, List<ProcessedEpisode> elist)
{
DirFilesCache dfc = new DirFilesCache();
try
Expand Down Expand Up @@ -74,7 +75,7 @@ protected override bool generate(System.IO.Stream str, List<ProcessedEpisode> 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;
}

Expand Down

0 comments on commit 4e4adf5

Please sign in to comment.