示例#1
0
        private void GetFromDB()
        {
            IMongoDatabase db         = Globals.GetGFMongoConnector(this._Environment).MongoClient.GetDatabase("groundframeQueuer");
            var            collection = db.GetCollection <BsonDocument>("processQueue");

            string       filter   = string.Format(@"{{ key: '{0}'}}", this._Key);
            BsonDocument Document = collection.Find(filter).FirstOrDefault();
            string       JSON     = JsonConvert.SerializeObject(BsonTypeMapper.MapToDotNetValue(Document));

            QueuerProcess TempQueuerProcess = JsonConvert.DeserializeObject <QueuerProcess>(JSON, new QueuerProcessConverter(this._Environment));

            this._Request       = TempQueuerProcess.Request;
            this._Key           = TempQueuerProcess.Key;
            this._AppAPIKey     = TempQueuerProcess.AppAPIKey;
            this._AppUserAPIKey = TempQueuerProcess.AppUserAPIKey;
            this._Authenticated = TempQueuerProcess.Authenticated;
            this._ID            = TempQueuerProcess.ID;
            this._ExecuteNow    = TempQueuerProcess.ExecuteNow;
            this._QueueTime     = TempQueuerProcess.QueueTime;
            this._Authenticated = TempQueuerProcess.Authenticated;
        }
        /// <summary>
        /// Override method to serialize a QueuerProcess object to a JSON string
        /// </summary>
        /// <returns></returns>
        public override void WriteJson(JsonWriter Writer, object Value, JsonSerializer Serializer)
        {
            //Validate Arguments
            //if (Serializer == null)
            //{
            //    throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Serializer" }, new System.Globalization.CultureInfo("en-GB")));
            //}

            //if (Writer == null)
            //{
            //    throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Writer" }, new System.Globalization.CultureInfo("en-GB")));
            //}

            //if (Value == null)
            //{
            //    throw new ArgumentNullException(ExceptionHelper.GetStaticException("GeneralNullArgument", new string[] { "Value" }, new System.Globalization.CultureInfo("en-GB")));
            //}

            QueuerProcess queuerProcess = (QueuerProcess)Value;

            // create the surrogate and serialize it instead
            // of the collection itself
            Serializer.Serialize(Writer, queuerProcess.ToQueuerProcessSurrogate());
        }