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 SendToPlexUsers { get; set; }
public string CustomUsers { get; set; }
[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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -78,22 +79,25 @@ namespace Ombi.Helpers
while (delimiterIndex >= 0)
{
delimiterIndex = input.IndexOf(delimiter, startIndex);
string substring = input;
if (delimiterIndex > 0)
if (input != null)
{
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("\""))
{
yield return substring;
input = input.Substring(delimiterIndex + 1).Trim();
startIndex = 0;
}
else
{
startIndex = delimiterIndex + 1;
if (!substring.Contains("\"") || substring.IndexOf("\"", StringComparison.Ordinal) != substring.LastIndexOf("\"", StringComparison.Ordinal))
{
yield return substring;
input = input.Substring(delimiterIndex + 1).Trim();
startIndex = 0;
}
else
{
startIndex = delimiterIndex + 1;
}
}
}
}

@ -234,64 +234,124 @@ namespace Ombi.Services.Jobs
var movies = GetPlexMovies(results);
// Time to destroy the plex movies from the DB
PlexContent.Custom(connection =>
{
connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 0 });
return new List<PlexContent>();
});
//// Time to destroy the plex movies from the DB
//PlexContent.Custom(connection =>
//{
// connection.Open();
// connection.Query("delete from PlexContent where type = @type", new { type = 0 });
// return new List<PlexContent>();
//});
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,
ReleaseYear = m.ReleaseYear ?? string.Empty,
Title = m.Title,
Type = Store.Models.Plex.PlexMediaType.Movie,
Url = m.Url
connection.Open();
var media = connection.QueryFirstOrDefault<PlexContent>("select * from PlexContent where ProviderId = @ProviderId and type = @type", new { m.ProviderId, type = 0 });
connection.Dispose();
return media;
});
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);
// Time to destroy the plex tv from the DB
PlexContent.Custom(connection =>
{
connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 1 });
return new List<PlexContent>();
});
//// Time to destroy the plex tv from the DB
//PlexContent.Custom(connection =>
//{
// connection.Open();
// connection.Query("delete from PlexContent where type = @type", new { type = 1 });
// return new List<PlexContent>();
//});
foreach (var t in tv)
{
PlexContent.Insert(new PlexContent
if (string.IsNullOrEmpty(t.ProviderId))
{
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)
Log.Error("Provider Id on tv {0} is null", t.Title);
continue;
}
// 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);
// Time to destroy the plex movies from the DB
PlexContent.Custom(connection =>
{
connection.Open();
connection.Query("delete from PlexContent where type = @type", new { type = 2 });
return new List<PlexContent>();
});
//// Time to destroy the plex movies from the DB
//PlexContent.Custom(connection =>
//{
// connection.Open();
// connection.Query("delete from PlexContent where type = @type", new { type = 2 });
// return new List<PlexContent>();
//});
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,
ReleaseYear = a.ReleaseYear ?? string.Empty,
Title = a.Title,
Type = Store.Models.Plex.PlexMediaType.Artist,
Url = a.Url
connection.Open();
var media = connection.QueryFirstOrDefault<PlexContent>("select * from PlexContent where ProviderId = @ProviderId and type = @type", new { a.ProviderId, type = 2 });
connection.Dispose();
return media;
});
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)
{
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;
}
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);

@ -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)
{
using (var cnn = Connection)
@ -72,6 +80,13 @@ namespace Ombi.Store.Repository
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)
{

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

Loading…
Cancel
Save