Exemplo n.º 1
0
        public virtual Response <IPerson> Decode(Stream stream, Client client)
        {
            using (var sr = new StreamReader(stream))
            {
                var json           = sr.ReadToEnd();
                var personResponse = JsonConvert.DeserializeObject <PersonResponse>(json, new EntityConverter());

                // now construct a Response<IPerson> from this
                var keys = personResponse.ResultKeys;
                var list = personResponse
                           .Dictionary
                           .Values
                           .ToList()
                           .Where(x => x.Id.IsPerson && keys.Contains(x.Id.Key))
                           .Select(x => x as IPerson)
                           .ToList();

                var messages = personResponse.ResponseMessages;
                var dict     = new ResponseDictionary(client);
                foreach (var v in personResponse.Dictionary.Values)
                {
                    v.ResponseDictionary = dict;
                    // this could be any type of base entity.
                    if (v.Id.IsPerson)
                    {
                        dict.Add(v as IPerson);
                    }
                    else if (v.Id.IsBusiness)
                    {
                        dict.Add(v as IBusiness);
                    }
                    else if (v.Id.IsLocation)
                    {
                        dict.Add(v as ILocation);
                    }
                    else if (v.Id.IsPhone)
                    {
                        dict.Add(v as IPhone);
                    }
                }

                foreach (var p in list)
                {
                    foreach (var a in p.Associations)
                    {
                        a.ResponseDictionary = dict;
                    }
                    if (p.BestLocationAssociation != null)
                    {
                        p.BestLocationAssociation.ResponseDictionary = dict;
                    }
                }

                var response = new Response <IPerson>(client, list, dict, messages);
                return(response);
            }
        }
        static ResponseDictionary GetDictionary(Client client)
        {
            var dict = new ResponseDictionary(client);

            dict.Add(_person);
            dict.Add(_business);
            dict.Add(_phone);
            dict.Add(_location);
            return(dict);
        }
        public virtual Response<IPerson> Decode(Stream stream, Client client)
        {
            using (var sr = new StreamReader(stream))
            {
                var json = sr.ReadToEnd();
                var personResponse = JsonConvert.DeserializeObject<PersonResponse>(json, new EntityConverter());

                // now construct a Response<IPerson> from this
                var keys = personResponse.ResultKeys;
                var list = personResponse
                    .Dictionary
                    .Values
                    .ToList()
                    .Where(x=>x.Id.IsPerson && keys.Contains(x.Id.Key))
                    .Select(x => x as IPerson)
                    .ToList();

                var messages = personResponse.ResponseMessages;
                var dict = new ResponseDictionary(client);
                foreach (var v in personResponse.Dictionary.Values)
                {
                    v.ResponseDictionary = dict;
                    // this could be any type of base entity.
                    if (v.Id.IsPerson)
                    {
                        dict.Add(v as IPerson);
                    }
                    else if (v.Id.IsBusiness)
                    {
                        dict.Add(v as IBusiness);
                    }
                    else if (v.Id.IsLocation)
                    {
                        dict.Add(v as ILocation);
                    }
                    else if (v.Id.IsPhone)
                    {
                        dict.Add(v as IPhone);
                    }

                }

                foreach (var p in list)
                {
                    foreach (var a in p.Associations)
                    {
                        a.ResponseDictionary = dict;
                    }
                }

                var response = new Response<IPerson>(client, list, dict, messages);
                return response;

            }
        }
        public void MakeEntity()
        {
            _associatedPhone = new Phone(_associatedPhoneId);
            var dict = new ResponseDictionary(null);

            dict.Add(_associatedPhone);
            _entity = new Person(_entityId)
            {
                BusinessAssociations = null,
                LocationAssociations = new List <LocationAssociation>(),
                PhoneAssociations    = new List <PhoneAssociation>
                {
                    new PhoneAssociation(_associatedPhoneId, dict)
                }
            };
        }