Exemplo n.º 1
0
 /// <summary>
 /// Calculate single sensor value with alarm option
 /// Non auto save changed to database, you must call entityConntext.SaveChanges() to save changed.
 /// </summary>
 /// <param name="sensorValue"></param>
 /// <param name="alarmLogger"></param>
 public void Calculating(SensorValue sensorValue, bool alarmLogger)
 {
     Calculating(sensorValue);
     if (alarmLogger)
     {
         AlarmBLL.Current.CheckAlarm(sensorValue);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Check sensor value and auto add alarm log if it is out of range.
        /// Non auto save changed to database, you must call entityConntext.SaveChanges() to save changed.
        /// </summary>
        /// <param name="sensorValue"></param>
        /// <returns></returns>
        public bool CheckAlarm(SensorValue sensorValue)
        {
            var sensor = sensorValue.Sensor;
            if (sensor.AlarmEnabled)
            {
                if ((sensor.MinValue != null && sensor.MinValue > sensorValue.CalcValue) || (sensor.MaxValue != null && sensor.MaxValue < sensorValue.CalcValue))
                {
                    if (sensor.AlarmFlag)
                    {
                        var lastAlarm =
                           sensor.AlarmLogs.LastOrDefault(
                               ent => !ent.IsEnded && ent.StartAlarmDatetime <= sensorValue.MeaTime);
                        if (lastAlarm == null || lastAlarm.CalcValue == sensorValue.CalcValue)
                        {
                            return false;
                        }
                    }
                    // Add Alarm
                    var alarm = new AlarmLog();
                    alarm.SensorID = sensor.SensorID;
                    // Set project ID
                    alarm.ProjectID = sensor.ProjectID;

                    alarm.CalcValue = sensorValue.CalcValue;
                    alarm.IsEnded = false;
                    alarm.StartAlarmDatetime = sensorValue.MeaTime;
                    alarm.Title = sensor.Logger.Name + " - " + sensor.Name;
                    // Edited by binhpro 23/11/2012
                    decimal range = sensor.MaxValue.Value - sensor.MinValue.Value;
                    if (range == 0) range = sensor.MaxValue.Value;

                    if (alarm.CalcValue < sensor.MinValue && range != 0)
                    {
                        alarm.Title += " - dưới ngưỡng " + Math.Round(Math.Abs((decimal)((sensor.MinValue - alarm.CalcValue) / range * 100)), 0) + " %";
                    }
                    else if (alarm.CalcValue > sensor.MaxValue && range != 0)
                    {
                        alarm.Title += " - vượt ngưỡng " + Math.Round(Math.Abs((decimal)((alarm.CalcValue - sensor.MaxValue) / range * 100)), 0) + " %";
                    }
                    alarm.Title += " - " + alarm.StartAlarmDatetime;
                    // Set Alarm Flag Of Sensor TRUE
                    sensor.AlarmFlag = true;
                    sensor.AlarmLogs.Add(alarm);
                    return true;
                }
                if (sensor.AlarmFlag)
                {
                    // Set Alarm Flag Of Sensor FALSE
                    sensor.AlarmFlag = false;
                    // Close All Alarm Log Before
                    var logs =
                        sensor.AlarmLogs.Where(ent => !ent.IsEnded && ent.StartAlarmDatetime <= sensorValue.MeaTime);
                    foreach (var alarmLog in logs)
                    {
                        alarmLog.IsEnded = true;
                        alarmLog.EndAlarmDatetime = sensorValue.MeaTime;
                    }
                    // entityConntext.SaveChanges();
                }
                return false;
            }
            return false;
        }
Exemplo n.º 3
0
 private decimal getSensorValue(SensorValue sensorValue)
 {
     if (_displayRawValue) return sensorValue.RawValue;
     return sensorValue.CalcValue;
 }
Exemplo n.º 4
0
 private string getDisplayValue(SensorValue sensorValue)
 {
     if (_displayRawValue) return sensorValue.RawValue.ToString();
     return sensorValue.CalcValue.ToString();
 }
Exemplo n.º 5
0
        private void LoadPicture(Models.PictureView pictureView)
        {
            try
            {
                panel.Controls.Clear();
                this.Text = pictureView.Name;
                // Linq to entities
                var objectlist = entityConntext.Objects.Where(ent => ent.PictureViewID == pictureView.PictureViewID).OrderBy(ent => ent.Z_Index);
                foreach (GeoViewer.Models.Object obj in objectlist)
                {
                    switch (obj.Type)
                    {
                        case 1: // Indicator
                            // Indicator Intitialization
                            indicator ind = new indicator();
                            ind.Location = new System.Drawing.Point(obj.X, obj.Y);
                            ind.Size = new System.Drawing.Size(obj.Width, obj.Height);
                            ind.FillColor = System.Drawing.Color.Lime;
                            ind.AccessibleName = obj.ObjectID.ToString();
                            ind.AccessibleDescription = "1";
                            // Get sensor name + unit + value
                            int sensorId = Convert.ToInt32(obj.Parameters);
                            var sensor = SensorBLL.Current.GetByID(sensorId);
                            Models.SensorValue sensorValue = new SensorValue();
                            if (sensor != null)
                            {
                                // Associate with sensor
                                // Add tooltip display description - binhpro 27/02/2013
                                if (!string.IsNullOrEmpty(sensor.Description))
                                {
                                    toolTip1.SetToolTip(ind, "Công thức: " + sensor.FormulaFunction + "\n" + sensor.Description);
                                }

                                ind.VarName = sensor.Name;
                                ind.UnitName = sensor.Unit;
                                if (entityConntext.SensorValues.
                                    Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).Count() > 0)
                                {
                                    sensorValue = entityConntext.SensorValues.
                                        Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).First();
                                    ind.Value = getDisplayValue(sensorValue);
                                    // Check if value is in alarm level
                                    if (PictureViewBLL.Current.CheckAlarmRunning(obj)) ind.FillColor = System.Drawing.Color.Red;
                                }
                            }
                            // Add to picture
                            this.panel.Controls.Add(ind);
                            ind.BringToFront();
                            break;
                        case 2: // Group Indicator
                            // Group Indicator Initialization
                            groupIndicator i = new groupIndicator();
                            i.Location = new System.Drawing.Point(obj.X, obj.Y);
                            i.Size = new System.Drawing.Size(obj.Width, obj.Height);
                            i.FillColor = System.Drawing.Color.Lime;
                            i.BackColor = System.Drawing.Color.Transparent;
                            i.AccessibleName = obj.ObjectID.ToString();
                            i.AccessibleDescription = "2";
                            // Check if value is in alarm level
                            //int idPicture = Convert.ToInt32(obj.Parameters);
                            //var subObjectList = entityConntext.Objects.
                            //    Where(ent => ent.PictureViewID == idPicture);
                            //foreach (GeoViewer.Models.Object subObject in subObjectList)
                            //{
                            //    if (PictureViewBLL.Current.CheckAlarmRunning(subObject))
                            //    {
                            //        i.FillColor = Color.Red;
                            //        break;
                            //    }
                            //}

                            //Edited By binhpro 18/10/2012
                            if (PictureViewBLL.Current.CheckAlarmRunning(obj))
                            {
                                i.FillColor = Color.Red;
                            }

                            // Add to picture
                            this.panel.Controls.Add(i);
                            i.BringToFront();
                            break;
                        case 3: // Image
                            // Image Initialization
                            System.Windows.Forms.PictureBox newpicture = new System.Windows.Forms.PictureBox();
                            newpicture.Location = new System.Drawing.Point(obj.X, obj.Y);
                            newpicture.ImageLocation = obj.Parameters;
                            newpicture.Size = new System.Drawing.Size(obj.Width, obj.Height);
                            newpicture.SizeMode = PictureBoxSizeMode.StretchImage;
                            newpicture.AccessibleName = obj.ObjectID.ToString();
                            newpicture.AccessibleDescription = "3";
                            // Add to picture
                            this.panel.Controls.Add(newpicture);
                            newpicture.BringToFront();
                            break;
                        case 4: // Gauge
                            // Gauge Initilization
                            Dundas.Gauges.WinControl.GaugeContainer gaugeContainer = new Dundas.Gauges.WinControl.GaugeContainer();
                            Dundas.Gauges.WinControl.CircularGauge circularGauge = new Dundas.Gauges.WinControl.CircularGauge();
                            Dundas.Gauges.WinControl.CircularPointer circularPointer = new Dundas.Gauges.WinControl.CircularPointer();
                            Dundas.Gauges.WinControl.CircularScale circularScale = new Dundas.Gauges.WinControl.CircularScale();
                            Dundas.Gauges.WinControl.GaugeLabel gaugeLabel = new Dundas.Gauges.WinControl.GaugeLabel();
                            gaugeContainer.BackFrame.BackColor = System.Drawing.Color.Transparent;
                            gaugeContainer.BackFrame.BackGradientEndColor = System.Drawing.Color.Transparent;
                            gaugeContainer.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer.BackFrame.FrameColor = System.Drawing.Color.Transparent;
                            gaugeContainer.BackFrame.FrameGradientEndColor = System.Drawing.Color.Transparent;
                            gaugeContainer.BackFrame.FrameGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.AutoShape;
                            gaugeContainer.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.Edged;
                            gaugeContainer.BackFrame.FrameWidth = 0F;
                            circularGauge.BackFrame.BackColor = System.Drawing.Color.White;
                            circularGauge.BackFrame.BackGradientEndColor = System.Drawing.Color.White;
                            circularGauge.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            circularGauge.BackFrame.BorderColor = System.Drawing.Color.Gray;
                            circularGauge.BackFrame.BorderWidth = 2;
                            circularGauge.BackFrame.FrameColor = System.Drawing.Color.Transparent;
                            circularGauge.BackFrame.FrameGradientEndColor = System.Drawing.Color.Transparent;
                            circularGauge.BackFrame.FrameGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            circularGauge.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.Rectangular;
                            circularGauge.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.Simple;
                            circularGauge.BackFrame.FrameWidth = 0F;
                            circularGauge.Location.X = 0F;
                            circularGauge.Location.Y = 0F;
                            circularGauge.Name = "Default";
                            circularGauge.PivotPoint.X = 50F;
                            circularGauge.PivotPoint.Y = 45F;
                            circularPointer.BorderStyle = Dundas.Gauges.WinControl.GaugeDashStyle.Solid;
                            circularPointer.BorderWidth = 0;
                            circularPointer.CapFillColor = System.Drawing.Color.DimGray;
                            circularPointer.CapFillGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            circularPointer.CapWidth = 24F;
                            circularPointer.FillColor = System.Drawing.Color.Lime;
                            circularPointer.FillGradientEndColor = System.Drawing.Color.LightGray;
                            circularPointer.FillGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            circularPointer.Name = "Default";
                            circularPointer.NeedleStyle = Dundas.Gauges.WinControl.NeedleStyle.NeedleStyle11;
                            circularPointer.ShadowOffset = 0F;
                            circularPointer.Width = 10F;
                            circularGauge.Pointers.Add(circularPointer);
                            circularScale.BorderColor = System.Drawing.Color.White;
                            circularScale.BorderWidth = 1;
                            circularScale.FillColor = System.Drawing.Color.Black;
                            circularScale.LabelStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.30189F);
                            circularScale.LabelStyle.RotateLabels = false;
                            circularScale.MajorTickMark.BorderWidth = 0;
                            circularScale.MajorTickMark.FillColor = System.Drawing.Color.Black;
                            circularScale.MajorTickMark.Shape = Dundas.Gauges.WinControl.MarkerStyle.Rectangle;
                            circularScale.MajorTickMark.Width = 2F;
                            circularScale.MinorTickMark.BorderWidth = 0;
                            circularScale.MinorTickMark.FillColor = System.Drawing.Color.Black;
                            circularScale.MinorTickMark.Width = 1.5F;
                            circularScale.Name = "Default";
                            circularScale.Radius = 44F;
                            circularScale.ShadowOffset = 0F;
                            circularScale.StartAngle = 30F;
                            circularScale.SweepAngle = 300F;
                            circularScale.Width = 0F;
                            circularScale.Minimum = 0D;
                            circularScale.Maximum = 100D;
                            circularGauge.Scales.Add(circularScale);
                            circularGauge.Size.Height = 100F;
                            circularGauge.Size.Width = 100F;
                            circularGauge.Pointers["Default"].Value = 0;
                            gaugeContainer.CircularGauges.Add(circularGauge);
                            gaugeContainer.InternalBackgroundPaint = false;
                            gaugeLabel.BackColor = System.Drawing.Color.Empty;
                            gaugeLabel.BackGradientEndColor = System.Drawing.Color.Empty;
                            gaugeLabel.Location.X = 19F;
                            gaugeLabel.Location.Y = 80F;
                            gaugeLabel.Name = "Default";
                            gaugeLabel.Parent = "CircularGauges.Default";
                            gaugeLabel.Size.Height = 18F;
                            gaugeLabel.Size.Width = 66F;
                            gaugeLabel.Text = "";
                            gaugeLabel.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
                            gaugeContainer.Labels.Add(gaugeLabel);

                            gaugeContainer.Location = new Point(obj.X, obj.Y);
                            gaugeContainer.Size = new System.Drawing.Size(obj.Width, obj.Height);
                            gaugeContainer.AccessibleName = obj.ObjectID.ToString();
                            gaugeContainer.AccessibleDescription = "4";
                            // Get sensor name + unit + value
                            sensorId = Convert.ToInt32(obj.Parameters);
                            sensor = SensorBLL.Current.GetByID(sensorId);
                            if (sensor != null)
                            {
                                // Associate with sensor
                                // Add tooltip display description - binhpro 27/02/2013
                                if (!string.IsNullOrEmpty(sensor.Description))
                                {
                                    toolTip1.SetToolTip(gaugeContainer, "Công thức: " + sensor.FormulaFunction + "\n" + sensor.Description);
                                }
                                gaugeLabel.Text = sensor.Name + "\n" + sensor.Unit;
                                if (sensor.MaxValue != null) circularScale.Maximum = System.Convert.ToDouble(sensor.MaxValue);
                                if (sensor.MinValue != null) circularScale.Minimum = System.Convert.ToDouble(sensor.MinValue);
                                // Read latest value (if exists)
                                if (entityConntext.SensorValues.
                                    Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).Count() != 0)
                                {
                                    sensorValue = entityConntext.SensorValues.
                                        Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).First();
                                    if (sensor.MaxValue == null)
                                        circularScale.Maximum = Math.Round(System.Convert.ToDouble(getSensorValue(sensorValue)) + 1D, 0);
                                    if (sensor.MinValue == null)
                                        circularScale.Minimum = Math.Round(System.Convert.ToDouble(getSensorValue(sensorValue)) - 1D, 0);
                                    gaugeContainer.CircularGauges["Default"].Pointers["Default"].Value = System.Convert.ToDouble(getSensorValue(sensorValue));
                                    gaugeLabel.Text = sensor.Name + "\n" + getDisplayValue(sensorValue) + " " + sensor.Unit;
                                    // Check if value is in alarm level
                                    if (PictureViewBLL.Current.CheckAlarmRunning(obj))
                                        circularPointer.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
                                }
                            }
                            // Add to picture
                            this.panel.Controls.Add(gaugeContainer);
                            gaugeContainer.BringToFront();
                            break;
                        case 5: // Vertical Bar
                            // Vertical Bar Initilization
                            Dundas.Gauges.WinControl.LinearGauge linearGauge1 = new Dundas.Gauges.WinControl.LinearGauge();
                            Dundas.Gauges.WinControl.LinearPointer linearPointer1 = new Dundas.Gauges.WinControl.LinearPointer();
                            Dundas.Gauges.WinControl.LinearScale linearScale1 = new Dundas.Gauges.WinControl.LinearScale();
                            Dundas.Gauges.WinControl.GaugeContainer gaugeContainer1 = new Dundas.Gauges.WinControl.GaugeContainer();
                            Dundas.Gauges.WinControl.GaugeLabel gaugeLabel1 = new Dundas.Gauges.WinControl.GaugeLabel();
                            gaugeContainer1.BackFrame.BackColor = System.Drawing.Color.White;
                            gaugeContainer1.BackFrame.BackGradientEndColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
                            gaugeContainer1.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer1.BackFrame.FrameGradientEndColor = System.Drawing.Color.DimGray;
                            gaugeContainer1.BackFrame.FrameGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer1.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.Rectangular;
                            gaugeContainer1.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.None;
                            gaugeContainer1.BackFrame.FrameWidth = 2F;
                            gaugeContainer1.InternalBackgroundPaint = false;
                            gaugeContainer1.LinearGauges.Add(linearGauge1);
                            gaugeLabel1.BackColor = System.Drawing.Color.Empty;
                            gaugeLabel1.BackGradientEndColor = System.Drawing.Color.Empty;
                            gaugeLabel1.Location.X = 14.27777F;
                            gaugeLabel1.Location.Y = 87.39495F;
                            gaugeLabel1.Name = "Default";
                            gaugeLabel1.Parent = "LinearGauges.Default";
                            gaugeLabel1.Size.Height = 14F;
                            gaugeLabel1.Size.Width = 72F;
                            gaugeLabel1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
                            gaugeLabel1.Text = "";
                            gaugeContainer1.Labels.Add(gaugeLabel1);
                            linearGauge1.BackFrame.BackColor = System.Drawing.Color.White;
                            linearGauge1.BackFrame.BackGradientEndColor = System.Drawing.Color.DimGray;
                            linearGauge1.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            linearGauge1.BackFrame.FrameColor = System.Drawing.Color.Silver;
                            linearGauge1.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.Rectangular;
                            linearGauge1.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.Edged;
                            linearGauge1.BackFrame.FrameWidth = 1F;
                            linearGauge1.Location.X = 0F;
                            linearGauge1.Location.Y = 0F;
                            linearGauge1.Name = "Default";
                            linearGauge1.Orientation = Dundas.Gauges.WinControl.GaugeOrientation.Vertical;
                            linearPointer1.BorderWidth = 0;
                            linearPointer1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(0)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
                            linearPointer1.FillGradientEndColor = System.Drawing.Color.FromArgb(((int)(((byte)(140)))), ((int)(((byte)(0)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
                            linearPointer1.FillGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            linearPointer1.Name = "Default";
                            linearPointer1.Placement = Dundas.Gauges.WinControl.Placement.Cross;
                            linearPointer1.ShadowOffset = 0F;
                            linearPointer1.ThermometerBackColor = System.Drawing.Color.Empty;
                            linearPointer1.ThermometerBackGradientEndColor = System.Drawing.Color.Empty;
                            linearPointer1.Type = Dundas.Gauges.WinControl.LinearPointerType.Bar;
                            linearPointer1.Width = 15F;
                            linearGauge1.Pointers.Add(linearPointer1);
                            linearScale1.Minimum = 0D;
                            linearScale1.Maximum = 100D;
                            linearScale1.EndMargin = 6F;
                            linearScale1.FillColor = System.Drawing.Color.Black;
                            linearScale1.LabelStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 10.18868F);
                            linearScale1.LabelStyle.FontUnit = Dundas.Gauges.WinControl.FontUnit.Default;
                            linearScale1.MajorTickMark.BorderWidth = 0;
                            linearScale1.MajorTickMark.FillColor = System.Drawing.Color.Black;
                            linearScale1.MajorTickMark.Length = 19F;
                            linearScale1.MajorTickMark.Width = 2F;
                            linearScale1.MinorTickMark.BorderWidth = 0;
                            linearScale1.MinorTickMark.FillColor = System.Drawing.Color.Black;
                            linearScale1.MinorTickMark.Length = 10F;
                            linearScale1.MinorTickMark.Width = 1.5F;
                            linearScale1.Name = "Default";
                            linearScale1.Position = 65F;
                            linearScale1.ShadowOffset = 0F;
                            linearScale1.StartMargin = 15F;
                            linearScale1.Width = 0F;
                            linearScale1.Maximum = 100D;
                            linearScale1.Minimum = 0D;
                            linearGauge1.Scales.Add(linearScale1);
                            linearGauge1.Size.Height = 100F;
                            linearGauge1.Size.Width = 100F;
                            gaugeContainer1.LinearGauges["Default"].Pointers["Default"].Value = 0;

                            gaugeContainer1.Location = new Point(obj.X, obj.Y);
                            gaugeContainer1.Size = new System.Drawing.Size(obj.Width, obj.Height);
                            gaugeContainer1.AccessibleName = obj.ObjectID.ToString();
                            gaugeContainer1.AccessibleDescription = "5";
                            // Get sensor name + unit + value
                            sensorId = Convert.ToInt32(obj.Parameters);
                            sensor = SensorBLL.Current.GetByID(sensorId);
                            if (sensor != null)
                            {
                                // Associate with sensor
                                // Add tooltip display description - binhpro 27/02/2013
                                if (!string.IsNullOrEmpty(sensor.Description))
                                {
                                    toolTip1.SetToolTip(gaugeContainer1, "Công thức: " + sensor.FormulaFunction + "\n" + sensor.Description);
                                }
                                gaugeLabel1.Text = sensor.Name + "\n" + sensor.Unit;
                                if (sensor.MaxValue != null) linearScale1.Maximum = System.Convert.ToDouble(sensor.MaxValue);
                                if (sensor.MinValue != null) linearScale1.Minimum = System.Convert.ToDouble(sensor.MinValue);
                                // Read latest value (if exists)
                                if (entityConntext.SensorValues.
                                    Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).Count() != 0)
                                {
                                    sensorValue = entityConntext.SensorValues.
                                        Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).First();
                                    if (sensor.MaxValue == null)
                                        linearScale1.Maximum = Math.Round(System.Convert.ToDouble(getSensorValue(sensorValue)) + 1D, 0);
                                    if (sensor.MinValue == null)
                                        linearScale1.Minimum = Math.Round(System.Convert.ToDouble(getSensorValue(sensorValue)) - 1D, 0);
                                    gaugeContainer1.LinearGauges["Default"].Pointers["Default"].Value = System.Convert.ToDouble(getSensorValue(sensorValue));
                                    gaugeLabel1.Text = sensor.Name + "\n" + getSensorValue(sensorValue).ToString() + " " + sensor.Unit;
                                    // Check if value is in alarm level
                                    if (PictureViewBLL.Current.CheckAlarmRunning(obj))
                                        linearPointer1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
                                }
                            }
                            // Add to picture
                            this.panel.Controls.Add(gaugeContainer1);
                            gaugeContainer1.BringToFront();
                            break;
                        case 6: // Horizontal Bar
                            // Horizontal Bar Initilization
                            linearGauge1 = new Dundas.Gauges.WinControl.LinearGauge();
                            linearPointer1 = new Dundas.Gauges.WinControl.LinearPointer();
                            linearScale1 = new Dundas.Gauges.WinControl.LinearScale();
                            gaugeContainer1 = new Dundas.Gauges.WinControl.GaugeContainer();
                            gaugeLabel1 = new Dundas.Gauges.WinControl.GaugeLabel();
                            gaugeContainer1.BackFrame.BackColor = System.Drawing.Color.White;
                            gaugeContainer1.BackFrame.BackGradientEndColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
                            gaugeContainer1.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer1.BackFrame.FrameGradientEndColor = System.Drawing.Color.DimGray;
                            gaugeContainer1.BackFrame.FrameGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer1.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.Rectangular;
                            gaugeContainer1.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.None;
                            gaugeContainer1.BackFrame.FrameWidth = 2F;
                            gaugeContainer1.InternalBackgroundPaint = false;
                            gaugeContainer1.LinearGauges.Add(linearGauge1);
                            gaugeLabel1.BackColor = System.Drawing.Color.Empty;
                            gaugeLabel1.BackGradientEndColor = System.Drawing.Color.Empty;
                            gaugeLabel1.Location.X = 32F;
                            gaugeLabel1.Location.Y = 62F;
                            gaugeLabel1.Name = "Default";
                            gaugeLabel1.Parent = "LinearGauges.Default";
                            gaugeLabel1.Size.Height = 34F;
                            gaugeLabel1.Size.Width = 39F;
                            gaugeLabel1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
                            gaugeLabel1.Text = "";
                            gaugeContainer1.Labels.Add(gaugeLabel1);
                            linearGauge1.BackFrame.BackColor = System.Drawing.Color.White;
                            linearGauge1.BackFrame.BackGradientEndColor = System.Drawing.Color.DimGray;
                            linearGauge1.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            linearGauge1.BackFrame.FrameColor = System.Drawing.Color.Silver;
                            linearGauge1.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.Rectangular;
                            linearGauge1.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.Edged;
                            linearGauge1.BackFrame.FrameWidth = 2F;
                            linearGauge1.Location.X = 0F;
                            linearGauge1.Location.Y = 0F;
                            linearGauge1.Name = "Default";
                            linearGauge1.Orientation = Dundas.Gauges.WinControl.GaugeOrientation.Horizontal;
                            linearPointer1.BorderWidth = 0;
                            linearPointer1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(0)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
                            linearPointer1.FillGradientEndColor = System.Drawing.Color.FromArgb(((int)(((byte)(182)))), ((int)(((byte)(0)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))));
                            linearPointer1.FillGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            linearPointer1.Name = "Default";
                            linearPointer1.ShadowOffset = 0F;
                            linearPointer1.ThermometerBackColor = System.Drawing.Color.Empty;
                            linearPointer1.ThermometerBackGradientEndColor = System.Drawing.Color.Empty;
                            linearPointer1.Type = Dundas.Gauges.WinControl.LinearPointerType.Bar;
                            linearPointer1.Placement = Dundas.Gauges.WinControl.Placement.Cross;
                            linearPointer1.Width = 15F;
                            linearGauge1.Pointers.Add(linearPointer1);
                            linearScale1.Minimum = 0D;
                            linearScale1.Maximum = 100D;
                            linearScale1.EndMargin = 5F;
                            linearScale1.FillColor = System.Drawing.Color.Black;
                            linearScale1.LabelStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.30189F);
                            linearScale1.MajorTickMark.BorderWidth = 0;
                            linearScale1.MajorTickMark.FillColor = System.Drawing.Color.Black;
                            linearScale1.MajorTickMark.Length = 20F;
                            linearScale1.MajorTickMark.Width = 2F;
                            linearScale1.MinorTickMark.BorderWidth = 0;
                            linearScale1.MinorTickMark.FillColor = System.Drawing.Color.Black;
                            linearScale1.MinorTickMark.Length = 12F;
                            linearScale1.MinorTickMark.Width = 1.5F;
                            linearScale1.Name = "Default";
                            linearScale1.Position = 45F;
                            linearScale1.ShadowOffset = 0F;
                            linearScale1.StartMargin = 5F;
                            linearScale1.Width = 0F;
                            linearScale1.Maximum = 100D;
                            linearScale1.Minimum = 0D;
                            linearGauge1.Scales.Add(linearScale1);
                            linearGauge1.Size.Height = 100F;
                            linearGauge1.Size.Width = 100F;
                            gaugeContainer1.LinearGauges["Default"].Pointers["Default"].Value = 0;

                            gaugeContainer1.Location = new Point(obj.X, obj.Y);
                            gaugeContainer1.Size = new System.Drawing.Size(obj.Width, obj.Height);
                            gaugeContainer1.AccessibleName = obj.ObjectID.ToString();
                            gaugeContainer1.AccessibleDescription = "6";
                            // Get sensor name + unit + value
                            sensorId = Convert.ToInt32(obj.Parameters);
                            sensor = SensorBLL.Current.GetByID(sensorId);
                            if (sensor != null)
                            {
                                // Associate with sensor
                                // Add tooltip display description - binhpro 27/02/2013
                                if (!string.IsNullOrEmpty(sensor.Description))
                                {
                                    toolTip1.SetToolTip(gaugeContainer1, "Công thức: " + sensor.FormulaFunction + "\n" + sensor.Description);
                                }
                                gaugeLabel1.Text = sensor.Name + "\n" + sensor.Unit;
                                if (sensor.MaxValue != null) linearScale1.Maximum = System.Convert.ToDouble(sensor.MaxValue);
                                if (sensor.MinValue != null) linearScale1.Minimum = System.Convert.ToDouble(sensor.MinValue);
                                // Read latest value (if exists)
                                if (entityConntext.SensorValues.
                                    Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).Count() != 0)
                                {
                                    sensorValue = entityConntext.SensorValues.
                                        Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).First();
                                    if (sensor.MaxValue == null)
                                        linearScale1.Maximum = Math.Round(System.Convert.ToDouble(getSensorValue(sensorValue)) + 1D, 0);
                                    if (sensor.MinValue == null)
                                        linearScale1.Minimum = Math.Round(System.Convert.ToDouble(getSensorValue(sensorValue)) - 1D, 0);
                                    gaugeContainer1.LinearGauges["Default"].Pointers["Default"].Value = System.Convert.ToDouble(getSensorValue(sensorValue));
                                    gaugeLabel1.Text = sensor.Name + "\n" + getSensorValue(sensorValue).ToString() + " " + sensor.Unit;
                                    // Check if value is in alarm level
                                    if (PictureViewBLL.Current.CheckAlarmRunning(obj))
                                        linearPointer1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
                                }
                            }
                            // Add to picture
                            this.panel.Controls.Add(gaugeContainer1);
                            gaugeContainer1.BringToFront();
                            break;
                        case 7: // Meter
                            // Meter Initilization
                            gaugeContainer = new Dundas.Gauges.WinControl.GaugeContainer();
                            circularGauge = new Dundas.Gauges.WinControl.CircularGauge();
                            circularPointer = new Dundas.Gauges.WinControl.CircularPointer();
                            circularScale = new Dundas.Gauges.WinControl.CircularScale();
                            gaugeLabel = new Dundas.Gauges.WinControl.GaugeLabel();

                            gaugeContainer.BackFrame.BackColor = System.Drawing.Color.White;
                            gaugeContainer.BackFrame.BackGradientEndColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
                            gaugeContainer.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer.BackFrame.FrameGradientEndColor = System.Drawing.Color.DimGray;
                            gaugeContainer.BackFrame.FrameGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.Rectangular;
                            gaugeContainer.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.None;
                            gaugeContainer.BackFrame.FrameWidth = 0F;
                            circularGauge.BackFrame.BackColor = System.Drawing.Color.White;
                            circularGauge.BackFrame.BackGradientEndColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
                            circularGauge.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            circularGauge.BackFrame.BorderColor = System.Drawing.Color.Gray;
                            circularGauge.BackFrame.BorderWidth = 2;
                            circularGauge.BackFrame.FrameGradientEndColor = System.Drawing.Color.DimGray;
                            circularGauge.BackFrame.FrameGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            circularGauge.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.Rectangular;
                            circularGauge.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.Edged;
                            circularGauge.BackFrame.FrameWidth = 0F;
                            circularGauge.Location.X = 0F;
                            circularGauge.Location.Y = 0F;
                            circularGauge.Name = "Default";
                            circularGauge.PivotPoint.X = 50F;
                            circularGauge.PivotPoint.Y = 263F;
                            circularPointer.BorderWidth = 0;
                            circularPointer.CapFillColor = System.Drawing.Color.Silver;
                            circularPointer.CapFillGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            circularPointer.CapVisible = false;
                            circularPointer.CapWidth = 30F;
                            circularPointer.FillColor = System.Drawing.Color.Lime;
                            circularPointer.FillGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            circularPointer.Name = "Default";
                            circularPointer.ShadowOffset = 0F;
                            circularPointer.Width = 6.1F;
                            circularGauge.Pointers.Add(circularPointer);
                            circularScale.BorderColor = System.Drawing.Color.White;
                            circularScale.BorderWidth = 1;
                            circularScale.FillColor = System.Drawing.Color.Black;
                            circularScale.LabelStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 5F);
                            circularScale.MajorTickMark.BorderWidth = 0;
                            circularScale.MajorTickMark.FillColor = System.Drawing.Color.Black;
                            circularScale.MajorTickMark.Length = 6F;
                            circularScale.MajorTickMark.Shape = Dundas.Gauges.WinControl.MarkerStyle.Rectangle;
                            circularScale.MajorTickMark.Width = 2F;
                            circularScale.MinorTickMark.BorderWidth = 0;
                            circularScale.MinorTickMark.FillColor = System.Drawing.Color.Black;
                            circularScale.MinorTickMark.Length = 4F;
                            circularScale.MinorTickMark.Width = 1F;
                            circularScale.Name = "Default";
                            circularScale.Radius = 249F;
                            circularScale.ShadowOffset = 0F;
                            circularScale.StartAngle = 150F;
                            circularScale.SweepAngle = 60F;
                            circularScale.Width = 0F;
                            circularScale.Minimum = 0D;
                            circularScale.Maximum = 100D;
                            circularGauge.Scales.Add(circularScale);
                            circularGauge.Size.Height = 100F;
                            circularGauge.Size.Width = 100F;
                            circularPointer.Value = 0;
                            gaugeContainer.CircularGauges.Add(circularGauge);
                            gaugeContainer.InternalBackgroundPaint = false;
                            gaugeLabel.BackColor = System.Drawing.Color.Empty;
                            gaugeLabel.BackGradientEndColor = System.Drawing.Color.Empty;
                            gaugeLabel.Location.X = 25F;
                            gaugeLabel.Location.Y = 68F;
                            gaugeLabel.Name = "Default";
                            gaugeLabel.Parent = "CircularGauges.Default";
                            gaugeLabel.Size.Height = 33F;
                            gaugeLabel.Size.Width = 56F;
                            gaugeLabel.Text = "";
                            gaugeLabel.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
                            gaugeContainer.Labels.Add(gaugeLabel);

                            gaugeContainer.Location = new Point(obj.X, obj.Y);
                            gaugeContainer.Size = new System.Drawing.Size(obj.Width, obj.Height);
                            gaugeContainer.AccessibleName = obj.ObjectID.ToString();
                            gaugeContainer.AccessibleDescription = "7";
                            // Get sensor name + unit + value
                            sensorId = Convert.ToInt32(obj.Parameters);
                            sensor = SensorBLL.Current.GetByID(sensorId);
                            if (sensor != null)
                            {
                                // Associate with sensor
                                // Add tooltip display description - binhpro 27/02/2013
                                if (!string.IsNullOrEmpty(sensor.Description))
                                {
                                    toolTip1.SetToolTip(gaugeContainer, "Công thức: " + sensor.FormulaFunction + "\n" + sensor.Description);
                                }
                                gaugeLabel.Text = sensor.Name + "\n" + sensor.Unit;
                                if (sensor.MaxValue != null) circularScale.Maximum = System.Convert.ToDouble(sensor.MaxValue);
                                if (sensor.MinValue != null) circularScale.Minimum = System.Convert.ToDouble(sensor.MinValue);
                                // Read latest value (if exists)
                                if (entityConntext.SensorValues.
                                    Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).Count() != 0)
                                {
                                    sensorValue = entityConntext.SensorValues.
                                        Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).First();
                                    if (sensor.MaxValue == null)
                                        circularScale.Maximum = Math.Round(System.Convert.ToDouble(getSensorValue(sensorValue)) + 1D, 0);
                                    if (sensor.MinValue == null)
                                        circularScale.Minimum = Math.Round(System.Convert.ToDouble(getSensorValue(sensorValue)) - 1D, 0);
                                    gaugeContainer.CircularGauges["Default"].Pointers["Default"].Value = System.Convert.ToDouble(getSensorValue(sensorValue));
                                    gaugeLabel.Text = sensor.Name + "\n" + getDisplayValue(sensorValue) + " " + sensor.Unit;
                                    // Check if value is in alarm level
                                    if (PictureViewBLL.Current.CheckAlarmRunning(obj))
                                        circularPointer.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
                                }
                            }
                            // Add to picture
                            this.panel.Controls.Add(gaugeContainer);
                            gaugeContainer.BringToFront();
                            break;
                        case 8: // Numeric Indicator
                            // Numeric Indicator Initilization
                            Dundas.Gauges.WinControl.GaugeContainer gaugeContainer2 = new Dundas.Gauges.WinControl.GaugeContainer();
                            Dundas.Gauges.WinControl.GaugeLabel gaugeLabel2 = new Dundas.Gauges.WinControl.GaugeLabel();
                            Dundas.Gauges.WinControl.NumericIndicator numericIndicator = new Dundas.Gauges.WinControl.NumericIndicator();
                            gaugeContainer2.BackFrame.BackColor = System.Drawing.Color.White;
                            gaugeContainer2.BackFrame.BackGradientEndColor = System.Drawing.Color.White;
                            gaugeContainer2.BackFrame.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer2.BackFrame.BorderWidth = 2;
                            gaugeContainer2.BackFrame.FrameGradientEndColor = System.Drawing.Color.DimGray;
                            gaugeContainer2.BackFrame.FrameGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            gaugeContainer2.BackFrame.FrameShape = Dundas.Gauges.WinControl.BackFrameShape.Rectangular;
                            gaugeContainer2.BackFrame.FrameStyle = Dundas.Gauges.WinControl.BackFrameStyle.Simple;
                            gaugeContainer2.BackFrame.FrameWidth = 0F;
                            gaugeContainer2.InternalBackgroundPaint = false;
                            gaugeContainer2.NumericIndicators.Add(numericIndicator);
                            numericIndicator.BackColor = System.Drawing.Color.Transparent;
                            numericIndicator.BackGradientType = Dundas.Gauges.WinControl.GradientType.None;
                            numericIndicator.BorderColor = System.Drawing.Color.Black;
                            numericIndicator.BorderWidth = 0;
                            numericIndicator.DecimalColor = System.Drawing.Color.Black;
                            numericIndicator.Decimals = 2;
                            numericIndicator.DigitColor = System.Drawing.Color.Black;
                            numericIndicator.IndicatorStyle = Dundas.Gauges.WinControl.NumericIndicatorStyle.Digital7Segment;
                            numericIndicator.LedDimColor = System.Drawing.Color.FromArgb(((int)(((byte)(230)))), ((int)(((byte)(230)))), ((int)(((byte)(230)))));
                            numericIndicator.Location.X = 0F;
                            numericIndicator.Location.Y = -20F;
                            numericIndicator.Name = "Default";
                            numericIndicator.Parent = "";
                            numericIndicator.ShowDecimalPoint = true;
                            numericIndicator.Size.Height = 99F;
                            numericIndicator.Size.Width = 99F;
                            numericIndicator.Value = 0;
                            numericIndicator.Digits = 6;
                            gaugeLabel2.BackColor = System.Drawing.Color.Empty;
                            gaugeLabel2.BackGradientEndColor = System.Drawing.Color.Empty;
                            gaugeLabel2.Location.X = 26F;
                            gaugeLabel2.Location.Y = 75F;
                            gaugeLabel2.Name = "Default";
                            gaugeLabel2.Parent = "NumericIndicators.Default";
                            gaugeLabel2.Size.Height = 50F;
                            gaugeLabel2.Size.Width = 51F;
                            gaugeLabel2.Text = "";
                            gaugeLabel2.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
                            gaugeContainer2.Labels.Add(gaugeLabel2);

                            gaugeContainer2.Location = new Point(obj.X, obj.Y);
                            gaugeContainer2.Size = new System.Drawing.Size(obj.Width, obj.Height);
                            gaugeContainer2.AccessibleName = obj.ObjectID.ToString();
                            gaugeContainer2.AccessibleDescription = "8";
                            // Get sensor name + unit + value
                            sensorId = Convert.ToInt32(obj.Parameters);
                            sensor = SensorBLL.Current.GetByID(sensorId);
                            if (sensor != null)
                            {
                                // Associate with sensor
                                // Add tooltip display description - binhpro 27/02/2013
                                if (!string.IsNullOrEmpty(sensor.Description))
                                {
                                    toolTip1.SetToolTip(gaugeContainer2, "Công thức: " + sensor.FormulaFunction + "\n" + sensor.Description);
                                }
                                gaugeLabel2.Text = sensor.Name + "\n" + sensor.Unit;
                                if (sensor.MaxValue != null)
                                    gaugeContainer2.NumericIndicators["Default"].Digits = System.Convert.ToInt32(System.Math.Log10(System.Convert.ToInt32(sensor.MaxValue) + 1)) + 1 + 2 + 1;
                                // Read latest value (if exists)
                                if (entityConntext.SensorValues.
                                    Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).Count() != 0)
                                {
                                    sensorValue = entityConntext.SensorValues.
                                        Where(ent => ent.SensorID == sensorId).OrderByDescending(ent => ent.MeaTime).First();
                                    if (sensor.MaxValue == null)
                                        gaugeContainer2.NumericIndicators["Default"].Digits = System.Convert.ToInt32(System.Math.Log10(System.Convert.ToInt32(getSensorValue(sensorValue)) + 1)) + 1 + 2 + 1;
                                    gaugeContainer2.NumericIndicators["Default"].Value = System.Convert.ToDouble(getSensorValue(sensorValue));
                                    gaugeLabel2.Text = sensor.Name + "\n" + getDisplayValue(sensorValue) + " " + sensor.Unit;
                                    // Check if value is in alarm level
                                    if (PictureViewBLL.Current.CheckAlarmRunning(obj))
                                    {
                                        gaugeContainer2.NumericIndicators["Default"].DigitColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
                                        gaugeContainer2.NumericIndicators["Default"].DecimalColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
                                        gaugeContainer2.NumericIndicators["Default"].SeparatorColor = System.Drawing.Color.FromArgb(((int)(((byte)(188)))), ((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
                                    }
                                }
                            }
                            // Add to picture
                            this.panel.Controls.Add(gaugeContainer2);
                            gaugeContainer2.BringToFront();
                            break;
                        default:
                            break;
                    }
                }
                //mainMenuStrip.BringToFront();
                MouseMoveEventRegister(this.panel.Controls);
                foreach (Control control in this.panel.Controls)
                {
                    if (control.GetType() != typeof(MenuStrip))
                        pb.WireControl(control);
                }
                pb.EditModeEnabled = false;
                if (!SecurityBLL.Current.IsUserInRoles(new string[] { SecurityBLL.ROLE_VIEWS_EDIT, SecurityBLL.ROLE_VIEWS_MANAGE, SecurityBLL.ROLE_VIEWS_VIEW }))
                {
                    this.viewModeToolStripMenuItem.Enabled = false;
                    this.editToolStripMenuItem.Enabled = false;
                }
                this.addToolStripMenuItem.Enabled = false;
                //
            }
            catch (Exception exception)
            {
                ShowErrorMessage(exception.Message);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Read data from file with option onlyNewData and calculateValue
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="dataPath"></param>
        /// <param name="onlyNewData"></param>
        /// <param name="calculateValue"></param>
        /// <param name="refreshEntityContext"></param>
        public void ReadData(Logger logger, string dataPath, bool onlyNewData, bool calculateValue, ReaderProccess readerProccess)
        {
            try
            {
                Console.WriteLine("Thread[" + Thread.CurrentThread.ManagedThreadId + "]: Start read data file " + dataPath);
                ReaderProccess fileReaderProccess;
                if (readerProccess.FileReaderProccesses == null)
                {
                    fileReaderProccess = readerProccess;
                }
                else
                {
                    fileReaderProccess = new ReaderProccess();
                    fileReaderProccess.TotalRecord = FileUtils.CountTotalLines(dataPath);
                    readerProccess.FileReaderProccesses.Add(fileReaderProccess);
                }
                fileReaderProccess.CurrentFile = dataPath;

                bool readFolder = !logger.DataPath.Equals(dataPath);

                var file = new FileInfo(dataPath);

                // Only read if file is modified
                if (onlyNewData)
                {
                    if (readFolder)
                    {
                        if (logger.LastModifyDatetime >= file.LastWriteTime && logger.Meta.Contains(file.Name)) return;
                    }
                    else
                    {
                        if (logger.LastModifyDatetime >= file.LastWriteTime || logger.FileSize == file.Length) return;
                    }
                }

                var streamReader = new StreamReader(dataPath, Encoding.UTF8);
                var spiliter = new[] { logger.Delimiter };

                // read meta line
                string lineData = streamReader.ReadLine();
                fileReaderProccess.ReadRecord++;

                if (String.IsNullOrEmpty(lineData))
                {
                    Console.WriteLine("File Empty!");
                    return;
                }
                // check type of data file
                int type = 0;
                string[] firstlineCells = lineData.Split(spiliter, StringSplitOptions.None);
                if (firstlineCells[0].ToInt32TryParse() > 0 && firstlineCells[1].ToInt32TryParse() > 0)
                {
                    type = 1;
                }

                if (type == 0)
                {
                    // Ignore 4 first lines
                    for (int i = 0; i < 4; i++)
                    {
                        lineData = streamReader.ReadLine();
                        fileReaderProccess.ReadRecord++;
                    }
                }

                // Begin to read data
                var entityConntext = new GeoViewerEntities();
                var sensors = entityConntext.Sensors.Where(ent => ent.LoggerID == logger.LoggerID).OrderBy(ent => ent.ColumnIndex).ToList();
                int line = 0;
                do
                {
                    if (!string.IsNullOrEmpty(lineData.Trim()))
                    {
                        string[] cells = lineData.Split(spiliter, StringSplitOptions.None);

                        var meaTime = type == 0
                                          ? Convert.ToDateTime(CleanValue(cells[0]))
                                          : new DateTime(cells[1].ToInt32TryParse(), 1, 1).AddDays(
                                              cells[2].ToInt32TryParse()).AddMinutes(
                                                  (int)(cells[3].ToInt32TryParse() * 60 / 100));

                        // Only read new record (by time)
                        if (!(onlyNewData && !readFolder && meaTime >= logger.FirstLogDatetime &&
                            meaTime <= logger.LastLogDatetime))
                        {
                            var valuesNeedCalc = new List<SensorValue>();
                            foreach (var sensor in sensors)
                            {
                                if (cells.Length > sensor.ColumnIndex)
                                {
                                    // Check Value exist
                                    //var sensorValue = sensor.SensorValues.SingleOrDefault(ent => ent.MeaTime == meaTime);
                                    var sensorValue = entityConntext.SensorValues.SingleOrDefault(ent => ent.SensorID == sensor.SensorID && ent.MeaTime == meaTime);
                                    if (sensorValue == null)
                                    {
                                        sensorValue = new SensorValue();
                                        sensorValue.SensorID = sensor.SensorID;
                                        sensorValue.MeaTime = meaTime;
                                        sensor.SensorValues.Add(sensorValue);
                                    }
                                    sensorValue.RawValue = CleanValue(cells[sensor.ColumnIndex]).ToDecimalTryParse();
                                    valuesNeedCalc.Add(sensorValue);
                                }
                            }
                            // Calc Value & Alarm Logger
                            if (calculateValue)
                            {
                                foreach (var sensorValue in valuesNeedCalc)
                                {
                                    CalculationBLL.Current.Calculating(sensorValue, true);
                                }
                            }
                        }
                        line++;
                        if (line % 50 == 0)
                        {
                            entityConntext.SaveChanges();
                            entityConntext = new GeoViewerEntities();
                            sensors = entityConntext.Sensors.Where(ent => ent.LoggerID == logger.LoggerID).OrderBy(ent => ent.ColumnIndex).ToList();
                            Console.WriteLine("Thread[" + Thread.CurrentThread.ManagedThreadId + "]: Read success " + line + " lines in " + dataPath);
                        }
                    }

                    // go to nextline
                    lineData = streamReader.ReadLine();
                    fileReaderProccess.ReadRecord++;

                } while ((lineData != null));

                streamReader.Close();
                if (fileReaderProccess.ReadRecord > 0)
                {
                    fileReaderProccess.ReadRecord--;
                }

                if (line > 0 && line % 50 != 0)
                {
                    entityConntext.SaveChanges();
                    Console.WriteLine("Thread[" + Thread.CurrentThread.ManagedThreadId + "]: Read success " + line + " lines in " + dataPath);
                }
                Console.WriteLine("Thread[" + Thread.CurrentThread.ManagedThreadId + "]: End read data from " + dataPath);

                if (readerProccess.FileReaderProccesses != null)
                {
                    readerProccess.ReadRecord += fileReaderProccess.ReadRecord;
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Calculate value of a sensor entry
        /// </summary>
        /// <param name="sensorValue"></param>
        /// <returns></returns>
        public decimal? Calculating(SensorValue sensorValue)
        {
            int formulaType = sensorValue.Sensor.FormulaType;
            if (formulaType == FORMULA_USER_DEFINED && !string.IsNullOrEmpty(sensorValue.Sensor.FormulaFunction))
            {
                sensorValue.CalcValue = CalculateUtils.CalculateInfixExpression(sensorValue.Sensor.FormulaFunction, "x",
                                                                                sensorValue.RawValue.ToString().Replace(",",".")).ToDecimalTryParse();
            }
            else
            {
                if (string.IsNullOrEmpty(sensorValue.Sensor.FunctionParameters)) return null;
                string[] parameters;
                parameters = sensorValue.Sensor.FunctionParameters.Contains("#") ? sensorValue.Sensor.FunctionParameters.Split('#') : new string[] { sensorValue.Sensor.FunctionParameters };
                // Calculate value
                if (formulaType == FORMULA_LINEAR)
                {
                    if (parameters.Length < 2) return null;
                    sensorValue.CalcValue = CalculateUtils.Linear(sensorValue.RawValue,
                                                                  parameters[0].ToDecimalTryParse(),
                                                                  parameters[1].ToDecimalTryParse());
                }
                else if (formulaType == FORMULA_ARCTOLENGTH_DEGREE)
                {
                    if (parameters.Length < 1) return null;
                    sensorValue.CalcValue =
                        CalculateUtils.ArcToLengthDegree(sensorValue.RawValue.ToDoubleTryParse(),
                                                         parameters[0].ToDoubleTryParse()).ToDecimalTryParse();
                }
                else if (formulaType == FORMULA_ARCTOLENGTH_RADIAN)
                {
                    if (parameters.Length < 1) return null;
                    sensorValue.CalcValue =
                        CalculateUtils.ArcToLengthRadian(sensorValue.RawValue.ToDoubleTryParse(),
                                                         parameters[0].ToDoubleTryParse()).ToDecimalTryParse();
                }
                else if (formulaType == FORMULA_POLYNOMIAL)
                {
                    if (parameters.Length < 6) return null;

                    sensorValue.CalcValue =
                        CalculateUtils.Polynomial(sensorValue.RawValue.ToDoubleTryParse(),
                                                  parameters[0].ToDoubleTryParse(),
                                                  parameters[1].ToDoubleTryParse(),
                                                  parameters[2].ToDoubleTryParse(),
                                                  parameters[3].ToDoubleTryParse(),
                                                  parameters[4].ToDoubleTryParse(),
                                                  parameters[5].ToDoubleTryParse()).
                            ToDecimalTryParse();
                }
                else if (formulaType == FORMULA_TEMPRATURE_COMP)
                {
                    if (parameters.Length < 9) return null;

                    var tcSensor = SensorBLL.Current.GetByID(parameters[2].ToInt32TryParse());
                    if (tcSensor == null) return null;
                    var tcValue = tcSensor.SensorValues.SingleOrDefault(ent => ent.MeaTime == sensorValue.MeaTime);
                    if (tcValue == null) return null;

                    sensorValue.CalcValue = CalculateUtils.TemperatureComp(
                        sensorValue.RawValue.ToDoubleTryParse(),
                        parameters[0].ToDoubleTryParse(),
                        parameters[1].ToDoubleTryParse(),
                        tcValue.RawValue.ToDoubleTryParse(), // Raw value or calc value???
                        parameters[3].ToDoubleTryParse(),
                        parameters[4].ToDoubleTryParse(),
                        parameters[5].ToDoubleTryParse(),
                        parameters[6].ToDoubleTryParse(),
                        parameters[7].ToDoubleTryParse(),
                        parameters[8].ToDoubleTryParse()
                        ).ToDecimalTryParse();

                }
                else if (formulaType == FORMULA_VW_LINEAR)
                {
                    if (parameters.Length < 10) return null;

                    var tcSensor = SensorBLL.Current.GetByID(parameters[2].ToInt32TryParse());
                    if (tcSensor == null) return null;
                    var bcSensor = SensorBLL.Current.GetByID(parameters[7].ToInt32TryParse());
                    if (bcSensor == null) return null;
                    var tcValue = tcSensor.SensorValues.SingleOrDefault(ent => ent.MeaTime == sensorValue.MeaTime);
                    if (tcValue == null) return null;
                    var bcValue = bcSensor.SensorValues.SingleOrDefault(ent => ent.MeaTime == sensorValue.MeaTime);
                    if (bcValue == null) return null;
                    sensorValue.CalcValue = CalculateUtils.VwLinear(
                        parameters[0].ToDoubleTryParse(),
                        parameters[1].ToDoubleTryParse(),
                        tcValue.RawValue.ToDoubleTryParse(), // Raw value of Tc Sensor
                        parameters[3].ToDoubleTryParse(),
                        parameters[4].ToDoubleTryParse(),
                        parameters[5].ToDoubleTryParse(),
                        sensorValue.RawValue.ToDoubleTryParse(), // Raw value of current sensor (Lc)
                        parameters[6].ToDoubleTryParse(),
                        bcValue.RawValue.ToDoubleTryParse(), // Raw value of Bc Sensor
                        parameters[8].ToDoubleTryParse(),
                        parameters[9].ToDoubleTryParse()
                        ).ToDecimalTryParse();
                }
                else if (formulaType == FORMULA_VW_POLY)
                {
                    if (parameters.Length < 11) return null;

                    var tcSensor = SensorBLL.Current.GetByID(parameters[2].ToInt32TryParse());
                    if (tcSensor == null) return null;
                    var bcSensor = SensorBLL.Current.GetByID(parameters[7].ToInt32TryParse());
                    if (bcSensor == null) return null;
                    var tcValue = tcSensor.SensorValues.SingleOrDefault(ent => ent.MeaTime == sensorValue.MeaTime);
                    if (tcValue == null) return null;
                    var bcValue = bcSensor.SensorValues.SingleOrDefault(ent => ent.MeaTime == sensorValue.MeaTime);
                    if (bcValue == null) return null;
                    sensorValue.CalcValue = CalculateUtils.VwPoly(
                        parameters[0].ToDoubleTryParse(),
                        parameters[1].ToDoubleTryParse(),
                        tcValue.RawValue.ToDoubleTryParse(), // Raw value of Tc Sensor
                        parameters[3].ToDoubleTryParse(),
                        parameters[4].ToDoubleTryParse(),
                        parameters[5].ToDoubleTryParse(),
                        sensorValue.RawValue.ToDoubleTryParse(), // Raw value of current sensor (Lc)
                        parameters[6].ToDoubleTryParse(),
                        bcValue.RawValue.ToDoubleTryParse(), // Raw value of Bc Sensor
                        parameters[8].ToDoubleTryParse(),
                        parameters[9].ToDoubleTryParse(),
                        parameters[10].ToDoubleTryParse()
                        ).ToDecimalTryParse();
                }
            }

            return sensorValue.CalcValue;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Create a new SensorValue object.
 /// </summary>
 /// <param name="sensorValueID">Initial value of the SensorValueID property.</param>
 /// <param name="meaTime">Initial value of the MeaTime property.</param>
 /// <param name="rawValue">Initial value of the RawValue property.</param>
 /// <param name="calcValue">Initial value of the CalcValue property.</param>
 /// <param name="sensorID">Initial value of the SensorID property.</param>
 public static SensorValue CreateSensorValue(global::System.Int64 sensorValueID, global::System.DateTime meaTime, global::System.Decimal rawValue, global::System.Decimal calcValue, global::System.Int32 sensorID)
 {
     SensorValue sensorValue = new SensorValue();
     sensorValue.SensorValueID = sensorValueID;
     sensorValue.MeaTime = meaTime;
     sensorValue.RawValue = rawValue;
     sensorValue.CalcValue = calcValue;
     sensorValue.SensorID = sensorID;
     return sensorValue;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Deprecated Method for adding a new object to the SensorValues EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSensorValues(SensorValue sensorValue)
 {
     base.AddObject("SensorValues", sensorValue);
 }