Пример #1
0
        private unsafe int GetContainer(PIActionReference reference, PIActionReference *value)
        {
            if (value == null)
            {
                return(PSError.kSPBadParameterError);
            }

            ActionReferenceContainer container;

            if (actionReferences.TryGetValue(reference, out container))
            {
                try
                {
                    ActionReferenceContainer nextContainer = container.GetNextContainer();
                    if (nextContainer != null)
                    {
                        *value = GenerateDictionaryKey();
                        actionReferences.Add(*value, nextContainer);
                    }
                    else
                    {
                        *value = PIActionReference.Null;
                    }
                }
                catch (OutOfMemoryException)
                {
                    return(PSError.kSPOutOfMemoryError);
                }

                return(PSError.kSPNoError);
            }

            return(PSError.kSPBadParameterError);
        }
Пример #2
0
        private unsafe int GetEnumerated(PIActionReference reference, uint *type, uint *enumValue)
        {
            if (enumValue == null)
            {
                return(PSError.kSPBadParameterError);
            }

            ActionReferenceContainer container;

            if (actionReferences.TryGetValue(reference, out container))
            {
                ActionReferenceItem item = container.GetReference();
                if (item != null)
                {
                    EnumeratedValue enumerated = (EnumeratedValue)item.Value;
                    if (type != null)
                    {
                        *type = enumerated.Type;
                    }
                    *enumValue = enumerated.Value;

                    return(PSError.kSPNoError);
                }
            }

            return(PSError.kSPBadParameterError);
        }
Пример #3
0
        private int PutName(PIActionReference reference, uint desiredClass, IntPtr cstrValue)
        {
            if (cstrValue != IntPtr.Zero)
            {
                try
                {
                    if (StringUtil.TryGetCStringLength(cstrValue, out int length))
                    {
                        byte[] bytes = new byte[length];
                        Marshal.Copy(cstrValue, bytes, 0, length);

                        actionReferences[reference].Add(new ActionReferenceItem(ActionReferenceForm.Name, desiredClass, bytes));
                    }
                    else
                    {
                        // The string length exceeds int.MaxValue.
                        return(PSError.kSPOutOfMemoryError);
                    }
                }
                catch (OutOfMemoryException)
                {
                    return(PSError.kSPOutOfMemoryError);
                }

                return(PSError.kSPNoError);
            }

            return(PSError.kSPBadParameterError);
        }
Пример #4
0
        private int GetName(PIActionReference reference, IntPtr cstrValue, uint maxLength)
        {
            if (cstrValue != IntPtr.Zero)
            {
                ActionReferenceContainer container;
                if (actionReferences.TryGetValue(reference, out container))
                {
                    ActionReferenceItem item = container.GetReference();
                    if (item != null)
                    {
                        if (maxLength > 0)
                        {
                            byte[] bytes = (byte[])item.Value;

                            // Ensure that the buffer has room for the null terminator.
                            int length = (int)Math.Min(bytes.Length, maxLength - 1);

                            Marshal.Copy(bytes, 0, cstrValue, length);
                            Marshal.WriteByte(cstrValue, length, 0);
                        }

                        return(PSError.kSPNoError);
                    }
                }
            }

            return(PSError.kSPBadParameterError);
        }
Пример #5
0
        private int Free(PIActionReference reference)
        {
            actionReferences.Remove(reference);
            if (actionReferencesIndex == reference.Index)
            {
                actionReferencesIndex--;
            }

            return(PSError.kSPNoError);
        }
Пример #6
0
        private int PutClass(PIActionReference reference, uint desiredClass)
        {
            try
            {
                actionReferences[reference].Add(new ActionReferenceItem(ActionReferenceForm.Class, desiredClass, null));
            }
            catch (OutOfMemoryException)
            {
                return(PSError.kSPOutOfMemoryError);
            }

            return(PSError.kSPNoError);
        }
Пример #7
0
        private int PutProperty(PIActionReference reference, uint desiredClass, uint value)
        {
            try
            {
                actionReferences[reference].Add(new ActionReferenceItem(ActionReferenceForm.Property, desiredClass, value));
            }
            catch (OutOfMemoryException)
            {
                return(PSError.kSPOutOfMemoryError);
            }

            return(PSError.kSPNoError);
        }
Пример #8
0
        private int PutEnumerated(PIActionReference reference, uint desiredClass, uint type, uint value)
        {
            try
            {
                actionReferences[reference].Add(new ActionReferenceItem(ActionReferenceForm.Enumerated, desiredClass, new EnumeratedValue(type, value)));
            }
            catch (OutOfMemoryException)
            {
                return(PSError.kSPOutOfMemoryError);
            }

            return(PSError.kSPNoError);
        }
Пример #9
0
        PIActionReference IActionReferenceSuite.CreateReference(ReadOnlyCollection <ActionReferenceItem> values)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            PIActionReference reference = GenerateDictionaryKey();

            actionReferences.Add(reference, new ActionReferenceContainer(values));

            return(reference);
        }
Пример #10
0
        bool IActionReferenceSuite.TryGetReferenceValues(PIActionReference reference, out ReadOnlyCollection <ActionReferenceItem> values)
        {
            values = null;

            ActionReferenceContainer container;

            if (actionReferences.TryGetValue(reference, out container))
            {
                values = container.GetReferencesAsReadOnly();

                return(true);
            }

            return(false);
        }
Пример #11
0
        private int PutReference(PIActionList list, PIActionReference reference)
        {
            try
            {
                ReadOnlyCollection <ActionReferenceItem> value;
                if (actionReferenceSuite.TryGetReferenceValues(reference, out value))
                {
                    actionLists[list].Add(new ActionListItem(DescriptorTypes.ObjectReference, value));
                }
                else
                {
                    return(PSError.kSPBadParameterError);
                }
            }
            catch (OutOfMemoryException)
            {
                return(PSError.kSPOutOfMemoryError);
            }

            return(PSError.kSPNoError);
        }
Пример #12
0
        private unsafe int GetProperty(PIActionReference reference, uint *value)
        {
            if (value == null)
            {
                return(PSError.kSPBadParameterError);
            }

            ActionReferenceContainer container;

            if (actionReferences.TryGetValue(reference, out container))
            {
                ActionReferenceItem item = container.GetReference();
                if (item != null)
                {
                    *value = (uint)item.Value;

                    return(PSError.kSPNoError);
                }
            }

            return(PSError.kSPBadParameterError);
        }
Пример #13
0
        private unsafe int GetNameLength(PIActionReference reference, uint *stringLength)
        {
            if (stringLength == null)
            {
                return(PSError.kSPBadParameterError);
            }

            ActionReferenceContainer container;

            if (actionReferences.TryGetValue(reference, out container))
            {
                ActionReferenceItem item = container.GetReference();
                if (item != null)
                {
                    byte[] bytes        = (byte[])item.Value;
                    *      stringLength = (uint)bytes.Length;

                    return(PSError.kSPNoError);
                }
            }

            return(PSError.kSPBadParameterError);
        }