Exemplo n.º 1
0
        /// <summary>
        /// 将返回代码转化为消息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string ToMessage(this EnumResultCode code)
        {
            var type        = code.GetType();                  //获取类型
            var memberInfos = type.GetMember(code.ToString()); //获取成员

            if (memberInfos.Length > 0)
            {
                var attrs = memberInfos[0].GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[]; //获取描述特性
                if (attrs != null && attrs.Length > 0)
                {
                    return(attrs[0].Description); //返回当前描述
                }
            }
            return("未知错误");
        }
Exemplo n.º 2
0
        private TestResult ValidateBrowsedElements(Softing.OPCToolbox.Client.DaAddressSpaceElement[] elements, int result)
        {
            if (ResultCode.SUCCEEDED(result))
            {
                if (!string.IsNullOrEmpty(Property))
                {
                    SetProperty(Property, elements);
                }

                if (ExpectedElements.Count != 0 && ExpectedElements.Count != elements.Length)
                {
                    return(new DaBrowseResult(result, elements, "Unexpected number of results"));
                }

                for (int i = 0; i < ExpectedElements.Count; i++)
                {
                    Softing.OPCToolbox.Client.DaAddressSpaceElement receivedElement = elements[i];
                    DaAddressSpaceElement expectedElement = ExpectedElements[i];

                    if ((expectedElement.ItemId != null && expectedElement.ItemId != receivedElement.ItemId) ||
                        (expectedElement.ItemPath != null && expectedElement.ItemPath != receivedElement.ItemPath) ||
                        (expectedElement.Name != null && expectedElement.Name != receivedElement.Name) ||
                        (expectedElement.IsItem.HasValue && expectedElement.IsItem.Value != receivedElement.IsItem) ||
                        (expectedElement.IsBranch.HasValue && expectedElement.IsBranch.Value != receivedElement.IsBranch) ||
                        (expectedElement.IsLeaf.HasValue && expectedElement.IsLeaf.Value != receivedElement.IsLeaf))
                    {
                        return(new DaBrowseResult(result, elements, string.Format("Unexpected result for item #{0}", i)));
                    }
                }

                return(new DaBrowseResult(result, elements));
            }
            else
            {
                EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());
                if (!string.IsNullOrEmpty(ExpectedServiceResult))
                {
                    EnumResultCode expectedResCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedServiceResult.ToString());
                    if (expectedResCode != resCode)
                    {
                        return(TestResult.Failed(string.Format("Unexpected service result: expected {0}, actual {1}", resCode, expectedResCode)));
                    }
                    return(TestResult.Success());
                }

                return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
            }
        }
Exemplo n.º 3
0
 public DataResult(EnumResultCode code, string msg, T data)
 {
     Code = code;
     Msg  = msg ?? code.ToString();
     Data = data;
 }
Exemplo n.º 4
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(Session) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            ValueQT[] values;

            if (Values.Count == 0)
            {
                if (!string.IsNullOrEmpty(ValuesProperty))
                {
                    values = GetProperty(ValuesProperty) as ValueQT[];
                    if (values == null)
                    {
                        return(TestResult.ParameterInvalid("ValuesProperty"));
                    }
                }
                else
                {
                    return(TestResult.ParameterMissing("Values"));
                }
            }
            else
            {
                //if the quality was not set ; set it to the value QUALITY_NOT_SET
                for (int i = 0; i < Values.Count; i++)
                {
                    if (Values[i].Wrapped.Quality == Softing.OPCToolbox.EnumQuality.BAD_WAITING_FOR_INITIAL_DATA)
                    {
                        Values[i].Wrapped.SetData(Values[i].Wrapped.Data, Softing.OPCToolbox.EnumQuality.QUALITY_NOT_SET, Values[i].Wrapped.TimeStamp);
                    }
                }
                values = Value.CreateSDKCollection(Values);
            }

            try
            {
                int   result = (int)EnumResultCode.S_FALSE;
                int[] results;

                string[] itemIDs   = ItemIds.ToArray();
                string[] itemPaths = ItemPaths.Count > 0 ? ItemPaths.ToArray() : null;

                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    result = session.Write(itemIDs, itemPaths, values, out results, null);
                }
                else
                {
                    m_asyncExecutionContext = DaExecutionContext.Next;
                    ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext);

                    m_waitHandle = new System.Threading.AutoResetEvent(false);

                    SessionWriteEventHandler asyncHandler = new SessionWriteEventHandler(session_WriteCompleted);
                    session.WriteCompleted += asyncHandler;

                    result = session.Write(itemIDs, itemPaths, values, out results, executionOptions);

                    if (m_waitHandle.WaitOne(30000))
                    {
                        result  = m_asyncResult;
                        results = m_asyncResults;
                    }

                    session.WriteCompleted -= asyncHandler;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(ResultsProperty))
                    {
                        SetProperty(ResultsProperty, results);
                    }

                    if (ValidateAllResults)
                    {
                        for (int i = 0; i < results.Length; i++)
                        {
                            if (ResultCode.FAILED(results[i]))
                            {
                                EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());

                                return(TestResult.Failed(string.Format("Result {0} failed with the code: {1}  ({2})", i, resCode.ToString(), results[i])));
                            }
                        }
                    }
                    else if (ExpectedResults.Count > 0)
                    {
                        //validate with expected values
                        if (ExpectedResults.Count != results.Length)
                        {
                            return(new DaWriteTestResult(result, results, "Unexpected number of results"));
                        }

                        for (int i = 0; i < results.Length; i++)
                        {
                            if (results[i] != ExpectedResults[i])
                            {
                                EnumResultCode resCode         = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());
                                EnumResultCode resExpectedCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedResults[i].ToString());

                                return(new DaWriteTestResult(result, results, string.Format("Unexpected result code for item {0}: received {1}  ({2}) instead of {3}  ({4})", i, resCode.ToString(), results[i], resExpectedCode.ToString(), ExpectedResults[i])));
                            }
                        }
                    }

                    return(new DaWriteTestResult(result, results));
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());
                    if (!string.IsNullOrEmpty(ExpectedServiceResult))
                    {
                        EnumResultCode expectedResCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedServiceResult.ToString());
                        if (expectedResCode != resCode)
                        {
                            return(TestResult.Failed(string.Format("Unexpected service result: expected {0}, actual {1}", resCode, expectedResCode)));
                        }
                        return(TestResult.Success());
                    }

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(Session) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }


            if (Count <= 0)
            {
                return(TestResult.ParameterInvalid("Count"));
            }

            try
            {
                // prepare values to write
                List <string> itemToWrite = new List <string>();
                itemToWrite.Add(m_ItemCountNodeId);
                itemToWrite.Add(m_ItemTypeNodeId);
                itemToWrite.Add(m_ItemIsAnalogNodeId);
                itemToWrite.Add(m_CreateItemsNodeId);

                string[] itemIDs = itemToWrite.ToArray();

                List <ValueQT> valuesToWrite = new List <ValueQT>();
                valuesToWrite.Add(new ValueQT(Count, EnumQuality.GOOD, DateTime.Now));
                valuesToWrite.Add(new ValueQT((uint)NodeType, EnumQuality.GOOD, DateTime.Now));
                valuesToWrite.Add(new ValueQT(IsAnalog, EnumQuality.GOOD, DateTime.Now));
                guid = Guid.NewGuid().ToString();
                valuesToWrite.Add(new ValueQT(guid, EnumQuality.GOOD, DateTime.Now));

                ValueQT[] values = valuesToWrite.ToArray();

                int   result = (int)EnumResultCode.S_FALSE;
                int[] results;

                // send CreateItemsRequest
                result = session.Write(itemIDs, null, values, out results, null);

                if (ResultCode.SUCCEEDED(result))
                {
                    // wait for Variables to be created
                    System.Threading.Thread.Sleep(1000);

                    string[]  itemsToRead = new string[] { ItemSetIDNodeId };
                    ValueQT[] readValues;

                    result = session.Read(0, itemsToRead, null, out readValues, out results, null);

                    if (ResultCode.SUCCEEDED(result))
                    {
                        string   itemSetIdValue = string.Empty;
                        string[] stringArray    = readValues[0].Data as string[];
                        string   item           = string.Empty;
                        for (int i = 0; i < stringArray.Length; i++)
                        {
                            item = stringArray[i];
                            if (item.Split('#')[1] == guid)
                            {
                                itemSetIdValue = item.Split('#')[0];
                                break;
                            }
                        }
                        if (itemSetIdValue == string.Empty)
                        {
                            return(TestResult.Failed(string.Format("ItemSetId value was not found! {0}", guid)));
                        }

                        itemSetIdValue = m_nodeSetPrefix + itemSetIdValue;

                        SetProperty(Property, itemSetIdValue);

                        return(TestResult.Success());
                    }
                    else
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ItemsProperty))
            {
                return(TestResult.ParameterMissing("ItemsProperty"));
            }

            DaItem[] items = GetProperty(ItemsProperty) as DaItem[];
            if (items == null)
            {
                return(TestResult.ParameterInvalid("ItemsProperty"));
            }

            ValueQT[] values;

            if (Values.Count == 0)
            {
                if (!string.IsNullOrEmpty(ValuesProperty))
                {
                    values = GetProperty(ValuesProperty) as ValueQT[];
                    if (values == null)
                    {
                        return(TestResult.ParameterInvalid("ValuesProperty"));
                    }
                }
                else
                {
                    return(TestResult.ParameterMissing("Values"));
                }
            }
            else
            {
                values = Value.CreateSDKCollection(Values);
            }

            try
            {
                int[] results = new int[items.Length];

                for (int i = 0; i < items.Length; i++)
                {
                    DaItem  item  = items[i];
                    ValueQT value = values[i];
                    int     writeResult;

                    int result = item.Write(value, out writeResult, new ExecutionOptions());

                    if (ResultCode.SUCCEEDED(result))
                    {
                        results[i] = writeResult;

                        if (ValidateAllResults)
                        {
                            if (ResultCode.FAILED(results[i]))
                            {
                                EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());

                                return(TestResult.Failed(string.Format("Result {0} failed with the code: {1}  ({2})", i, resCode.ToString(), results[i])));
                            }
                        }
                        else if (ExpectedResults.Count > i)
                        {
                            //validate with expected values

                            if (results[i] != ExpectedResults[i])
                            {
                                EnumResultCode resCode         = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());
                                EnumResultCode resExpectedCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedResults[i].ToString());

                                return(new DaWriteTestResult(result, results, string.Format("Unexpected result code for item {0}: received {1}  ({2}) instead of {3}  ({4})", i, resCode.ToString(), results[i], resExpectedCode.ToString(), ExpectedResults[i])));
                            }
                        }
                    }
                    else
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }

                if (!string.IsNullOrEmpty(ResultsProperty))
                {
                    SetProperty(ResultsProperty, results);
                }

                return(TestResult.Success());
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemplo n.º 7
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ItemsProperty))
            {
                return(TestResult.ParameterMissing("ItemsProperty"));
            }

            DaItem[] items = GetProperty(ItemsProperty) as DaItem[];
            if (items == null)
            {
                return(TestResult.ParameterInvalid("ItemsProperty"));
            }

            DaSubscription subscription = items[0].DaSubscription;

            ValueQT[] values;

            if (Values.Count == 0)
            {
                if (!string.IsNullOrEmpty(ValuesProperty))
                {
                    values = GetProperty(ValuesProperty) as ValueQT[];
                    if (values == null)
                    {
                        return(TestResult.ParameterInvalid("ValuesProperty"));
                    }
                }
                else
                {
                    return(TestResult.ParameterMissing("Values"));
                }
            }
            else
            {
                values = Value.CreateSDKCollection(Values);
            }

            try
            {
                int   result  = (int)EnumResultCode.S_FALSE;
                int[] results = null;

                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    result = subscription.Write(items, values, out results, null);
                }
                else
                {
                    m_asyncExecutionContext = DaExecutionContext.Next;
                    ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext);

                    m_waitHandle = new System.Threading.AutoResetEvent(false);

                    SubscriptionWriteEventHandler asyncHandler = new SubscriptionWriteEventHandler(subscription_WriteCompleted);
                    subscription.WriteCompleted += asyncHandler;

                    result = subscription.Write(items, values, out results, executionOptions);

                    if (m_waitHandle.WaitOne(30000))
                    {
                        result  = m_asyncResult;
                        results = m_asyncResults;
                    }

                    subscription.WriteCompleted -= asyncHandler;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(ResultsProperty))
                    {
                        SetProperty(ResultsProperty, results);
                    }

                    if (ValidateAllResults)
                    {
                        for (int i = 0; i < results.Length; i++)
                        {
                            if (ResultCode.FAILED(results[i]))
                            {
                                EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());

                                return(TestResult.Failed(string.Format("Result {0} failed with the code: {1}  ({2})", i, resCode.ToString(), results[i])));
                            }
                        }
                    }
                    else if (ExpectedResults.Count > 0)
                    {
                        //validate with expected values
                        if (ExpectedResults.Count != results.Length)
                        {
                            return(new DaWriteTestResult(result, results, "Unexpected number of results"));
                        }

                        for (int i = 0; i < results.Length; i++)
                        {
                            if (results[i] != ExpectedResults[i])
                            {
                                EnumResultCode resCode         = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), results[i].ToString());
                                EnumResultCode resExpectedCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), ExpectedResults[i].ToString());

                                return(new DaWriteTestResult(result, results, string.Format("Unexpected result code for item {0}: received {1}  ({2}) instead of {3}  ({4})", i, resCode.ToString(), results[i], resExpectedCode.ToString(), ExpectedResults[i])));
                            }
                        }
                    }

                    return(new DaWriteTestResult(result, results));
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemplo n.º 8
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Subscription))
            {
                return(TestResult.ParameterMissing("Subscription"));
            }

            DaSubscription subscription = GetProperty(Subscription) as DaSubscription;

            if (subscription == null)
            {
                return(TestResult.ParameterInvalid("Subscription"));
            }

            try
            {
                int result = subscription.Refresh(MaxAge, new ExecutionOptions());

                if (ResultCode.SUCCEEDED(result))
                {
                    return(TestResult.Success());
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemplo n.º 9
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(Session) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            if (string.IsNullOrEmpty(NodeSetId))
            {
                return(TestResult.ParameterMissing("NodeSetId"));
            }

            string nodeSetId = GetProperty(NodeSetId) as string;

            if (nodeSetId == null)
            {
                return(TestResult.ParameterInvalid("NodeSetId"));
            }

            try
            {
                int       result = (int)EnumResultCode.S_FALSE;
                int[]     results;
                string[]  itemIDs;
                ValueQT[] values;

                if (StartStopCommand)
                {
                    // set start simulation params
                    itemIDs = new string[] { nodeSetId + m_changeInterval,
                                             nodeSetId + m_repeatCount,
                                             nodeSetId + m_increment,
                                             nodeSetId + m_startStopCommand };

                    values = new ValueQT[] { new ValueQT(ChangeInterval, EnumQuality.GOOD, DateTime.Now),
                                             new ValueQT(ChangesCount, EnumQuality.GOOD, DateTime.Now),
                                             new ValueQT(Increment, EnumQuality.GOOD, DateTime.Now),
                                             new ValueQT(StartStopCommand, EnumQuality.GOOD, DateTime.Now) };
                }
                else
                {
                    // set stop simulation params
                    itemIDs = new string[] { nodeSetId + m_startStopCommand };
                    values  = new ValueQT[] { new ValueQT(StartStopCommand, EnumQuality.GOOD, DateTime.Now) };
                }

                // send write request
                result = session.Write(itemIDs, null, values, out results, null);

                if (ResultCode.SUCCEEDED(result))
                {
                    return(TestResult.Success());
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemplo n.º 10
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }
            if (string.IsNullOrEmpty(RootID))
            {
                return(TestResult.ParameterMissing("RootID"));
            }
            //	if (string.IsNullOrEmpty(RootPath))
            //	return TestResult.ParameterMissing("RootPath");


            Softing.OPCToolbox.Client.DaSession session = GetProperty(Session) as DaSession;
            if (session == null)
            {
                return(TestResult.Failed("Session non existent"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                session.Connect(false, false, executionOptions);
                int result = 1;

                Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions browseOptions = new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions();
                browseOptions.ElementTypeFilter = EnumAddressSpaceElementType.LEAF;

                Softing.OPCToolbox.Client.DaAddressSpaceElement[] DaElements;

                //get the nodes children
                if (ResultCode.SUCCEEDED(session.Browse(RootID, RootPath, browseOptions, out DaElements, executionOptions)))
                {
                    //Softing.OPCToolbox.Client.DaAddressSpaceElement daElement;
                    Softing.OPCToolbox.Client.DaSubscription workerSubscription = new Softing.OPCToolbox.Client.DaSubscription(updateRate, session);

                    foreach (Softing.OPCToolbox.Client.DaAddressSpaceElement daElement in DaElements)
                    {
                        DaItem newItem = new DaItem(daElement.ItemId, workerSubscription);
                        //	result =  Connect(true, true, executionOptions);
                    }
                    result = workerSubscription.Connect(true, true, executionOptions);
                    if (ResultCode.FAILED(result))
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Subscribe Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }                //end if
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format(" Browse Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
Exemplo n.º 11
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ItemsProperty))
            {
                return(TestResult.ParameterMissing("ItemsProperty"));
            }

            DaItem[] items = GetProperty(ItemsProperty) as DaItem[];
            if (items == null || items.Length == 0)
            {
                return(TestResult.ParameterInvalid("ItemsProperty"));
            }

            DaSubscription subscription = items[0].DaSubscription;

            try
            {
                int       result = (int)EnumResultCode.S_FALSE;
                ValueQT[] values;
                int[]     results;

                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    result = subscription.Read(MaxAge, items, out values, out results, null);
                }
                else
                {
                    m_asyncExecutionContext = DaExecutionContext.Next;
                    ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext);

                    m_waitHandle = new System.Threading.AutoResetEvent(false);

                    SubscriptionReadEventHandler asyncHandler = new SubscriptionReadEventHandler(subscription_ReadCompleted);
                    subscription.ReadCompleted += asyncHandler;

                    result = subscription.Read(MaxAge, items, out values, out results, executionOptions);

                    if (m_waitHandle.WaitOne(30000))
                    {
                        result  = m_asyncResult;
                        values  = m_asyncValues;
                        results = m_asyncResults;
                    }

                    subscription.ReadCompleted -= asyncHandler;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(ValuesProperty))
                    {
                        SetProperty(ValuesProperty, values);
                    }

                    if (!string.IsNullOrEmpty(ResultsProperty))
                    {
                        SetProperty(ResultsProperty, results);
                    }


                    //validate with expected values
                    if (ExpectedValues.Count > 0)
                    {
                        if (ExpectedValues.Count != values.Length)
                        {
                            return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, "Unexpected number of results"));
                        }

                        for (int i = 0; i < ExpectedValues.Count; i++)
                        {
                            Softing.OPCToolbox.ValueQT receivedValue = values[i];
                            Value expectedValue = ExpectedValues[i];

                            if (expectedValue.Data != null)
                            {
                                if (!expectedValue.Data.Equals(receivedValue.Data))
                                {
                                    return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Unexpected result Value for item #{0}", i)));
                                }
                            }
                            else if (expectedValue.DataArray != null)
                            {
                                IList receivedList = receivedValue.Data as IList;

                                if (receivedList != null)
                                {
                                    if (expectedValue.DataArray.Count != receivedList.Count)
                                    {
                                        return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Result Value array is of different size then expected for item #{0}", i)));
                                    }

                                    for (int j = 0; j < receivedList.Count; j++)
                                    {
                                        if (!expectedValue.DataArray[j].Equals(receivedList[j]))
                                        {
                                            return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Unexpected result Array Item Value for item #{0}", i)));
                                        }
                                    }
                                }
                            }

                            if (expectedValue.Quality != null && expectedValue.Quality != receivedValue.Quality)
                            {
                                return(new DaReadTestResult(result, values, results, string.Format("Unexpected result Quality for item #{0}", i)));
                            }

                            //BUG in TB 4.0
                            //if( expectedValue.TimeStamp != null && expectedValue.TimeStamp != receivedValue.TimeStamp )
                            //	return new DaReadTestResult( result, values, results, string.Format( "Unexpected result Timestamp for item #{0}", i ) );
                        }
                    }

                    return(new DaReadTestResult(result, values, results));
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Url))
            {
                return(TestResult.ParameterMissing("Url"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                DaSession        session          = new DaSession(ExpandProperty(Url));

                if (!session.Valid)
                {
                    return(TestResult.Failed("DaSession not Valid"));
                }

                // set the global prioperty no matter what
                SetProperty(Property, session);

                if (ForcedOpcSpecification != EnumOPCSpecification.DEFAULT)
                {
                    session.ForcedOpcSpecification = ForcedOpcSpecification;
                }

                if (Connect)
                {
                    int result = session.Connect(Deep, Active, executionOptions);

                    if (ResultCode.FAILED(result))
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
Exemplo n.º 13
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(SessionProperty))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(SessionProperty) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            try
            {
                Softing.OPCToolbox.Client.DaAddressSpaceElement[] elements;

                Softing.OPCToolbox.Client.DaAddressSpaceElement rootDaAddressSpaceElement = new Softing.OPCToolbox.Client.DaAddressSpaceElement(
                    EnumAddressSpaceElementType.BRANCH, String.Empty, string.Empty, string.Empty, 0, null);
                rootDaAddressSpaceElement.Session = session;

                int result = rootDaAddressSpaceElement.Browse(new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions(), out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext));

                if (!ResultCode.SUCCEEDED(result))
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }

                Softing.OPCToolbox.Client.DaAddressSpaceElement addressSpaceElement = null;
                for (int i = 0; i < elements.Length; i++)
                {
                    if (elements[i].ItemId == RootID)
                    {
                        addressSpaceElement = elements[i];
                        break;
                    }
                }

                if (addressSpaceElement == null)
                {
                    return(TestResult.Failed(string.Format("Address space element {0} not found!", RootID)));
                }

                if (BrowseOptions == null)
                {
                    BrowseOptions = new DaAddressSpaceElementBrowseOptions();
                }

                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    //browse again => this time the specified item id
                    result = addressSpaceElement.Browse(BrowseOptions.Wrapped, out elements, new ExecutionOptions(ExecutionType, 0));
                }
                else
                {
                    m_asyncExecutionContext  = DaExecutionContext.Next;
                    session.BrowseCompleted += session_BrowseCompleted;
                    m_waitHandle             = new System.Threading.AutoResetEvent(false);
                    result = addressSpaceElement.Browse(BrowseOptions.Wrapped, out elements, new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext));

                    if (m_waitHandle.WaitOne(3000))
                    {
                        result   = m_browseAsyncResult;
                        elements = m_browseAsyncResults;
                    }
                    session.BrowseCompleted -= session_BrowseCompleted;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(Property))
                    {
                        SetProperty(Property, elements);
                    }

                    if (ExpectedElements.Count != 0 && ExpectedElements.Count != elements.Length)
                    {
                        return(new DaBrowseResult(result, elements, "Unexpected number of results"));
                    }

                    for (int i = 0; i < ExpectedElements.Count; i++)
                    {
                        Softing.OPCToolbox.Client.DaAddressSpaceElement receivedElement = elements[i];
                        DaAddressSpaceElement expectedElement = ExpectedElements[i];

                        if ((expectedElement.ItemId != null && expectedElement.ItemId != receivedElement.ItemId) ||
                            (expectedElement.ItemPath != null && expectedElement.ItemPath != receivedElement.ItemPath) ||
                            (expectedElement.Name != null && expectedElement.Name != receivedElement.Name) ||
                            (expectedElement.IsItem.HasValue && expectedElement.IsItem.Value != receivedElement.IsItem) ||
                            (expectedElement.IsBranch.HasValue && expectedElement.IsBranch.Value != receivedElement.IsBranch) ||
                            (expectedElement.IsLeaf.HasValue && expectedElement.IsLeaf.Value != receivedElement.IsLeaf))
                        {
                            return(new DaBrowseResult(result, elements, string.Format("Unexpected result for item #{0}", i)));
                        }
                    }

                    return(new DaBrowseResult(result, elements));
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemplo n.º 14
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ObjectProperty))
            {
                return(TestResult.ParameterMissing("Object"));
            }

            ObjectSpaceElement element = GetProperty(ObjectProperty) as ObjectSpaceElement;

            ObjectSpaceElement[] elements = null;

            if (element == null)
            {
                elements = GetProperty(ObjectProperty) as DaItem[];

                if (elements == null)
                {
                    return(TestResult.ParameterInvalid("Object"));
                }
            }

            try
            {
                int result = (int)EnumResultCode.E_FAIL;

                if (element != null)
                {
                    result = element.Connect(Deep, Active, new ExecutionOptions());
                }
                else
                {
                    foreach (ObjectSpaceElement el in elements)
                    {
                        result = el.Connect(Deep, Active, new ExecutionOptions());

                        if (!ResultCode.SUCCEEDED(result))
                        {
                            break;
                        }
                    }
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    return(TestResult.Success());
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemplo n.º 15
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Subscription))
            {
                return(TestResult.ParameterMissing("Subscription"));
            }

            DaSubscription subscription = GetProperty(Subscription) as DaSubscription;

            if (subscription == null)
            {
                return(TestResult.ParameterInvalid("Subscription"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                int           result;
                List <DaItem> items = new List <DaItem>(ItemIds.Count);

                foreach (string itemId in ItemIds)
                {
                    DaItem item = new DaItem(itemId, subscription);

                    if (!item.Valid)
                    {
                        return(TestResult.Failed("Item not Valid"));
                    }

                    if (Deadband.HasValue)
                    {
                        item.Deadband = Deadband.Value;
                    }

                    if (Connect)
                    {
                        result = item.Connect(false, Active, executionOptions);

                        if (ResultCode.FAILED(result))
                        {
                            EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                            return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                        }
                    }

                    items.Add(item);
                }

                SetProperty(Property, items.ToArray());
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
Exemplo n.º 16
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(SessionProperty))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(SessionProperty) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            try
            {
                Softing.OPCToolbox.Client.DaAddressSpaceElement[] adElements;

                Softing.OPCToolbox.Client.DaAddressSpaceElement rootDaAddressSpaceElement = new Softing.OPCToolbox.Client.DaAddressSpaceElement(
                    EnumAddressSpaceElementType.BRANCH, String.Empty, string.Empty, string.Empty, 0, null);
                rootDaAddressSpaceElement.Session = session;

                int result = rootDaAddressSpaceElement.Browse(new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions(), out adElements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext));

                Softing.OPCToolbox.Client.DaAddressSpaceElement addressSpaceElement = null;
                if (ResultCode.SUCCEEDED(result))
                {
                    for (int i = 0; i < adElements.Length; i++)
                    {
                        if (adElements[i].ItemId == RootID)
                        {
                            addressSpaceElement = adElements[i];
                        }
                    }
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }

                if (addressSpaceElement == null)
                {
                    return(TestResult.Failed(string.Format("Address space element {0} not found!", RootID)));
                }

                Softing.OPCToolbox.Client.DaProperty[] elements;
                result = int.MaxValue;
                if (ExecutionType == EnumExecutionType.SYNCHRONOUS)
                {
                    result = addressSpaceElement.GetDaProperties(DaGetPropertiesOptions, out elements, new ExecutionOptions(ExecutionType, 0));
                }
                else
                {
                    m_asyncExecutionContext           = DaExecutionContext.Next;
                    session.GetDaPropertiesCompleted += session_GetDaPropertiesCompleted;
                    m_waitHandle = new System.Threading.AutoResetEvent(false);
                    result       = addressSpaceElement.GetDaProperties(DaGetPropertiesOptions, out elements, new ExecutionOptions(EnumExecutionType.ASYNCHRONOUS, m_asyncExecutionContext));

                    if (m_waitHandle.WaitOne(3000))
                    {
                        result   = m_browseAsyncResult;
                        elements = m_browseAsyncResults;
                    }
                    session.GetDaPropertiesCompleted -= session_GetDaPropertiesCompleted;
                }

                if (ResultCode.SUCCEEDED(result))
                {
                    if (!string.IsNullOrEmpty(Property))
                    {
                        SetProperty(Property, elements);
                    }

                    if (ExpectedElements.Count != 0 && ExpectedElements.Count != elements.Length)
                    {
                        return(TestResult.Failed(string.Format("Unexpected number of results, expected {0}, actual {1}", ExpectedElements.Count, elements.Length)));
                    }

                    for (int i = 0; i < ExpectedElements.Count; i++)
                    {
                        Softing.OPCToolbox.Client.DaProperty receivedElement = elements[i];
                        TestClientGui.Support.DaProperty     expectedElement = ExpectedElements[i];

                        if ((expectedElement.ItemId != null && expectedElement.ItemId != receivedElement.ItemId) ||
                            (expectedElement.ItemPath != null && expectedElement.ItemPath != receivedElement.ItemPath) ||
                            (!string.IsNullOrEmpty(expectedElement.Name) && expectedElement.Name != receivedElement.Name) ||
                            (expectedElement.DataType != null && expectedElement.DataType != receivedElement.DataType) ||
                            (!string.IsNullOrEmpty(expectedElement.Description) && expectedElement.Description != receivedElement.Description) ||
                            (expectedElement.ValueQT != null && !expectedElement.ValueQT.Data.Equals(receivedElement.ValueQT.Data)) ||
                            (expectedElement.ValueQT != null && expectedElement.ValueQT.Quality != receivedElement.ValueQT.Quality))
                        {
                            return(TestResult.Failed(string.Format("Unexpected result for item #{0}", i)));
                        }

                        if (DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.ITEMID || DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.NONE)
                        {
                            if (receivedElement.ValueQT.Data != null)
                            {
                                return(TestResult.Failed(string.Format("Value was not NULL for element #{0}", i)));
                            }
                        }
                        if (DaGetPropertiesOptions.WhatPropertyData == EnumPropertyData.VALUE)
                        {
                            if (!string.IsNullOrEmpty(receivedElement.ItemId))
                            {
                                return(TestResult.Failed(string.Format("ItemId was not NULL for element #{0}", i)));
                            }
                        }
                    }

                    return(TestResult.Success());
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}\t({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemplo n.º 17
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ObjectProperty))
            {
                return(TestResult.ParameterMissing("Object"));
            }

            ObjectSpaceElement element = GetProperty(ObjectProperty) as ObjectSpaceElement;

            if (element == null)
            {
                return(TestResult.ParameterInvalid("Object"));
            }

            try
            {
                int result = element.Disconnect(new ExecutionOptions());

                if (ResultCode.SUCCEEDED(result))
                {
                    return(TestResult.Success());
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(Session) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            try
            {
                DaSubscription subscription = new DaSubscription(UpdateRate, session);

                if (!subscription.Valid)
                {
                    return(TestResult.Failed("DaSubscription not Valid"));
                }

                if (RequestedKeepAliveTime.HasValue)
                {
                    subscription.RequestedKeepAliveTime = RequestedKeepAliveTime.Value;
                }

                // set the global property anyhow.
                SetProperty(Property, subscription);

                if (Connect)
                {
                    int result = subscription.Connect(Deep, Active, null);

                    if (ResultCode.FAILED(result))
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }

                if (Deadband.HasValue)
                {
                    subscription.Deadband = Deadband.Value;
                }
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }
            if (string.IsNullOrEmpty(RootID))
            {
                return(TestResult.ParameterMissing("RootID"));
            }
            //	if (string.IsNullOrEmpty(RootPath))
            //	return TestResult.ParameterMissing("RootPath");


            Softing.OPCToolbox.Client.DaSession session = GetProperty(Session) as DaSession;
            if (session == null)
            {
                return(TestResult.Failed("Session non existent"));
            }

            try
            {
                ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                session.Connect(false, false, executionOptions);

                Softing.OPCToolbox.Client.DaAddressSpaceElement[] elements;

                Softing.OPCToolbox.Client.DaAddressSpaceElement rootDaAddressSpaceElement = new Softing.OPCToolbox.Client.DaAddressSpaceElement(
                    EnumAddressSpaceElementType.BRANCH, String.Empty, string.Empty, string.Empty, 0, null);
                rootDaAddressSpaceElement.Session = session;


                int result = rootDaAddressSpaceElement.Browse(new Softing.OPCToolbox.Client.DaAddressSpaceElementBrowseOptions(), out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, m_asyncExecutionContext));

                if (!ResultCode.SUCCEEDED(result))
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }

                Softing.OPCToolbox.Client.DaAddressSpaceElement addressSpaceElement = null;
                for (int i = 0; i < elements.Length; i++)
                {
                    if (elements[i].ItemId == RootID)
                    {
                        addressSpaceElement = elements[i];
                        break;
                    }
                }

                if (addressSpaceElement == null)
                {
                    return(TestResult.Failed(string.Format("Address space element {0} not found!", RootID)));
                }

                if (BrowseOptions == null)
                {
                    BrowseOptions = new DaAddressSpaceElementBrowseOptions();
                }



                if (ResultCode.SUCCEEDED(addressSpaceElement.Browse(BrowseOptions.Wrapped, out elements, new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0))))
                {
                    //Softing.OPCToolbox.Client.DaAddressSpaceElement daElement;
                    Softing.OPCToolbox.Client.DaSubscription workerSubscription = new Softing.OPCToolbox.Client.DaSubscription(updateRate, session);

                    foreach (Softing.OPCToolbox.Client.DaAddressSpaceElement daElement in elements)
                    {
                        DaItem newItem = new DaItem(daElement.ItemId, workerSubscription);
                        //	result =  Connect(true, true, executionOptions);
                    }

                    result = workerSubscription.Connect(true, true, executionOptions);
                    if (ResultCode.FAILED(result))
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Subscribe Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }

                    SetProperty(Property, workerSubscription);
                }//end if
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format(" Browse Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                if (ExpectedSuccess)
                {
                    return(new TestResult(ex));
                }
            }

            return(TestResult.Success());
        }
Exemplo n.º 20
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(ItemsProperty))
            {
                return(TestResult.ParameterMissing("ItemsProperty"));
            }

            DaItem[] items = GetProperty(ItemsProperty) as DaItem[];
            if (items == null)
            {
                return(TestResult.ParameterInvalid("ItemsProperty"));
            }

            try
            {
                ValueQT[] values  = new ValueQT[items.Length];
                int[]     results = new int[items.Length];

                for (int i = 0; i < items.Length; i++)
                {
                    DaItem  item = items[i];
                    ValueQT value;
                    int     readResult;

                    int result = item.Read(MaxAge, out value, out readResult, new ExecutionOptions());
                    values[i]  = value;
                    results[i] = result;

                    if (ResultCode.FAILED(result))
                    {
                        EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                        return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                    }
                }

                if (!string.IsNullOrEmpty(ValuesProperty))
                {
                    SetProperty(ValuesProperty, values);
                }

                if (!string.IsNullOrEmpty(ResultsProperty))
                {
                    SetProperty(ResultsProperty, results);
                }

                //validate with expected values
                if (ExpectedValues.Count != 0 && ExpectedValues.Count != values.Length)
                {
                    return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, "Unexpected number of results"));
                }

                for (int i = 0; i < ExpectedValues.Count; i++)
                {
                    Softing.OPCToolbox.ValueQT receivedValue = values[i];
                    Value expectedValue = ExpectedValues[i];

                    if (expectedValue.Data != null)
                    {
                        if (!expectedValue.Data.Equals(receivedValue.Data))
                        {
                            return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Unexpected result Value for item #{0}", i)));
                        }
                    }
                    else if (expectedValue.DataArray != null)
                    {
                        IList receivedList = receivedValue.Data as IList;

                        if (receivedList != null)
                        {
                            if (expectedValue.DataArray.Count != receivedList.Count)
                            {
                                return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Result Value array is of different size then expected for item #{0}", i)));
                            }

                            for (int j = 0; j < receivedList.Count; j++)
                            {
                                if (!expectedValue.DataArray[j].Equals(receivedList[j]))
                                {
                                    return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Unexpected result Array Item Value for item #{0}", i)));
                                }
                            }
                        }
                    }

                    if (expectedValue.Quality != null && expectedValue.Quality != receivedValue.Quality)
                    {
                        return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results, string.Format("Unexpected result Quality for item #{0}", i)));
                    }

                    //BUG in TB 4.0
                    //if( expectedValue.TimeStamp != null && expectedValue.TimeStamp != receivedValue.TimeStamp )
                    //	return new DaReadTestResult( (int) EnumResultCode.S_OK, values, results, string.Format( "Unexpected result Timestamp for item #{0}", i ) );
                }

                return(new DaReadTestResult((int)EnumResultCode.S_OK, values, results));
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }
Exemplo n.º 21
0
        public override TestResult Execute()
        {
            if (string.IsNullOrEmpty(Session))
            {
                return(TestResult.ParameterMissing("Session"));
            }

            DaSession session = GetProperty(Session) as DaSession;

            if (session == null)
            {
                return(TestResult.ParameterInvalid("Session"));
            }

            if (string.IsNullOrEmpty(NodeSetId))
            {
                return(TestResult.ParameterMissing("NodeSetId"));
            }

            string nodeSetId = GetProperty(NodeSetId) as string;

            if (nodeSetId == null)
            {
                return(TestResult.ParameterInvalid("NodeSetId"));
            }

            try
            {
                DaSubscription subscription = new DaSubscription(UpdateRate, session);

                if (!subscription.Valid)
                {
                    return(TestResult.Failed("DaSubscription not Valid"));
                }

                int result = subscription.Connect(true, true, null);

                if (ResultCode.SUCCEEDED(result))
                {
                    // subscription created
                    ExecutionOptions executionOptions = new ExecutionOptions(EnumExecutionType.SYNCHRONOUS, 0);
                    List <DaItem>    items            = new List <DaItem>();

                    // create items
                    for (uint i = 0; i < Count; i++)
                    {
                        string itemId = String.Format("{0}, {1}, {2}", nodeSetId, m_variableNodeIdPrefix, i);

                        DaItem item = new DaItem(itemId, subscription);

                        if (!item.Valid)
                        {
                            return(TestResult.Failed("Item not Valid"));
                        }

                        result = item.Connect(false, true, executionOptions);

                        if (ResultCode.FAILED(result))
                        {
                            EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                            return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                        }

                        items.Add(item);
                    }

                    SetProperty(Property, items.ToArray());
                    SetProperty(SubscriptionProperty, subscription);

                    return(TestResult.Success());
                }
                else
                {
                    EnumResultCode resCode = (EnumResultCode)Enum.Parse(typeof(EnumResultCode), result.ToString());

                    return(TestResult.Failed(string.Format("Call returned: {0}  ({1})", resCode.ToString(), result)));
                }
            }
            catch (Exception ex)
            {
                return(new TestResult(ex));
            }
        }