public void InsertOrUpdateResourceSecurityInformation(string cluster, Common.Security.Interfaces.IResourceItem resourceItem)
 {
     lock (_store)
     {
         IDocumentsWriteOperation insertOperation = new InsertDocumentsOperation();
         //JsonSerializer<IResourceItem> serializer = new JsonSerializer<IResourceItem>();
         IList <IJSONDocument> jsonDocuments = new List <IJSONDocument>();
         JSONDocument          jdoc          = new JSONDocument();
         bool found = false;
         if (resourceItem != null)
         {
             //jdoc.Key = new DocumentKey(configuration.Name);
             found = FindDocument(resourceItem.ResourceId.Name, Alachisoft.NosDB.Core.Util.MiscUtil.SystemCollection.SecurityInformationCollection, out jdoc);
             if (found)
             {
                 jdoc     = JsonSerializer.Serialize <IResourceItem>(resourceItem);
                 jdoc.Key = resourceItem.ResourceId.Name;
                 IDocumentsWriteOperation replaceOperation = new ReplaceDocumentsOperation();
                 replaceOperation.Collection = Alachisoft.NosDB.Core.Util.MiscUtil.SystemCollection.SecurityInformationCollection;
                 replaceOperation.Database   = MiscUtil.SYSTEM_DATABASE;
                 jsonDocuments.Add(jdoc);
                 replaceOperation.Documents = jsonDocuments;
                 _store.ReplaceDocuments(replaceOperation);
                 //TODO for updating document only deleting previous document require some time to wait In Future this operation done with replace operation.
             }
             else
             {
                 jsonDocuments.Clear();
                 jdoc     = JsonSerializer.Serialize <IResourceItem>(resourceItem);
                 jdoc.Key = resourceItem.ResourceId.Name;
                 jsonDocuments.Add(jdoc);
                 insertOperation.Documents  = jsonDocuments;
                 insertOperation.Collection = Alachisoft.NosDB.Core.Util.MiscUtil.SystemCollection.SecurityInformationCollection;
                 insertOperation.Database   = MiscUtil.SYSTEM_DATABASE;
                 _store.InsertDocuments(insertOperation);
             }
         }
     }
 }
Exemple #2
0
        internal List<FailedDocument> ReplaceDocuments(ICollection<JSONDocument> documents, bool noResponse = false)
        {         

            ReplaceDocumentsOperation replaceOperation = new ReplaceDocumentsOperation();
            replaceOperation.Documents = documents.Cast<IJSONDocument>().ToList();
            replaceOperation.Database = _database.DatabaseName;
            replaceOperation.Collection = _collectionName;
            replaceOperation.NoResponse = noResponse;

            ReplaceDocumentsResponse replaceResponse = (ReplaceDocumentsResponse)_database.ExecutionMapper.ReplaceDocuments(replaceOperation);

            if (!replaceResponse.IsSuccessfull)
            {
                if (replaceResponse.FailedDocumentsList == null || replaceResponse.FailedDocumentsList.Count == 0)
                {
                    throw new DataException(ErrorMessages.GetErrorMessage(replaceResponse.ErrorCode, replaceResponse.ErrorParams));
                }
                return replaceResponse.FailedDocumentsList;
            }
            return new List<FailedDocument>();

        }
 public void InsertOrUpdateUserInformation(IUser userInfo)
 {
     lock (_store)
     {
         IDocumentsWriteOperation insertOperation = new InsertDocumentsOperation();
         IList <IJSONDocument>    jsonDocuments   = new List <IJSONDocument>();
         JSONDocument             jdoc            = new JSONDocument();
         bool found = false;
         if (userInfo != null)
         {
             //jdoc.Key = new DocumentKey(configuration.Name);
             found = FindDocument(userInfo.Username, Alachisoft.NosDB.Core.Util.MiscUtil.SystemCollection.UserInformationCollection, out jdoc);
             if (found)
             {
                 jdoc = JsonSerializer.Serialize <IUser>(userInfo);
                 IDocumentsWriteOperation replaceOperation = new ReplaceDocumentsOperation();
                 replaceOperation.Collection = Alachisoft.NosDB.Core.Util.MiscUtil.SystemCollection.UserInformationCollection;
                 replaceOperation.Database   = MiscUtil.SYSTEM_DATABASE;
                 jsonDocuments.Add(jdoc);
                 replaceOperation.Documents = jsonDocuments;
                 _store.ReplaceDocuments(replaceOperation);
                 //TODO for updating document only deleting previous document require some time to wait In Future this operation done with replace operation.
             }
             else
             {
                 jsonDocuments.Clear();
                 jdoc     = JsonSerializer.Serialize <IUser>(userInfo);
                 jdoc.Key = userInfo.Username;
                 jsonDocuments.Add(jdoc);
                 insertOperation.Documents  = jsonDocuments;
                 insertOperation.Collection = Alachisoft.NosDB.Core.Util.MiscUtil.SystemCollection.UserInformationCollection;
                 insertOperation.Database   = MiscUtil.SYSTEM_DATABASE;
                 _store.InsertDocuments(insertOperation);
             }
         }
     }
 }