Ver Fonte

Added PostCancelled exception

Kenric Nugteren há 1 ano atrás
pai
commit
55166b1bb5

+ 31 - 0
InABox.Core/Postable/PostExceptions.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace InABox.Core
+{
+    namespace Postable
+    {
+        public class MissingSettingsException : Exception
+        {
+            public Type PostableType { get; }
+
+            public MissingSettingsException(Type postableType) : base($"No PostableSettings for ${postableType}")
+            {
+                PostableType = postableType;
+            }
+        }
+        public class RepostedException : Exception
+        {
+            public RepostedException() : base("Cannot process an item twice.")
+            {
+            }
+        }
+        public class PostCancelledException : Exception
+        {
+            public PostCancelledException() : base("Processing cancelled")
+            {
+            }
+        }
+    }
+}

+ 1 - 6
InABox.Core/Postable/PosterEngine.cs

@@ -1,5 +1,6 @@
 using InABox.Clients;
 using InABox.Configuration;
+using InABox.Core.Postable;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -7,12 +8,6 @@ using System.Text;
 
 namespace InABox.Core
 {
-    public class RepostedException : Exception
-    {
-        public RepostedException(): base("Cannot process an item twice.")
-        {
-        }
-    }
 
     public interface IPosterEngine<TPostable>
         where TPostable : Entity, IPostable, IRemotable, IPersistent, new()

+ 11 - 12
InABox.Core/Postable/PosterUtils.cs

@@ -9,18 +9,6 @@ using System.Text;
 
 namespace InABox.Core
 {
-    namespace Postable
-    {
-        public class MissingSettingsException : Exception
-        {
-            public Type PostableType { get; }
-
-            public MissingSettingsException(Type postableType) : base($"No PostableSettings for ${postableType}")
-            {
-                PostableType = postableType;
-            }
-        }
-    }
 
     public static class PosterUtils
     {
@@ -151,6 +139,17 @@ namespace InABox.Core
             return (Activator.CreateInstance(GetEngine<T>()) as IPosterEngine<T>)!;
         }
 
+        /// <summary>
+        /// Process <paramref name="entities"/> with the currently set <see cref="IPosterEngine{TPostable, TPoster, TSettings}"/>
+        /// for <typeparamref name="T"/>.
+        /// </summary>
+        /// <typeparam name="T">The type of <paramref name="entities"/> that needs to be processed.</typeparam>
+        /// <param name="entities"></param>
+        /// <exception cref="RepostedException">If any of the <paramref name="entities"/> has already been processed. In this case, nothing happens.</exception>
+        /// <exception cref="MissingSettingsException">If the <see cref="PostableSettings"/> for <typeparamref name="T"/> do not exist.</exception>
+        /// <exception cref="PostCancelledException">If the post has been cancelled by the user.</exception>
+        /// <returns><see langword="true"/> if post was successful.</returns>
+        /// 
         public static bool Process<T>(IEnumerable<T> entities)
             where T : Entity, IPostable, IRemotable, IPersistent, new()
         {

+ 5 - 1
InABox.Poster.CSV/CSVPosterEngine.cs

@@ -1,5 +1,6 @@
 using CsvHelper;
 using InABox.Core;
+using InABox.Core.Postable;
 using InABox.Scripting;
 using Microsoft.Win32;
 using System;
@@ -60,7 +61,10 @@ namespace InABox.Poster.CSV
                 method.Invoke(csv, new object?[] { results.Records });
                 return true;
             }
-            return false;
+            else
+            {
+                throw new PostCancelledException();
+            }
         }
     }
 }