Exemplo n.º 1
0
        public void TestRapidAddRemoveIterateAcrossThreads()
        {
            // Start with a bunch of behaviors already collected, to work with.
            for (int i = 0; i < 100; i++)
            {
                behaviorManager.Add(new SimpleTestBehavior());
            }

            // Prepare stress threads to determine if BehaviorManager is safe from simultaneous add/remove/iterate attempts.
            DateTime endTime      = DateTime.Now.AddMilliseconds(100);
            Action   addAction    = () => behaviorManager.Add(new SimpleTestBehavior());
            Action   removeAction = () =>
            {
                var toRemove = behaviorManager.FindFirst <SimpleTestBehavior>();
                if (toRemove != null)
                {
                    behaviorManager.Remove(toRemove);
                }
            };
            Action iterateAction = () =>
            {
                foreach (var behavior in behaviorManager.AllBehaviors)
                {
                    // Do nothing; just iterate.
                }
            };
            Action typedAction = () =>
            {
                foreach (var behavior in behaviorManager.OfType <SimpleTestBehavior>())
                {
                    // Do nothing; just iterate.
                }
            };
            var addThread     = new BackgroundStressTestThread(endTime, addAction);
            var removeThread  = new BackgroundStressTestThread(endTime, removeAction);
            var iterateThread = new BackgroundStressTestThread(endTime, iterateAction);
            var typedThread   = new BackgroundStressTestThread(endTime, typedAction);

            addThread.Join();
            removeThread.Join();
            iterateThread.Join();
            typedThread.Join();
            Assert.IsNull(addThread.Exception, "Add: " + addThread.ExceptionTestMessage);
            Assert.IsNull(removeThread.Exception, "Remove: " + removeThread.ExceptionTestMessage);
            Assert.IsNull(iterateThread.Exception, "Iterate: " + iterateThread.ExceptionTestMessage);
            Assert.IsNull(typedThread.Exception, "OfType: " + typedThread.ExceptionTestMessage);
        }
        public void BehaviorManager_MultipleWorflows()
        {
            using (Sequence.Create())
            {
                //setup
                var             b1          = new Mock <IBehavior>();
                var             w1          = new Mock <IWorkflowB1>();
                var             w1_same     = new Mock <IWorkflowB1>();
                var             w2          = new Mock <IWorkflowB2>();
                var             w3          = new Mock <IWorkflowB3>();
                WorkflowManager w1_end      = null;
                WorkflowManager w1_same_end = null;
                WorkflowManager w3_end      = null;
                b1.Setup(i => i.Enable(It.IsAny <Arm>())).InSequence();
                w1.Setup(i => i.Enable(It.IsAny <Arm>())).InSequence();
                w1.Setup(i => i.StartWorkflow(It.IsAny <WorkflowManager>())).Callback((WorkflowManager i) => w1_end = i);
                w1.Setup(i => i.Disable()).InSequence();
                w1.Setup(i => i.StopWorkflow()).InSequence();
                w1_same.Setup(i => i.Enable(It.IsAny <Arm>())).InSequence();
                w1_same.Setup(i => i.StartWorkflow(It.IsAny <WorkflowManager>())).Callback((WorkflowManager i) => w1_same_end = i);
                w2.Setup(i => i.Enable(It.IsAny <Arm>())).InSequence();
                w3.Setup(i => i.Enable(It.IsAny <Arm>())).InSequence();
                w2.Setup(i => i.Disable()).InSequence();
                w1_same.Setup(i => i.Disable()).InSequence();
                w1_same.Setup(i => i.StopWorkflow()).InSequence();
                w3.Setup(i => i.StartWorkflow(It.IsAny <WorkflowManager>())).Callback((WorkflowManager i) => w3_end = i);
                b1.Setup(i => i.Disable()).InSequence();
                w3.Setup(i => i.Disable()).InSequence();
                w3.Setup(i => i.StopWorkflow()).InSequence();
                //never called
                w2.Setup(i => i.StartWorkflow(It.IsAny <WorkflowManager>())).InSequence(Times.Never());
                w2.Setup(i => i.StopWorkflow()).InSequence(Times.Never());

                //test
                var behaviors = new BehaviorManager(null);
                behaviors.Add(b1.Object);
                behaviors.Add(w1.Object);
                behaviors.Add(w1_same.Object);
                behaviors.Add(w2.Object);
                behaviors.Add(w3.Object);
                behaviors.Remove(w2.Object);
                w1_same_end.EndWorkflow();
                behaviors.Remove(b1.Object);
                behaviors.Remove(w3.Object);
            }
        }
        public void BehaviorManager_MultipleBehavior()
        {
            using (Sequence.Create())
            {
                //setup
                var b1 = new Mock <IBehavior>();
                var b2 = new Mock <IBehavior2>();
                b1.Setup(i => i.Enable(It.IsAny <Arm>())).InSequence();
                b2.Setup(i => i.Enable(It.IsAny <Arm>())).InSequence();
                b1.Setup(i => i.Disable()).InSequence();
                b2.Setup(i => i.Disable()).InSequence();

                //test
                var behaviors = new BehaviorManager(null);
                behaviors.Add(b1.Object);
                behaviors.Add(b2.Object);
                behaviors.Remove(b1.Object);
                behaviors.Remove(b2.Object);
            }
        }
Exemplo n.º 4
0
        public Thing(params Behavior[] behaviors)
        {
            Children        = new List <Thing>();
            BehaviorManager = new BehaviorManager(this);

            Name        = string.Empty;
            Description = string.Empty;

            if (behaviors != null)
            {
                foreach (Behavior behavior in behaviors)
                {
                    BehaviorManager.Add(behavior);
                }
            }
        }
Exemplo n.º 5
0
        public void Launcher_Load(object sender, EventArgs e)
        {
            prevState  = new WiimoteState();
            m_vkcodes  = new VKCodes();
            m_profiles = new List <Profile>();

            // Behavior
            m_bMgr = new BehaviorManager();
            m_bMgr.Add(new StandardBehavior());
            m_bMgr.Add(new MinecraftBehavior());

            // Profileフォルダの読み込み
            if (!Directory.Exists("./Profile/"))
            {
                // Defaultプロファイルの作成
                Directory.CreateDirectory("./Profile/");
                var defaultProfile = new Profile();
                defaultProfile.Name              = "Default";
                defaultProfile.Behavior          = (new StandardBehavior()).GetName();
                defaultProfile.ActionAssignments = new Dictionary <WiimoteModel, List <ActionAttribute> >();
                defaultProfile.Save("./Profile/default.json");
            }

            LoadProfiles();

            // フォルダ内JSON変更の検知
            m_fileSystemWatcher.Path   = "./Profile";
            m_fileSystemWatcher.Filter = "*.json";
            m_fileSystemWatcher.SynchronizingObject = this;
            m_fileSystemWatcher.NotifyFilter        = NotifyFilters.LastAccess;
            m_fileSystemWatcher.Changed            += m_fileSystemWatcher_Changed;
            // m_fileSystemWatcher.EnableRaisingEvents = true; //監視を開始

            m_wm = new Wiimote();

            try
            {
                // 接続
                m_wm.WiimoteChanged          += (s, args) => UpdateState(args);
                m_wm.WiimoteExtensionChanged += (s, args) => UpdateExtension(args);
                m_wm.Connect();
                m_wm.SetReportType(InputReport.IRExtensionAccel, true);

                // LED
                m_wm.SetLEDs(true, false, false, false);

                // 振動
                Task.Run(() =>
                {
                    m_wm.SetRumble(true);
                    Thread.Sleep(200);
                    m_wm.SetRumble(false);
                });

                // デバッグ情報
                m_debugInfo         = new DebugInfo();
                m_debugInfo.OnHiden = () =>
                {
                    MenuItem_debugInfo.Checked = false;
                };
#if DEBUG
                m_debugInfo.Show();
                MenuItem_debugInfo.Checked = true;
#endif
            }
            catch (Exception ex)
            {
                string msg;

                switch (ex)
                {
                case WiimoteNotFoundException _:
                    msg = "Wiiリモコンを認識できませんでした.\n\n1. Bluetoothが有効になっているか,\n2. Wiiリモコンに電池が入っているか,\n3. LEDが点滅して接続待機状態になっているかどうか\n等を確認してください.";
                    break;

                case WiimoteException _:
                    msg = "Wiiリモコンに何らかのエラーが発生しました.";
                    break;

                default:
                    msg = "予期せぬエラーが発生しました.";
                    break;
                }

                MessageBox.Show(
                    msg,
                    "エラー",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
#if !DEBUG
                Environment.Exit(1);
#endif
            }
        }
Exemplo n.º 6
0
        public void Profiler_Load(object sender, EventArgs e)
        {
            m_vkcodes  = new VKCodes();
            m_profiles = new List <Profile>();

            // ModelRect
            m_dic_buttonRect = new Dictionary <WiimoteModel, Rectangle>();
            ReadRectsFromCsv(csv: Properties.Resources.modelRect);

            // Behavior
            m_bMgr = new BehaviorManager();
            m_bMgr.Add(new StandardBehavior());
            m_bMgr.Add(new MinecraftBehavior());

            m_dic_mouseAction = new Dictionary <string, MouseAction>
            {
                { "マウスのXを相対移動", MouseAction.MoveDx },
                { "マウスのYを相対移動", MouseAction.MoveDy },
                { "マウスのXを指定", MouseAction.MoveX },
                { "マウスのYを指定", MouseAction.MoveY },
                { "マウスのホイールを回転", MouseAction.ScrollWheel },
                { "マウスの左クリック", MouseAction.LeftClick },
                { "マウスの右クリック", MouseAction.RightClick },
                { "マウスの中クリック", MouseAction.MiddleClick }
            };

            // 装飾キーを追加
            m_dic_modKeys = new Dictionary <string, byte>
            {
                { "Shift", m_vkcodes["Shift"] },
                { "Ctrl", m_vkcodes["Ctrl"] },
                { "Alt", m_vkcodes["Alt"] },
                { "Win", m_vkcodes["LWin"] }
            };

            #region UIの初期化
            // RadioButton
            radioBtn_none.Checked    = true;
            radioBtn_JoyNone.Checked = true;

            // 設定Panel
            panel_setKeyMouse.Visible = true;
            panel_setJoystick.Visible = false;

            // Behavior
            combo_behavior.Items.AddRange(m_bMgr.GetBehaviorNames().ToArray());
            combo_behavior.SelectedIndex = 0;

            // キーボード
            combo_key.Items.AddRange(m_vkcodes.GetKeys().ToArray());

            // マウス
            combo_mouse.Items.AddRange(m_dic_mouseAction.Keys.ToArray());

            // 装飾キー
            combo_modKey.Items.AddRange(m_dic_modKeys.Keys.ToArray());

            #endregion

            LoadProfiles();

            // 詳細タブ
            listBox_models.Items.AddRange(Enum.GetNames(typeof(WiimoteModel)).Where(x => x != "_N_STICK").ToArray());
            listBox_models.SelectedIndex = 0;
        }