Beispiel #1
0
        private static void ExportToPiWeb(string serverUri, string inspectionName, IEnumerable <Characteristic> data,
                                          Dictionary <string, ushort> attributeMapping)
        {
            //1. Create the client
            var client = new DataServiceRestClient(new Uri(serverUri));

            //2. Check the server configuration
            foreach (var entry in attributeMapping)
            {
                Configuration.CheckAttribute(client, EntityDto.Characteristic, entry.Value, entry.Key, AttributeTypeDto.Float);
            }

            //2.1 Make sure the essential time and value attributes are present
            Configuration.CheckAttribute(client, EntityDto.Measurement, WellKnownKeys.Measurement.Time, "Time",
                                         AttributeTypeDto.DateTime);
            Configuration.CheckAttribute(client, EntityDto.Value, WellKnownKeys.Value.MeasuredValue, "Value", AttributeTypeDto.Float);

            //3. Check the inspection plan

            //3.1 Check the inspection plan part
            var part = InspectionPlan.GetOrCreatePart(client, inspectionName);
            var characteristicMapping = new Dictionary <Characteristic, InspectionPlanCharacteristicDto>();

            //3.2 Check the inspection plan characteristics
            foreach (var characteristic in data)
            {
                var inspectionPlanCharacteristic = InspectionPlan.GetOrCreateCharacteristic(client, part.Path.Name,
                                                                                            characteristic.Name, attributeMapping, characteristic.Attributes);
                characteristicMapping.Add(characteristic, inspectionPlanCharacteristic);
            }

            //4. Create the measurement
            var dataCharacteristics = characteristicMapping.Select(pair => new DataCharacteristicDto
            {
                Uuid  = pair.Value.Uuid,
                Path  = pair.Value.Path,
                Value = new DataValueDto
                {
                    Attributes = new[] { new AttributeDto(1, pair.Key.Value) }
                }
            }).ToArray();

            var measurement = new DataMeasurementDto
            {
                Uuid            = Guid.NewGuid(),
                PartUuid        = part.Uuid,
                Time            = DateTime.UtcNow,
                Attributes      = new[] { new AttributeDto(WellKnownKeys.Measurement.Time, DateTime.UtcNow) },
                Characteristics = dataCharacteristics
            };

            //4.1 Write the measurement to the database
            client.CreateMeasurementValues(new[] { measurement }).Wait();
        }
Beispiel #2
0
        public static async Task Lesson(DataServiceRestClient client)
        {
            //Create the most commonly used attributes for measurement and measurement value

            var configuration = await client.GetConfiguration();

            if (configuration.GetDefinition(EntityDto.Measurement, MeasurementAttributeDefinition.Key) == null)
            {
                await client.CreateAttributeDefinition(EntityDto.Measurement, MeasurementAttributeDefinition);
            }

            if (configuration.GetDefinition(EntityDto.Value, ValueAttributeDefinition.Key) == null)
            {
                await client.CreateAttributeDefinition(EntityDto.Value, ValueAttributeDefinition);
            }

            //Every measurement is attached to a part, and every value is attached to a characteristic
            await client.CreateParts(new[] { Part });

            await client.CreateCharacteristics(new[] { Characteristic });

            //The function 'CreateMeasurements' will create measurements without any values. You'll much more likely use the 'CreateMeasurementValues' function
            await client.CreateMeasurementValues(new[] { Measurement });

            Value.Value = new DataValueDto(0.0)               //This will result in an unmeasured characteristic, because the attribute array doesn't contain K1
            {
                Attributes = new AttributeDto[] { }
            };

            await client.UpdateMeasurementValues(new[] { Measurement });

            Value.Value = new DataValueDto             //this will work!
            {
                Attributes = new[] { new AttributeDto(ValueAttributeDefinition.Key, 0.5) }
            };

            await client.UpdateMeasurementValues(new[] { Measurement });

            var result = await client.GetMeasurementValues(
                PathInformationDto.Root,                                                           // Part where to search measurements
                new MeasurementValueFilterAttributesDto
            {
                AggregationMeasurements = AggregationMeasurementSelectionDto.All,                      // Decide how to include aggregated measurements in your query
                CharacteristicsUuidList = null,                                                        // Use characteristic uuids to fetch single measurement values
                Deep = true,                                                                           // A deep search will find measurements recursively below the start path
                FromModificationDate = null,                                                           // Will only search measurements with a modification date (LastModified) newer than the specified one
                ToModificationDate   = null,                                                           // Will only search measurements with a modification date (LastModified) older than the specified one
                LimitResult          = 10,                                                             // Will limit the number of returned measurements
                MeasurementUuids     = null,                                                           // Use measurement uuids to search for specific measurements
                OrderBy = new[]                                                                        // Order the returned measurements by specific attributes
                {
                    new OrderDto(WellKnownKeys.Measurement.Time, OrderDirectionDto.Asc, EntityDto.Measurement)
                },
                RequestedMeasurementAttributes = null,                                                 // Specify, which measurement attributes should be returned (default: all)
                RequestedValueAttributes       = null,                                                 // Specify, which value attributes should be returned (default: all)
                SearchCondition = new GenericSearchAttributeConditionDto                               // You can create more complex attribute conditions using the GenericSearchAnd, GenericSearchOr and GenericSearchNot class
                {
                    Attribute = WellKnownKeys.Measurement.Time,                                        //Only measurement attributes are supported
                    Operation = OperationDto.GreaterThan,
                    Value     = XmlConvert.ToString(DateTime.UtcNow - TimeSpan.FromDays(2), XmlDateTimeSerializationMode.Utc)
                }
            });

            foreach (var measurement in result)
            {
                Console.WriteLine(measurement.ToString());
            }
        }
Beispiel #3
0
        private async void creatNewDemo(string demoType)
        {
            try
            {
                creatSuccessed = true;
                var partPath = PathHelper.String2PartPathInformation("/Demo/");
                var parts    = await _RestDataServiceClient.GetParts(partPath);

                if (parts.Count() != 0)
                {
                    var Part       = (InspectionPlanPart)parts.ToList()[0];
                    var attributes = new List <Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute>();
                    //demo type
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20043, demoType + "_Demo"));
                    //serial number
                    string date = DateTime.Now.ToString("yyyyMMddHHmmss");
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)14, CC_Data["CC"] + date));
                    //CC
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)801, CC_Data["CC"]));
                    //owner
                    if (comboBox1.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20028, comboBox1.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("专案负责人未填写!");
                        creatSuccessed = false;
                    }
                    //sales
                    if (comboBox2.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20004, comboBox2.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("销售联系人未填写!");
                        creatSuccessed = false;
                    }
                    //application engineer
                    if (comboBox3.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20003, comboBox3.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("Demo工程师未填写!");
                        creatSuccessed = false;
                    }
                    //customer
                    if (comboBox4.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)1062, comboBox4.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("客户名称未填写!");
                        creatSuccessed = false;
                    }
                    //province
                    if (comboBox5.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20001, comboBox5.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("客户所在省份未填写!");
                        creatSuccessed = false;
                    }
                    //city
                    if (comboBox6.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20002, comboBox6.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("客户所在城市未填写!");
                        creatSuccessed = false;
                    }
                    //customer Contact person
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20053, textBox1.Text.Trim()));
                    //customer phone number
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20054, textBox2.Text.Trim()));
                    //customer address
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20055, textBox3.Text.Trim()));
                    //customer person count
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20056, textBox4.Text.Trim()));
                    //cmm info
                    if (comboBox7.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20051, comboBox7.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("三坐标信息未填写!");
                        creatSuccessed = false;
                    }
                    //sensor info
                    if (comboBox8.Text != "")
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20052, comboBox8.Text.Trim()));
                    }
                    else
                    {
                        MessageBox.Show("传感器信息未填写!");
                        creatSuccessed = false;
                    }
                    //time K4
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)4, DateTime.Now));
                    //check report
                    if (checkBox1.Checked)
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20048, "已完成"));
                    }
                    //check handover
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20029, textBox5.Text));
                    //part number
                    attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20041, 1));
                    //process status
                    if (checkBox2.Checked)
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20027, "技术交接完成"));
                    }
                    else
                    {
                        attributes.Add(new Zeiss.IMT.PiWeb.Api.DataService.Rest.Attribute((ushort)20027, "创建完成"));
                    }
                    var Measurement = new DataMeasurement
                    {
                        Uuid       = Guid.NewGuid(),
                        PartUuid   = Part.Uuid,
                        Time       = DateTime.Now,
                        Attributes = attributes.ToArray()
                    };
                    if (creatSuccessed)
                    {
                        //Create measurement on the server
                        await _RestDataServiceClient.CreateMeasurementValues(new[] { Measurement });
                    }
                    else
                    {
                        creatSuccessed = false;
                    }
                }
                else
                {
                    creatSuccessed = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                creatSuccessed = false;
            }
            finally
            {
                if (creatSuccessed)
                {
                    DirectoryInfo path_exe = new DirectoryInfo(Application.StartupPath); //exe目录
                    RealAction(path_exe + @"\PiWebInterface.exe", " 主界面");
                    //写入完成
                    DialogResult dr = MessageBox.Show("创建Demo完成,是否继续创建Demo?", "创建Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        //询问是否清空界面内容
                        comboBox2.Text    = "";
                        comboBox3.Text    = "";
                        comboBox4.Text    = "";
                        comboBox5.Text    = "";
                        comboBox6.Text    = "";
                        comboBox7.Text    = "";
                        comboBox8.Text    = "";
                        textBox1.Text     = "";
                        textBox2.Text     = "";
                        textBox3.Text     = "";
                        textBox4.Text     = "";
                        checkBox1.Checked = false;
                        checkBox2.Checked = false;
                        textBox5.Text     = "";
                    }
                    else
                    {
                        Application.Exit();
                    }
                }
            }
        }