예제 #1
0
        public override bool RunBody(State state)
        {
            RequirePropertyHandlerRegistered();
            RequireExtHasHandler();

            const string cval         = "bcomment??";
            string       propertyName = "System.Comment";

            //Create a temp file to put metadata on
            string fileName = CreateFreshFile(1);

            var handler = new CPropertyHandler();

            handler.Initialize(fileName, 0);

            PropVariant value = new PropVariant(cval);

            handler.SetValue(new TestDriverCodePack.PropertyKey(new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"), 6), value);
            handler.Commit();

            Marshal.ReleaseComObject(handler);  // preempt GC for CCW

            // Use API Code Pack to read the value
            IShellProperty prop = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName);
            object         oval = prop.ValueAsObject;

            File.Delete(fileName);  // only works if all have let go of the file

            return((string)oval == cval);
        }
예제 #2
0
        public override bool RunBody(State state)
        {
            RequirePropertyHandlerRegistered();
            RequireExtHasHandler();

            const string cval1 = "할말있어";

            string[] cval2 = { "hello", "Приветствия" };

            //Create a temp file to put metadata on
            string fileName = CreateFreshFile(1);

            var handler = new CPropertyHandler();

            handler.Initialize(fileName, 0);

            PropVariant value1 = new PropVariant(cval1);
            PropVariant value2 = new PropVariant(cval2);

            // System.Comment
            handler.SetValue(new TestDriverCodePack.PropertyKey(new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"), 6), value1);
            // System.Category
            handler.SetValue(new TestDriverCodePack.PropertyKey(new Guid("D5CDD502-2E9C-101B-9397-08002B2CF9AE"), 2), value2);
            handler.Commit();

            PropVariant getvalue1 = new PropVariant();
            PropVariant getvalue2 = new PropVariant();

            handler.GetValue(new TestDriverCodePack.PropertyKey(new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9"), 6), getvalue1);
            handler.GetValue(new TestDriverCodePack.PropertyKey(new Guid("D5CDD502-2E9C-101B-9397-08002B2CF9AE"), 2), getvalue2);
            string result1 = (string)getvalue1.Value;

            string[] result2 = (string[])getvalue2.Value;

            Marshal.ReleaseComObject(handler); // preempt GC for CCW

            File.Delete(fileName);             // only works if all have let go of the file

            return(result1 == cval1 && result2[0] == cval2[0] && result2[1] == cval2[1]);
        }
예제 #3
0
        private void SetPropertyValue(string fileName, TestDriverCodePack.ShellPropertyDescription propDesc, IShellProperty prop)
        {
            Type   t = propDesc.ValueType;
            string s;

            try
            {
                if (t == typeof(string))
                {
                    object obj = GetEnumValueForProperty(propDesc);

                    if (obj != null)
                    {
                        s = (string)obj;
                    }
                    else
                    {
                        s = RandomString();
                    }

                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = s
                    });
                    //(prop as ShellProperty<string>).Value = s;

                    // Workaround Code Pack bug with 1 char strings by using PropertyHandler
                    // Have to open and release each time to avoid lock problems - still, it ups the pounding
                    var handler = new CPropertyHandler();
                    handler.Initialize(fileName, 0);

                    PropVariant value = new PropVariant(s);
                    handler.SetValue(new TestDriverCodePack.PropertyKey(prop.PropertyKey.FormatId, prop.PropertyKey.PropertyId), value);
                    handler.Commit();

                    Marshal.ReleaseComObject(handler);  // preempt GC for CCW
                }
                else if (t == typeof(string[]))
                {
                    string[] ss = GetStringArrayValueForProperty(propDesc);

                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = ss
                    });
                    //(prop as ShellProperty<string[]>).Value = ss;

                    // Workaround Code Pack bug with 1 char strings by using PropertyHandler
                    // Have to open and release each time to avoid lock problems - still, it ups the pounding
                    var handler = new CPropertyHandler();
                    handler.Initialize(fileName, 0);

                    PropVariant value = new PropVariant(ss);
                    handler.SetValue(new TestDriverCodePack.PropertyKey(prop.PropertyKey.FormatId, prop.PropertyKey.PropertyId), value);
                    handler.Commit();

                    Marshal.ReleaseComObject(handler);  // preempt GC for CCW
                }
                else if (t == typeof(Int16?) || t == typeof(Int32?) || t == typeof(UInt16?) || t == typeof(UInt32?))
                {
                    object obj = GetEnumValueForProperty(propDesc);

                    if (t == typeof(Int16?))
                    {
                        Int16?val = obj != null ? (Int16?)obj : (Int16?)NullableRandomNumber(-max16, max16);
                        savedProps.Add(new SavedProp {
                            Name = prop.CanonicalName, Value = val
                        });
                        (prop as ShellProperty <Int16?>).Value = val;
                    }
                    else if (t == typeof(Int32?))
                    {
                        Int32?val = obj != null ? (Int32?)obj : (Int32?)NullableRandomNumber(-max32, max32);
                        savedProps.Add(new SavedProp {
                            Name = prop.CanonicalName, Value = val
                        });
                        (prop as ShellProperty <Int32?>).Value = val;
                    }
                    else if (t == typeof(UInt16?))
                    {
                        UInt16?val = obj != null ? (UInt16?)obj : (UInt16?)NullableRandomNumber(max16);
                        savedProps.Add(new SavedProp {
                            Name = prop.CanonicalName, Value = val
                        });
                        (prop as ShellProperty <UInt16?>).Value = val;
                    }
                    else // UInt32?
                    {
                        UInt32?val = obj != null ? (UInt32?)obj : (UInt32?)NullableRandomNumber(max16);
                        savedProps.Add(new SavedProp {
                            Name = prop.CanonicalName, Value = val
                        });
                        (prop as ShellProperty <UInt32?>).Value = val;
                    }
                }
                else if (t == typeof(Int32[]))
                {
                    Int32[] vals = new Int32[4];
                    for (int i = 0; i < 4; i++)
                    {
                        vals[i] = RandomNumber(-max32, max32);
                    }
                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = vals
                    });
                    (prop as ShellProperty <Int32[]>).Value = vals;
                }
                else if (t == typeof(UInt32[]))
                {
                    UInt32[] vals = new UInt32[4];
                    for (int i = 0; i < 4; i++)
                    {
                        vals[i] = (UInt32)RandomNumber(max32);
                    }
                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = vals
                    });
                    (prop as ShellProperty <UInt32[]>).Value = vals;
                }
                else if (t == typeof(bool?))
                {
                    int? r     = NullableRandomNumber();
                    bool?value = (r == null) ? (bool?)null : (r % 2 == 0);
                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = value
                    });
                    (prop as ShellProperty <bool?>).Value = value;
                }
                else if (t == typeof(DateTime?))
                {
                    DateTime dt = new DateTime((long)(random.NextDouble() * (maxTocks - minTicks) + minTicks));
                    savedProps.Add(new SavedProp {
                        Name = prop.CanonicalName, Value = dt
                    });
                    (prop as ShellProperty <DateTime?>).Value = dt;
                }
                else if (t == typeof(double?))
                {
                    // fails in Code Pack, so skip
                    //(prop as ShellProperty<double>).Value = (double)RandomNumber(max64);
                }
                else if (t == typeof(Int64?))
                {
                    // fails in Code Pack, so skip
                    //(prop as ShellProperty<Int64>).Value = RandomNumber(max64);
                }
                else if (t == typeof(UInt64?))
                {
                    // fails in Code Pack, so skip
                    // (prop as ShellProperty<UInt64>).Value = (UInt64) RandomNumber(max64);
                }
                else if (t == typeof(byte?))
                {
                    // The Code Pack does not support setting these, so skip for now
                    //(prop as ShellProperty<byte>).Value = (byte)RandomNumber(max8);
                }
                else if (t == typeof(byte[]))
                {
                    // The Code Pack does not support setting these, so skip for now
                    // Mostly 128 byte arrays e.g. System.Photo.MakerNote
                    //byte[] bs = new byte[128];
                    //random.NextBytes(bs);
                    //(prop as ShellProperty<byte[]>).Value = bs;
                }
                else if (t == typeof(object) || t == typeof(IntPtr?) || t == typeof(System.Runtime.InteropServices.ComTypes.IStream))
                {
                    // ignore these, they are system artefacts like group header props, and don't appear in settable lists
                }
                else
                {
                    throw new System.Exception("Need " + t.ToString() + " for " + propDesc.CanonicalName);
                }
            }
            catch (System.Exception e)
            {
                throw new System.Exception(String.Format("Error setting property {0} to '{1}'",
                                                         savedProps.Last().Name, ToDisplayString(savedProps.Last().Value)), e);
            }
        }
예제 #4
0
        public override bool RunBody(State state)
        {
            RequirePropertyHandlerRegistered();
            RequireExtHasHandler();

            string       propertyName1 = "System.Comment";
            const string cval1         = "comment";
            const string cval1a        = "commenta";
            Guid         format1       = new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9");
            int          id1           = 6;

            string       propertyName2 = "System.Title";
            const string cval2         = "title";
            const string cval2a        = "titlea";
            Guid         format2       = new Guid("F29F85E0-4FF9-1068-AB91-08002B27B3D9");
            int          id2           = 2;

            //Create a temp file to put metadata on
            string fileName = CreateFreshFile(1);

            // Use API Code Pack to set the values
            IShellProperty prop1 = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName1);

            (prop1 as ShellProperty <string>).Value = cval1;
            IShellProperty prop2 = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName2);

            (prop2 as ShellProperty <string>).Value = cval2;

            var handler = new CPropertyHandler();

            handler.Initialize(fileName, 0);

            // Read the values with the Property Handler
            PropVariant getvalue1 = new PropVariant();
            PropVariant getvalue2 = new PropVariant();

            handler.GetValue(new TestDriverCodePack.PropertyKey(format1, id1), getvalue1);
            handler.GetValue(new TestDriverCodePack.PropertyKey(format2, id2), getvalue2);
            string result1 = (string)getvalue1.Value;
            string result2 = (string)getvalue2.Value;

            if (result1 != cval1 || result2 != cval2)
            {
                return(false);
            }

            // Set the values with the Property Handler
            PropVariant value1 = new PropVariant(cval1a);
            PropVariant value2 = new PropVariant(cval2a);

            // System.Comment
            handler.SetValue(new TestDriverCodePack.PropertyKey(format1, id1), value1);
            // System.Category
            handler.SetValue(new TestDriverCodePack.PropertyKey(format2, id2), value2);
            handler.Commit();

            // Read the updated values with the Property Handler
            getvalue1 = new PropVariant();
            getvalue2 = new PropVariant();
            handler.GetValue(new TestDriverCodePack.PropertyKey(format1, id1), getvalue1);
            handler.GetValue(new TestDriverCodePack.PropertyKey(format2, id2), getvalue2);
            result1 = (string)getvalue1.Value;
            result2 = (string)getvalue2.Value;

            Marshal.ReleaseComObject(handler); // preempt GC for CCW

            File.Delete(fileName);             // only works if all have let go of the file

            return(result1 == cval1a && result2 == cval2a);
        }