Microsoft.ManagementConsole.SharedDataItem.GetData C# (CSharp) Method

GetData() public method

public GetData ( ) : byte[]
return byte[]
        public override byte[] GetData()
        {
            if (this._snapInPlatform == null)
            {
                throw new InvalidOperationException(Microsoft.ManagementConsole.Internal.Utility.LoadResourceString(Microsoft.ManagementConsole.Internal.Strings.AdvancedSharedDataItemNotInitialized));
            }
            ReadDataCommand command = new ReadDataCommand();
            command.DataObjectId = this._dataObjectId;
            command.ClipboardFormatId = base.ClipboardFormatId;
            try
            {
                ReadDataCommandResult result = (ReadDataCommandResult) this._snapInPlatform.ProcessCommand(command);
                base.InternalSetData(result.Data.GetValue());
            }
            catch (Microsoft.ManagementConsole.Internal.PrimarySnapInDataException exception)
            {
                throw new Microsoft.ManagementConsole.Advanced.PrimarySnapInDataException(exception.Message, exception);
            }
            return base.GetData();
        }

Usage Example

        /// <summary>
        /// The DisplayName of the extension node will be the computer name 
        /// published by the primary.  Note: this defaults to an empty string for localhost.
        /// </summary>
        void SetDisplayName(ScopeNode scopeNode, SharedDataItem sharedDataItem)
        {
            // get buffer containing the machine name
            string machineName = Encoding.Unicode.GetString(sharedDataItem.GetData());

            // find first null terminated string in buffer.
            if (machineName.IndexOf('\0') <= 0)
            {
                // either not found in buffer or first entry in buffer
                machineName = String.Empty;
            }
            else
            {
                machineName = machineName.Substring(0, machineName.IndexOf('\0'));
            }

            // if empty then localhost
            if (machineName == string.Empty)
            {
                scopeNode.DisplayName = "Sample Extension to (localhost)";
            }
            else
            {
                scopeNode.DisplayName = "Sample Extension to (" + machineName + ")";
            }
        }
All Usage Examples Of Microsoft.ManagementConsole.SharedDataItem::GetData