Example #1
0
        void IJob.DoJob(Operation operation)
        {
            try
            {
                using (SQLCEDatabaseEntities entities = Helpers.CreateContext <SQLCEDatabaseEntities>())
                {
                    int oid = operation.Id;
                    if (operation.Id == 0)
                    {
                        oid = entities.Operations.Any() ? entities.Operations.Max(o => o.OperationId) + 1 : 1;
                    }

                    // We need to see if the timestamp could be parsed. It will cause a Overflow in SQL Server if we allow DateTime.MinValue!
                    DateTime timestamp = (operation.Timestamp != DateTime.MinValue) ? operation.Timestamp : DateTime.Now;

                    OperationData data = new OperationData()
                    {
                        OperationId     = oid,
                        Timestamp       = Helpers.EnsureSaneTimestamp(timestamp),
                        City            = operation.City,
                        ZipCode         = operation.ZipCode,
                        Location        = operation.Location,
                        OperationNumber = operation.OperationNumber,
                        Keyword         = operation.Keyword,
                        Comment         = operation.Comment,
                        IsAcknowledged  = operation.IsAcknowledged,
                        Messenger       = operation.Messenger,
                        Building        = operation.Property,
                        Street          = operation.Street,
                        StreetNumber    = operation.StreetNumber,
                        CustomData      = Utilities.Serialize(operation.CustomData),
                        // TODO: Compress route image!?
                        RouteImage = operation.RouteImage,
                    };
                    entities.Operations.AddObject(data);
                    entities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogFormat(LogType.Error, this, "An error occurred while trying to write the operation to the database!");
                Logger.Instance.LogException(this, ex);
            }
        }
        void IJob.DoJob(Operation operation)
        {
            try
            {
                using (SQLCEDatabaseEntities entities = Helpers.CreateContext<SQLCEDatabaseEntities>())
                {
                    int oid = operation.Id;
                    if (operation.Id == 0)
                    {
                        oid = entities.Operations.Any() ? entities.Operations.Max(o => o.OperationId) + 1 : 1;
                    }

                    // We need to see if the timestamp could be parsed. It will cause a Overflow in SQL Server if we allow DateTime.MinValue!
                    DateTime timestamp = (operation.Timestamp != DateTime.MinValue) ? operation.Timestamp : DateTime.Now;

                    OperationData data = new OperationData()
                    {
                        OperationId = oid,
                        Timestamp = Helpers.EnsureSaneTimestamp(timestamp),
                        City = operation.City,
                        ZipCode = operation.ZipCode,
                        Location = operation.Location,
                        OperationNumber = operation.OperationNumber,
                        Keyword = operation.Keyword,
                        Comment = operation.Comment,
                        IsAcknowledged = operation.IsAcknowledged,
                        Messenger = operation.Messenger,
                        Building = operation.Property,
                        Street = operation.Street,
                        StreetNumber = operation.StreetNumber,
                        CustomData = Utilities.Serialize(operation.CustomData),
                        // TODO: Compress route image!?
                        RouteImage = operation.RouteImage,
                    };
                    entities.Operations.AddObject(data);
                    entities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogFormat(LogType.Error, this, "An error occurred while trying to write the operation to the database!");
                Logger.Instance.LogException(this, ex);
            }
        }
Example #3
0
        void IOperationStore.AcknowledgeOperation(int operationId)
        {
            lock (Lock)
            {
                using (SQLCEDatabaseEntities entities = Helpers.CreateContext <SQLCEDatabaseEntities>())
                {
                    OperationData data = entities.Operations.FirstOrDefault(d => d.OperationId == operationId);
                    // If either there is no operation by this id, or the operation exists and is already acknowledged, do nothing
                    if (data == null || data.IsAcknowledged)
                    {
                        return;
                    }

                    // Acknowledge this operation and save changes
                    data.IsAcknowledged = true;
                    entities.SaveChanges();
                }
            }
        }
        Operation IOperationStore.StoreOperation(Operation operation)
        {
            lock (Lock)
            {
                try
                {
                    using (SQLCEDatabaseEntities entities = Helpers.CreateContext<SQLCEDatabaseEntities>())
                    {
                        int oid = operation.Id;
                        if (operation.Id == 0)
                        {
                            oid = entities.Operations.Any() ? entities.Operations.Max(o => o.OperationId) + 1 : 1;
                        }

                        // We need to see if the timestamp could be parsed. It will cause a Overflow in SQL Server if we allow DateTime.MinValue!
                        DateTime timestamp = (operation.Timestamp != DateTime.MinValue) ? operation.Timestamp : DateTime.Now;

                        OperationData data = new OperationData()
                        {
                            ID = operation.OperationGuid,
                            OperationId = oid,
                            Timestamp = Helpers.EnsureSaneTimestamp(timestamp),
                            IsAcknowledged = operation.IsAcknowledged,
                            Serialized = Utilities.Serialize(operation),
                        };
                        entities.Operations.AddObject(data);
                        entities.SaveChanges();

                        // Update Operation ID afterwards
                        operation.Id = oid;
                        return operation;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogFormat(LogType.Error, this, "An error occurred while trying to write the operation to the database!");
                    Logger.Instance.LogException(this, ex);
                    throw ex;
                }
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Operations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOperations(OperationData operationData)
 {
     base.AddObject("Operations", operationData);
 }
 /// <summary>
 /// Create a new OperationData object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="isAcknowledged">Initial value of the IsAcknowledged property.</param>
 /// <param name="timestamp">Initial value of the Timestamp property.</param>
 /// <param name="operationId">Initial value of the OperationId property.</param>
 public static OperationData CreateOperationData(global::System.Guid id, global::System.Boolean isAcknowledged, global::System.DateTime timestamp, global::System.Int32 operationId)
 {
     OperationData operationData = new OperationData();
     operationData.ID = id;
     operationData.IsAcknowledged = isAcknowledged;
     operationData.Timestamp = timestamp;
     operationData.OperationId = operationId;
     return operationData;
 }
Example #7
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Operations EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToOperations(OperationData operationData)
 {
     base.AddObject("Operations", operationData);
 }