Beispiel #1
0
        private void SaveDevicePendingApproval(string deviceId, string applicationName)
        {
            User systemUser = GetSystemUser();
            List <DevicePendingApproval> query = (from d in DB.GetTable <DevicePendingApproval>()
                                                  where (d.DeviceId == deviceId) && (d.ApplicationName == applicationName)
                                                  select d).ToList();
            DevicePendingApproval devicePendingApproval = query.Count < 1 ? null : query[0];

            if (devicePendingApproval == null)
            {
                devicePendingApproval = new DevicePendingApproval()
                {
                    DevicePendingApprovalId = Guid.NewGuid(),
                    DeviceId        = deviceId,
                    ApplicationName = applicationName,
                    DateCreated     = DateTime.Now
                };
            }
            devicePendingApproval.LatestAttemptDate = DateTime.Now;
            using (TransactionScope t = new TransactionScope())
            {
                Save <DevicePendingApproval>(devicePendingApproval, false).ForEach(c => HandleChange(c, systemUser));
                t.Complete();
            }
            SendDevicePendingApprovalEmailNotification(devicePendingApproval, systemUser);
        }
        private void mnuEditApprove_Click(object sender, EventArgs e)
        {
            Nullable <Guid> selectedId = UIHelper.GetSelectedRowId(
                grdDevicesPendingApproval,
                EntityReader <DevicePendingApproval> .GetPropertyName(p => p.DevicePendingApprovalId, true),
                true);
            DevicePendingApproval devicePendingApproval = _devicePendingApprovalCache[selectedId.Value];

            using (ApproveDeviceForm f = new ApproveDeviceForm(devicePendingApproval))
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    Refresh(true);
                }
            }
        }
Beispiel #3
0
        private void SendDevicePendingApprovalEmailNotification(DevicePendingApproval devicePendingApproval, User user)
        {
            GlobalVariable g = GetGlobalVariable(GlobalVariableName.EmailDevicePendingApproval);

            if (!bool.Parse(g.VariableValue))
            {
                return;
            }
            using (TransactionScope t = new TransactionScope())
            {
                List <User> usersOptedIn = GetUsersOptedIn();
                if (usersOptedIn == null || usersOptedIn.Count < 1)
                {
                    return;
                }
                StringBuilder body = new StringBuilder();
                body.AppendLine(string.Format("Device Id : {0}", devicePendingApproval.DeviceId));
                body.AppendLine(string.Format("Application Name : {0}", devicePendingApproval.ApplicationName));
                body.AppendLine(string.Format("Latest Attempt Date : {0}", devicePendingApproval.LatestAttemptDate.ToString()));
                body.AppendLine(string.Format("Date Created : {0}", devicePendingApproval.DateCreated.ToString()));
                List <string> emailRecipients  = new List <string>();
                StringBuilder toEmailAddresses = new StringBuilder();
                foreach (User u in usersOptedIn)
                {
                    emailRecipients.Add(u.Email);
                    toEmailAddresses.AppendFormat("{0};", u.Email);
                }
                EmailSender.SendMail(
                    Options.Instance.Settings.DevicePendingApprovalNotificationSubject,
                    body.ToString(),
                    null,
                    emailRecipients);
                EmailAction emailAction = new EmailAction()
                {
                    EmailActionId    = Guid.NewGuid(),
                    ToEmailAddress   = toEmailAddresses.ToString(),
                    FromEmailAddress = Options.Instance.Settings.FromEmailAddress,
                    Subject          = Options.Instance.Settings.DevicePendingApprovalNotificationSubject,
                    Body             = body.ToString(),
                    UserId           = user.UserId,
                    DateCreated      = DateTime.Now
                };
                Save <EmailAction>(emailAction, false).ForEach(c => HandleChange(c, user));
                t.Complete();
            }
        }
Beispiel #4
0
 public ApproveDeviceForm(DevicePendingApproval devicePendingApproval)
 {
     InitializeComponent();
     _devicePendingApproval = devicePendingApproval;
 }
Beispiel #5
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)));
     }
 }