diff --git a/Notesnook.API/Models/Announcement.cs b/Notesnook.API/Models/Announcement.cs
index 649df50..8917d5c 100644
--- a/Notesnook.API/Models/Announcement.cs
+++ b/Notesnook.API/Models/Announcement.cs
@@ -22,11 +22,9 @@ using System.Runtime.Serialization;
using System.Text.Json.Serialization;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
-using Streetwriters.Data.Attributes;
namespace Notesnook.API.Models
{
- [BsonCollection("notesnook", "announcements")]
public class Announcement
{
public Announcement()
diff --git a/Notesnook.API/Models/Monograph.cs b/Notesnook.API/Models/Monograph.cs
index 0b521a6..992df02 100644
--- a/Notesnook.API/Models/Monograph.cs
+++ b/Notesnook.API/Models/Monograph.cs
@@ -21,11 +21,9 @@ using System.Text.Json.Serialization;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Notesnook.API.Interfaces;
-using Streetwriters.Data.Attributes;
namespace Notesnook.API.Models
{
- [BsonCollection("notesnook", "monographs")]
public class Monograph : IMonograph
{
public Monograph()
diff --git a/Notesnook.API/Models/SyncItem.cs b/Notesnook.API/Models/SyncItem.cs
index 1b8fbfa..f4cf969 100644
--- a/Notesnook.API/Models/SyncItem.cs
+++ b/Notesnook.API/Models/SyncItem.cs
@@ -23,13 +23,14 @@ using System.Text.Json.Serialization;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Notesnook.API.Interfaces;
-using Streetwriters.Data.Attributes;
namespace Notesnook.API.Models
{
+ [MessagePack.MessagePackObject]
public class SyncItem : ISyncItem
{
[IgnoreDataMember]
+ [MessagePack.IgnoreMember]
[JsonPropertyName("dateSynced")]
public long DateSynced
{
@@ -38,6 +39,7 @@ namespace Notesnook.API.Models
[DataMember(Name = "userId")]
[JsonPropertyName("userId")]
+ [MessagePack.Key("userId")]
public string UserId
{
get; set;
@@ -45,6 +47,7 @@ namespace Notesnook.API.Models
[JsonPropertyName("iv")]
[DataMember(Name = "iv")]
+ [MessagePack.Key("iv")]
[Required]
public string IV
{
@@ -54,6 +57,7 @@ namespace Notesnook.API.Models
[JsonPropertyName("cipher")]
[DataMember(Name = "cipher")]
+ [MessagePack.Key("cipher")]
[Required]
public string Cipher
{
@@ -62,6 +66,7 @@ namespace Notesnook.API.Models
[DataMember(Name = "id")]
[JsonPropertyName("id")]
+ [MessagePack.Key("id")]
public string ItemId
{
get; set;
@@ -71,6 +76,7 @@ namespace Notesnook.API.Models
[BsonIgnoreIfDefault]
[BsonRepresentation(BsonType.ObjectId)]
[JsonIgnore]
+ [MessagePack.IgnoreMember]
public ObjectId Id
{
get; set;
@@ -78,6 +84,7 @@ namespace Notesnook.API.Models
[JsonPropertyName("length")]
[DataMember(Name = "length")]
+ [MessagePack.Key("length")]
[Required]
public long Length
{
@@ -86,6 +93,7 @@ namespace Notesnook.API.Models
[JsonPropertyName("v")]
[DataMember(Name = "v")]
+ [MessagePack.Key("v")]
[Required]
public double Version
{
@@ -94,6 +102,7 @@ namespace Notesnook.API.Models
[JsonPropertyName("alg")]
[DataMember(Name = "alg")]
+ [MessagePack.Key("alg")]
[Required]
public string Algorithm
{
@@ -101,33 +110,33 @@ namespace Notesnook.API.Models
} = Algorithms.Default;
}
- [BsonCollection("notesnook", "attachments")]
+ [MessagePack.MessagePackObject]
public class Attachment : SyncItem { }
- [BsonCollection("notesnook", "content")]
+ [MessagePack.MessagePackObject]
public class Content : SyncItem { }
- [BsonCollection("notesnook", "notes")]
+ [MessagePack.MessagePackObject]
public class Note : SyncItem { }
- [BsonCollection("notesnook", "notebooks")]
+ [MessagePack.MessagePackObject]
public class Notebook : SyncItem { }
- [BsonCollection("notesnook", "relations")]
+ [MessagePack.MessagePackObject]
public class Relation : SyncItem { }
- [BsonCollection("notesnook", "reminders")]
+ [MessagePack.MessagePackObject]
public class Reminder : SyncItem { }
- [BsonCollection("notesnook", "settings")]
+ [MessagePack.MessagePackObject]
public class Setting : SyncItem { }
- [BsonCollection("notesnook", "shortcuts")]
+ [MessagePack.MessagePackObject]
public class Shortcut : SyncItem { }
- [BsonCollection("notesnook", "tags")]
+ [MessagePack.MessagePackObject]
public class Tag : SyncItem { }
- [BsonCollection("notesnook", "colors")]
+ [MessagePack.MessagePackObject]
public class Color : SyncItem { }
}
diff --git a/Notesnook.API/Models/UserSettings.cs b/Notesnook.API/Models/UserSettings.cs
index ad32215..885ec93 100644
--- a/Notesnook.API/Models/UserSettings.cs
+++ b/Notesnook.API/Models/UserSettings.cs
@@ -20,11 +20,9 @@ along with this program. If not, see .
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Notesnook.API.Interfaces;
-using Streetwriters.Data.Attributes;
namespace Notesnook.API.Models
{
- [BsonCollection("notesnook", "user_settings")]
public class UserSettings : IUserSettings
{
public UserSettings()
diff --git a/Notesnook.API/Repositories/SyncItemsRepository.cs b/Notesnook.API/Repositories/SyncItemsRepository.cs
index 1663fdc..90faa70 100644
--- a/Notesnook.API/Repositories/SyncItemsRepository.cs
+++ b/Notesnook.API/Repositories/SyncItemsRepository.cs
@@ -35,13 +35,13 @@ using Streetwriters.Data.Repositories;
namespace Notesnook.API.Repositories
{
- public class SyncItemsRepository : Repository where T : SyncItem
+ public class SyncItemsRepository : Repository where T : SyncItem
{
- public SyncItemsRepository(IDbContext dbContext) : base(dbContext)
+ public SyncItemsRepository(IDbContext dbContext, string databaseName, string collectionName) : base(dbContext, databaseName, collectionName)
{
- Collection.Indexes.CreateOne(new CreateIndexModel(Builders.IndexKeys.Ascending(i => i.UserId).Descending(i => i.DateSynced)));
- Collection.Indexes.CreateOne(new CreateIndexModel(Builders.IndexKeys.Ascending(i => i.UserId).Ascending((i) => i.ItemId)));
- Collection.Indexes.CreateOne(new CreateIndexModel(Builders.IndexKeys.Ascending(i => i.UserId)));
+ Collection.Indexes.CreateOne(new CreateIndexModel(Builders.IndexKeys.Ascending(i => i.UserId).Descending(i => i.DateSynced)));
+ Collection.Indexes.CreateOne(new CreateIndexModel(Builders.IndexKeys.Ascending(i => i.UserId).Ascending((i) => i.ItemId)));
+ Collection.Indexes.CreateOne(new CreateIndexModel(Builders.IndexKeys.Ascending(i => i.UserId)));
}
private readonly List ALGORITHMS = new List { Algorithms.Default };
@@ -85,7 +85,7 @@ namespace Notesnook.API.Repositories
await base.UpsertAsync(item, (x) => (x.ItemId == item.ItemId) && x.UserId == userId);
}
- public void Upsert(T item, string userId, long dateSynced)
+ public void Upsert(SyncItem item, string userId, long dateSynced)
{
if (item.Length > 15 * 1024 * 1024)
diff --git a/Notesnook.API/Startup.cs b/Notesnook.API/Startup.cs
index 9a1d72d..cbb96f4 100644
--- a/Notesnook.API/Startup.cs
+++ b/Notesnook.API/Startup.cs
@@ -179,8 +179,20 @@ namespace Notesnook.API
services.AddScoped();
services.AddScoped();
- services.AddScoped(typeof(Repository<>));
- services.AddScoped(typeof(SyncItemsRepository<>));
+
+ services.AddScoped((provider) => new Repository(provider.GetRequiredService(), "notesnook", "user_settings"));
+ services.AddScoped((provider) => new Repository(provider.GetRequiredService(), "notesnook", "monographs"));
+ services.AddScoped((provider) => new Repository(provider.GetRequiredService(), "notesnook", "announcements"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "attachments"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "content"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "notes"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "notebooks"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "relations"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "reminders"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "settings"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "shortcuts"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "tags"));
+ services.AddScoped((provider) => new SyncItemsRepository(provider.GetRequiredService(), "notesnook", "colors"));
services.TryAddTransient();
services.TryAddTransient();
@@ -192,8 +204,9 @@ namespace Notesnook.API
services.AddSignalR((hub) =>
{
hub.MaximumReceiveMessageSize = 100 * 1024 * 1024;
+ hub.ClientTimeoutInterval = TimeSpan.FromMinutes(10);
hub.EnableDetailedErrors = true;
- }).AddMessagePackProtocol();
+ }).AddMessagePackProtocol().AddJsonProtocol();
services.AddResponseCompression(options =>
{
diff --git a/Streetwriters.Common/Models/Offer.cs b/Streetwriters.Common/Models/Offer.cs
index 11edf71..45bb7de 100644
--- a/Streetwriters.Common/Models/Offer.cs
+++ b/Streetwriters.Common/Models/Offer.cs
@@ -26,11 +26,9 @@ using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Streetwriters.Common.Enums;
using Streetwriters.Common.Interfaces;
-using Streetwriters.Data.Attributes;
namespace Streetwriters.Common.Models
{
- [BsonCollection("subscriptions", "offers")]
public class Offer : IOffer
{
public Offer()
diff --git a/Streetwriters.Common/Models/Role.cs b/Streetwriters.Common/Models/Role.cs
index b81bd1b..7264fb6 100644
--- a/Streetwriters.Common/Models/Role.cs
+++ b/Streetwriters.Common/Models/Role.cs
@@ -20,11 +20,9 @@ along with this program. If not, see .
using AspNetCore.Identity.Mongo.Model;
-using Streetwriters.Data.Attributes;
namespace Streetwriters.Common.Models
{
- [BsonCollection("identity", "roles")]
public class Role : MongoRole
{
// [DataMember(Name = "email")]
diff --git a/Streetwriters.Common/Models/Subscription.cs b/Streetwriters.Common/Models/Subscription.cs
index 33906bb..8c28910 100644
--- a/Streetwriters.Common/Models/Subscription.cs
+++ b/Streetwriters.Common/Models/Subscription.cs
@@ -24,11 +24,9 @@ using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using Streetwriters.Common.Enums;
using Streetwriters.Common.Interfaces;
-using Streetwriters.Data.Attributes;
namespace Streetwriters.Common.Models
{
- [BsonCollection("subscriptions", "subscriptions")]
public class Subscription : ISubscription
{
public Subscription()
diff --git a/Streetwriters.Common/Models/User.cs b/Streetwriters.Common/Models/User.cs
index 5b50286..ba888fa 100644
--- a/Streetwriters.Common/Models/User.cs
+++ b/Streetwriters.Common/Models/User.cs
@@ -20,11 +20,9 @@ along with this program. If not, see .
using AspNetCore.Identity.Mongo.Model;
-using Streetwriters.Data.Attributes;
namespace Streetwriters.Common.Models
{
- [BsonCollection("identity", "users")]
public class User : MongoUser
{
}
diff --git a/Streetwriters.Data/Attributes/BsonCollection.cs b/Streetwriters.Data/Attributes/BsonCollection.cs
deleted file mode 100644
index 0fd8d74..0000000
--- a/Streetwriters.Data/Attributes/BsonCollection.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-This file is part of the Notesnook Sync Server project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the Affero GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-Affero GNU General Public License for more details.
-
-You should have received a copy of the Affero GNU General Public License
-along with this program. If not, see .
-*/
-
-using System;
-
-namespace Streetwriters.Data.Attributes
-{
- [AttributeUsage(AttributeTargets.Class, Inherited = false)]
- public class BsonCollectionAttribute : Attribute
- {
- public string CollectionName { get; }
- public string DatabaseName { get; }
-
- public BsonCollectionAttribute(string databaseName, string collectionName)
- {
- CollectionName = collectionName;
- DatabaseName = databaseName;
- }
- }
-}
\ No newline at end of file
diff --git a/Streetwriters.Data/Repositories/Repository.cs b/Streetwriters.Data/Repositories/Repository.cs
index 2ebc85a..3d4f6f1 100644
--- a/Streetwriters.Data/Repositories/Repository.cs
+++ b/Streetwriters.Data/Repositories/Repository.cs
@@ -24,7 +24,6 @@ using System.Linq.Expressions;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
-using Streetwriters.Data.Attributes;
using Streetwriters.Data.Interfaces;
namespace Streetwriters.Data.Repositories
@@ -34,19 +33,15 @@ namespace Streetwriters.Data.Repositories
protected readonly IDbContext dbContext;
protected IMongoCollection Collection { get; set; }
- public Repository(IDbContext _dbContext)
+ public Repository(IDbContext _dbContext, string databaseName, string collectionName)
{
dbContext = _dbContext;
- Collection = GetCollection();
+ Collection = GetCollection(databaseName, collectionName);
}
- private protected IMongoCollection GetCollection()
+ private protected IMongoCollection GetCollection(string databaseName, string collectionName)
{
- var attribute = (BsonCollectionAttribute)typeof(TEntity).GetCustomAttributes(
- typeof(BsonCollectionAttribute),
- true).FirstOrDefault();
- if (string.IsNullOrEmpty(attribute.CollectionName) || string.IsNullOrEmpty(attribute.DatabaseName)) throw new Exception("Could not get a valid collection or database name.");
- return dbContext.GetCollection(attribute.DatabaseName, attribute.CollectionName);
+ return dbContext.GetCollection(databaseName, collectionName);
}