mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
The move!
This commit is contained in:
parent
1daf480b1b
commit
25526cc4d9
1147 changed files with 85 additions and 8524 deletions
21
src/Ombi.Store/Context/IOmbiContext.cs
Normal file
21
src/Ombi.Store/Context/IOmbiContext.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Context
|
||||
{
|
||||
public interface IOmbiContext : IDisposable
|
||||
{
|
||||
int SaveChanges();
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||
DbSet<RequestBlobs> Requests { get; set; }
|
||||
DbSet<GlobalSettings> Settings { get; set; }
|
||||
DbSet<PlexContent> PlexContent { get; set; }
|
||||
DbSet<User> Users { get; set; }
|
||||
EntityEntry<GlobalSettings> Entry(GlobalSettings settings);
|
||||
EntityEntry<TEntity> Attach<TEntity>(TEntity entity) where TEntity : class;
|
||||
}
|
||||
}
|
49
src/Ombi.Store/Context/OmbiContext.cs
Normal file
49
src/Ombi.Store/Context/OmbiContext.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System.IO;
|
||||
using System.Resources;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Context
|
||||
{
|
||||
public class OmbiContext : DbContext, IOmbiContext
|
||||
{
|
||||
private static bool _created;
|
||||
public OmbiContext()
|
||||
{
|
||||
if (_created) return;
|
||||
|
||||
_created = true;
|
||||
Database.EnsureCreated();
|
||||
Database.Migrate();
|
||||
|
||||
#if DEBUG
|
||||
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
var directory = System.IO.Path.GetDirectoryName(location);
|
||||
var file = File.ReadAllText(Path.Combine(directory,"SqlTables.sql"));
|
||||
#else
|
||||
|
||||
var file = File.ReadAllText("SqlTables.sql");
|
||||
#endif
|
||||
// Run Script
|
||||
|
||||
Database.ExecuteSqlCommand(file, 0);
|
||||
}
|
||||
|
||||
public DbSet<RequestBlobs> Requests { get; set; }
|
||||
public DbSet<GlobalSettings> Settings { get; set; }
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<PlexContent> PlexContent { get; set; }
|
||||
|
||||
|
||||
public EntityEntry<GlobalSettings> Entry(GlobalSettings settings)
|
||||
{
|
||||
return Entry(settings);
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseSqlite("Data Source=Ombi.db");
|
||||
}
|
||||
}
|
||||
}
|
10
src/Ombi.Store/Entities/Entity.cs
Normal file
10
src/Ombi.Store/Entities/Entity.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Ombi.Store.Entities
|
||||
{
|
||||
public abstract class Entity
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
11
src/Ombi.Store/Entities/GlobalSettings.cs
Normal file
11
src/Ombi.Store/Entities/GlobalSettings.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("GlobalSettings")]
|
||||
public class GlobalSettings : Entity
|
||||
{
|
||||
public string Content { get; set; }
|
||||
public string SettingsName { get; set; }
|
||||
}
|
||||
}
|
68
src/Ombi.Store/Entities/PlexContent.cs
Normal file
68
src/Ombi.Store/Entities/PlexContent.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: PlexContent.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("PlexContent")]
|
||||
public class PlexContent : Entity
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string ReleaseYear { get; set; }
|
||||
public string ProviderId { get; set; }
|
||||
public PlexMediaTypeEntity Type { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only used for TV Shows
|
||||
/// </summary>
|
||||
public List<SeasonsContent> Seasons { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Plex's internal ID for this item
|
||||
/// </summary>
|
||||
public string Key { get; set; }
|
||||
public DateTime AddedAt { get; set; }
|
||||
}
|
||||
|
||||
public class SeasonsContent : Entity
|
||||
{
|
||||
public int SeasonNumber { get; set; }
|
||||
public int SeasonKey { get; set; }
|
||||
public int ParentKey { get; set; }
|
||||
}
|
||||
|
||||
public enum PlexMediaTypeEntity
|
||||
{
|
||||
Movie = 0,
|
||||
Show = 1
|
||||
}
|
||||
}
|
18
src/Ombi.Store/Entities/RequestBlobs.cs
Normal file
18
src/Ombi.Store/Entities/RequestBlobs.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Ombi.Store.Entities
|
||||
{
|
||||
[Table("RequestBlobs")]
|
||||
public class RequestBlobs : Entity
|
||||
{
|
||||
public int ProviderId { get; set; }
|
||||
public byte[] Content { get; set; }
|
||||
public RequestType Type { get; set; }
|
||||
|
||||
}
|
||||
public enum RequestType
|
||||
{
|
||||
Movie = 1,
|
||||
TvShow = 2
|
||||
}
|
||||
}
|
60
src/Ombi.Store/Entities/User.cs
Normal file
60
src/Ombi.Store/Entities/User.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: Users.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Security.Claims;
|
||||
using Newtonsoft.Json;
|
||||
using Ombi.Helpers;
|
||||
|
||||
|
||||
namespace Ombi.Store.Entities
|
||||
{
|
||||
public class User : Entity
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Alias { get; set; }
|
||||
public string ClaimsSerialized { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
public string Password { get; set; }
|
||||
public byte[] Salt { get; set; }
|
||||
public UserType UserType { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public List<Claim> Claims {
|
||||
get => JsonConvert.DeserializeObject<List<Claim>>(ClaimsSerialized, new ClaimConverter());
|
||||
set => ClaimsSerialized = JsonConvert.SerializeObject(value, new ClaimConverter());
|
||||
}
|
||||
}
|
||||
|
||||
public enum UserType
|
||||
{
|
||||
LocalUser = 1,
|
||||
PlexUser = 2,
|
||||
EmbyUser = 3,
|
||||
}
|
||||
}
|
42
src/Ombi.Store/Ombi.Store.csproj
Normal file
42
src/Ombi.Store/Ombi.Store.csproj
Normal file
|
@ -0,0 +1,42 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.6</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="SqlTables.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Design" Version="1.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="SqlTables.sql">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Helpers\Ombi.Helpers.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Sql.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Sql.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Sql.resx">
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Sql.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
</Project>
|
17
src/Ombi.Store/Repository/IPlexContentRepository.cs
Normal file
17
src/Ombi.Store/Repository/IPlexContentRepository.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface IPlexContentRepository
|
||||
{
|
||||
Task<PlexContent> Add(PlexContent content);
|
||||
Task AddRange(IEnumerable<PlexContent> content);
|
||||
Task<bool> ContentExists(string providerId);
|
||||
Task<IEnumerable<PlexContent>> GetAll();
|
||||
Task<PlexContent> Get(string providerId);
|
||||
Task<PlexContent> GetByKey(string key);
|
||||
Task Update(PlexContent existingContent);
|
||||
}
|
||||
}
|
21
src/Ombi.Store/Repository/IRequestRepository.cs
Normal file
21
src/Ombi.Store/Repository/IRequestRepository.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface IRequestRepository
|
||||
{
|
||||
void Delete(RequestBlobs entity);
|
||||
void DeleteAll(IEnumerable<RequestBlobs> entity);
|
||||
RequestBlobs Get(int id);
|
||||
IEnumerable<RequestBlobs> GetAll();
|
||||
Task<IEnumerable<RequestBlobs>> GetAllAsync();
|
||||
Task<IEnumerable<RequestBlobs>> GetAllAsync(int count, int position);
|
||||
Task<RequestBlobs> GetAsync(int id);
|
||||
RequestBlobs Insert(RequestBlobs entity);
|
||||
Task<RequestBlobs> InsertAsync(RequestBlobs entity);
|
||||
RequestBlobs Update(RequestBlobs entity);
|
||||
void UpdateAll(IEnumerable<RequestBlobs> entity);
|
||||
}
|
||||
}
|
49
src/Ombi.Store/Repository/ISettingsRepository.cs
Normal file
49
src/Ombi.Store/Repository/ISettingsRepository.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface ISettingsRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Inserts the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
GlobalSettings Insert(GlobalSettings entity);
|
||||
Task<GlobalSettings> InsertAsync(GlobalSettings entity);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerable<GlobalSettings> GetAll();
|
||||
Task<IEnumerable<GlobalSettings>> GetAllAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified identifier.
|
||||
/// </summary>
|
||||
/// <param name="settingsName">Name of the settings.</param>
|
||||
/// <returns></returns>
|
||||
GlobalSettings Get(string settingsName);
|
||||
Task<GlobalSettings> GetAsync(string settingsName);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
Task DeleteAsync(GlobalSettings entity);
|
||||
void Delete(GlobalSettings entity);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specified entity.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity.</param>
|
||||
/// <returns></returns>
|
||||
Task UpdateAsync(GlobalSettings entity);
|
||||
void Update(GlobalSettings entity);
|
||||
|
||||
|
||||
}
|
||||
}
|
15
src/Ombi.Store/Repository/IUserRepository.cs
Normal file
15
src/Ombi.Store/Repository/IUserRepository.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface IUserRepository
|
||||
{
|
||||
Task CreateUser(User user);
|
||||
Task<User> GetUser(string username);
|
||||
Task<IEnumerable<User>> GetUsers();
|
||||
Task DeleteUser(User user);
|
||||
Task<User> UpdateUser(User user);
|
||||
}
|
||||
}
|
85
src/Ombi.Store/Repository/PlexContentRepository.cs
Normal file
85
src/Ombi.Store/Repository/PlexContentRepository.cs
Normal file
|
@ -0,0 +1,85 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: PlexContentRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Store.Context;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class PlexContentRepository : IPlexContentRepository
|
||||
{
|
||||
|
||||
public PlexContentRepository(IOmbiContext db)
|
||||
{
|
||||
Db = db;
|
||||
}
|
||||
|
||||
private IOmbiContext Db { get; }
|
||||
|
||||
public async Task<IEnumerable<PlexContent>> GetAll()
|
||||
{
|
||||
return await Db.PlexContent.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task AddRange(IEnumerable<PlexContent> content)
|
||||
{
|
||||
await Db.PlexContent.AddRangeAsync(content);
|
||||
await Db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> ContentExists(string providerId)
|
||||
{
|
||||
return await Db.PlexContent.AnyAsync(x => x.ProviderId == providerId);
|
||||
}
|
||||
|
||||
public async Task<PlexContent> Add(PlexContent content)
|
||||
{
|
||||
await Db.PlexContent.AddAsync(content);
|
||||
await Db.SaveChangesAsync();
|
||||
return content;
|
||||
}
|
||||
|
||||
public async Task<PlexContent> Get(string providerId)
|
||||
{
|
||||
return await Db.PlexContent.FirstOrDefaultAsync(x => x.ProviderId == providerId);
|
||||
}
|
||||
|
||||
public async Task<PlexContent> GetByKey(string key)
|
||||
{
|
||||
return await Db.PlexContent.FirstOrDefaultAsync(x => x.Key == key);
|
||||
}
|
||||
|
||||
public async Task Update(PlexContent existingContent)
|
||||
{
|
||||
Db.PlexContent.Update(existingContent);
|
||||
await Db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
147
src/Ombi.Store/Repository/RequestJsonRepository.cs
Normal file
147
src/Ombi.Store/Repository/RequestJsonRepository.cs
Normal file
|
@ -0,0 +1,147 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Store.Context;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class RequestJsonRepository : IRequestRepository
|
||||
{
|
||||
//private ICacheProvider Cache { get; }
|
||||
|
||||
public RequestJsonRepository(IOmbiContext ctx)
|
||||
{
|
||||
Db = ctx;
|
||||
}
|
||||
|
||||
private IOmbiContext Db { get; }
|
||||
|
||||
public RequestBlobs Insert(RequestBlobs entity)
|
||||
{
|
||||
|
||||
var id = Db.Requests.Add(entity);
|
||||
Db.SaveChanges();
|
||||
return id.Entity;
|
||||
|
||||
}
|
||||
|
||||
public async Task<RequestBlobs> InsertAsync(RequestBlobs entity)
|
||||
{
|
||||
|
||||
var id = await Db.Requests.AddAsync(entity).ConfigureAwait(false);
|
||||
await Db.SaveChangesAsync();
|
||||
return id.Entity;
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<RequestBlobs> GetAll()
|
||||
{
|
||||
//var key = "GetAll";
|
||||
//var item = Cache.GetOrSet(key, () =>
|
||||
//{
|
||||
|
||||
var page = Db.Requests.ToList();
|
||||
return page;
|
||||
|
||||
//}, 5);
|
||||
//return item;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RequestBlobs>> GetAllAsync()
|
||||
{
|
||||
//var key = "GetAll";
|
||||
//var item = await Cache.GetOrSetAsync(key, async () =>
|
||||
//{
|
||||
|
||||
var page = await Db.Requests.ToListAsync().ConfigureAwait(false);
|
||||
return page;
|
||||
|
||||
//}, 5);
|
||||
//return item;
|
||||
}
|
||||
public async Task<IEnumerable<RequestBlobs>> GetAllAsync(int count, int position)
|
||||
{
|
||||
//var key = "GetAll";
|
||||
//var item = await Cache.GetOrSetAsync(key, async () =>
|
||||
//{
|
||||
|
||||
var page = await Db.Requests.ToListAsync().ConfigureAwait(false);
|
||||
return page.Skip(position).Take(count);
|
||||
|
||||
//}, 5);
|
||||
//return item;
|
||||
}
|
||||
|
||||
public RequestBlobs Get(int id)
|
||||
{
|
||||
//var key = "Get" + id;
|
||||
//var item = Cache.GetOrSet(key, () =>
|
||||
//{
|
||||
|
||||
var page = Db.Requests.Find(id);
|
||||
return page;
|
||||
|
||||
//}, 5);
|
||||
//return item;
|
||||
}
|
||||
|
||||
public async Task<RequestBlobs> GetAsync(int id)
|
||||
{
|
||||
//var key = "Get" + id;
|
||||
//var item = await Cache.GetOrSetAsync(key, async () =>
|
||||
//{
|
||||
|
||||
var page = await Db.Requests.FindAsync(id).ConfigureAwait(false);
|
||||
return page;
|
||||
|
||||
//}, 5);
|
||||
//return item;
|
||||
}
|
||||
|
||||
public void Delete(RequestBlobs entity)
|
||||
{
|
||||
//ResetCache();
|
||||
|
||||
Db.Requests.Remove(entity);
|
||||
Db.SaveChanges();
|
||||
|
||||
}
|
||||
|
||||
public RequestBlobs Update(RequestBlobs entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
Db.SaveChanges();
|
||||
|
||||
return entity;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void UpdateAll(IEnumerable<RequestBlobs> entity)
|
||||
{
|
||||
|
||||
Db.Requests.UpdateRange(entity);
|
||||
Db.SaveChanges();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void DeleteAll(IEnumerable<RequestBlobs> entity)
|
||||
{
|
||||
|
||||
Db.Requests.RemoveRange(entity);
|
||||
Db.SaveChanges();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
82
src/Ombi.Store/Repository/SettingsJsonRepository.cs
Normal file
82
src/Ombi.Store/Repository/SettingsJsonRepository.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Store.Context;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class SettingsJsonRepository : ISettingsRepository
|
||||
{
|
||||
public SettingsJsonRepository(IOmbiContext ctx)
|
||||
{
|
||||
Db = ctx;
|
||||
}
|
||||
|
||||
private IOmbiContext Db { get; }
|
||||
|
||||
public GlobalSettings Insert(GlobalSettings entity)
|
||||
{
|
||||
|
||||
var settings = Db.Settings.Add(entity);
|
||||
Db.SaveChanges();
|
||||
return settings.Entity;
|
||||
|
||||
}
|
||||
|
||||
public async Task<GlobalSettings> InsertAsync(GlobalSettings entity)
|
||||
{
|
||||
|
||||
var settings = await Db.Settings.AddAsync(entity).ConfigureAwait(false);
|
||||
await Db.SaveChangesAsync().ConfigureAwait(false);
|
||||
return settings.Entity;
|
||||
}
|
||||
|
||||
public IEnumerable<GlobalSettings> GetAll()
|
||||
{
|
||||
|
||||
var page = Db.Settings.ToList();
|
||||
return page;
|
||||
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<GlobalSettings>> GetAllAsync()
|
||||
{
|
||||
var page = await Db.Settings.ToListAsync();
|
||||
return page;
|
||||
}
|
||||
|
||||
public GlobalSettings Get(string pageName)
|
||||
{
|
||||
return Db.Settings.FirstOrDefault(x => x.SettingsName == pageName);
|
||||
}
|
||||
|
||||
public async Task<GlobalSettings> GetAsync(string settingsName)
|
||||
{
|
||||
return await Db.Settings.FirstOrDefaultAsync(x => x.SettingsName == settingsName);
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(GlobalSettings entity)
|
||||
{
|
||||
Db.Settings.Remove(entity);
|
||||
await Db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(GlobalSettings entity)
|
||||
{
|
||||
await Db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void Delete(GlobalSettings entity)
|
||||
{
|
||||
Db.Settings.Remove(entity);
|
||||
Db.SaveChanges();
|
||||
}
|
||||
|
||||
public void Update(GlobalSettings entity)
|
||||
{
|
||||
Db.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
75
src/Ombi.Store/Repository/UserRepository.cs
Normal file
75
src/Ombi.Store/Repository/UserRepository.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2017 Jamie Rees
|
||||
// File: UserRepository.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Store.Context;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class UserRepository : IUserRepository
|
||||
{
|
||||
public UserRepository(IOmbiContext ctx)
|
||||
{
|
||||
Db = ctx;
|
||||
}
|
||||
|
||||
private IOmbiContext Db { get; }
|
||||
|
||||
public async Task<User> GetUser(string username)
|
||||
{
|
||||
return await Db.Users.FirstOrDefaultAsync(x => x.Username.ToLower() == username.ToLower());
|
||||
}
|
||||
|
||||
public async Task CreateUser(User user)
|
||||
{
|
||||
Db.Users.Add(user);
|
||||
await Db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<User>> GetUsers()
|
||||
{
|
||||
return await Db.Users.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteUser(User user)
|
||||
{
|
||||
Db.Users.Remove(user);
|
||||
await Db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<User> UpdateUser(User user)
|
||||
{
|
||||
Db.Users.Update(user);
|
||||
await Db.SaveChangesAsync();
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
89
src/Ombi.Store/Sql.Designer.cs
generated
Normal file
89
src/Ombi.Store/Sql.Designer.cs
generated
Normal file
|
@ -0,0 +1,89 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Ombi.Store {
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
public class Sql {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Sql() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Ombi.Store.Sql", typeof(Sql).GetTypeInfo().Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
public static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to CREATE TABLE IF NOT EXISTS GlobalSettings
|
||||
///(
|
||||
/// Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
/// SettingsName varchar(50) NOT NULL,
|
||||
/// Content BLOB NOT NULL
|
||||
///);
|
||||
///
|
||||
///CREATE TABLE IF NOT EXISTS PlexContent
|
||||
///(
|
||||
/// Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
/// Title varchar(50) NOT NULL,
|
||||
/// ProviderId varchar(50) NOT NULL,
|
||||
/// Url varchar(100) NOT NULL,
|
||||
/// Key varchar(50) NOT NULL,
|
||||
/// AddedAt varchar(50) NOT NULL,
|
||||
/// Type INTEGER NOT NULL,
|
||||
/// Relea [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
public static string SqlTables {
|
||||
get {
|
||||
return ResourceManager.GetString("SqlTables", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
124
src/Ombi.Store/Sql.resx
Normal file
124
src/Ombi.Store/Sql.resx
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="SqlTables" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>SqlTables.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||
</data>
|
||||
</root>
|
49
src/Ombi.Store/SqlTables.sql
Normal file
49
src/Ombi.Store/SqlTables.sql
Normal file
|
@ -0,0 +1,49 @@
|
|||
CREATE TABLE IF NOT EXISTS GlobalSettings
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
SettingsName varchar(50) NOT NULL,
|
||||
Content BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS PlexContent
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
Title varchar(50) NOT NULL,
|
||||
ProviderId varchar(50) NOT NULL,
|
||||
Url varchar(100) NOT NULL,
|
||||
Key varchar(50) NOT NULL,
|
||||
AddedAt varchar(50) NOT NULL,
|
||||
Type INTEGER NOT NULL,
|
||||
ReleaseYear varchar(100) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS SeasonsContent
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
SeasonNumber INTEGER NOT NULL,
|
||||
SeasonKey INTEGER NOT NULL,
|
||||
ParentKey INTEGER NOT NULL
|
||||
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS RequestBlobs
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ProviderId INTEGER NOT NULL,
|
||||
Content BLOB NOT NULL,
|
||||
Type INTEGER NOT NULL
|
||||
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Users
|
||||
(
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
Username VARCHAR(100) NOT NULL,
|
||||
Alias VARCHAR(100) NULL,
|
||||
ClaimsSerialized BLOB NOT NULL,
|
||||
EmailAddress VARCHAR(100) NULL,
|
||||
Password VARCHAR(100) NULL,
|
||||
Salt BLOB NULL,
|
||||
UserType INTEGER NOT NULL
|
||||
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue