Exemplo n.º 1
0
        public static Boolean CreateMessage(string title, string body, MessageType type, int deviceId)
        {
            var transaction = new Transaction(IsolationLevel.ReadCommitted, "create message");

            try
            {
                var messageEntity = new MessageEntity {
                    MessageType = type, Title = title, Body = body, CreateTime = DateTime.Now, StartTime = DateTime.Now
                };
                transaction.Add(messageEntity);
                messageEntity.Save();

                var deviceMessage = new DeviceMessageEntity {
                    DeviceId = deviceId, MessageId = messageEntity.MessageId
                };
                transaction.Add(deviceMessage);
                deviceMessage.Save();

                transaction.Commit();

                return(true);
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex);
                return(false);
            }
            finally
            {
                transaction.Dispose();
            }
        }
Exemplo n.º 2
0
 public static void SendEmail(EmailParameters emailParameters, Decimal LocationId, Decimal UserId)
 {
     try
     {
         // Create the mail object
         MailMessage myMailMessage = new MailMessage();
         myMailMessage.Sender  = new MailAddress(emailParameters.Sender);
         myMailMessage.From    = new MailAddress(emailParameters.Sender);
         myMailMessage.Subject = emailParameters.SubjectLine;
         // Construct a friendly to line
         myMailMessage.To.Add(new MailAddress(emailParameters.Receiver, emailParameters.friendlyToLine()));
         myMailMessage.Body       = emailParameters.BodyContent;
         myMailMessage.IsBodyHtml = emailParameters.IsHTMLBody;
         if (emailParameters.ImportantFlag)
         {
             myMailMessage.Priority = MailPriority.High;
         }
         // Send the email
         SmtpClient client = new SmtpClient();
         client.Send(myMailMessage);
     }
     catch (Exception ex)
     {
         Loggers.LogException(UserId, ex, true);
     }
 }
Exemplo n.º 3
0
 public static Boolean DeleteMessage(long messageId)
 {
     try
     {
         MessageEntity messageEntity = new MessageEntity(messageId);
         messageEntity.Delete();
         return(true);
     }
     catch (Exception ex)
     {
         Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex);
         return(false);
     }
 }
        public static string CreateUniqueId(UniqueIdType idType)
        {
            Int32  attempts    = 0;
            string returnValue = String.Empty;

            try
            {
                do
                {
                    attempts++;
                    returnValue = Guid.NewGuid().ToString();
                    if (idType == UniqueIdType.OrganizationUniqueId)
                    {
                        OrganizationCollection ecCustomerCollection = new OrganizationCollection();
                        PredicateExpression    filter = new PredicateExpression(OrganizationFields.UniqueIdentifier == returnValue);
                        ecCustomerCollection.GetMulti(filter);
                        if (ecCustomerCollection.Count == 0)
                        {
                            break;
                        }
                    }
                    else if (idType == UniqueIdType.DeviceUniqueId)
                    {
                        DeviceCollection    ecDeviceCollection = new DeviceCollection();
                        PredicateExpression filter             = new PredicateExpression(DeviceFields.UniqueIdentifier == returnValue);
                        ecDeviceCollection.GetMulti(filter);
                        if (ecDeviceCollection.Count == 0)
                        {
                            break;
                        }
                    }
                    else if (idType == UniqueIdType.LocationUniqueId)
                    {
                        LocationCollection  ecCustomerLocationCollection = new LocationCollection();
                        PredicateExpression filter = new PredicateExpression(LocationFields.UniqueIdentifier == returnValue);
                        ecCustomerLocationCollection.GetMulti(filter);
                        if (ecCustomerLocationCollection.Count == 0)
                        {
                            break;
                        }
                    }
                } while (attempts < GlobalSettings.MAX_KEYGEN_ATTEMPTS);
                return(returnValue);
            }
            catch (Exception ex)
            {
                Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex);
                return(returnValue);
            }
        }
Exemplo n.º 5
0
 public static int ConvertDeviceKey(string deviceUid)
 {
     try
     {
         DeviceCollection    deviceCollection = new DeviceCollection();
         PredicateExpression filter           = new PredicateExpression(DeviceFields.UniqueIdentifier == deviceUid);
         deviceCollection.GetMulti(filter);
         if (deviceCollection.Count > 0)
         {
             return(deviceCollection[0].DeviceId);
         }
         else
         {
             throw(new Exception("Unable to locate device with key: " + deviceUid));
         }
     }
     catch (Exception ex)
     {
         Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex);
         return(-1);
     }
 }
Exemplo n.º 6
0
 public static int ConvertLocationKey(string locationUid)
 {
     try
     {
         LocationCollection  locationCollection = new LocationCollection();
         PredicateExpression filter             = new PredicateExpression(LocationFields.UniqueIdentifier == locationUid);
         locationCollection.GetMulti(filter);
         if (locationCollection.Count > 0)
         {
             return(locationCollection[0].LocationId);
         }
         else
         {
             throw(new Exception("Unable to locate location with key: " + locationUid));
         }
     }
     catch (Exception ex)
     {
         Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex);
         return(-1);
     }
 }
Exemplo n.º 7
0
 public static int ConvertCustomerKey(string organizationUid)
 {
     try
     {
         OrganizationCollection organizationCollection = new OrganizationCollection();
         PredicateExpression    filter = new PredicateExpression(OrganizationFields.UniqueIdentifier == organizationUid);
         organizationCollection.GetMulti(filter);
         if (organizationCollection.Count > 0)
         {
             return(organizationCollection[0].OrganizationId);
         }
         else
         {
             throw(new Exception("Unable to locate customer with key: " + organizationUid));
         }
     }
     catch (Exception ex)
     {
         Loggers.LogException(GlobalSettings.SYSTEM_DAEMON_USER_ID, ex);
         return(-1);
     }
 }