Пример #1
0
 public HmdTypeverifydevicesarenotpresent(HmdBlockID blockID, HmdProperties hmdProperties)
 {
     for (int i = 0; i < blockID.ChildCount; i++)
     {
         HmdID childID = blockID.GetChild(i);
         if (childID.isBlock)
         {
             HmdBlockID childBlockID = (HmdBlockID)childID;
             // parse field UsbDevice
             if (childBlockID.idLowerCase.Equals("usbdevice", StringComparison.CurrentCultureIgnoreCase))
             {
                 // set List to not null
                 this.UsbDevice.Add(new HmdTypeusbdevice(childBlockID, hmdProperties));
             }
             else
             {
                 throw new FormatException(String.Format("Unrecognized child block id \"{0}\"", childID.idOriginalCase));
             }
         }
         else
         {
             HmdValueID childValueID = (HmdValueID)childID;
             throw new FormatException(String.Format("Unrecognized child value id \"{0}\"", childID.idOriginalCase));
         }
     }
 }
Пример #2
0
        private void ValidateValueID(HmdValueID valueID, HmdValueIDProperties valueIDProperties, HmdProperties hmdProperties)
        {
            //
            // Check that the current parent is valid
            //
            debugOutput.Write(blockStack.Count, "Checking that \"{0}\" has \"{1}\" as a valid parent...", valueID.idOriginalCase, currentBlock.blockIDProperties.idOriginalCase);
            if (!valueIDProperties.IsValidParent(currentBlock.blockIDProperties))
            {
                throw new FormatException(String.Format("Value ID \"{0}\" appeared in Block \"{1}\", but this is not allowed with the current properties",
                                                        valueID.idOriginalCase, currentBlock.blockIDProperties.idOriginalCase));
            }
            debugOutput.WriteLine("Pass.");

            if (valueID.value != null)
            {
                debugOutput.Write(blockStack.Count, "Checking the Value Type for \"{0}\"...", valueID.idOriginalCase);
                if (!valueIDProperties.IsValidValue(valueID.value, hmdProperties))
                {
                    throw new FormatException(String.Format("Value ID \"{0}\" of type {1}, had an invalid value of \"{2}\"",
                                                            valueID.idOriginalCase, valueIDProperties.hmdType.ToHmdTypeString(), valueID.value));
                }
                debugOutput.WriteLine("Pass.");
            }


            // Add ID to current block validator
            currentBlock.NewChild(valueIDProperties);
        }
Пример #3
0
 public static void Iterate(this HmdBlockID blockID, HmdProperties hmdProperties,
                            AtValueIDWithProperties atValueIDWithProperties, AtBlockIDWithProperties atBlockIDWithProperties)
 {
     for (int i = 0; i < blockID.ChildCount; i++)
     {
         HmdID childID = blockID.GetChild(i);
         if (childID.isBlock)
         {
             HmdBlockID           childBlockID           = childID.CastAsBlockID;
             HmdBlockIDProperties childBlockIDProperties = hmdProperties.GetProperties(childBlockID);
             if (childBlockIDProperties == null)
             {
                 throw new InvalidOperationException(String.Format("Found a block id \"{0}\", but it was not defined in the property dictionary", childID.idOriginalCase));
             }
             atBlockIDWithProperties(childBlockID, childBlockIDProperties, hmdProperties);
         }
         else
         {
             HmdValueID           childValueID           = childID.CastAsValueID;
             HmdValueIDProperties childValueIDProperties = hmdProperties.GetProperties(childValueID);
             if (childValueIDProperties == null)
             {
                 throw new InvalidOperationException(String.Format("Found a value id \"{0}\", but it was not defined in the property dictionary", childID.idOriginalCase));
             }
             atValueIDWithProperties(childValueID, childValueIDProperties, hmdProperties);
         }
     }
 }
Пример #4
0
 public DefaultRootClassName(HmdBlockID blockID, HmdProperties hmdProperties)
 {
     for (int i = 0; i < blockID.ChildCount; i++)
     {
         HmdID childID = blockID.GetChild(i);
         if (childID.isBlock)
         {
             HmdBlockID childBlockID = (HmdBlockID)childID;
             // parse field VerifyDevicesArePresent
             if (childBlockID.idLowerCase.Equals("verifydevicesarepresent", StringComparison.CurrentCultureIgnoreCase))
             {
                 // set List to not null
                 this.VerifyDevicesArePresent.Add(new HmdTypeverifydevicesarepresent(childBlockID, hmdProperties));
             }
             // parse field VerifyDevicesAreNotPresent
             else if (childBlockID.idLowerCase.Equals("verifydevicesarenotpresent", StringComparison.CurrentCultureIgnoreCase))
             {
                 // set List to not null
                 this.VerifyDevicesAreNotPresent.Add(new HmdTypeverifydevicesarenotpresent(childBlockID, hmdProperties));
             }
             else
             {
                 throw new FormatException(String.Format("Unrecognized child block id \"{0}\"", childID.idOriginalCase));
             }
         }
         else
         {
             HmdValueID childValueID = (HmdValueID)childID;
             // parse field Message
             if (childValueID.idLowerCase.Equals("message", StringComparison.CurrentCultureIgnoreCase))
             {
                 this.Message.Add(childValueID.value);
             }
             // parse field UsbSwitch
             else if (childValueID.idLowerCase.Equals("usbswitch", StringComparison.CurrentCultureIgnoreCase))
             {
                 this.UsbSwitch.Add((usbswitch)Enum.Parse(typeof(usbswitch), childValueID.value, true));
             }
             // parse field Sleep
             else if (childValueID.idLowerCase.Equals("sleep", StringComparison.CurrentCultureIgnoreCase))
             {
                 this.Sleep.Add(UInt32.Parse(childValueID.value));
             }
             else
             {
                 throw new FormatException(String.Format("Unrecognized child value id \"{0}\"", childID.idOriginalCase));
             }
         }
     }
 }
Пример #5
0
        public void TestConcreteExample()
        {
            //
            // Parse Properties File
            //
            TextReader    propertiesReader = new System.IO.StringReader("%enum:ExecuteEnum Local Remote Ignore Unsupported;Script{%props:1;Source:enum(File Remote);File:0-1;ListenPort:0-1 int4;}RebootCommand {%props:1;Execute:1 enum(Ignore Unsupported Emulator);RemoteHost:0-1;RemotePort:0-1 int4;}UsbSwitchCommand {	%props:1;	Execute:1 enum ExecuteEnum;	Platform:0-1 enum(Windows Linux);	RemoteHost:0-1;	RemotePort:0-1 int4;}TestCommands {	%props:1;	Execute:1 enum ExecuteEnum;	RemoteHost:0-1;	RemotePort:0-1 int4;}");
            HmdProperties properties       = HmdFileParser.ParsePropertiesFile(propertiesReader, null);

            properties.ResolveChildParentReferences();
            properties.Print(Console.Out);


            HmdEnum hmdEnum;

            hmdEnum = properties.TryGetEnum("ExecuteEnum");
            Assert.IsNotNull(hmdEnum);
            Assert.IsTrue(hmdEnum.IsValidEnumValue("local"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("remote"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("IGNORE"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("unsupported"));

            hmdEnum = properties.TryGetEnum("script.source");
            Assert.IsNotNull(hmdEnum);
            Assert.IsTrue(hmdEnum.IsValidEnumValue("FILE"));
            Assert.IsTrue(hmdEnum.IsValidEnumValue("remote"));

            HmdBlockID fileRoot = new HmdBlockID("THE_ROOT!", null);

            HmdBlockID script = new HmdBlockID("script", fileRoot);

            Assert.IsNotNull(properties.GetProperties(script));

            HmdValueID scriptSource = new HmdValueID("source", "file", script);

            Assert.IsNotNull(properties.GetProperties(scriptSource));



            //
            // Parse Hmd File
            //
            TextReader hmdReader = new System.IO.StringReader("Script {Source:Remote;}RebootCommand {Execute:Unsupported;}UsbSwitchCommand {Execute:Unsupported;}TestCommands {Execute:Local;}");
            HmdBlockID rootID    = new HmdBlockID(String.Empty, null);

            HmdFileParser.Parse(rootID, hmdReader, "", null);


            //HmdValidator.ValidateStatic(rootID, properties);
        }
Пример #6
0
 public HmdTypeusbdevice(HmdBlockID blockID, HmdProperties hmdProperties)
 {
     for (int i = 0; i < blockID.ChildCount; i++)
     {
         HmdID childID = blockID.GetChild(i);
         if (childID.isBlock)
         {
             HmdBlockID childBlockID = (HmdBlockID)childID;
             throw new FormatException(String.Format("Unrecognized child block id \"{0}\"", childID.idOriginalCase));
         }
         else
         {
             HmdValueID childValueID = (HmdValueID)childID;
             // parse field LegacyName
             if (childValueID.idLowerCase.Equals("legacyname", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.LegacyName != null)
                 {
                     throw new FormatException("Found multiple value id's \"LegacyName\"");
                 }
                 this.LegacyName = (usbdevicelegacyname)Enum.Parse(typeof(usbdevicelegacyname), childValueID.value, true);
             }
             // parse field Protocol
             else if (childValueID.idLowerCase.Equals("protocol", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.Protocol != null)
                 {
                     throw new FormatException("Found multiple value id's \"Protocol\"");
                 }
                 this.Protocol = Byte.Parse(childValueID.value);
             }
             // parse field SubClass
             else if (childValueID.idLowerCase.Equals("subclass", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.SubClass != null)
                 {
                     throw new FormatException("Found multiple value id's \"SubClass\"");
                 }
                 this.SubClass = Byte.Parse(childValueID.value);
             }
             // parse field Class
             else if (childValueID.idLowerCase.Equals("class", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.Class != null)
                 {
                     throw new FormatException("Found multiple value id's \"Class\"");
                 }
                 this.Class = Byte.Parse(childValueID.value);
             }
             // parse field Interface
             else if (childValueID.idLowerCase.Equals("interface", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.Interface != null)
                 {
                     throw new FormatException("Found multiple value id's \"Interface\"");
                 }
                 this.Interface = Byte.Parse(childValueID.value);
             }
             // parse field SerialNumber
             else if (childValueID.idLowerCase.Equals("serialnumber", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.SerialNumber != null)
                 {
                     throw new FormatException("Found multiple value id's \"SerialNumber\"");
                 }
                 this.SerialNumber = childValueID.value;
             }
             // parse field Product
             else if (childValueID.idLowerCase.Equals("product", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.Product != null)
                 {
                     throw new FormatException("Found multiple value id's \"Product\"");
                 }
                 this.Product = childValueID.value;
             }
             // parse field Manufacturer
             else if (childValueID.idLowerCase.Equals("manufacturer", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.Manufacturer != null)
                 {
                     throw new FormatException("Found multiple value id's \"Manufacturer\"");
                 }
                 this.Manufacturer = childValueID.value;
             }
             // parse field ProductID
             else if (childValueID.idLowerCase.Equals("productid", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.ProductID != null)
                 {
                     throw new FormatException("Found multiple value id's \"ProductID\"");
                 }
                 this.ProductID = UInt16.Parse(childValueID.value);
             }
             // parse field VendorID
             else if (childValueID.idLowerCase.Equals("vendorid", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.VendorID != null)
                 {
                     throw new FormatException("Found multiple value id's \"VendorID\"");
                 }
                 this.VendorID = UInt16.Parse(childValueID.value);
             }
             // parse field Speed
             else if (childValueID.idLowerCase.Equals("speed", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.Speed != null)
                 {
                     throw new FormatException("Found multiple value id's \"Speed\"");
                 }
                 this.Speed = (usbdevicespeed)Enum.Parse(typeof(usbdevicespeed), childValueID.value, true);
             }
             // parse field PortName
             else if (childValueID.idLowerCase.Equals("portname", StringComparison.CurrentCultureIgnoreCase))
             {
                 // check that field is not set already
                 if (this.PortName != null)
                 {
                     throw new FormatException("Found multiple value id's \"PortName\"");
                 }
                 this.PortName = childValueID.value;
             }
             else
             {
                 throw new FormatException(String.Format("Unrecognized child value id \"{0}\"", childID.idOriginalCase));
             }
         }
     }
 }
Пример #7
0
 public HmdValueIDProperties GetProperties(HmdValueID valueID)
 {
     return(valueIDTable.GetProperties(valueID));
 }