Example #1
0
        private bool CheckIfEtagHasChanged(DirectDocumentManipulator db)
        {
            this.Logger?.Trace(this.GetType().Name, $"Check if etag has changed - {this.GetContextDescription()}");

            foreach (KeyValuePair <string, TrackedObject> obj in this.TrackingDictionary)
            {
                Type   docType = obj.Value.DocumentType;
                string etag    = obj.Value.ETag;
                string id      = obj.Key;
                Type   subtype = obj.Value.Document.GetType();

                string   invokeMethod = "GetEtag";
                object[] argument     = { id, false };

                string existingEtag = CallStorageMethod <string>(subtype, docType, db, obj.Value.DocumentName, invokeMethod, argument);

                if (existingEtag != etag)
                {
                    this.Logger?.Trace(this.GetType().Name, $"Etag has changed for {id} {docType?.Name} {subtype?.Name} from {etag} to {existingEtag} - {this.GetContextDescription()}");
                    return(false);
                }
                else
                {
                    this.Logger?.Trace(this.GetType().Name, $"Etag {etag}  has not changed for {id} {docType?.Name} {subtype?.Name} - {this.GetContextDescription()}");
                }
            }
            return(true);
        }
Example #2
0
        private void SaveModelChangesAndTryUpdateEtag(bool saveWithEtag, DirectDocumentManipulator db)
        {
            this.Logger?.Trace(this.GetType().Name, $"save model. use direct db manipulator. Try update with etag {saveWithEtag} - {this.GetContextDescription()}");

            foreach (KeyValuePair <string, TrackedObject> obj in this.TrackingDictionary)
            {
                object d       = obj.Value.Document;
                Type   docType = obj.Value.DocumentType;
                string etag    = obj.Value.ETag;
                Type   subtype = d.GetType();

                string existingEtag;
                if (saveWithEtag)
                {
                    this.Logger?.Trace(this.GetType().Name, $"Saving  {d} type {docType?.Name} {subtype?.Name} with etag {etag} use direct db manipulator. Try update with etag {saveWithEtag} - {this.GetContextDescription()}");

                    existingEtag = CallStorageMethod <string>(subtype, docType, db, obj.Value.DocumentName, "Update", new[] { d, etag });
                }
                else
                {
                    this.Logger?.Trace(this.GetType().Name, $"Saving  {d} type {docType?.Name} {subtype?.Name} with NO etag {etag} use direct db manipulator. Try update with etag {saveWithEtag} - {this.GetContextDescription()}");

                    existingEtag = CallStorageMethod <string>(subtype, docType, db, obj.Value.DocumentName, "Update", new[] { d, null });
                }
                obj.Value.ETag = existingEtag;

                this.Logger?.Trace(this.GetType().Name, $"Successfully Saved  {d} type {docType?.Name} with new etag {existingEtag} use direct db manipulator. Try update with etag {saveWithEtag} - {this.GetContextDescription()}");
            }
        }
Example #3
0
        private static T CallStorageMethod <T>(Type documentWithObjectType, Type objectOnlyType, DirectDocumentManipulator db, string documentName, string invokeMethod, object[] argument)
        {
            MethodInfo method = typeof(DirectDocumentManipulator).GetMethod("GetDBRef")
                                .MakeGenericMethod(documentWithObjectType, objectOnlyType);
            object     dbref   = method.Invoke(db, new object[] { documentName });
            MethodInfo method2 = dbref.GetType().GetMethod(invokeMethod);
            var        result  = (T)method2.Invoke(dbref, argument);

            return(result);
        }