pull/848/head
Jamie.Rees 8 years ago
parent 2d7ded325f
commit 698356d55e

@ -36,10 +36,21 @@ namespace Ombi.Core.SettingModels
public bool SendRecentlyAddedEmail { get; set; } public bool SendRecentlyAddedEmail { get; set; }
public bool SendToPlexUsers { get; set; } public bool SendToPlexUsers { get; set; }
public string CustomUsers { get; set; } public string CustomUsers { get; set; }
[JsonIgnore] [JsonIgnore]
public IEnumerable<string> CustomUsersEmailAddresses => CustomUsers.SplitEmailsByDelimiter(';'); public IEnumerable<string> CustomUsersEmailAddresses
{
get
{
var retVal = (IEnumerable<string>)new List<string>();
if (!string.IsNullOrEmpty(CustomUsers))
{
retVal = CustomUsers.SplitEmailsByDelimiter(';');
}
return retVal;
}
}
} }
} }

@ -25,6 +25,7 @@
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -78,22 +79,25 @@ namespace Ombi.Helpers
while (delimiterIndex >= 0) while (delimiterIndex >= 0)
{ {
delimiterIndex = input.IndexOf(delimiter, startIndex); if (input != null)
string substring = input;
if (delimiterIndex > 0)
{ {
substring = input.Substring(0, delimiterIndex).Trim(); delimiterIndex = input.IndexOf(delimiter, startIndex);
} var substring = input;
if (delimiterIndex > 0)
{
substring = input.Substring(0, delimiterIndex).Trim();
}
if (!substring.Contains("\"") || substring.IndexOf("\"") != substring.LastIndexOf("\"")) if (!substring.Contains("\"") || substring.IndexOf("\"", StringComparison.Ordinal) != substring.LastIndexOf("\"", StringComparison.Ordinal))
{ {
yield return substring; yield return substring;
input = input.Substring(delimiterIndex + 1).Trim(); input = input.Substring(delimiterIndex + 1).Trim();
startIndex = 0; startIndex = 0;
} }
else else
{ {
startIndex = delimiterIndex + 1; startIndex = delimiterIndex + 1;
}
} }
} }
} }

@ -234,64 +234,124 @@ namespace Ombi.Services.Jobs
var movies = GetPlexMovies(results); var movies = GetPlexMovies(results);
// Time to destroy the plex movies from the DB //// Time to destroy the plex movies from the DB
PlexContent.Custom(connection => //PlexContent.Custom(connection =>
{ //{
connection.Open(); // connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 0 }); // connection.Query("delete from PlexContent where type = @type", new { type = 0 });
return new List<PlexContent>(); // return new List<PlexContent>();
}); //});
foreach (var m in movies) foreach (var m in movies)
{ {
PlexContent.Insert(new PlexContent if (string.IsNullOrEmpty(m.ProviderId))
{
Log.Error("Provider Id on movie {0} is null",m.Title);
continue;
}
// Check if it exists
var item = PlexContent.Custom(connection =>
{ {
ProviderId = m.ProviderId, connection.Open();
ReleaseYear = m.ReleaseYear ?? string.Empty, var media = connection.QueryFirstOrDefault<PlexContent>("select * from PlexContent where ProviderId = @ProviderId and type = @type", new { m.ProviderId, type = 0 });
Title = m.Title, connection.Dispose();
Type = Store.Models.Plex.PlexMediaType.Movie, return media;
Url = m.Url
}); });
if (item == null)
{
// Doesn't exist, insert it
PlexContent.Insert(new PlexContent
{
ProviderId = m.ProviderId,
ReleaseYear = m.ReleaseYear ?? string.Empty,
Title = m.Title,
Type = Store.Models.Plex.PlexMediaType.Movie,
Url = m.Url
});
}
} }
var tv = GetPlexTvShows(results); var tv = GetPlexTvShows(results);
// Time to destroy the plex tv from the DB //// Time to destroy the plex tv from the DB
PlexContent.Custom(connection => //PlexContent.Custom(connection =>
{ //{
connection.Open(); // connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 1 }); // connection.Query("delete from PlexContent where type = @type", new { type = 1 });
return new List<PlexContent>(); // return new List<PlexContent>();
}); //});
foreach (var t in tv) foreach (var t in tv)
{ {
PlexContent.Insert(new PlexContent if (string.IsNullOrEmpty(t.ProviderId))
{ {
ProviderId = t.ProviderId, Log.Error("Provider Id on tv {0} is null", t.Title);
ReleaseYear = t.ReleaseYear ?? string.Empty, continue;
Title = t.Title, }
Type = Store.Models.Plex.PlexMediaType.Show,
Url = t.Url,
Seasons = ByteConverterHelper.ReturnBytes(t.Seasons) // Check if it exists
var item = PlexContent.Custom(connection =>
{
connection.Open();
var media = connection.QueryFirstOrDefault<PlexContent>("select * from PlexContent where ProviderId = @ProviderId and type = @type", new { t.ProviderId, type = 1 });
connection.Dispose();
return media;
}); });
if (item == null)
{
PlexContent.Insert(new PlexContent
{
ProviderId = t.ProviderId,
ReleaseYear = t.ReleaseYear ?? string.Empty,
Title = t.Title,
Type = Store.Models.Plex.PlexMediaType.Show,
Url = t.Url,
Seasons = ByteConverterHelper.ReturnBytes(t.Seasons)
});
}
} }
var albums = GetPlexAlbums(results); var albums = GetPlexAlbums(results);
// Time to destroy the plex movies from the DB //// Time to destroy the plex movies from the DB
PlexContent.Custom(connection => //PlexContent.Custom(connection =>
{ //{
connection.Open(); // connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 2 }); // connection.Query("delete from PlexContent where type = @type", new { type = 2 });
return new List<PlexContent>(); // return new List<PlexContent>();
}); //});
foreach (var a in albums) foreach (var a in albums)
{ {
PlexContent.Insert(new PlexContent if (string.IsNullOrEmpty(a.ProviderId))
{
Log.Error("Provider Id on album {0} is null", a.Title);
continue;
}
// Check if it exists
var item = PlexContent.Custom(connection =>
{ {
ProviderId = a.ProviderId, connection.Open();
ReleaseYear = a.ReleaseYear ?? string.Empty, var media = connection.QueryFirstOrDefault<PlexContent>("select * from PlexContent where ProviderId = @ProviderId and type = @type", new { a.ProviderId, type = 2 });
Title = a.Title, connection.Dispose();
Type = Store.Models.Plex.PlexMediaType.Artist, return media;
Url = a.Url
}); });
if (item == null)
{
PlexContent.Insert(new PlexContent
{
ProviderId = a.ProviderId,
ReleaseYear = a.ReleaseYear ?? string.Empty,
Title = a.Title,
Type = Store.Models.Plex.PlexMediaType.Artist,
Url = a.Url
});
}
} }
} }
} }

@ -472,7 +472,10 @@ namespace Ombi.Services.Jobs
{ {
foreach (var user in newletterSettings.CustomUsersEmailAddresses) foreach (var user in newletterSettings.CustomUsersEmailAddresses)
{ {
message.Bcc.Add(new MailboxAddress(user, user)); if (!string.IsNullOrEmpty(user))
{
message.Bcc.Add(new MailboxAddress(user, user));
}
} }
} }
} }

@ -81,7 +81,11 @@ namespace Ombi.Services.Notification
continue; continue;
} }
selectedUsers.Add(requestUser); // Make sure we do not already have the user
if (!selectedUsers.Contains(requestUser))
{
selectedUsers.Add(requestUser);
}
} }
//var selectedUsers = users.Select(x => x.Username).Intersect(model.RequestedUsers, StringComparer.CurrentCultureIgnoreCase); //var selectedUsers = users.Select(x => x.Username).Intersect(model.RequestedUsers, StringComparer.CurrentCultureIgnoreCase);

@ -65,6 +65,14 @@ namespace Ombi.Store.Repository
} }
} }
public T Custom(Func<IDbConnection, T> func)
{
using (var cnn = Connection)
{
return func(cnn);
}
}
public async Task<IEnumerable<T>> CustomAsync(Func<IDbConnection, Task<IEnumerable<T>>> func) public async Task<IEnumerable<T>> CustomAsync(Func<IDbConnection, Task<IEnumerable<T>>> func)
{ {
using (var cnn = Connection) using (var cnn = Connection)
@ -72,6 +80,13 @@ namespace Ombi.Store.Repository
return await func(cnn); return await func(cnn);
} }
} }
public async Task<T> CustomAsync(Func<IDbConnection, Task<T>> func)
{
using (var cnn = Connection)
{
return await func(cnn);
}
}
public long Insert(T entity) public long Insert(T entity)
{ {

@ -87,5 +87,8 @@ namespace Ombi.Store.Repository
Task<IEnumerable<T>> CustomAsync(Func<IDbConnection, Task<IEnumerable<T>>> func); Task<IEnumerable<T>> CustomAsync(Func<IDbConnection, Task<IEnumerable<T>>> func);
void DeleteAll(string tableName); void DeleteAll(string tableName);
Task DeleteAllAsync(string tableName); Task DeleteAllAsync(string tableName);
T Custom(Func<IDbConnection, T> func);
Task<T> CustomAsync(Func<IDbConnection, Task<T>> func);
} }
} }

Loading…
Cancel
Save