示例#1
0
 public int Delete(Expression <Func <T, bool> > whereExpression)
 {
     using (var context = GetContext())
     {
         OnDataChanged?.BeginInvoke(this, new DataChangedEventArgs <T>(ChangedTypes.Deleted), null, null);
         return(context.Set <T>().Where(whereExpression).Delete());
     }
 }
示例#2
0
 public int Insert(T entity)
 {
     using (var context = GetContext())
     {
         OnDataChanged?.BeginInvoke(this, new DataChangedEventArgs <T>(ChangedTypes.Inserted), null, null);
         context.Set <T>().Add(entity);
         return(context.SaveChanges());
     }
 }
示例#3
0
        public IEnumerable <T> Insert(IEnumerable <T> entities)
        {
            using (var context = GetContext())
            {
                OnDataChanged?.BeginInvoke(this, new DataChangedEventArgs <T>(ChangedTypes.Inserted), null, null);
                context.Set <T>().AddRange(entities);
                var result = context.SaveChanges();
                if (result > 0)
                {
                    return(entities);
                }

                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// 处理订阅事件
        /// </summary>
        /// <param name="item"></param>
        /// <param name="e"></param>
        private void OnMonitoredNotification(MonitoredItem item, MonitoredItemNotificationEventArgs e)
        {
            MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification;
            var node          = e.NotificationValue as NodeId;
            var opcUaDataItem = this.OpcUaDataItems.FirstOrDefault(a => a.Name == item.ResolvedNodeId.ToString());

            if (!Equals(opcUaDataItem, null))
            {
                opcUaDataItem.OldValue         = opcUaDataItem.NewValue;
                opcUaDataItem.NewValue         = notification?.Value.Value;
                opcUaDataItem.OpcUaStatusCodes = (OpcUaStatusCodes)notification?.Value.StatusCode.Code;
                OpcUaDataEventArgs args = new OpcUaDataEventArgs(opcUaDataItem.OpcUaStatusCodes, opcUaDataItem);
                OnDataChanged?.BeginInvoke(this, args, new AsyncCallback((a) =>
                {
                    if (a.IsCompleted)
                    {
                        OnDataChanged?.EndInvoke(a);
                    }
                }), null);
            }
        }