forked from stricq/UPKManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the database and the code to communicate with it.
Changed the UpkFile format once again to better keep history.
- Loading branch information
Showing
23 changed files
with
409 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Raven.Client.Documents; | ||
|
||
|
||
namespace UpkManager.Repository.Contracts { | ||
|
||
public interface IDocumentStoreManager { | ||
|
||
IDocumentStore GetDocumentStoreFor(string DatabaseName); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Reflection; | ||
|
||
using Raven.Client.Documents; | ||
using Raven.Client.Documents.Session; | ||
|
||
|
||
namespace UpkManager.Repository.Contracts { | ||
|
||
public interface IRavenStorage { | ||
|
||
IDocumentStore Store { get; } | ||
|
||
IAsyncDocumentSession Session { get; } | ||
|
||
void Initialize(string DatabaseName, Assembly IndexAssembly = null); | ||
|
||
void Shutdown(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Linq; | ||
|
||
using Raven.Client.Documents.Indexes; | ||
|
||
using UpkManager.Entities; | ||
|
||
|
||
namespace UpkManager.Repository.Indexes { | ||
|
||
public sealed class UpkFileCommonIndex : AbstractIndexCreationTask<UpkFile> { | ||
|
||
public UpkFileCommonIndex() { | ||
Map = files => from file in files | ||
select new { file.Package }; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.ComponentModel.Composition; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
using Raven.Client.Documents; | ||
|
||
using UpkManager.Repository.Contracts; | ||
|
||
|
||
namespace UpkManager.Repository.Services { | ||
|
||
[Export(typeof(IDocumentStoreManager))] | ||
public sealed class DocumentStoreManager : IDocumentStoreManager { | ||
|
||
#region Private Fields | ||
|
||
private readonly ConcurrentDictionary<string, Lazy<IDocumentStore>> stores = new ConcurrentDictionary<string, Lazy<IDocumentStore>>(); | ||
|
||
#endregion Private Fields | ||
|
||
#region IDocumentStoreManager Implementation | ||
|
||
public IDocumentStore GetDocumentStoreFor(string DatabaseName) { | ||
Lazy<IDocumentStore> store = createDocumentStore(DatabaseName); | ||
|
||
return stores.GetOrAdd(DatabaseName, store).Value; | ||
} | ||
|
||
#endregion IDocumentStoreManager Implementation | ||
|
||
#region Private Methods | ||
|
||
private static Lazy<IDocumentStore> createDocumentStore(string databaseName) { | ||
X509Certificate2 certificate; | ||
|
||
using(Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"UpkManager.Repository.Certificates.{databaseName}Client.pfx")) { | ||
if (stream == null) return null; | ||
|
||
byte[] data = new byte[stream.Length]; | ||
|
||
stream.Read(data, 0, data.Length); | ||
|
||
certificate = new X509Certificate2(data); | ||
} | ||
|
||
return new Lazy<IDocumentStore>(() => { | ||
IDocumentStore documentStore = new DocumentStore { | ||
Certificate = certificate, | ||
Database = databaseName, | ||
Urls = new [] { | ||
"https://a.stricq.com:8844", | ||
"https://b.stricq.com:8845", | ||
"https://c.stricq.com:8846" | ||
} | ||
}; | ||
|
||
documentStore.Initialize(); | ||
|
||
return documentStore; | ||
}); | ||
} | ||
|
||
#endregion Private Methods | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.ComponentModel.Composition; | ||
using System.Reflection; | ||
|
||
using Raven.Client.Documents; | ||
using Raven.Client.Documents.Indexes; | ||
using Raven.Client.Documents.Session; | ||
|
||
using UpkManager.Repository.Contracts; | ||
|
||
|
||
namespace UpkManager.Repository.Services { | ||
|
||
[Export(typeof(IRavenStorage))] | ||
public sealed class RavenStorage : IRavenStorage { | ||
|
||
#region Private Fields | ||
|
||
private readonly IDocumentStoreManager manager; | ||
|
||
#endregion Private Fields | ||
|
||
#region Constructor | ||
|
||
[ImportingConstructor] | ||
public RavenStorage(IDocumentStoreManager Manager) { | ||
manager = Manager; | ||
} | ||
|
||
#endregion Constructor | ||
|
||
#region IRavenStorage Implementation | ||
|
||
public IDocumentStore Store { get; private set; } | ||
|
||
public IAsyncDocumentSession Session => Store?.OpenAsyncSession(); | ||
|
||
public void Initialize(string DatabaseName, Assembly IndexAssembly = null) { | ||
Store = manager.GetDocumentStoreFor(DatabaseName); | ||
|
||
#if DEBUG | ||
// if (IndexAssembly != null) IndexCreation.CreateIndexes(IndexAssembly, Store); | ||
#endif | ||
} | ||
|
||
public void Shutdown() { | ||
Store?.Dispose(); | ||
} | ||
|
||
#endregion IRavenStorage Implementation | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.