Ejemplo n.º 1
0
        /*public static (EquipmentType equip,RoomTypes room) CheckForMultiple()
         * {
         *  if (NumberOfWords == 2)
         *  {
         *      if (Splitted[0] == "and")
         *      {
         *          Splitted.RemoveAndDecrease("and");
         *          try
         *          {
         *
         *              RoomTypes second = WhichRoom(Splitted[0]);
         *
         *              EquipmentType second1 = WhatToDo(Splitted[0]);
         *
         *              if (second != RoomTypes.none || second1 != EquipmentType.none)
         *              {
         *                  return (second1, second);
         *              }
         *              else return (EquipmentType.none, RoomTypes.none);
         *
         *          }
         *          catch
         *          {
         *              return (EquipmentType.none, RoomTypes.none);
         *          }
         *      }
         *
         *  }
         *  return (EquipmentType.none, RoomTypes.none);
         * }
         */

        public static void AnalyzeRequest()
        {
            EquipmentType equipment = WhatToDo();

            RoomTypes room = WhichRoom();

            DecideType decide = StateDecide();

            //var Result = CheckForMultiple();

            DecisionMechanism.ExecuteRequest(equipment, room, decide);

            /*if (Result.equip != EquipmentType.none)
             * {
             *  equipment = Result.equip;
             *
             *  DecisionMechanism.ExecuteRequest(equipment, room, decide);
             * }
             * else if (Result.room != RoomTypes.none)
             * {
             *  room = Result.room;
             *
             *  DecisionMechanism.ExecuteRequest(equipment, room, decide);
             * }
             */
        }
Ejemplo n.º 2
0
        public static void ExecuteRequest(EquipmentType equip, RoomTypes room, DecideType decide)
        {
            switch (equip)
            {
            case EquipmentType.sleepmode:
                switch (decide)
                {
                case DecideType.On:

                    home.Door(true);

                    home.Light(false);

                    kitchen.Light(false);

                    bedroom.Light(false);

                    toilet.Light(false);

                    break;

                case DecideType.Off:

                    home.Door(false);

                    break;
                }
                break;
            }
            switch (room)
            {
            case RoomTypes.kitchen:
                switch (equip)
                {
                case EquipmentType.@lock:
                    switch (decide)
                    {
                    case DecideType.On:
                        kitchen.Door(true);
                        break;

                    case DecideType.Off:
                        kitchen.Door(false);
                        break;
                    }
                    break;

                case EquipmentType.lights:
                    switch (decide)
                    {
                    case DecideType.On:
                        kitchen.Light(true);
                        break;

                    case DecideType.Off:
                        kitchen.Light(false);
                        break;
                    }
                    break;
                }
                break;

            case RoomTypes.bedroom:
                switch (equip)
                {
                case EquipmentType.@lock:
                    switch (decide)
                    {
                    case DecideType.On:
                        bedroom.Door(true);
                        break;

                    case DecideType.Off:
                        bedroom.Door(false);
                        break;
                    }
                    break;

                case EquipmentType.lights:
                    switch (decide)
                    {
                    case DecideType.On:
                        bedroom.Light(true);
                        break;

                    case DecideType.Off:
                        bedroom.Light(false);
                        break;
                    }
                    break;
                }
                break;

            case RoomTypes.toilet:
                switch (equip)
                {
                case EquipmentType.@lock:
                    switch (decide)
                    {
                    case DecideType.On:
                        toilet.Door(true);
                        break;

                    case DecideType.Off:
                        toilet.Door(false);
                        break;
                    }
                    break;

                case EquipmentType.lights:
                    switch (decide)
                    {
                    case DecideType.On:
                        toilet.Light(true);
                        break;

                    case DecideType.Off:
                        toilet.Light(false);
                        break;
                    }
                    break;
                }
                break;

            case RoomTypes.home:
                switch (equip)
                {
                case EquipmentType.lights:
                    switch (decide)
                    {
                    case DecideType.On:

                        home.Light(true);

                        break;

                    case DecideType.Off:

                        home.Light(false);

                        break;
                    }
                    break;

                case EquipmentType.@lock:
                    switch (decide)
                    {
                    case DecideType.On:

                        home.Door(true);

                        break;

                    case DecideType.Off:

                        home.Door(false);

                        break;
                    }
                    break;
                }
                break;

            case RoomTypes.all:
                switch (equip)
                {
                case EquipmentType.lights:

                    switch (decide)
                    {
                    case DecideType.On:

                        kitchen.Light(true);

                        bedroom.Light(true);

                        toilet.Light(true);

                        home.Light(true);

                        break;

                    case DecideType.Off:

                        kitchen.Light(false);

                        bedroom.Light(false);

                        toilet.Light(false);

                        home.Light(false);

                        break;
                    }
                    break;
                }
                break;
            }
        }
Ejemplo n.º 3
0
        public void PluginTagWithDeciderTest()
        {
            // Arrange
            const TagSignature SignaturelNET = (TagSignature)0x6C4E4554;  // 'lNET'

            // ensure delegates are not garbage collected from managed code
            var decide = new DecideType(Decide);

            PluginTag tag = new PluginTag
            {
                Base = new PluginBase
                {
                    Magic           = Cms.PluginMagicNumber,
                    ExpectedVersion = (uint)Cms.EncodedCMMVersion,    // >= 2.8
                    Type            = PluginType.Tag,
                    Next            = IntPtr.Zero
                },
                Signature  = SignaturelNET,
                Descriptor = new TagDescriptor
                {
                    ElemCount       = 1,
                    nSupportedTypes = 1,
                    SupportedTypes  = new TagTypeSignature[TagDescriptor.MAX_TYPES_IN_LCMS_PLUGIN],
                    Decider         = Marshal.GetFunctionPointerForDelegate(decide)
                }
            };

            tag.Descriptor.SupportedTypes[0] = TagTypeSignature.Text;

            string expected = "PluginTagWithDeciderTest";

            // Act
            int    rawsize = Marshal.SizeOf(tag);
            IntPtr plugin  = Marshal.AllocHGlobal(rawsize);

            Marshal.StructureToPtr(tag, plugin, false);
            try
            {
                using (var context = Context.Create(plugin, IntPtr.Zero))
                    using (var profile = Profile.CreatePlaceholder(context))
                    {
                        using (var mlu = MultiLocalizedUnicode.Create(context))
                        {
                            mlu.SetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry, expected);
                            bool written = profile.WriteTag(SignaturelNET, mlu);
                            Assert.IsTrue(written);
                        }

                        using (var mlu = profile.ReadTag <MultiLocalizedUnicode>(SignaturelNET))
                        {
                            var actual = mlu.GetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry);

                            // Assert
                            Assert.AreEqual(expected, actual);
                        }
                    }
            }
            finally
            {
                Marshal.DestroyStructure(plugin, typeof(PluginTag));
                Marshal.FreeHGlobal(plugin);
            }

            TagTypeSignature Decide(double iccVersion, IntPtr data)
            {
                TestContext.WriteLine($"iccVersion: {iccVersion}, data: 0x{data:X}");

                using (var mlu = MultiLocalizedUnicode.FromHandle(data))
                {
                    var text = mlu.GetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry);
                    TestContext.WriteLine($"text: {text}");
                }

                return(TagTypeSignature.Text);
            }
        }