Пример #1
0
        private static ComponentDefinitionData Create(string deviceId, long agentInstanceId, string parentId, MTConnectDevices.Component component)
        {
            var obj = new ComponentDefinitionData();

            // TrakHound Properties
            obj.DeviceId = deviceId;
            obj.ParentId = parentId;

            // MTConnect Properties
            obj.AgentInstanceId = agentInstanceId;
            obj.Type            = component.Type;
            obj.Id             = component.Id;
            obj.Uuid           = component.Uuid;
            obj.Name           = component.Name;
            obj.NativeName     = component.NativeName;
            obj.SampleInterval = component.SampleInterval;
            obj.SampleRate     = component.SampleRate;

            return(obj);
        }
        public bool Write(List <ComponentDefinitionData> definitions)
        {
            if (definitions.IsNullOrEmpty <ComponentDefinitionData>())
            {
                return(false);
            }
            string str    = "`device_id`,`agent_instance_id`, `id`, `uuid`, `name`, `native_name`, `sample_interval`, `sample_rate`, `type`,`parent_id`";
            string format = "INSERT IGNORE INTO `components` ({0}) VALUES {1}";
            string str3   = "('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')";

            string[] strArray = new string[definitions.Count];
            for (int i = 0; i < definitions.Count; i++)
            {
                ComponentDefinitionData data = definitions[i];
                strArray[i] = string.Format(str3, new object[] { this.EscapeString(data.DeviceId), data.AgentInstanceId,
                                                                 this.EscapeString(data.Id), this.EscapeString(data.Uuid), this.EscapeString(data.Name),
                                                                 this.EscapeString(data.NativeName), data.SampleInterval, data.SampleRate, this.EscapeString(data.Type),
                                                                 this.EscapeString(data.ParentId) });
            }
            string str4  = string.Join(",", strArray);
            string query = string.Format(format, str, str4);

            return(this.Write(query));
        }