Exemplo n.º 1
0
        public void Save()
        {
            if (this.RowKey != this.Id)
            {
                this.RowKey = this.Id;
                System.Diagnostics.Debug.WriteLine("Issue: RowKey did not match Id");
            }

            if (this.PartitionKey == null) this.PartitionKey = string.Empty;

            var previousState = FromRowKey(this.PartitionKey, this.RowKey);
            var tabelResult = ThingTable.Execute(TableOperation.InsertOrReplace(this));
            var currentState = tabelResult.Result as ThingModel;


            // Send events
            if(previousState == null)
            {
                // Thing Added
                EventModel eventModel = new EventModel(currentState, EventType.Add);
                eventModel.Send();
            }
            else
            {
                var thingDiff = this.ThingDiff(currentState, previousState);
                if (thingDiff.Count > 0)
                {
                    // Thing Changed
                    EventModel eventModel = new EventModel(currentState, EventType.Change);
                    foreach (var item in thingDiff)
                    {
                        eventModel.EventProperties.Add("diff_" + item.Key, item.Value.Item1);
                    }
                    eventModel.Send();
                }
            }            
        }
Exemplo n.º 2
0
        private void StateChangedEvent(ThingModel current, ThingModel previous)
        {
            var thingDiff = this.ThingDiff(current, previous);

            if (thingDiff.Count == 0)
            {
                // No actual changes
                System.Diagnostics.Debug.WriteLine("No Changes Found: " + current.Id);
                return;
            }

            EventModel eventModel = new EventModel(current);
            foreach (var item in thingDiff)
            {
                eventModel.EventProperties.Add(item.Key, item.Value.Item1);
            }
            eventModel.Send();
        }
Exemplo n.º 3
0
 public void Delete()
 {
     var eventModel = new EventModel(this, EventType.Delete); 
     var result = ThingTable.Execute(TableOperation.Delete(this));
     eventModel.Send(); // Thing Deleted
 }