mongodb gridfs in C# new api - c#

i am new with MongoDB, and i can't find GridFS.
Where can i get GridFS to store files now ?
I can get it this way:
mongoClient = new MongoClient(Settings.Default.MongoDB);
var server = mongoClient.GetServer();
MongoDatabase = server.GetDatabase(Settings.Default.DatabaseName);
MongoDatabase.GridFS...
but GetServer() method is obsolete.
if I get database as here:
MongoDatabase2 = mongoClient.GetDatabase(Settings.Default.DatabaseName);
MongoDatabase2.GridFS... not working
Then i receive IMongoDatabase instead MongoDatabase, and i didnt have GridFS.

Heureka!! Got it! Give me the Nobel prize! :)
var grid = new MongoGridFS(new MongoServer(new MongoServerSettings {Server = new MongoServerAddress(host, port)}), databaseName, new MongoGridFSSettings());
grid.Upload(file.InputStream, file.FileName, new MongoGridFSCreateOptions
{
Id = imageId,
ContentType = file.ContentType
});

I have the same problem. I did find something I thought would solve my problem, the class MongoGridFS. My problem now is that it takes a MongoServer, as it's first arg and times out when I give it a new instance or complains about a connectionstring not found.
var grid = new MongoGridFS(new MongoServer(new MongoServerSettings { Server = new MongoServerAddress(Settings.Default.WizdooMongoConnectionString) }), Settings.Default.WizdooMongoDatabaseName, new MongoGridFSSettings());
grid.Upload(file.InputStream, file.FileName, new MongoGridFSCreateOptions
{
Id = imageId,
ContentType = file.ContentType
});
//Yealds: The settings property 'ConnectionString' was not found.
I suppose I need to give it a connectionstring, but I've been able to do CRUD fine in MongoDB without it. So weird for this service to require it all of a sudden. Maybe you can make it work for you though. I'm going to look in to it more when I have time... should work with correct config. If you get it to work pls give me a hint! Good luck! :)

Related

GraphServiceClient, Create ContentVersions to intune with GraphServiceClient

I'm having trouble creating a new ContentVersion - Right now I have created a new entry with this code.
var newItem = await client.DeviceAppManagement.MobileApps.Request().AddAsync(new Win32LobApp {});
But I can't find the method to create a new ContentVersion. I know the URL, but not the method to call.
The URL to call is this
POST: https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/{0}/microsoft.graph.win32LobApp/contentVersions
So far I have tried to clone the github project (https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet) to see how it works, but without luck. And right now, I just don't know where to look.
Any help would be appreciated
Okay, I solved it by doing it like this
ManagedMobileLobAppRequestBuilder builder = new ManagedMobileLobAppRequestBuilder($"{client.BaseUrl}/deviceAppManagement/mobileApps/{newItem.Id}/{newItem.ODataType.Substring(1)}", client);
var result = await builder.ContentVersions.Request().AddAsync(new MobileAppContent());
Not sure if this is the correct way of doing it, but it works!
An alternative solution with a little less string concatenation:
var lobType = createAppResult.ODataType.Substring(1);
var baseUrl = client.DeviceAppManagement.MobileApps[appId].AppendSegmentToRequestUrl(lobType)
var lobRequestBuilder = new ManagedMobileLobAppRequestBuilder(baseUrl, client);

How to use Orc.SystemInfo?

I downloaded via nuget the package Orc.SystemInfo (Orc.SystemInfo). I managed to display some SystemInfoElements as a list. However no name is provided (name in List is null). I think there is a problem with the LanguageService. I already googled for this problem but I was unable to find a solution.
Here is my code so far (Linq-Pad)
void Main()
{
var service = new Orc.SystemInfo.WindowsManagementInformationService();
var dotnet = new Orc.SystemInfo.DotNetFrameworkService();
var db = new Orc.SystemInfo.DbProvidersService();
ILanguageService lang = new Catel.Services.LanguageService();
var info = new Orc.SystemInfo.SystemInfoService(service, dotnet, lang, db);
var infoList = info.GetSystemInfo();
infoList.Dump();
}
Thank you for your help!
You can simply resolve the ISystemInfo service using the ServiceLocator and all should be taken care of for you.

Sharing a business notebook with Evernote API

I'm getting a Evernote.EDAM.Error.EDAMErrorCode.PERMISSION_DENIED error on createSharedNotebook when trying to share a business notebook.
AuthenticationResult busAuthResult = _userStore.authenticateToBusiness(authToken);
var bAuthToken = busAuthResult.AuthenticationToken;
var bNoteStoreUri = busAuthResult.NoteStoreUrl;
TTransport noteStoreTransport = new THttpClient(new Uri(bNoteStoreUri));
TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
var noteStore = new NoteStore.Client(noteStoreProtocol);
var notebook = noteStore.getNotebook(bAuthToken, notebookGuid);
var sharedNotebook = new SharedNotebook();
sharedNotebook.Email = "test#test.com";
sharedNotebook.NotebookModifiable = true;
sharedNotebook.AllowPreview = true;
sharedNotebook.NotebookGuid = notebookGuid;
noteStore.createSharedNotebook(bAuthToken, sharedNotebook);
The account I'm using has access to share the notebook, so I can't figure out where this error is coming from. I haven't been able to find anything on sharing business notebooks, so any ideas or links would be greatly appreciated!
I think NotebookModifiable is deprecated. Instead, can you add privilege? After that, hopefully you would get another error message that tell you exactly what other parameters like recipientSettings you have to add.

ASP.NET CORE w/ NEST/Elasticsearch.net: custom contract resolver

public ISearchResponse<object> GetById(string id) {
var uri = new Uri("<myendpoint>");
var settings = new ConnectionSettings(uri).DefaultIndex("useraction-*").PrettyJson().DisableDirectStreaming(); //or try _all
var client = new ElasticClient(settings);
var search = new SearchRequest<object>
{
Query = new TermQuery
{
Field = "field",
Value = "example"
}
};
var response = client.Search<object>(search);
return response;
}
I'm having trouble getting NEST to work. When I try to call the query defined above, I get the following error:
System.Exception: If you use a custom contract resolver be sure to subclass from ElasticResolver
at Nest.JsonExtensions.GetConnectionSettings(JsonSerializer serializer) in C:\Users\russ\source\elasticsearch-net-master\src\Nest\CommonAbstractions\Extensions\JsonExtensions.cs
I've searched the internet for mention of this and can't seem to find anything other than the source code. I've pretty much followed the documentation exactly so I don't know what to change.
Does anyone out there know what this error is trying to tell me? I feel like it's an error behind the scenes that I don't have control over.
I'm happy to answer additional questions if people need more info.
Thanks.
Also I don't know where that path is coming from in the exception because I have no user "russ"

How does one connect to the RootDSE and/or retrieve highestCommittedUSN with System.DirectoryServices.Protocols?

Using System.DirectoryServices, one can get the highestCommittedUSN this way:
using(DirectoryEntry entry = new DirectoryEntry("LDAP://servername:636/RootDSE"))
{
var usn = entry.Properties["highestCommittedUSN"].Value;
}
However, I need to get this information from a remote ADLDS using System.DirectoryServices.Protocols, which does not leverage ADSI. Following is a simplified code sample of what I'm attempting to do:
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(highestCommittedUSN=*))";
var searchRequest = new SearchRequest("RootDSE", filter, SearchScope.Subtree, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestCommittedUSN"][0];
}
Unfortunately this kicks back a "DirectoryOperationException: The distinguished name contains invalid syntax." At first I thought there might be something wrong in GetWin32LdapConnection() but that code is called in numerous other places to connect to the directory and never errors out.
Any ideas?
Thanks for the idea, Zilog. Apparently to connect to the RootDSE, you have to specify null for the root container. I also switched the filter to objectClass=* and the search scope to "base." Now it works!
using(LdapConnection connection = GetWin32LdapConnection())
{
var filter = "(&(objectClass=*))";
var searchRequest = new SearchRequest(null, filter, SearchScope.Base, "highestCommittedUSN");
var response = connection.SendRequest(searchRequest) as SearchResponse;
var usn = response.Entries[0].Attributes["highestcommittedusn"][0];
}
I hope this saves someone else some time in the future.

Categories