Beispiel #1
0
        public void GetPropertyValueTest()
        {
            var test = new TestClass();
            var anon = new { Str = "Test2", Int = 9000, Date = new DateTime(1900, 1, 1) };

            test.StringProperty = "Test";
            test.IntProperty = 9999;
            test.DateTimeProperty = new DateTime(2000, 1, 1);

            var stringResult = (string)test.GetPropertyValue("StringProperty");
            var intResult = (int)test.GetPropertyValue("IntProperty");
            var dateResult = (DateTime)test.GetPropertyValue("DateTimeProperty");

            var anonStr = (string)anon.GetPropertyValue("Str");
            var anonInt = (int)anon.GetPropertyValue("Int");
            var anonDateTime = (DateTime)anon.GetPropertyValue("Date");

            Assert.AreEqual<string>(stringResult, "Test");
            Assert.AreEqual<int>(intResult, 9999);
            Assert.AreEqual<DateTime>(dateResult, new DateTime(2000, 1, 1));

            Assert.AreEqual<string>(anonStr, "Test2");
            Assert.AreEqual<int>(anonInt, 9000);
            Assert.AreEqual<DateTime>(anonDateTime, new DateTime(1900, 1, 1));
        }
 public void GetPropertiesTest()
 {
     var anon = new { Michael = "batty" };
     anon.GetPropertyValue("Michael").ShouldEqual("batty");
 }
Beispiel #3
0
        internal Game(System.Management.ManagementBaseObject game)
        {
            this.name = game.GetPropertyValue("Name") as string;
            this.instanceID = game.GetPropertyValue("InstanceID") as string;
            this.gameID = game.GetPropertyValue("GameID") as string;
            this.gdfPath = game.GetPropertyValue("GDFBinaryPath") as string;
            string str1 = this.gdfPath;
            this.installPath = game.GetPropertyValue("GameInstallPath") as string;
            this.gdfResourceID = game.GetPropertyValue("ResourceIDForGDFInfo") as string;
            this.installScope = (Game.GameInstallScope)game.GetPropertyValue("InstallScope");
            this.RefreshTasks();
            if (this.gdfPath != null)
            {
                try
                {
                    using (UnmanagedLibrary unmanagedLibrary = new UnmanagedLibrary(this.gdfPath))
                    {
                        try
                        {
                            byte[] bytes = ResourceExtensions.GetBytes(unmanagedLibrary.GetResource("__GDF_THUMBNAIL", (object)"DATA"));
                            if (bytes != null)
                            {
                                try
                                {
                                    this.image = (ImageSource)BitmapDecoder.Create((Stream)new MemoryStream(bytes), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
                                }
                                catch (Exception ex)
                                {
                                    Trace.TraceWarning("Image for " + this.name + "could not be loaded: " + ex .Message);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.TraceWarning("Error attempting to get image resource for " + this.name + "could not be loaded: " + ex.Message);
                        }
                        using (RegistryKey registryKey1 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GameUX\\"))
                        {
                            if (registryKey1 != null)
                            {
                                foreach (object obj in registryKey1.GetSubKeyNames())
                                {
                                    string name = string.Format("{0}\\{1}", obj, (object)this.instanceID);
                                    RegistryKey registryKey2 = registryKey1.OpenSubKey(name);
                                    if (registryKey2 != null)
                                    {
                                        using (registryKey2)
                                        {
                                            if (this.image == null)
                                            {
                                                string uriString = registryKey2.GetValue("BoxArt") as string;
                                                if (uriString != null)
                                                {
                                                    try
                                                    {
                                                        this.image = (ImageSource)BitmapDecoder.Create(new Uri(uriString), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Trace.TraceWarning("Image for legacy game " + this.name + "could not be loaded: " + ex.Message);
                                                    }
                                                }
                                            }
                                            this.description = registryKey2.GetValue("Description") as string;
                                            if (this.playTasks.Count == 0)
                                            {
                                                string str2 = registryKey2.GetValue("AppExePath") as string;
                                                if (str2 != null)
                                                {
                                                    this.playTasks.Add(str2);
                                                    str1 = str2;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        string name1 = this.gdfResourceID ?? "__GDF_XML";
                        byte[] bytes1 = ResourceExtensions.GetBytes(unmanagedLibrary.GetResource(name1, (object)"DATA"));
                        if (bytes1 != null)
                        {
                            XmlDocument xmlDocument = new XmlDocument();
                            xmlDocument.Load((XmlReader)new XmlTextReader((Stream)new MemoryStream(bytes1)));
                            foreach (XmlNode xmlNode in xmlDocument.DocumentElement.FirstChild.ChildNodes)
                            {
                                XmlElement xmlElement = xmlNode as XmlElement;
                                if (xmlElement != null && xmlElement.Name == "Description")
                                    this.description = xmlElement.InnerXml;
                            }
                        }
                        else
                            Trace.TraceWarning("GDF resource not found for " + this.Name + ".");
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning("Error getting GDF data for " + this.name + "could not be loaded: " + ex.Message);
                }
            }
            if (this.playTasks.Count == 0)
            {
                this.IsValid = false;
                this.InvalidReason = "Could not find a play task for " + this.name + ".";
                return;
            }
            if (this.image != null)
                return;
            string filename = (string)null;
            if (this.playTasks.Count > 0)
            {
                try
                {
                    WshShell shell = new WshShell();
                    filename = ((IWshShortcut)shell.CreateShortcut(this.playTasks[0])).TargetPath;
                }
                catch
                {

                }
            }
            if (string.IsNullOrEmpty(filename))
                filename = str1;
            if (string.IsNullOrEmpty(filename))
                return;
            this.image = Shell.GenerateThumbnail(filename);
        }
        static bool testValueExists(System.Management.ManagementClass instance, String value)
        {
            try
            {
                instance.GetPropertyValue(value);
            }
            catch (System.Management.ManagementException me)
            {
                if (me.ErrorCode.Equals(System.Management.ManagementStatus.NotFound))
                {
                    return false;
                }
                throw me;
            }
            return true;

        }