예제 #1
0
		/// <summary>
		/// Allocates and marshals an arary of OPCITEMPROPERTY structures.
		/// </summary>
		internal static OpcRcw.Da.OPCITEMPROPERTY GetItemProperty(ItemProperty input)
		{
			OpcRcw.Da.OPCITEMPROPERTY output = new OpcRcw.Da.OPCITEMPROPERTY();

			if (input != null)
			{
				output.dwPropertyID  = input.Id;
				output.szDescription = input.Description;
				output.vtDataType    = input.DataType;
				output.vValue        = ComUtils.GetVARIANT(input.Value);
				output.wReserved     = 0;
				output.hrErrorID     = input.ErrorId;
			}

			return output;
		}
예제 #2
0
        /// <summary>
        /// Gets the properties for the browse element.
        /// </summary>
        private List<ItemProperty> GetItemProperties(
            INode node,
            bool  returnAllProperties,
            int[] propertyIds,
            bool  returnPropertyValues)
        {
            int[] availablePropertyIds = GetAvailableProperties(node);

            List<ItemProperty> properties = new List<ItemProperty>();
            
            // determine whether any of the request properties are supported.
            if (propertyIds != null && propertyIds.Length > 0)
            {
                for (int ii = 0; ii < propertyIds.Length; ii++)
                {
                    bool exists = false;

                    for (int jj = 0; jj < availablePropertyIds.Length; jj++)
                    {
                        if (availablePropertyIds[jj] == propertyIds[ii])
                        {
                            exists = true;
                            break;
                        }
                    }

                    ItemProperty property = new ItemProperty();
                    
                    property.Id = propertyIds[ii];
                    property.ErrorId = ResultIds.S_OK;

                    if (!exists)
                    {
                        property.ErrorId = ResultIds.E_INVALID_PID;
                    }

                    properties.Add(property);
                }
            } 

            // return all available properties.
            else
            {
                for (int ii = 0; ii < availablePropertyIds.Length; ii++)
                {
                    ItemProperty property = new ItemProperty();
                    
                    property.Id = availablePropertyIds[ii];
                    property.ErrorId = ResultIds.S_OK;

                    properties.Add(property);
                }
            }

            // get description and datatype.
            List<int> valuesToFetch = new List<int>(properties.Count);
            List<int> indexesForValues = new List<int>(properties.Count);

            for (int ii = 0; ii < properties.Count; ii++)
            {
                ItemProperty property = properties[ii];

                if (property.ErrorId == 0)
                {
                    property.Description = PropertyIds.GetDescription(property.Id);
                    property.DataType = (short)PropertyIds.GetVarType(property.Id);

                    if (returnPropertyValues)
                    {
                        valuesToFetch.Add(property.Id);
                        indexesForValues.Add(ii);
                    }
                }
            }

            // fetch any property values.
            if (valuesToFetch.Count > 0)
            {
                try
                {
                    int[] errors = null;

                    object[] values = ReadPropertyValues(node, valuesToFetch, out errors);
                    
                    // update property objects.
                    for (int ii = 0; ii < errors.Length; ii++)
                    {
                        ItemProperty property = properties[indexesForValues[ii]];

                        property.Value = values[ii];
                        property.ErrorId = errors[ii];

                        if (property.ErrorId < 0)
                        {
                            property.Value = null;
                        }
                    }
                }
                catch (Exception e)
                {
                    // update property objects with errors.
                    int error = Marshal.GetHRForException(e);

                    for (int ii = 0; ii < indexesForValues.Count; ii++)
                    {
                        ItemProperty property = properties[indexesForValues[ii]];

                        property.Value = null;
                        property.ErrorId = error;
                    }
                }
            }

            // save the properties in the element.
            return properties;
        }