Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
d3c88667
Commit
d3c88667
authored
Jul 05, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert file format
parent
42ea47cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
64 deletions
+64
-64
IStorage.MongoDB.cs
src/DotNetCore.CAP.MongoDB/IStorage.MongoDB.cs
+64
-64
No files found.
src/DotNetCore.CAP.MongoDB/IStorage.MongoDB.cs
View file @
d3c88667
// Copyright (c) .NET Core Community. All rights reserved.
// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Licensed under the MIT License. See License.txt in the project root for license information.
using
System.Linq
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Dashboard
;
using
DotNetCore.CAP.Dashboard
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
MongoDB.Driver
;
using
MongoDB.Driver
;
namespace
DotNetCore.CAP.MongoDB
namespace
DotNetCore.CAP.MongoDB
{
{
public
class
MongoDBStorage
:
IStorage
public
class
MongoDBStorage
:
IStorage
{
{
private
readonly
CapOptions
_capOptions
;
private
readonly
CapOptions
_capOptions
;
private
readonly
IMongoClient
_client
;
private
readonly
IMongoClient
_client
;
private
readonly
ILogger
<
MongoDBStorage
>
_logger
;
private
readonly
ILogger
<
MongoDBStorage
>
_logger
;
private
readonly
MongoDBOptions
_options
;
private
readonly
MongoDBOptions
_options
;
public
MongoDBStorage
(
CapOptions
capOptions
,
public
MongoDBStorage
(
CapOptions
capOptions
,
MongoDBOptions
options
,
MongoDBOptions
options
,
IMongoClient
client
,
IMongoClient
client
,
ILogger
<
MongoDBStorage
>
logger
)
ILogger
<
MongoDBStorage
>
logger
)
{
{
_capOptions
=
capOptions
;
_capOptions
=
capOptions
;
_options
=
options
;
_options
=
options
;
_client
=
client
;
_client
=
client
;
_logger
=
logger
;
_logger
=
logger
;
}
}
public
IStorageConnection
GetConnection
()
public
IStorageConnection
GetConnection
()
{
{
return
new
MongoDBStorageConnection
(
_capOptions
,
_options
,
_client
);
return
new
MongoDBStorageConnection
(
_capOptions
,
_options
,
_client
);
}
}
public
IMonitoringApi
GetMonitoringApi
()
public
IMonitoringApi
GetMonitoringApi
()
{
{
return
new
MongoDBMonitoringApi
(
_client
,
_options
);
return
new
MongoDBMonitoringApi
(
_client
,
_options
);
}
}
public
async
Task
InitializeAsync
(
CancellationToken
cancellationToken
)
public
async
Task
InitializeAsync
(
CancellationToken
cancellationToken
)
{
{
if
(
cancellationToken
.
IsCancellationRequested
)
if
(
cancellationToken
.
IsCancellationRequested
)
{
{
return
;
return
;
}
}
var
database
=
_client
.
GetDatabase
(
_options
.
DatabaseName
);
var
database
=
_client
.
GetDatabase
(
_options
.
DatabaseName
);
var
names
=
(
await
database
.
ListCollectionNamesAsync
(
cancellationToken
:
cancellationToken
))?.
ToList
();
var
names
=
(
await
database
.
ListCollectionNamesAsync
(
cancellationToken
:
cancellationToken
))?.
ToList
();
if
(
names
.
All
(
n
=>
n
!=
_options
.
ReceivedCollection
))
if
(
names
.
All
(
n
=>
n
!=
_options
.
ReceivedCollection
))
{
{
await
database
.
CreateCollectionAsync
(
_options
.
ReceivedCollection
,
cancellationToken
:
cancellationToken
);
await
database
.
CreateCollectionAsync
(
_options
.
ReceivedCollection
,
cancellationToken
:
cancellationToken
);
}
}
if
(
names
.
All
(
n
=>
n
!=
_options
.
PublishedCollection
))
if
(
names
.
All
(
n
=>
n
!=
_options
.
PublishedCollection
))
{
{
await
database
.
CreateCollectionAsync
(
_options
.
PublishedCollection
,
await
database
.
CreateCollectionAsync
(
_options
.
PublishedCollection
,
cancellationToken
:
cancellationToken
);
cancellationToken
:
cancellationToken
);
}
}
var
receivedMessageIndexNames
=
new
string
[]
{
var
receivedMessageIndexNames
=
new
string
[]
{
nameof
(
ReceivedMessage
.
Name
),
nameof
(
ReceivedMessage
.
Added
),
nameof
(
ReceivedMessage
.
ExpiresAt
),
nameof
(
ReceivedMessage
.
Name
),
nameof
(
ReceivedMessage
.
Added
),
nameof
(
ReceivedMessage
.
ExpiresAt
),
nameof
(
ReceivedMessage
.
StatusName
),
nameof
(
ReceivedMessage
.
Retries
),
nameof
(
ReceivedMessage
.
Version
)
};
nameof
(
ReceivedMessage
.
StatusName
),
nameof
(
ReceivedMessage
.
Retries
),
nameof
(
ReceivedMessage
.
Version
)
};
...
@@ -99,7 +99,7 @@ namespace DotNetCore.CAP.MongoDB
...
@@ -99,7 +99,7 @@ namespace DotNetCore.CAP.MongoDB
}).
ToArray
();
}).
ToArray
();
await
col
.
Indexes
.
CreateManyAsync
(
indexes
,
cancellationToken
);
await
col
.
Indexes
.
CreateManyAsync
(
indexes
,
cancellationToken
);
}
}
}
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment