Exemplo n.º 1
0
 private void button4_Click(object sender, EventArgs e)
 {
     if (!SerialCom.instance.IsComOpened())
     {
         SerialCom.instance.OpenComPort();
     }
     SerialCom.instance.SetRecvFrm(this);
     byte[] data = DataChange.strToToHexByte(richTextBox1.Text);
     SerialCom.instance.SendFile(data);
 }
        private bool IsVolumeGreaterThanVolumeForMarket(DataChange change)
        {
            if (!change.IsModelSummary)
                return false;

            var filter = TakeRateFilter.FromTakeRateParameters(Parameters);
            var marketVolume = _context.TakeRate.GetVolumeForMarket(filter).Result;

            return change.Volume > marketVolume;
        }
 /// <summary>
 /// Method to update item values
 /// </summary>
 /// <param name="items">
 /// A reference parameter containing a List of Items. Ref since this method will update the object in place.
 /// b/c pass through mutation is gross - better to treat this method like a sea urchin (they eat, then throw up)</param>
 public static void UpdateQuality(ref List <IUpdateableItem> items)
 {
     foreach (var item in items)
     {
         var previousData = DataChange.Record(item);
         item.Update();
         var newData = DataChange.Record(item);
         PrintChange(previousData, newData);
     }
 }
Exemplo n.º 4
0
        public void byteToHexStrTest()
        {
            byte[] tt = new byte[3];
            tt[0] = 0x65;
            tt[1] = 0x66;
            tt[2] = 0x00;
            string data = DataChange.byteToHexOXStr(tt);

            Assert.AreEqual(data.Trim(), "0x65 0x66 0x00");
        }
Exemplo n.º 5
0
 public frmPacsHistory(frmReportEdit.PicBoxClick pbClick)
 {
     InitializeComponent();
     fOpe         = new FileOperator();
     this.pbClick = pbClick;
     CacheDir     = Application.StartupPath + "\\PacsTemp";
     bs           = new BStudy();
     dc           = new DataChange();
     this.dgv_Study.AutoGenerateColumns = false;
 }
Exemplo n.º 6
0
    void OnPlayerMove(DataChange change)
    {
//    Debug.Log ("OnPlayerMove");
//    Debug.Log ("playerId: " + change.path["id"] + ", Axis: " + change.path["axis"]);
//    Debug.Log (change.value);

        GameObject cube;
        //players.TryGetValue (change.path ["id"], out cube);

        //cube.transform.Translate (new Vector3 (Convert.ToSingle(change.value), 0, 0));
    }
        /// <summary>
        /// Triggers when server player changes his color while game play
        /// </summary>
        public void OnColor(DataChange obj)
        {
            print("On color");

            /**
             * See <see cref="ListenServer"/>. OnColor is triggered when "players/:id/color" changes its' value.
             * obj.path contains the unknown :id value of the changed path. obj.value contains the changed value while
             * obj.operation can has values add, replace and remove.
             */
            GetPlayerByID(obj.path["id"]).SetColor(int.Parse(obj.value.ToString()));
        }
Exemplo n.º 8
0
        public override void OnRecvData(byte[] datas)
        {
            string recv = DataChange.byteToHexOXStr(datas).Replace("0x00", "").Trim();

            if (!string.IsNullOrEmpty(recv))
            {
                richTextBox2.Text = "读取成功!/r/n";
            }

            richTextBox2.Text += recv;
        }
Exemplo n.º 9
0
        public Subscription CreateSubscription(string groupName, DataChange callback)
        {
            if (!m_connected)
            {
                throw new InvalidOperationException("Not connected to OPC-Server!");
            }
            Subscription subscription = new Subscription(this);

            subscription.Create(groupName, callback);
            return(subscription);
        }
Exemplo n.º 10
0
        public override void OnRecvData(byte[] datas)
        {
            string recv = DataChange.byteToHexOXStr(datas).Replace("0x00", "").Trim();

            if (recv == "0xEE 0x04 0x01 0xC3 0xC7")
            {
                richTextBox2.Text = "设置成功!/r/n";
            }

            richTextBox2.Text += recv;
        }
Exemplo n.º 11
0
        public virtual int BatchWrite(SortedDictionary <ITag, object> items, bool isSync = true)
        {
            int             len   = items.Count;
            int             rev   = 0;
            IMultiReadWrite multi = _plcReader as IMultiReadWrite;

            if (multi != null)
            {
                DeviceAddress[] addrs = new DeviceAddress[len];
                object[]        objs  = new object[len];
                int             i     = 0;
                foreach (var item in items)
                {
                    addrs[i] = item.Key.Address;
                    objs[i]  = item.Value;
                    i++;
                }

                rev = multi.WriteMultiple(addrs, objs);
            }
            else
            {
                foreach (var tag in items)
                {
                    if (tag.Key.Write(tag.Value) < 0)
                    {
                        rev = -1;
                    }
                }
            }

            if (DataChange != null && rev >= 0)
            {
                HistoryData[] data = new HistoryData[len];
                int           i    = 0;
                foreach (var item in items)
                {
                    ITag tag = item.Key;
                    data[i].ID        = tag.ID;
                    data[i].TimeStamp = tag.TimeStamp;
                    data[i].Quality   = tag.Quality;
                    data[i].Value     = item.Key.ToStorage(item.Value);
                    i++;
                }

                foreach (DataChangeEventHandler deleg in DataChange.GetInvocationList())
                {
                    deleg.BeginInvoke(this, new DataChangeEventArgs(1, data), null, null);
                }
            }

            return(rev);
        }
Exemplo n.º 12
0
        public async Task <Status> RollbackPassword(Guid id, CancellationToken cancellationToken)
        {
            var dataAction = await _passwordWalletContext.DataChanges
                             .FirstOrDefaultAsync(x => x.Id == id, cancellationToken);

            var passwordToRollback = await _passwordWalletContext.Passwords
                                     .FirstOrDefaultAsync(x => x.Id == dataAction.RecordId, cancellationToken);

            var actionChanges = new DataChange
            {
                UserId        = passwordToRollback.UserId,
                PreviousValue = JsonConvert.SerializeObject(new Password
                {
                    Id            = passwordToRollback.Id,
                    IsDeleted     = passwordToRollback.IsDeleted,
                    Login         = passwordToRollback.Login,
                    Description   = passwordToRollback.Description,
                    PasswordValue = passwordToRollback.PasswordValue,
                    UserId        = passwordToRollback.UserId,
                    WebAddress    = passwordToRollback.WebAddress,
                }),
                CurrentValue = null,
                ActionType   = ActionType.RESTORE,
                RecordId     = passwordToRollback.Id,
                UpdatedAt    = DateTime.Now,
            };

            var deserializedPassword = JsonConvert.DeserializeObject <Password>(dataAction.CurrentValue);

            passwordToRollback.IsDeleted     = deserializedPassword.IsDeleted;
            passwordToRollback.Login         = deserializedPassword.Login;
            passwordToRollback.PasswordValue = deserializedPassword.PasswordValue;
            passwordToRollback.Description   = deserializedPassword.Description;
            passwordToRollback.WebAddress    = deserializedPassword.WebAddress;

            actionChanges.CurrentValue = JsonConvert.SerializeObject(new Password
            {
                Id            = passwordToRollback.Id,
                IsDeleted     = passwordToRollback.IsDeleted,
                Login         = passwordToRollback.Login,
                Description   = passwordToRollback.Description,
                PasswordValue = passwordToRollback.PasswordValue,
                UserId        = passwordToRollback.UserId,
                WebAddress    = passwordToRollback.WebAddress,
            });

            await _passwordWalletContext.AddAsync(actionChanges, cancellationToken);

            _passwordWalletContext.Update(passwordToRollback);
            await _passwordWalletContext.SaveChangesAsync(cancellationToken);

            return(new Status(true, "Succesfully restore password"));
        }
Exemplo n.º 13
0
    void Room_OnPlayerGameStateStat(DataChange obj)
    {
        var playerId = obj.path["id"];

        if (playerId == ColyseusRoom.Instance.PlayerId)
        {
            return;
        }

        players.TryGetValue(playerId, out GameObject cube);
        UpdatePlayerStat(obj, cube);
    }
        private static void PrintChange(DataChange previousData, DataChange newData)
        {
            Console.WriteLine(Environment.NewLine + $"Item Name: {previousData.Name}");
            for (var i = 0; i < previousData.Properties.Count(); i++)
            {
                var previous = previousData.Properties[i];
                var current  = newData.Properties[i];
                var key      = previous.Keys.Last();

                Console.WriteLine($"{key,10}: {previous[key],-2} => {current[key],-2}");
            }
        }
Exemplo n.º 15
0
        public void Log()
        {
            while (true)
            {
                Thread.Sleep(1000);
                this.Current = DateTime.Now;

                System.Diagnostics.Debug.WriteLine("bgn DataChange?.Invoke");
                DataChange?.Invoke(this, new EventArgs());
                System.Diagnostics.Debug.WriteLine("end DataChange?.Invoke");
            }
        }
        private bool IsVolumeGreaterThanVolumeForMarket(DataChange change)
        {
            if (!change.IsModelSummary)
            {
                return(false);
            }

            var filter       = TakeRateFilter.FromTakeRateParameters(Parameters);
            var marketVolume = _context.TakeRate.GetVolumeForMarket(filter).Result;

            return(change.Volume > marketVolume);
        }
Exemplo n.º 17
0
        public void OnChange(DataChange obj)
        {
            var jsonString = JsonConvert.SerializeObject(obj);
            var jsonObj    = JToken.Parse(jsonString);

            var operation = jsonObj["operation"].ToString();

            if (operation == "add")
            {
                OperationAdd(jsonObj);
            }
        }
Exemplo n.º 18
0
        public SubscriptionPrivate(DataChange fct, int ClientHandle, object group)
        {
            m_hClient = ClientHandle;
            m_fct     = fct;

            Guid iid = Guid.Empty;

            iid = typeof(IOPCDataCallback).GUID;
            OpcRcw.Comn.IConnectionPointContainer ConnectionPointContainer = (OpcRcw.Comn.IConnectionPointContainer)group;
            OpcRcw.Comn.IConnectionPoint          ConnectionPoint;
            ConnectionPointContainer.FindConnectionPoint(ref iid, out ConnectionPoint);
            ConnectionPoint.Advise(this, out m_ConnectionPointCookie);
        }
Exemplo n.º 19
0
        private void ChangeValue(Action <ProductArticleOrder> changeAction)
        {
            DataChange.GetLock();

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid id = OrderId;
                ProductArticleOrder order = dataContext.ProductArticleOrders.Find(id);

                changeAction(order);
                dataContext.SaveChanges();
            }
        }
Exemplo n.º 20
0
        private void ChangeValue(Action <ProductArticleItem> changeAction)
        {
            DataChange.GetLock();

            using (StoreKeeperDataContext dataContext = new StoreKeeperDataContext())
            {
                Guid id = ArticleItemId;
                ProductArticleItem articleItem = dataContext.ProductArticleItems.Find(id);

                changeAction(articleItem);

                dataContext.SaveChanges();
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 主通信流程:Step 6:根据数据更新上位机相关信息
        /// </summary>
        protected void Update()
        {
            DateTime dt = DateTime.Now;

            if (DataChange != null)
            {
                HistoryData[] values = new HistoryData[_changedList.Count];
                int           i      = 0;
                foreach (int index in _changedList)
                {
                    ITag item     = _items[index];
                    var  itemData = item.Read();//这是从缓存Cache中读取的数据
                    if (item.Active)
                    {
                        item.Update(itemData, dt, QUALITIES.QUALITY_GOOD);
                    }

                    /*
                     * 下面的语言判断是否要更新有变化的Itag:
                     * 1.对敏感度为零的,只要有任何变化都要更新;??浮点数和零 比较大小
                     * 2.对于浮点数,新值的变化要超过敏感的 百分比
                     */
                    if (_deadband == 0 || (item.Address.VarType == DataType.FLOAT &&
                                           (Math.Abs(itemData.Single / item.Value.Single - 1) > _deadband)))
                    {
                        values[i].ID        = item.ID;
                        values[i].Quality   = item.Quality;
                        values[i].Value     = itemData;
                        values[i].TimeStamp = item.TimeStamp;
                        i++;
                    }
                }

                foreach (DataChangeEventHandler deleg in DataChange.GetInvocationList())     //批量调用绑定在事件上面的委托
                {
                    deleg.BeginInvoke(this, new DataChangeEventArgs(1, values), null, null); //只在这个地方,才去调用绑定的事件,对那些更新周期为零的变量进行存储,存储周期随Group
                }
            }
            else
            {
                foreach (int index in _changedList)
                {
                    ITag item = _items[index];
                    if (item.Active)
                    {
                        item.Update(item.Read(), dt, QUALITIES.QUALITY_GOOD);
                    }
                }
            }
        }
Exemplo n.º 22
0
        public async Task <Status> DeletePassword(Guid id, ClaimsPrincipal user, CancellationToken cancellationToken)
        {
            var function = await _passwordWalletContext.Functions.FirstOrDefaultAsync(x => x.Name == FunctionName.Wallet.DeletePassword, cancellationToken);

            await LogFunction(function.Id, Guid.Parse(user.FindFirst(ClaimTypes.NameIdentifier).Value), cancellationToken);

            var passwordToRemove = await _passwordWalletContext.Passwords.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);

            if (passwordToRemove == null)
            {
                return(new Status(false, string.Format("Cannot find password with id: {0}", id)));
            }

            var authorizationResult = await _authorizationService
                                      .AuthorizeAsync(user, passwordToRemove, Policy.OnlyOwner);

            if (!authorizationResult.Succeeded)
            {
                return(new Status(false, "You have to be an owner to delete password"));
            }

            var userIdString = user.FindFirst(ClaimTypes.NameIdentifier).Value;

            Guid.TryParse(userIdString, out Guid userId);

            var actionChanges = new DataChange
            {
                UserId        = userId,
                PreviousValue = JsonConvert.SerializeObject(passwordToRemove),
                CurrentValue  = null,
                ActionType    = ActionType.DELETE,
                RecordId      = passwordToRemove.Id,
                UpdatedAt     = DateTime.Now,
            };

            passwordToRemove.IsDeleted = true;
            actionChanges.CurrentValue = JsonConvert.SerializeObject(passwordToRemove);

            _passwordWalletContext.Update(passwordToRemove);
            await _passwordWalletContext.AddAsync(actionChanges, cancellationToken);

            await _passwordWalletContext.SaveChangesAsync();

            return(new Status
            {
                Success = true,
                Messege = "Successfully removed password from wallet!"
            });
        }
Exemplo n.º 23
0
        public override void OnRecvData(byte[] datas)
        {
            string recv = DataChange.byteToHexOXStr(datas).Replace("0x00", "").Trim();

            if (recv == "0xEE 0x04 0x01 0xD4 0xD1")
            {
                richTextBox2.Text = "写1部分成功!/r/n";
            }
            else if (recv == "0xEE 0x05 0x01 0xD4 0xED 0x3D")
            {
                richTextBox2.Text = "写2部分成功!/r/n";
            }

            richTextBox2.Text += recv;
        }
        /// <summary>
        /// Triggers when server player changes his position while game play
        /// </summary>
        public void OnMove(DataChange obj)
        {
            print("On Move");
            Vector3          delta  = Vector3.zero;
            PlayerController player = GetPlayerByID(obj.path["id"]);

            if (obj.path["axis"] == "x")
            {
                delta.x = float.Parse(obj.value.ToString()) - player.gameObject.transform.localPosition.x;
            }
            else
            {
                delta.y = float.Parse(obj.value.ToString()) - player.gameObject.transform.localPosition.y;
            }
            player.gameObject.transform.localPosition += delta;
        }
Exemplo n.º 25
0
        private void IncrementMetric(Dictionary <string, MetricCount> result, DataChange dataChange, bool success = true)
        {
            var key = $"{dataChange.DbName}.{dataChange.TableName}.{dataChange.EventType}";

            if (!result.ContainsKey(key))
            {
                result[key] = new MetricCount();
            }
            var target = result[key];

            target.Total++;//总数
            if (success)
            {
                target.SuccCount++;//成功数
            }
        }
        public DataChange Add(DataChange dataChange)
        {
            try
            {
                db.DataChanges.Add(dataChange);
                db.SaveChanges();

                return(dataChange);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception occured: " + ex.Message, "Adding dataChange to database failed", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            return(null);
        }
Exemplo n.º 27
0
 //数据项内容改变事件
 private void KepGroup_DataChange(int transactionId, int numItems, ref Array clientHandles, ref Array itemValues, ref Array qualities, ref Array timeStamps)
 {
     try
     {
         for (int i = 1; i <= numItems; i++)
         {
             int id = (int)clientHandles.GetValue(i);
             _tagValue[id] = Convert.ToDouble(itemValues.GetValue(i));
         }
         DataChange?.Invoke(_tagValue);
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog(typeof(OpcClient), ex.StackTrace + ex.Message);
     }
 }
Exemplo n.º 28
0
        private void button1_Click(object sender, EventArgs e)
        {
            int     commandAddr = Convert.ToInt16(comboBox1.Text);
            CmdInit ci          = new CmdInit();

            switch (commandAddr)
            {
            case 2400:
            {
                Global.gBaudRate = 0x00;
                break;
            }

            case 4800:
            {
                Global.gBaudRate = 0x01;
                break;
            }

            case 9600:
            {
                Global.gBaudRate = 0x02;
                break;
            }

            case 19200:
            {
                Global.gBaudRate = 0x03;
                break;
            }

            case 38400:
            {
                Global.gBaudRate = 0x04;
                break;
            }

            default:
            {
                Global.gBaudRate = 0x05;
                break;
            }
            }
            addrc             = ci.GetBaudRateCmd(Global.gBaudRate);
            richTextBox1.Text = DataChange.byteToHexStr(addrc);
        }
Exemplo n.º 29
0
    void Room_OnPlayerLeave(DataChange change)
    {
        var playerId = change.path["id"];

        if (playerId == ColyseusRoom.Instance.PlayerId)
        {
            return;
        }

        if (change.operation == "remove")
        {
            Debug.Log("Removing player " + playerId);
            players.TryGetValue(playerId, out GameObject cube);
            Destroy(cube);
            players.Remove(playerId);
        }
    }
Exemplo n.º 30
0
        protected void Update()
        {
            DateTime dt = DateTime.Now;

            if (DataChange != null)
            {
                HistoryData[] values = new HistoryData[_changedList.Count];
                int           i      = 0;
                foreach (int index in _changedList)
                {
                    ITag item     = _items[index];
                    var  itemData = item.Read();
                    if (item.Active)
                    {
                        item.Update(itemData, dt, QUALITIES.QUALITY_GOOD);
                    }
                    if (_deadband == 0 || (item.Address.VarType == DataType.FLOAT &&
                                           (Math.Abs(itemData.Single / item.Value.Single - 1) > _deadband)))
                    {
                        values[i].ID        = item.ID;
                        values[i].Quality   = item.Quality;
                        values[i].Value     = itemData;
                        values[i].TimeStamp = item.TimeStamp;
                        i++;
                    }
                }

                foreach (DataChangeEventHandler deleg in DataChange.GetInvocationList())
                {
                    deleg.BeginInvoke(this, new DataChangeEventArgs(1, values), null, null);
                }
            }
            else
            {
                foreach (int index in _changedList)
                {
                    ITag item = _items[index];
                    if (item.Active)
                    {
                        item.Update(item.Read(), dt, QUALITIES.QUALITY_GOOD);
                    }
                }
            }

            _changedList.Clear();
        }
        private bool IsFeatureVolumeGreaterThanVolumeForModel(DataChange change)
        {
            if (!change.IsFeatureChange)
                return false;

            var filter = TakeRateFilter.FromTakeRateParameters(Parameters);
            if (change.IsFdpModel)
            {
                filter.FdpModelId = change.GetModelId();
            }
            else
            {
                filter.ModelId = change.GetModelId();
            }
            var modelVolume = _context.TakeRate.GetVolumeForModel(filter).Result;

            return change.Volume > modelVolume;
        }
Exemplo n.º 32
0
        private IEnumerable <DataChange> DiscoverDataChangesUsingEventTables(SqlDatabaseConnectorJobConfiguration config, DatabaseJobState stateBase)
        {
            foreach (var eventTable in config.EventTables)
            {
                var dataChange = new DataChange(new TableDetail()
                {
                    TableName      = eventTable.TableName,
                    PrimaryKeyName = eventTable.MainTableIdColumnName
                });

                using (var conn = new SqlConnection(config.ConnectionString))
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText =
                            string
                            .Format(
                                "SELECT {0}, {1}, {2} FROM {3} WHERE {0} > {4} ORDER BY {0} asc",
                                eventTable.EventSequenceColumnName,
                                eventTable.MainTableIdColumnName,
                                eventTable.EventTypeColumnName,
                                eventTable.TableName,
                                stateBase.GetChangetableVersionThreshold(eventTable.TableName));
                        Log.Logger.Debug($"{config.JobName}: Getting data changes from changetables with: {cmd.CommandText}");

                        try
                        {
                            conn.Open();
                            using (var reader = cmd.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    dataChange.AddChange(DataRowToChangeTableEvent(reader, eventTable));
                                }
                            }
                        }
                        catch (SqlException e)
                        {
                            Log.Logger.Error($"{config.JobName}: SQL error when executing {cmd.CommandText}", e);
                            throw;
                        }
                    }
                yield return(dataChange);
            }
        }