示例#1
0
        private PecanDocument <T> LoadDocument <T>(string id, string documentName = null, bool includeDeleted = false, bool expectFullJsonStringReturned = false)
        {
            this.Logger?.Trace(this.GetType().Name, $"Load document {id} of {typeof(T).Name}. Supplied document name {documentName} - {this.GetContextDescription()}");

            PecanDocument <T> finalResult = null;

            if (IsAnonymousObject <T>())
            {
                StorageDatabase <PecanDocument <object>, object> handle = this.GetDatabaseServiceHandle <object>(documentName);
                if (expectFullJsonStringReturned)
                {
                    string result = handle.LoadJson(id, includeDeleted, expectFullJsonStringReturned);
                    finalResult = new PecanDocument <T>
                    {
                        DocumentEntity = (T)(object)result
                    };
                }
                else
                {
                    PecanDocument <object> result = handle.Load(id, includeDeleted, expectFullJsonStringReturned);
                    finalResult = this.TrackDocument(id, documentName, result, false) as PecanDocument <T>;
                }
            }
            else
            {
                StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName);
                PecanDocument <T> result = handle.Load(id, includeDeleted);
                finalResult = this.TrackDocument(id, documentName, result, false);
            }
            return(finalResult);
        }
示例#2
0
        private PecanDocument <TAs> LoadDocument <T, TAs>(string id, string documentName = null, bool includeDeleted = false, bool expectFullJsonStringReturned = false)
        {
            this.Logger?.Trace(this.GetType().Name, $"Load document {id} of {typeof(T).Name}  as {typeof(TAs).Name}. Supplied document name {documentName} - {this.GetContextDescription()}");

            PecanDocument <TAs> finalResult = null;

            if (IsAnonymousObject <T>())
            {
                StorageDatabase <PecanDocument <object>, object> handle = this.GetDatabaseServiceHandle <object>(documentName);
                if (expectFullJsonStringReturned)
                {
                    string result = handle.LoadJson(id, includeDeleted, expectFullJsonStringReturned);
                    finalResult = new PecanDocument <TAs>
                    {
                        DocumentEntity = (TAs)(object)result
                    };
                }
                else
                {
                    var result = handle.Load <PecanDocument <TAs> >(id, includeDeleted);

                    finalResult = result;
                }

                //todo as is not tracked  finalResult = this.TrackDocument(id, documentName, result, false);
            }
            else
            {
                this.Logger?.Trace(this.GetType().Name, $"Loading document {id} of {typeof(T).Name}  as {typeof(TAs).Name} . Supplied document name {documentName} - {this.GetContextDescription()}");
                StorageDatabase <PecanDocument <T>, T> handle = this.GetDatabaseServiceHandle <T>(documentName);

                string result = handle.LoadJson(id, includeDeleted, expectFullJsonStringReturned);

                if (expectFullJsonStringReturned)
                {
                    finalResult = new PecanDocument <TAs>
                    {
                        DocumentEntity = (TAs)(object)result
                    }
                }
                ;
                else
                {
                    finalResult = this.databaseService.DataBaseSettings.StorageMechanismMech.FileSystem.SerializationFactory.DeserializeObject <PecanDocument <TAs> >(result);
                }
            }
            return(finalResult);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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);
            }
        }
示例#6
0
        private PecanDocument <T> TrackDocument <T>(string id, string documentName, PecanDocument <T> result, bool isNew)
        {
            this.Logger?.Trace(this.GetType().Name, $"Tracking document {id} of {typeof(T).Name} . Is new :{isNew}. Supplied document name {documentName} - {this.GetContextDescription()}");

            if (result == null)
            {
                this.Logger?.Trace(this.GetType().Name, $"Error : Document with id {id}:{documentName} doesnt exist while trying to track it. Is new :{isNew}. Supplied document name {documentName} - {this.GetContextDescription()}");

                throw new Exception($"Document with id {id}:{documentName} doesnt exist");
            }
            if (this.TrackingDictionary.ContainsKey(id))
            {
                this.Logger?.Trace(this.GetType().Name, $"Document {id}  {typeof(T).Name} . Is new :{isNew} is already in the tracking dictionary. Supplied document name {documentName} - {this.GetContextDescription()}");
            }
            else
            {
                this.Logger?.Trace(this.GetType().Name, $"Adding document {id}  {typeof(T).Name}  new :{isNew} to tracking dictionary. Supplied document name {documentName} - {this.GetContextDescription()}");

                this.TrackingDictionary.Add(id, new TrackedObject(result, typeof(T), result.ETag, result.DocumentName, isNew));
            }

            return(this.TrackingDictionary[id].Document as PecanDocument <T>);
        }