Example #1
0
        public void AddClient(DT.Client client)
        {
            string country = string.Empty;

            OperationContext opContext = OperationContext.Current;

            if (opContext != null)
            {
                MessageProperties             properties = opContext.IncomingMessageProperties;
                RemoteEndpointMessageProperty endpoint   = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                string ipAdr = endpoint.Address;
                country = GeoIPLookupService.Instance.GetCountryName(ipAdr);
            }

            using (DA.AccessServiceDataContext context = new DA.AccessServiceDataContext()) {
                DA.Client entity = Convert.ToEntity(client);

                if (country != string.Empty)
                {
                    var query = from c in context.GetTable <DA.Country>()
                                where c.Name == country
                                select c;
                    if (query.Count() > 0)
                    {
                        entity.CountryId = query.First().Id;
                    }
                }

                if (entity.OperatingSystem != null)
                {
                    string osversion = entity.OperatingSystem.Name;
                    var    query     = from os in context.GetTable <DA.OperatingSystem>()
                                       where os.Name == osversion
                                       select os;
                    if (query.Count() > 0)
                    {
                        entity.OperatingSystem = query.First();
                    }
                }

                if (entity.ClientType != null)
                {
                    string cType = entity.ClientType.Name;
                    var    query = from t in context.GetTable <DA.ClientType>()
                                   where t.Name == cType
                                   select t;
                    if (query.Count() > 0)
                    {
                        entity.ClientType = query.First();
                    }
                }

                context.Resources.InsertOnSubmit(entity);
                context.SubmitChanges();
            }
        }
Example #2
0
 public static DT.Client ToDto(DA.Client source)
 {
     return(new DT.Client()
     {
         Id = source.Id,
         Description = source.Description,
         Name = source.Name,
         ClientConfiguration = ToDto(source.ClientConfiguration),
         HeuristicLabVersion = source.HeuristicLabVersion,
         Country = ToDto(source.Country),
         OperatingSystem = ToDto(source.OperatingSystem),
         MemorySize = source.MemorySize.GetValueOrDefault(),
         Timestamp = source.Timestamp.GetValueOrDefault(),
         NumberOfCores = source.NumberOfCores.GetValueOrDefault(),
         ProcessorType = source.ProcessorType,
         PerformanceValue = source.PerformanceValue.GetValueOrDefault(),
         ClientType = ToDto(source.ClientType)
     });
 }