Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/13/11 21:05:21 (13 years ago)
Author:
ascheibe
Message:

#1648 added GeoIP support to access webservice

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ClientUserManagement/HeuristicLab.Services.Access/3.3/AccessService.cs

    r6858 r6927  
    2424using System.Linq;
    2525using System.ServiceModel;
     26using System.ServiceModel.Channels;
    2627using System.Web.Security;
     28using HeuristicLab.GeoIP;
    2729using DA = HeuristicLab.Services.Access.DataAccess;
    2830using DT = HeuristicLab.Services.Access.DataTransfer;
     
    7779
    7880    public Guid AddClient(DT.Client client) {
     81      string country = string.Empty;
     82
     83      OperationContext opContext = OperationContext.Current;
     84
     85      if (opContext != null) {
     86        MessageProperties properties = opContext.IncomingMessageProperties;
     87        RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
     88        string ipAdr = endpoint.Address;
     89        country = GeoIPLookupService.Instance.GetCountryName(ipAdr);
     90      }
     91
    7992      using (DA.ClientManagementDataContext context = new DA.ClientManagementDataContext()) {
    8093        DA.Client entity = Convert.ToEntity(client);
     94
     95        if (country != string.Empty) {
     96          var query = from c in context.GetTable<DA.Country>()
     97                      where c.Name == country
     98                      select c;
     99
     100          if (query.Count() > 0) {
     101            entity.CountryId = query.First().Id;
     102          }
     103        }
     104
    81105        context.Resources.InsertOnSubmit(entity);
    82106        context.SubmitChanges();
Note: See TracChangeset for help on using the changeset viewer.