示例#1
0
        // short StoreEvent(String timestamp, String deviceName, String dataItemName, String value, String workPieceId, String partId, String alarm_code, String alarm_severity, String alarm_nativecode, String alarm_state);
        private short handleStoreEvent(System.Collections.Specialized.NameValueCollection queryString, StreamWriter writer)
        {
            short    storeEventReturn = ReturnValue.ERROR; //default
            XElement returnElement;
            String   timestamp, deviceName, dataItemName, value, workPieceId, partId, code, severity, nativecode, state;

            if ((returnElement = handleStoreSampleStoreEventCommon(queryString, out timestamp, out deviceName, out dataItemName, out value, out workPieceId, out partId, out code, out severity, out nativecode, out state)) == null)
            {
                try
                {
                    storeEventReturn = sharedData.StoreEvent(timestamp, deviceName, dataItemName, value, workPieceId, partId, code, severity, nativecode, state);

                    if (storeEventReturn == ReturnValue.SUCCESS)
                    {
                        returnElement = new XElement("Acknowledge", new XAttribute("dateTime", Util.GetDateTime()));
                    }
                    else
                    {
                        returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA);
                    }
                }
                catch (AgentException e)
                {
                    returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, e.Message);
                }
            }
            returnElement.Save(writer);
            return(storeEventReturn);
        }
        //short StoreSample(String timestamp, String deviceName, String dataItemName, String value, String workPieceId, String partId);
        private short handleStoreSample(System.Collections.Specialized.NameValueCollection queryString, StreamWriter writer)
        {
            short    storeSampleReturn = ReturnValue.ERROR; //default
            XElement returnElement;
            String   timestamp, dataItemId, condition, value, code, nativeCode;

            if ((returnElement = handleStoreSampleStoreEventCommon(queryString, out timestamp, out dataItemId, out condition, out value, out code, out nativeCode)) == null)
            {
                if (value == null)
                {
                    returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The value is missing.");
                }
                else if (condition != null)
                {
                    returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The storeSample should not define \"condition\" .");
                }
                else if (code != null)
                {
                    returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The storeSample should not define \"code\" .");
                }
                else if (nativeCode != null)
                {
                    returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The storeSample should not define \"nativeCode\" .");
                }

                else
                {
                    try
                    {
                        storeSampleReturn = sharedData.StoreSample(timestamp, dataItemId, value);

                        if (storeSampleReturn == ReturnValue.SUCCESS)
                        {
                            returnElement = new XElement(MTConnectNameSpace.mtStreams + "Acknowledge", new XAttribute("dateTime", Util.GetDateTime()));
                        }
                        else //not currently used
                        {
                            returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA);
                        }
                    }
                    catch (AgentException e)
                    {
                        returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, e.Message);
                    }
                }
            }
            returnElement.Save(writer);
            return(storeSampleReturn);
        }
示例#3
0
        private short handleStoreCondition(System.Collections.Specialized.NameValueCollection queryString, StreamWriter writer)
        {
            short    storeConditionReturn = ReturnValue.ERROR; //default
            XElement returnElement;
            String   timestamp, dataItemId, condition, value, code, nativeCode;

            if ((returnElement = handleStoreSampleStoreEventCommon(queryString, out timestamp, out dataItemId, out condition, out value, out code, out nativeCode)) == null)
            {
                if (condition == null)
                {
                    returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The storeCondition should define \"condition\".");
                }


                else if (!Util.CheckTypesOfCondition(condition))
                {
                    returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The condition is not one of the four recognizable condition types.");
                }
                else
                {
                    try {
                        storeConditionReturn = sharedData.StoreCondition(timestamp, dataItemId, condition, value, nativeCode, code);

                        if (storeConditionReturn == ReturnValue.SUCCESS)
                        {
                            returnElement = new XElement(MTConnectNameSpace.mtcUrnStreams + "Acknowledge", new XAttribute("dateTime", Util.GetDateTime()));
                        }
                        else //not possible
                        {
                            returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA);
                        }
                    } catch (AgentException e) {
                        returnElement = MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, e.Message);
                    }
                }
            }
            returnElement.Save(writer);
            return(storeConditionReturn);
        }
        private XElement handleStoreSampleStoreEventCommon(System.Collections.Specialized.NameValueCollection queryString,
                                                           out String timestamp, out String dataItemId, out String condition, out String value, out String code, out String nativeCode)
        {
            timestamp = null;


            dataItemId = null;
            condition  = null;
            value      = null;
            code       = null;
            nativeCode = null;


            // Get names of all keys into a string array.
            String[] keys = queryString.AllKeys;
            for (int i = 0; i < keys.Length; i++)
            {
                String[] values = queryString.GetValues(keys[i]);
                switch (keys[i])
                {
                case "timestamp":
                    timestamp = values[0];
                    break;


                case "dataItemId":
                    dataItemId = values[0];
                    break;

                case "condition":
                    condition = values[0];
                    break;

                case "value":
                    value = values[0];
                    break;

                case "code":
                    code = values[0];
                    break;

                case "nativeCode":
                    nativeCode = values[0];
                    break;
                }
            }
            if (timestamp == null)
            {
                // return MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The timestamp is missing.");
                timestamp = Util.GetDateTime();
            }
            //else if (deviceName == null)
            // return MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The deviceName is missing.");
            if (dataItemId == null)
            {
                return(MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The dataItemId is missing."));
            }
            //else if (value == null)
            //  return MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The value is missing.");
            else
            {
                return(null); //success
            }
        }
示例#5
0
        private XElement handleStoreSampleStoreEventCommon(System.Collections.Specialized.NameValueCollection queryString,
                                                           out String timestamp, out String deviceName, out String dataItemName, out String value, out String workPieceId, out String partId, out String code, out String severity, out String nativecode, out String state)
        {
            timestamp    = null;
            deviceName   = null;
            dataItemName = null;
            value        = null;
            workPieceId  = null;
            partId       = null;
            code         = null;
            severity     = null;
            nativecode   = null;
            state        = null;


            //// Get names of all keys into a string array.
            String[] keys = queryString.AllKeys;
            for (int i = 0; i < keys.Length; i++)
            {
                String[] values = queryString.GetValues(keys[i]);
                switch (keys[i])
                {
                case "timestamp":
                    timestamp = values[0];
                    break;

                case "deviceName":
                    deviceName = values[0];
                    break;

                case "dataItemName":
                    dataItemName = values[0];
                    break;

                case "value":
                    value = values[0];
                    break;

                case "workPieceId":
                    workPieceId = values[0];
                    break;

                case "partId":
                    partId = values[0];
                    break;

                case "code":
                    code = values[0];
                    break;

                case "severity":
                    severity = values[0];
                    break;

                case "nativecode":
                    nativecode = values[0];
                    break;

                case "state":
                    state = values[0];
                    break;
                }
            }

            if (timestamp == null)
            {
                return(MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The timestamp is missing."));
            }
            else if (deviceName == null)
            {
                return(MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The deviceName is missing."));
            }
            else if (dataItemName == null)
            {
                return(MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The dataItemName is missing."));
            }
            else if (value == null)
            {
                return(MachineAPIError.createError(MachineAPIError.UNRECOGNIZEDDATA, "The value is missing."));
            }
            else
            {
                return(null); //success
            }
        }