public void OnMessageRaised(string message, MessageImportance importance = MessageImportance.Normal)
        {
            BuildMessageEventArgs args = new BuildMessageEventArgs(message, null, null, importance);

            MessageRaised?.Invoke(this, args);
            OnAnyEventRaised(args);
        }
Esempio n. 2
0
        /// <summary>
        /// Raise one of the events that is appropriate for the type of the BuildEventArgs
        /// </summary>
        public void Dispatch(BuildEventArgs buildEvent)
        {
            if (buildEvent is BuildMessageEventArgs)
            {
                MessageRaised?.Invoke(null, (BuildMessageEventArgs)buildEvent);
            }
            else if (buildEvent is TaskStartedEventArgs)
            {
                TaskStarted?.Invoke(null, (TaskStartedEventArgs)buildEvent);
            }
            else if (buildEvent is TaskFinishedEventArgs)
            {
                TaskFinished?.Invoke(null, (TaskFinishedEventArgs)buildEvent);
            }
            else if (buildEvent is TargetStartedEventArgs)
            {
                TargetStarted?.Invoke(null, (TargetStartedEventArgs)buildEvent);
            }
            else if (buildEvent is TargetFinishedEventArgs)
            {
                TargetFinished?.Invoke(null, (TargetFinishedEventArgs)buildEvent);
            }
            else if (buildEvent is ProjectStartedEventArgs)
            {
                ProjectStarted?.Invoke(null, (ProjectStartedEventArgs)buildEvent);
            }
            else if (buildEvent is ProjectFinishedEventArgs)
            {
                ProjectFinished?.Invoke(null, (ProjectFinishedEventArgs)buildEvent);
            }
            else if (buildEvent is BuildStartedEventArgs)
            {
                BuildStarted?.Invoke(null, (BuildStartedEventArgs)buildEvent);
            }
            else if (buildEvent is BuildFinishedEventArgs)
            {
                BuildFinished?.Invoke(null, (BuildFinishedEventArgs)buildEvent);
            }
            else if (buildEvent is CustomBuildEventArgs)
            {
                CustomEventRaised?.Invoke(null, (CustomBuildEventArgs)buildEvent);
            }
            else if (buildEvent is BuildStatusEventArgs)
            {
                StatusEventRaised?.Invoke(null, (BuildStatusEventArgs)buildEvent);
            }
            else if (buildEvent is BuildWarningEventArgs)
            {
                WarningRaised?.Invoke(null, (BuildWarningEventArgs)buildEvent);
            }
            else if (buildEvent is BuildErrorEventArgs)
            {
                ErrorRaised?.Invoke(null, (BuildErrorEventArgs)buildEvent);
            }

            AnyEventRaised?.Invoke(null, buildEvent);
        }
Esempio n. 3
0
        /// <summary>
        /// 标定
        /// </summary>
        public void GetCalibMatrix()
        {
            //拼接数据
            double[] pxArray = new double[CalibPointList.Count];
            double[] pyArray = new double[CalibPointList.Count];
            double[] qxArray = new double[CalibPointList.Count];
            double[] qyArray = new double[CalibPointList.Count];
            double[] posMatrix;
            double[] invMatrix;
            bool     result1 = false;
            bool     result2 = false;

            CalibParam.CalibPointList.Clear();

            for (int i = 0; i < CalibPointList.Count; i++)
            {
                pxArray[i] = CalibPointList[i].Px;
                pyArray[i] = CalibPointList[i].Py;
                qxArray[i] = CalibPointList[i].Qx;
                qyArray[i] = CalibPointList[i].Qy;
            }
            CalibParam.CalibPointList = CalibPointList.ToList();

            //计算标定矩阵
            if (GetCalibMatrixCallback != null)
            {
                result1 = GetCalibMatrixCallback.Invoke(pxArray, pyArray, qxArray, qyArray, out posMatrix);
                result2 = GetCalibMatrixCallback.Invoke(qxArray, qyArray, pxArray, pyArray, out invMatrix);
            }
            else
            {
                result1 = SimpleVision.Calibration.CreateCalibMatrix(pxArray, pyArray, qxArray, qyArray, out posMatrix);
                result2 = SimpleVision.Calibration.CreateCalibMatrix(qxArray, qyArray, pxArray, pyArray, out invMatrix);
            }

            //结果保存
            CalibParam.IsValid   = result1 && result2;
            CalibParam.Matrix    = posMatrix;
            CalibParam.InvMatrix = invMatrix;

            NotifyOfPropertyChange(() => Matrix);

            if (CalibParam.IsValid)
            {
                MessageRaised?.Invoke(this, new MessageRaisedEventArgs(MessageLevel.Message, "标定成功!"));
            }
            else
            {
                MessageRaised?.Invoke(this, new MessageRaisedEventArgs(MessageLevel.Warning, "标定失败!请检查相关的数据"));
            }
        }
Esempio n. 4
0
        public void ReadData()
        {
            unsafe
            {
                uint dataLength = 10240;
                //uint dataLength = 1000;
                IntPtr channel1Data   = Marshal.AllocHGlobal(2 * (int)dataLength);
                IntPtr channel2Data   = Marshal.AllocHGlobal(2 * (int)dataLength);
                uint   trigPointIndex = 0;

                if (Hantek66022BE.dsoReadHardData(0, channel1Data, channel2Data, dataLength, calData, 5, 5, 0, 0, 64, 0, 14, 50, (uint)dataLength, ref trigPointIndex, 0) != -1)
                {
                    //显示数据
                    ushort *channel1 = (ushort *)channel1Data.ToPointer();
                    ushort *channel2 = (ushort *)channel2Data.ToPointer();


                    short[] channel1Buff = new short[dataLength];
                    Marshal.Copy(channel1Data, channel1Buff, 0, (int)dataLength);

                    PerformanceView.SetData(channel1Buff);


                    var collection = new System.Collections.ObjectModel.ObservableCollection <Data>();
                    for (int i = 0; i < dataLength; i++)
                    {
                        //LiveDataViewModel.Collection.Add(channel1Buff[i]);
                        collection.Add(new Data()
                        {
                            Value1 = channel1Buff[i], Value = i
                        });
                    }

                    LiveDataViewModel.Collection = collection;

                    //
                    //SeriesCollection[0].Values = new ChartValues<short>(channel1Buff);
                    //NotifyOfPropertyChange(() => SeriesCollection);
                }
                else
                {
                    MessageRaised?.Invoke(this, new MessageRaisedEventArgs(MessageLevel.Err, "读取数据失败!"));
                }

                Marshal.FreeHGlobal(channel1Data);
                Marshal.FreeHGlobal(channel2Data);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 初始化系统
 /// </summary>
 public void Init()
 {
     if (Hantek66022BE.dsoOpenDevice(0) != 0)
     {
         unsafe
         {
             Hantek66022BE.dsoGetCalLevel(0, calData, 32);
             Hantek66022BE.dsoSetVoltDIV(0, 0, 5);
             Hantek66022BE.dsoSetVoltDIV(0, 1, 5);
             Hantek66022BE.dsoSetTimeDIV(0, 14);
         }
     }
     else
     {
         MessageRaised?.Invoke(this, new MessageRaisedEventArgs(MessageLevel.Err, "打开设备失败!"));
     }
 }
Esempio n. 6
0
 public void LogMessageEvent(BuildMessageEventArgs args)
 {
     MessageRaised?.Invoke(this, args);
     AnyEventRaised?.Invoke(this, args);
 }
Esempio n. 7
0
 /// <summary>
 /// Force raise of event 'ServiceMessageRaised'
 /// </summary>
 /// <param name="raisedMessage">Raised message</param>
 protected void RaiseMessage(string raisedMessage)
 {
     //Se il gestore è stato collegatio
     MessageRaised?.Invoke(this, new ServiceMessageRaisedEventArgs(raisedMessage));
 }
Esempio n. 8
0
        public void UdpListener_Received(byte[] data, IPEndPoint endPoint)
        {
            try
            {
                var dhcpData = new DhcpData(data)
                {
                    RelatedServer = this
                };
                var msgType = dhcpData.GetCurrentMessageType();
                var client  = dhcpData.GetClientInfo();
                switch (msgType)
                {
                case DhcpMessgeType.DHCP_DISCOVER:
                    MessageRaised?.Invoke(this, new MessageEventArgs {
                        Message = "DHCPDISCOVER received."
                    });
                    Discovered?.Invoke(client);
                    var newIp = ownedIpAddressPool.Find(x => (x.AuthorizedClientMac == client.MacAddress) || (x.IsAllocated == false && x.AuthorizedClientMac == null));
                    if (newIp.Ip == null)
                    {
                        MessageRaised?.Invoke(this, new MessageEventArgs {
                            Message = "No ip is available to allocate."
                        });
                        return;
                    }
                    MessageRaised?.Invoke(this, new MessageEventArgs {
                        Message = "DHCPOFFER sent."
                    });
                    // MUST be unicast over raw socket (unimplemented)
                    // broadcast used
                    SendDhcpMessage(DhcpMessgeType.DHCP_OFFER, dhcpData, newIp);
                    break;

                case DhcpMessgeType.DHCP_REQUEST:
                    MessageRaised?.Invoke(this, new MessageEventArgs {
                        Message = "DHCPREQUEST received."
                    });
                    Requested?.Invoke(client);
                    switch (GetDhcpRequestType(client, endPoint))
                    {
                    // respond to client which has responded to DHCPOFFER message from this server
                    case DhcpRequestType.Selecting:
                        MessageRaised?.Invoke(this, new MessageEventArgs {
                            Message = "Response to DHCPREQUEST generated during SELECTING state."
                        });
                        if (_settings.ServerIp.Equals(client.ServerAddress))
                        {
                            var allocatedIp = ownedIpAddressPool.Find(x => x.Ip.Equals(client.RequestAddress));
                            if (allocatedIp.Ip != null && !allocatedIp.IsAllocated)
                            {
                                allocatedIp.IsAllocated         = true;
                                allocatedIp.AuthorizedClientMac = client.MacAddress;
                                MessageRaised?.Invoke(this, new MessageEventArgs {
                                    Message = "DHCPACK sent."
                                });
                                // broadcast
                                SendDhcpMessage(DhcpMessgeType.DHCP_ACK, dhcpData, allocatedIp);
                            }
                        }
                        break;

                    case DhcpRequestType.InitReboot:
                        MessageRaised?.Invoke(this, new MessageEventArgs {
                            Message = "Response to DHCPREQUEST generated during INIT-REBOOT state."
                        });
                        if (!client.RelayAgentAddress.Equals(IPAddress.Any))
                        {
                            MessageRaised?.Invoke(this, new MessageEventArgs {
                                Message = "Relay agent is not supported in this version."
                            });
                        }
                        var rebootIp = ownedIpAddressPool.Find(x => x.Ip.Equals(client.RequestAddress));
                        if (rebootIp.Ip != null && rebootIp.AuthorizedClientMac == client.MacAddress)
                        {
                            // broadcast
                            SendDhcpMessage(DhcpMessgeType.DHCP_ACK, dhcpData, rebootIp);
                            MessageRaised?.Invoke(this, new MessageEventArgs {
                                Message = "DHCPACK sent."
                            });
                        }
                        break;

                    case DhcpRequestType.ReNewing:
                        MessageRaised?.Invoke(this, new MessageEventArgs {
                            Message = "Response to DHCPREQUEST generated during RENEWING state."
                        });
                        var reNewIp = ownedIpAddressPool.Find(x => x.Ip.Equals(client.ClientAddress));
                        if (reNewIp.Ip != null && reNewIp.AuthorizedClientMac == client.MacAddress)
                        {
                            // unicast
                            SendDhcpMessage(client.ClientAddress.ToString(), DhcpMessgeType.DHCP_ACK, dhcpData, reNewIp);
                            MessageRaised?.Invoke(this, new MessageEventArgs {
                                Message = "DHCPACK sent."
                            });
                        }
                        break;

                    case DhcpRequestType.ReBinding:
                        MessageRaised?.Invoke(this, new MessageEventArgs {
                            Message = "Response to DHCPREQUEST generated during REBINDING state."
                        });
                        var reBindIp = ownedIpAddressPool.Find(x => x.IsAllocated == false);
                        if (reBindIp.Ip != null)
                        {
                            reBindIp.IsAllocated         = true;
                            reBindIp.AuthorizedClientMac = client.MacAddress;
                            // broadcast
                            SendDhcpMessage(DhcpMessgeType.DHCP_ACK, dhcpData, reBindIp);
                            MessageRaised?.Invoke(this, new MessageEventArgs {
                                Message = "DHCPACK sent."
                            });
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    break;

                case DhcpMessgeType.DHCP_DECLINE:
                    MessageRaised?.Invoke(this, new MessageEventArgs {
                        Message = "DHCPDECLINE received."
                    });
                    var declinedIp = ownedIpAddressPool.Find(x => x.Ip.Equals(client.ClientAddress));
                    if (declinedIp.Ip != null)
                    {
                        ownedIpAddressPool.Remove(declinedIp);
                    }
                    break;

                case DhcpMessgeType.DHCP_RELEASE:
                    MessageRaised?.Invoke(this, new MessageEventArgs {
                        Message = "DHCPRELESE received."
                    });
                    var releasedIp = ownedIpAddressPool.Find(x => x.Ip.Equals(client.ClientAddress));
                    if (releasedIp.Ip != null)
                    {
                        releasedIp.IsAllocated = false;
                    }
                    break;

                case DhcpMessgeType.DHCP_INFORM:
                    MessageRaised?.Invoke(this, new MessageEventArgs {
                        Message = "DHCPINFORM received."
                    });
                    // unicast
                    SendDhcpMessage(client.ClientAddress.ToString(), DhcpMessgeType.DHCP_ACK, dhcpData, null);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                ErrorRaised?.Invoke(this, new ErrorMessageEventArgs {
                    Message = e.Message
                });
                Terminate();
                throw e;
            }
        }
Esempio n. 9
0
 internal void OnMessageRaised(MessageLevel messageLevel, string message, Exception exception = null)
 {
     MessageRaised?.Invoke(this, new MessageRaisedEventArgs(messageLevel, message, exception));
 }
Esempio n. 10
0
 private void EventSourceOnMessageRaised(object sender, BuildMessageEventArgs e)
 {
     MessageRaised?.Invoke(sender, e);
 }