Exemplo n.º 1
0
 public ServiceFunctionResult <DeviceConfigAction> LogDeviceConfigAction(
     string function,
     string deviceId,
     string applicationName,
     string tag)
 {
     try
     {
         DeviceConfigAction result = null;
         using (TransactionScope t = new TransactionScope())
         {
             /*We need a separate to get the entity in order to be able to update its LastConnectionDate, otherwise the underlying LINQConext
              * will not update the database because the "original entity" will be the same object as the "new entity we're getting here.*/
             DeviceConfigContext ctx = new DeviceConfigContext();
             List <DeviceConfig> deviceConfigQuery = (from d in ctx.DB.GetTable <DeviceConfig>()
                                                      where d.DeviceId == deviceId && d.ApplicationName == applicationName
                                                      select d).ToList();
             DeviceConfig deviceConfig = deviceConfigQuery.Count < 1 ? null : deviceConfigQuery[0];
             if (deviceConfig == null)
             {
                 throw new ServiceException(
                           string.Format(
                               "Could not retrieve settings for application on device {0}. Device not registered. Attempt to get device configuration for device to be added as a device pending approval.",
                               deviceId),
                           ServiceResultCode.FatalError);
             }
             User systemUser = GetSystemUser();
             deviceConfig.LastConnectionDate = DateTime.Now;
             if (deviceConfig.ActionCount.HasValue)
             {
                 deviceConfig.ActionCount++;
             }
             else
             {
                 deviceConfig.ActionCount = 1;
             }
             Save <DeviceConfig>(deviceConfig, false).ForEach(c => HandleChange(c, systemUser));
             SaveDeviceConfigAction(deviceConfig, function, tag, systemUser);
             t.Complete();
         }
         return(new ServiceFunctionResult <DeviceConfigAction>()
         {
             Contents = result
         });
     }
     catch (Exception ex)
     {
         return(new ServiceFunctionResult <DeviceConfigAction>(HandleException(ex)));
     }
 }
Exemplo n.º 2
0
 public ServiceProcedureResult UpdateDeviceConfig(
     string deviceId,
     string applicationName,
     string applicationWebServiceURL,
     string applicationReplicationWebServiceURL,
     string clientConfigWebServiceURL,
     DateTime licenseExpiryDate,
     User user)
 {
     try
     {
         ValidateUser(user);
         List <DeviceConfig> deviceConfigQuery = (from dc in DB.GetTable <DeviceConfig>()
                                                  where (dc.DeviceId == deviceId) && (dc.ApplicationName == applicationName)
                                                  select dc).ToList();
         DeviceConfig deviceConfig = deviceConfigQuery.Count < 1 ? null : deviceConfigQuery[0];
         if (deviceConfig == null)
         {
             throw new ServiceException(
                       string.Format("Device config for device ID {0} for application {1} does not exist.", deviceId, applicationName),
                       ServiceResultCode.FatalError);
         }
         deviceConfig.ApplicationWebServiceURL            = applicationReplicationWebServiceURL;
         deviceConfig.ApplicationReplicationWebServiceURL = applicationReplicationWebServiceURL;
         deviceConfig.ClientConfigWebServiceURL           = clientConfigWebServiceURL;
         deviceConfig.LicenseExpiryDate = licenseExpiryDate;
         using (TransactionScope t = new TransactionScope())
         {
             Save <DeviceConfig>(deviceConfig, false).ForEach(c => HandleChange(c, user));
             t.Complete();
         }
         return(new ServiceProcedureResult()
         {
             Message = "Updated device config successfully."
         });
     }
     catch (Exception ex)
     {
         return(new ServiceProcedureResult(HandleException(ex)));
     }
 }
Exemplo n.º 3
0
 public ServiceProcedureResult ApproveDevicePendingApproval(
     string deviceId,
     string applicationName,
     string applicationWebServiceURL,
     string applicationReplicationWebServiceURL,
     string clientConfigWebServiceURL,
     int daysToActivate,
     Customer customer,
     User user)
 {
     try
     {
         ValidateUser(user);
         List <DevicePendingApproval> devicePendingApprovalQuery = (from d in DB.GetTable <DevicePendingApproval>()
                                                                    where (d.DeviceId == deviceId) && (d.ApplicationName == applicationName)
                                                                    select d).ToList();
         DevicePendingApproval devicePendingApproval = devicePendingApprovalQuery.Count < 1 ? null : devicePendingApprovalQuery[0];
         if (devicePendingApproval == null)
         {
             throw new ServiceException(
                       string.Format("No device pending approval with device ID {0} for application {1} could be found.", deviceId, applicationName),
                       ServiceResultCode.FatalError);
         }
         List <DeviceConfig> deviceConfigQuery = (from dc in DB.GetTable <DeviceConfig>()
                                                  where (dc.DeviceId == deviceId) && (dc.ApplicationName == applicationName)
                                                  select dc).ToList();
         DeviceConfig deviceConfig = deviceConfigQuery.Count < 1 ? null : deviceConfigQuery[0];
         if (deviceConfig != null)
         {
             throw new ServiceException(
                       string.Format("Device with device ID {0} for application {1} already approved.", deviceId, applicationName),
                       ServiceResultCode.FatalError);
         }
         DateTime licenseExpiryDate = DateTime.Now.AddDays(daysToActivate);
         deviceConfig = new DeviceConfig()
         {
             DeviceConfigId                      = Guid.NewGuid(),
             DeviceId                            = deviceId,
             ApplicationName                     = applicationName,
             ApplicationWebServiceURL            = applicationWebServiceURL,
             ApplicationReplicationWebServiceURL = applicationReplicationWebServiceURL,
             ClientConfigWebServiceURL           = clientConfigWebServiceURL,
             LicenseExpiryDate                   = licenseExpiryDate,
             DateCreated                         = DateTime.Now,
             CustomerId                          = customer.CustomerId
         };
         using (TransactionScope t = new TransactionScope())
         {
             Delete <DevicePendingApproval>(devicePendingApproval).ForEach(c => HandleChange(c, user));
             Save <DeviceConfig>(deviceConfig, false).ForEach(c => HandleChange(c, user));
             t.Complete();
         }
         return(new ServiceProcedureResult()
         {
             Message = "Device approved successfully."
         });
     }
     catch (Exception ex)
     {
         return(new ServiceProcedureResult(HandleException(ex, user)));
     }
 }