Beispiel #1
0
        public string LoadRawDocument <T>(string id, string documentName = null, bool includeDeleted = false)
        {
            if (RunAsHttpClient)
            {
                var databaseName = PecanDatabaseUtilityObj.DetermineDatabaseName <PecanDocument <T>, T>(documentName);
                var resultStr    = RemoteAccess.MakeRequest <string>(RemoteServerAdrress, $"Load?id={id}&database={databaseName}&includeDeleted={includeDeleted}");
                return(resultStr);
            }

            this.Logger?.Trace(this.GetType().Name, $"Load json document {id} from dynamic . Supplied document name {documentName} - {this.GetContextDescription()}");
            string result = this.LoadDocument <T, string>(id, documentName, includeDeleted, true).DocumentEntity;

            return(result);
        }
Beispiel #2
0
        public string GetETagFor <T>(string id, string documentName = null)
        {
            if (RunAsHttpClient)
            {
                var databaseName = PecanDatabaseUtilityObj.DetermineDatabaseName <PecanDocument <T>, T>(documentName);
                var resultStr    = RemoteAccess.MakeRequest <string>(RemoteServerAdrress, $"GetETagFor?id={id}&database={databaseName}");
                return(resultStr);
            }
            this.Logger?.Trace(this.GetType().Name, $"Get etag for document {documentName} with id {id}  Supplied document name {documentName} - {this.GetContextDescription()}");

            PecanDocument <T> result = this.LoadDocument <T>(id, documentName);

            this.Logger?.Trace(this.GetType().Name, $"Get etag {result?.ETag} from document {documentName} with id {id}  Supplied document name {documentName} - {this.GetContextDescription()}");

            return(result.ETag);
        }
Beispiel #3
0
        public T Load <T>(string id, string documentName = null, bool includeDeleted = false)
        {
            if (RunAsHttpClient)
            {
                var databaseName = PecanDatabaseUtilityObj.DetermineDatabaseName <PecanDocument <T>, T>(documentName);
                var resultStr    = RemoteAccess.MakeRequest <string>(RemoteServerAdrress, $"Load?id={id}&database={databaseName}");
                var resultData   = string.IsNullOrEmpty(resultStr) ? default(T) : JsonConvert.DeserializeObject <T>(resultStr);
                return(resultData);
            }

            this.Logger?.Trace(this.GetType().Name, $"Load document {id} of {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}");

            PecanDocument <T> result = this.LoadDocument <T>(id, documentName, includeDeleted);

            return(result.DocumentEntity);
        }
Beispiel #4
0
        public string Save <T>(string documentName, T document, string id = null)
        {
            if (RunAsHttpClient)
            {
                var databaseName = PecanDatabaseUtilityObj.DetermineDatabaseName <PecanDocument <T>, T>(documentName);
                var data         = JsonConvert.SerializeObject(document);
                var resultStr    = RemoteAccess.MakeRequest <string>(RemoteServerAdrress, $"Save?data={data}&database={databaseName}");
                return(resultStr);
            }

            this.Logger?.Trace(this.GetType().Name, $"STORING NEW Document with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}");

            if (IsAnonymousObject <T>())
            {
                this.Logger?.Trace(this.GetType().Name, $"STORING NEW Document determined to be anonymous with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}");

                StorageDatabase <PecanDocument <object>, object> handle = this.GetDatabaseServiceHandle <object>(documentName);
                var data = new PecanDocument <object>
                {
                    DocumentEntity = document.ToDynamic()
                };

                PecanDocument <object> result = handle.Create(data, false, id);

                this.Logger?.Trace(this.GetType().Name, $"STORING NEW successfully obtained final Order id {result?.Id} after the storing Document with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}");

                return(result.Id);
            }
            else
            {
                this.Logger?.Trace(this.GetType().Name, $"STORING NEW storing Document determined to be NOT anonymous with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}");

                StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName);
                var data = new PecanDocument <T>
                {
                    DocumentEntity = document
                };

                PecanDocument <T> result = handle.Create(data, false, id);
                this.Logger?.Trace(this.GetType().Name, $"STORING NEW successfully obtained final Order id {result?.Id} after the storing Document with id {id} of {documentName} type {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}");

                return(result.Id);
            }
        }