Skip to content

Commit

Permalink
V3.1.0
Browse files Browse the repository at this point in the history
RemindMe now has API Support!! Users can create new 'Conditional' reminders, where the reminder will pop up once 1(or more) customized conditions have been met
  • Loading branch information
Stefangansevles committed Feb 4, 2021
1 parent 50ce258 commit 7eb7fbd
Show file tree
Hide file tree
Showing 142 changed files with 3,948 additions and 728 deletions.
59 changes: 52 additions & 7 deletions Business Logic Layer/BLFormLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using WMPLib;
using System.Drawing;
using MaterialSkin.Controls;
using System.Drawing.Imaging;

namespace Business_Logic_Layer
{
Expand All @@ -15,6 +16,7 @@ public class BLFormLogic
private BLFormLogic() { }
private static WindowsMediaPlayer myPlayer = new WindowsMediaPlayer();


/// <summary>
/// Adds an reminder to the listview, showing the details of that reminder.
/// </summary>
Expand All @@ -33,16 +35,19 @@ public static void AddReminderToListview(object lv, Reminder rem, bool material)
ListViewItem itm = new ListViewItem(rem.Name);
itm.Tag = rem.Id; //Add the id as a tag(invisible)

if (rem.HttpId == null)
{
if (rem.PostponeDate == null)
itm.SubItems.Add(Convert.ToDateTime(rem.Date.Split(',')[0]).ToShortDateString() + " " + Convert.ToDateTime(rem.Date.Split(',')[0]).ToShortTimeString());
else
itm.SubItems.Add(Convert.ToDateTime(rem.PostponeDate).ToShortDateString() + " " + Convert.ToDateTime(rem.PostponeDate).ToShortTimeString() + " (p)");
}
else
itm.SubItems.Add("Conditional");

if (rem.PostponeDate == null)
itm.SubItems.Add(Convert.ToDateTime(rem.Date.Split(',')[0]).ToShortDateString() + " " + Convert.ToDateTime(rem.Date.Split(',')[0]).ToShortTimeString());
else
itm.SubItems.Add(Convert.ToDateTime(rem.PostponeDate).ToShortDateString() + " " + Convert.ToDateTime(rem.PostponeDate).ToShortTimeString() + " (p)");


if (rem.EveryXCustom == null)
{

if (rem.RepeatType == ReminderRepeatType.MULTIPLE_DAYS.ToString())
{
string cutOffString = "";
Expand Down Expand Up @@ -109,7 +114,9 @@ public static void AddRemindersToListview(object lv, List<Reminder> reminderList
}
}

List<Reminder> list = reminderList.OrderBy(t => Convert.ToDateTime(t.Date.Split(',')[0])).ToList();
List<Reminder> list = reminderList.Where(r => r.HttpId == null).OrderBy(t => Convert.ToDateTime(t.Date.Split(',')[0])).ToList();
list.AddRange(reminderList.Where(r => r.HttpId != null));

foreach (Reminder rem in list)
{
if (rem.Enabled == 1) //not disabled? add to listview
Expand All @@ -123,6 +130,44 @@ public static void AddRemindersToListview(object lv, List<Reminder> reminderList
AddReminderToListview(lv, rem, material);
}

public static void SetImageAlpha(PictureBox pb, int alpha)
{
if (pb.Image == null)
return;

var original = (Bitmap)pb.Image.Clone();
pb.BackColor = Color.Transparent;
pb.Image = SetAlpha((Bitmap)original, alpha);
}
private static Bitmap SetAlpha(Image bmpIn, int alpha)
{
Bitmap bmpOut = new Bitmap(bmpIn.Width, bmpIn.Height);
float a = alpha / 255f;
Rectangle r = new Rectangle(0, 0, bmpIn.Width, bmpIn.Height);

float[][] matrixItems = {
new float[] {1, 0, 0, 0, 0},
new float[] {0, 1, 0, 0, 0},
new float[] {0, 0, 1, 0, 0},
new float[] {0, 0, 0, a, 0},
new float[] {0, 0, 0, 0, 1}};

ColorMatrix colorMatrix = new ColorMatrix(matrixItems);

ImageAttributes imageAtt = new ImageAttributes();
imageAtt.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

using (Graphics g = Graphics.FromImage(bmpOut))
g.DrawImage(bmpIn, r, r.X, r.Y, r.Width, r.Height, GraphicsUnit.Pixel, imageAtt);

return bmpOut;
}

public static void CenterFormToParent(Form c, Form parent)
{
c.StartPosition = FormStartPosition.Manual;
c.Location = new Point(parent.Location.X + ((parent.Width / 2) - c.Width / 2), parent.Location.Y + ((parent.Height / 2) - (c.Height / 2)));
}
/// <summary>
/// Gets the amount of minutes from a bunifu textbox string. Includes formats like h, for example 1h30 returns 90
/// </summary>
Expand Down
73 changes: 71 additions & 2 deletions Business Logic Layer/BLIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
using System.Net;
using HtmlAgilityPack;
using System.Management;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Text;

namespace Business_Logic_Layer
{
Expand Down Expand Up @@ -251,7 +255,72 @@ public static void WriteError(Exception ex, string message,bool sendToOnlineData

}).Start();

}

}

public static async Task<JObject> HttpRequest(string method, string uri, string headers = "{ }", string accept = "", string contentType = "", string body = "{ }")
{
try
{
Log("Starting " + method + " for " + uri);

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.UserAgent = "RemindMe application";
request.Method = method;

if (!string.IsNullOrWhiteSpace(accept))
request.Accept = accept;

if (!string.IsNullOrWhiteSpace(contentType))
request.ContentType = contentType;

//Parse user-input headers into JSON
JObject jsonHeaders = JObject.Parse(headers);

//Initialize collection
WebHeaderCollection headerCollection = new WebHeaderCollection();
foreach (var header in jsonHeaders)
{
if (!WebHeaderCollection.IsRestricted(header.Key))
headerCollection.Add(header.Key, header.Value.ToString());
else
Log("Detected restricted header " + header.Key);
}

//Set the headers
request.Headers = headerCollection;

if (method == "POST")
{
//Add Body
byte[] bodyBytes = Encoding.UTF8.GetBytes(body);
request.ContentLength = bodyBytes.Length;
request.GetRequestStream().Write(bodyBytes, 0, bodyBytes.Length);
}



using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
if (response.StatusCode == HttpStatusCode.OK)
{
string bod = await reader.ReadToEndAsync();
return (JObject)JsonConvert.DeserializeObject(bod);
}
else
{
Log(method + " Failed with status code " + response.StatusCode.ToString());
return null;
}
}
}
catch (Exception ex)
{
Log(method + " [ " + uri + " ] Failed! Exception " + ex.GetType().ToString());
return null;
}
}
}
}
105 changes: 105 additions & 0 deletions Business Logic Layer/BLLocalDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,5 +484,110 @@ public static void InsertDefaultThemes()


}

public class HttpRequest
{
private HttpRequest() { }

public static HttpRequests GetHttpRequestById(long id)
{
return DLLocalDatabase.HttpRequest.GetHttpRequest(id);
}

public static void DeleteHttpRequestByReminderId(long id)
{
DLLocalDatabase.HttpRequest.DeleteHttpRequestByReminderId(id);
}
public static void DeleteHttpRequestById(long id)
{
DLLocalDatabase.HttpRequest.DeleteHttpRequestById(id);
}
public static List<HttpRequests> GetHttpRequests()
{
return DLLocalDatabase.HttpRequest.GetHttpRequests();
}

public static long InsertHttpRequest(HttpRequests http)
{
if (http != null)
return DLLocalDatabase.HttpRequest.InsertHttpRequest(http);
else return -1;
}
/// <summary>
/// Update the settings in the SQLite database
/// </summary>
/// <param name="set">The new settings object</param>
public static void UpdateTheme(HttpRequests http)
{
if (http != null)
DLLocalDatabase.HttpRequest.UpdateHttpRequest(http);
}
}

public class HttpRequestConditions
{
private HttpRequestConditions() { }

/// <summary>
/// Get the HttpRequest conditions for a HttpRequest
/// </summary>
/// <param name="requestId">The id of the parent HttpRequest</param>
/// <returns></returns>
public static List<HttpRequestCondition> GetConditions(long requestId)
{
return DLLocalDatabase.HttpRequestConditions.GetConditions(requestId);
}

/// <summary>
/// Get the HttpRequest conditions for a HttpRequest
/// </summary>
/// <param name="requestId">The id of the parent HttpRequest</param>
/// <returns></returns>
public static HttpRequestCondition GetCondition(long id)
{
return DLLocalDatabase.HttpRequestConditions.GetCondition(id);
}

/// <summary>
/// Insert a new Request condition into the db
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public static long InsertCondition(HttpRequestCondition condition)
{
if (condition != null)
{
condition.Property = condition.Property.Trim(); //remove whitespace

return DLLocalDatabase.HttpRequestConditions.InsertCondition(condition);
}
else
return -1;
}

/// <summary>
/// Delete a single condition by its id
/// </summary>
/// <param name="id"></param>
public static void DeleteConditionById(long id)
{
DLLocalDatabase.HttpRequestConditions.DeleteConditionById(id);
}

/// <summary>
/// Delete all conditions that are paired to a HttpRequest
/// </summary>
/// <param name="httpRequestId"></param>
public static void DeleteConditionsForHttpRequest(long httpRequestId)
{
DLLocalDatabase.HttpRequestConditions.DeleteConditionsForHttpRequest(httpRequestId);
}

public static void UpdateHttpRequest(HttpRequestCondition cond)
{
if(cond != null)
DLLocalDatabase.HttpRequestConditions.UpdateHttpRequest(cond);
}
}
}
}
54 changes: 45 additions & 9 deletions Business Logic Layer/BLReminder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,37 @@ public class BLReminder
private BLReminder() { }

/// <summary>
/// Gets all non-deleted/archived reminders from the database
/// Gets all "existing" reminders from the database (Not the deleted/archived ones)
/// </summary>
/// <param name="includeConditionalReminders">Wether to include conditional (HTTP) reminders or not. These do not have a date</param>
/// <returns></returns>
public static List<Reminder> GetReminders()
public static List<Reminder> GetReminders(bool includeConditionalReminders = false)
{
List<Reminder> reminders = DLReminders.GetReminders();
List<Reminder> reminders = DLReminders.GetReminders(includeConditionalReminders);
GC.Collect();
return reminders;
}

/// <summary>
/// Orders reminders, ready to be served to the reminder list
/// </summary>
/// <returns>A list of ordered reminders, normal reminders first, then HTTP conditional reminders, then disabled reminders. Normal reminders are ordered by date</returns>
public static List<Reminder> GetOrderedReminders()
{
List<Reminder> reminders = new List<Reminder>();

//Add active reminders
reminders.AddRange(GetReminders().OrderBy(r => Convert.ToDateTime(r.Date.Split(',')[0])).Where(r => r.Enabled == 1).Where(r => r.Hide == 0).ToList());
//Add conditional (HTTP) reminders
reminders.AddRange(GetReminders(true).OrderBy(r => r.HttpId).Where(r => r.Enabled == 1).Where(r => r.Hide == 0).Where(r => r.HttpId != null).ToList());
//Add disabled reminders
reminders.AddRange(GetReminders().OrderBy(r => Convert.ToDateTime(r.Date.Split(',')[0])).Where(r => r.Enabled == 0).Where(r => r.Hide == 0).ToList());
//Add disabled conditional reminders
reminders.AddRange(GetReminders(true).OrderBy(r => r.HttpId).Where(r => r.Enabled == 0).Where(r => r.Hide == 0).Where(r => r.HttpId != null).ToList());

return reminders;
}

/// <summary>
/// Gets every reminder from the database
/// </summary>
Expand Down Expand Up @@ -667,12 +688,15 @@ public static Exception IsValidReminder(Reminder rem)
{
DateTime date;

//Check all possible dates
foreach (string stringDate in rem.Date.Split(','))
date = Convert.ToDateTime(stringDate);
if (rem.HttpId == null)
{
//Check all possible dates
foreach (string stringDate in rem.Date.Split(','))
date = Convert.ToDateTime(stringDate);

if (rem.PostponeDate != null)
date = Convert.ToDateTime(rem.PostponeDate.Split(',')[0]);
if (rem.PostponeDate != null)
date = Convert.ToDateTime(rem.PostponeDate.Split(',')[0]);
}


if (rem.Enabled > 1 || rem.Enabled < 0)
Expand Down Expand Up @@ -712,6 +736,11 @@ public static Exception IsValidReminder(Reminder rem)
AdvancedReminderProperties avrProps = DLLocalDatabase.AVRProperty.GetAVRProperties(rem.Id);
List<AdvancedReminderFilesFolders> avrFF = DLLocalDatabase.AVRProperty.GetAVRFilesFolders(rem.Id);

if (rem.HttpId != null)
{
HttpRequests req = DLLocalDatabase.HttpRequest.GetHttpRequest(rem.Id);
}

}
catch (Exception ex)
{
Expand Down Expand Up @@ -933,7 +962,14 @@ public static string GetRepeatTypeText(Reminder rem)
case "MONTHLY": return "Monthly";
case "WORKDAYS": return "Work days";
case "NONE": return "No repeat";

case "CONDITIONAL":
HttpRequests req = BLLocalDatabase.HttpRequest.GetHttpRequestById(rem.Id);
if (req.AfterPopup == "Stop")
return "No repeat";
else if (req.AfterPopup == "Repeat")
return "Interval";
else
return req.AfterPopup;
case "MULTIPLE_DAYS":
string dayString = "";
foreach (string day in rem.RepeatDays.Split(','))
Expand Down
3 changes: 3 additions & 0 deletions Business Logic Layer/Business Logic Layer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<HintPath>..\packages\HtmlAgilityPack.1.11.7\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand Down
Loading

0 comments on commit 7eb7fbd

Please sign in to comment.