예제 #1
0
        private Client LoadClientFromDoc(BsonDocument doc)
        {
            Client result = null;

            if (doc != null)
            {
                result                = new Client();
                result.ClientID       = BsonHelper.GetGuid(doc, "_id");
                result.Name           = BsonHelper.GetString(doc, "Name");
                result.OrganisationID = BsonHelper.GetInt32(doc, "OrganisationID");
                result.Lifetime       = BsonHelper.GetDateTime(doc, "Lifetime");
                string  versionText = BsonHelper.GetString(doc, "Version");
                Version version;
                if (Version.TryParse(versionText, out version))
                {
                    result.Version = version;
                }
                result.BindingMode            = (TBindingMode)BsonHelper.GetInt32(doc, "BindingMode");
                result.SMSNumber              = BsonHelper.GetString(doc, "SMSNumber");
                result.Server                 = BsonHelper.GetString(doc, "Server");
                result.LastActivityTime       = BsonHelper.GetDateTime(doc, "LastActivityTime");
                result.LastUpdateActivityTime = result.LastActivityTime;
                if (doc.Contains("SupportedTypes"))
                {
                    BsonArray array = doc["SupportedTypes"].AsBsonArray;
                    foreach (BsonValue arrayItem in array)
                    {
                        BsonDocument supportedTypeDoc = arrayItem.AsBsonDocument;
                        if (supportedTypeDoc != null)
                        {
                            ObjectType supportedType = new ObjectType();
                            supportedType.ObjectTypeID = BsonHelper.GetInt32(supportedTypeDoc, "_id");
                            supportedType.Path         = BsonHelper.GetString(supportedTypeDoc, "Path");
                            if (supportedTypeDoc.Contains("Instances"))
                            {
                                BsonArray instances = supportedTypeDoc["Instances"].AsBsonArray;
                                foreach (BsonValue instance in instances)
                                {
                                    supportedType.Instances.Add(instance.AsInt32);
                                }
                            }
                            if (result.SupportedTypes == null)
                            {
                                result.SupportedTypes = new ObjectTypes();
                            }
                            result.SupportedTypes.AddObjectType(supportedType);
                        }
                    }
                }
            }
            return(result);
        }