public static AppVar Initialize(WindowsAppFriend app)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            string key = typeof(WindowControl).Module.Name + "[Initialize]";
            object ohterSystemAnalyzersObj;
            if (!app.TryGetAppControlInfo(key, out ohterSystemAnalyzersObj))
            {
                //自身のアセンブリをロードさせる。
                WindowsAppExpander.LoadAssembly(app, typeof(TargetAppInitializer).Assembly);

                //WpfAnalyzerをコンパイルしてインストール
                AppVar ohterSystemAnalyzers = null;
                try
                {
                    app["System.Windows.Application.Current"]()["Windows"]()["Count"]()["ToString"](); //ここでWPFのライブラリがロードできるかチェックする。
                    if ((bool)app[typeof(TargetAppInitializer), "InstallWpfInApp"]().Core)
                    {
                        AppVar wpfAnalyzer = app.Dim(new NewInfo("Codeer.Friendly.Windows.Wpf.Grasp.WpfAnalyzer"));
                        ohterSystemAnalyzers = app.Dim(new IOtherSystemWindowAnalyzer[1]);
                        ohterSystemAnalyzers["[]"](0, wpfAnalyzer);
                    }
                }
                catch { }
                if (ohterSystemAnalyzers == null)
                {
                    ohterSystemAnalyzers = app.Dim(new IOtherSystemWindowAnalyzer[0]);
                }
                app.AddAppControlInfo(key, ohterSystemAnalyzers);
                ohterSystemAnalyzersObj = ohterSystemAnalyzers;
            }
            return ohterSystemAnalyzersObj as AppVar;
        }
예제 #2
0
        public void TestValid()
        {
            //正しく使用することができた
            AppVar v = app.Dim(new NewInfo <DimTargetPublic>(null), new OperationTypeInfo(typeof(DimTargetPublic).FullName, typeof(Control).FullName));

            Assert.AreEqual(((DimTargetPublic)v.Core).IntValue, 10);
        }
예제 #3
0
        /// <summary>
        /// AppVarを宣言
        /// 宣言する元はこの関数内で接続する
        /// これでも、WindowsAppFriendがGCで消されないことを証明したい
        /// </summary>
        /// <param name="process">プロセス</param>
        /// <returns>AppVar</returns>
        private static AppVar DimAppVar(Process process)
        {
            WindowsAppFriend appCpuTest = new WindowsAppFriend(process, "2.0");
            AppVar           list       = appCpuTest.Dim(new List <int>());

            return(list);
        }
예제 #4
0
        public void TestButtonClick()
        {
            app.LoadAssembly(GetType().Assembly);
            app.LoadAssembly(typeof(Cell).Assembly);
            app.LoadAssembly(typeof(WindowControl).Assembly);
            app.LoadAssembly(typeof(FormsControlBase).Assembly);
            var    cell = app.Dim(new Cell());
            string t    = (string)cell["GetType"]()["Assembly"]()["ToString"]().Core;

            app[GetType(), "AAA"]();

            FormsButton button = new FormsButton(testDlg["button"]());

            button.EmulateClick();
            int count = (int)testDlg["async_counter"]().Core;

            Assert.AreEqual(1, count);

            //非同期
            app[GetType(), "ClickEvent"](button.AppVar);
            button.EmulateClick(new Async());
            new NativeMessageBox(testDlg.WaitForNextModal()).EmulateButtonClick("OK");
            count = (int)testDlg["async_counter"]().Core;
            Assert.AreEqual(2, count);
        }
예제 #5
0
        /// <summary>
        /// Wait for the timer message to be executed inside the target application.
        /// </summary>
        /// <param name="app">WindowsAppFriend.</param>
        public static void WaitForTimerMessage(WindowsAppFriend app)
        {
            var waiter = app.Dim(new NewInfo <TimerMessageWaiter>());

            while (!(bool)waiter["Arrived"]().Core)
            {
                System.Threading.Thread.Sleep(0);
            }
        }
 public void TestDoubleAppFriendAccessException()
 {
     //ウィンドウハンドルからWindowsAppFriendを生成
     using (WindowsAppFriend app2 = new WindowsAppFriend(Process.GetProcessById(app.ProcessId).MainWindowHandle, "2.0"))
     {
         AppVar vInApp  = app.Dim(3);
         AppVar vInApp2 = app2.Dim(3);
         try
         {
             vInApp["Equals"](vInApp2);
             Assert.IsTrue(false);
         }
         catch (FriendlyOperationException e)
         {
             Assert.AreEqual(e.Message, "第1引数が不正です。" + Environment.NewLine +
                             "引数に使用されたAppVarの中に、異なるAppFriendの管理する変数プールに属するAppVarがあります。");
         }
     }
 }
예제 #7
0
 public void Test()
 {
     //publicメンバ
     {
         AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
         v["_publicIntValue"](1);
         Assert.AreEqual((int)v["_publicIntValue"]().Core, 1);
     }
     //privateメンバ
     {
         AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
         v["_privateIntValue"](2);
         Assert.AreEqual((int)v["ChildIntValue"]().Core, 2);
         Assert.AreEqual((int)v["ParentIntValue"]().Core, 0);
     }
     //privateメンバで隠された親メンバ
     {
         AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
         v["_privateIntValue", new OperationTypeInfo(typeof(OperationTestClassBasePublic).FullName, typeof(int).FullName)](3);
         Assert.AreEqual((int)v["ChildIntValue"]().Core, 0);
         Assert.AreEqual((int)v["ParentIntValue"]().Core, 3);
     }
 }
 public void TestDoubleAppFriendAccessException()
 {
     //ウィンドウハンドルからWindowsAppFriendを生成
     using (WindowsAppFriend app2 = new WindowsAppFriend(Process.GetProcessById(app.ProcessId).MainWindowHandle, "2.0"))
     {
         AppVar vInApp = app.Dim(3);
         AppVar vInApp2 = app2.Dim(3);
         try
         {
             vInApp["Equals"](vInApp2);
             Assert.IsTrue(false);
         }
         catch (FriendlyOperationException e)
         {
             Assert.AreEqual(e.Message, "第1引数が不正です。" + Environment.NewLine +
                 "引数に使用されたAppVarの中に、異なるAppFriendの管理する変数プールに属するAppVarがあります。");
         }
     }
 }
 /// <summary>
 /// AppVarを宣言
 /// 宣言する元はこの関数内で接続する
 /// これでも、WindowsAppFriendがGCで消されないことを証明したい
 /// </summary>
 /// <param name="process">プロセス</param>
 /// <returns>AppVar</returns>
 private static AppVar DimAppVar(Process process)
 {
     WindowsAppFriend appCpuTest = new WindowsAppFriend(process, "2.0");
     AppVar list = appCpuTest.Dim(new List<int>());
     return list;
 }
예제 #10
0
        public void TestGetItem()
        {
            //publicメンバ
            {
                AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
                v["[]"](1, 1);
                Assert.AreEqual((int)v["[]"](1).Core, 1);
            }
            //privateメンバ
            {
                AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
                v["[]"](2, 2);
                Assert.AreEqual((int)v["[]"](2).Core, 2);
            }
            //privateメンバでnewによって隠された親メンバ
            {
                AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
                v["[]"](2, 2);
                v["[]", new OperationTypeInfo(typeof(OperationTestClassBasePublic).FullName, typeof(int).FullName, typeof(int).FullName)](3, 3);
                Assert.AreEqual((int)v["[]"](2).Core, 2);
                Assert.AreEqual((int)v["[]", new OperationTypeInfo(typeof(OperationTestClassBasePublic).FullName, typeof(int).FullName)](3).Core, 3);
            }
            //インデックスが2つあるget_Item
            {
                AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
                v["[,]"]("3", 2, 6);
                Assert.AreEqual((int)v["[,]"]("3", 2).Core, 6);
            }

            //get_Item, set_Itemでもアクセス
            {
                AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
                v["set_Item"]("3", 2, 6);
                Assert.AreEqual((int)v["get_Item"]("3", 2).Core, 6);
            }

            //ボタンとフォームで切り替え
            {
                AppVar button = app.Dim(new NewInfo <Button>());
                AppVar form   = app.Dim(new NewInfo <Form>());
                AppVar v      = app.Dim(new NewInfo <OperationTestClassPublic>());
                v["[]"](button, 2);
                v["[]"](form, 3);
                Assert.AreEqual((int)v["[]"](button).Core, 2);
                Assert.AreEqual((int)v["[]"](form).Core, 3);
            }

            //引数を型情報で解決
            {
                AppVar v = app.Dim(new NewInfo <OperationTestClassPublic>());
                v["[]", new OperationTypeInfo(typeof(OperationTestClassPublic).FullName, typeof(Button).FullName, typeof(int).FullName)](null, 2);
                v["[]", new OperationTypeInfo(typeof(OperationTestClassPublic).FullName, typeof(Form).FullName, typeof(int).FullName)](null, 3);
                Assert.AreEqual((int)v["[]", new OperationTypeInfo(typeof(OperationTestClassPublic).FullName, typeof(Button).FullName)](null).Core, 2);
                Assert.AreEqual((int)v["[]", new OperationTypeInfo(typeof(OperationTestClassPublic).FullName, typeof(Form).FullName)](null).Core, 3);
            }
        }
예제 #11
0
        public void TestConstructor()
        {
            //普通に呼び出すとintの方が採用される
            {
                AppVar v = app.Dim(new NewInfo <ObjectArgsTarget>(1, 2));
                Assert.IsFalse((bool)v["_constructorObjArray"]().Core);
                Assert.IsTrue((bool)v["_constructorInt"]().Core);
                Assert.IsFalse((bool)v["_constructorObj"]().Core);
            }
            {
                AppVar v = app.Dim(new NewInfo <ObjectArgsTarget>(new object[] { 1, 2 }));
                Assert.IsFalse((bool)v["_constructorObjArray"]().Core);
                Assert.IsTrue((bool)v["_constructorInt"]().Core);
                Assert.IsFalse((bool)v["_constructorObj"]().Core);
            }

            //見つからない
            {
                try
                {
                    AppVar v = app.Dim(new NewInfo <ObjectArgsTarget>(new object[] { 1, 2, 3 }));
                    Assert.Fail();
                }
                catch (FriendlyOperationException e)
                {
                    Assert.AreEqual("[new ObjectArgsTarget(Int32, Int32, Int32)]" + Environment.NewLine +
                                    "コンストラクタが見つかりませんでした。" + Environment.NewLine +
                                    "引数指定が間違っている可能性があります。" + Environment.NewLine +
                                    "params付きの配列の場合は、その型の配列に格納して渡してください。" + Environment.NewLine +
                                    "また、object[] の場合 params object[]と区別がつかず、分解されて引数に渡されます。" + Environment.NewLine +
                                    "そのため、object[]の要素にobject[]を入れて引き渡してください。" + Environment.NewLine +
                                    "object[] arg;//引き渡したいobject[]" + Environment.NewLine +
                                    "object[] tmpArg = new object[0];" + Environment.NewLine +
                                    "tmpArg[0] = arg;//これを引き渡してください。", e.Message);
                }
            }

            //new object[]で再度ラップしたら呼び出し可能
            {
                AppVar v = app.Dim(new NewInfo <ObjectArgsTarget>(new object[] { new object[] { 1, 2 } }));
                Assert.IsTrue((bool)v["_constructorObjArray"]().Core);
                Assert.IsFalse((bool)v["_constructorInt"]().Core);
                Assert.IsFalse((bool)v["_constructorObj"]().Core);
            }

            //型指定で呼び出した場合はマッチする
            {
                AppVar v = app.Dim(new NewInfo <ObjectArgsTarget>(null), new OperationTypeInfo(typeof(ObjectArgsTarget).ToString(), typeof(object[]).ToString()));
                Assert.IsTrue((bool)v["_constructorObjArray"]().Core);
                Assert.IsFalse((bool)v["_constructorInt"]().Core);
                Assert.IsFalse((bool)v["_constructorObj"]().Core);
            }
            {
                AppVar v = app.Dim(new NewInfo <ObjectArgsTarget>(null), new OperationTypeInfo(typeof(ObjectArgsTarget).ToString(), typeof(object).ToString()));
                Assert.IsFalse((bool)v["_constructorObjArray"]().Core);
                Assert.IsFalse((bool)v["_constructorInt"]().Core);
                Assert.IsTrue((bool)v["_constructorObj"]().Core);
            }

            //指定に合わないのでエラー
            {
                try
                {
                    AppVar v = app.Dim(new NewInfo <ObjectArgsTarget>(new object[] { 1, 2 }), new OperationTypeInfo(typeof(ObjectArgsTarget).ToString(), typeof(object[]).ToString()));
                }
                catch (FriendlyOperationException e)
                {
                    Assert.AreEqual("[OperationTypeInfo.Arguments : (Object[])][引数 : (Int32, Int32)]" + Environment.NewLine +
                                    "操作型情報の引数指定が不正です。実際に引き渡している引数の数と型指定の数が一致しません。" + Environment.NewLine +
                                    "params付きの配列の場合は、その型の配列に格納して渡してください。" + Environment.NewLine +
                                    "また、object[] の場合 params object[]と区別がつかず、分解されて引数に渡されます。" + Environment.NewLine +
                                    "そのため、object[]の要素にobject[]を入れて引き渡してください。" + Environment.NewLine +
                                    "object[] arg;//引き渡したいobject[]" + Environment.NewLine +
                                    "object[] tmpArg = new object[0];" + Environment.NewLine +
                                    "tmpArg[0] = arg;//これを引き渡してください。", e.Message);
                }
            }
        }
예제 #12
0
 public void TestDimPublic()
 {
     //生成 デフォルトコンストラクタ
     {
         AppVar v = app.Dim(new NewInfo <DimTargetPublic>());
         Assert.AreEqual(((DimTargetPublic)v.Core).IntValue, 0);
     }
     //生成 引数付コンストラクタ
     {
         AppVar v = app.Dim(new NewInfo <DimTargetPublic>(1));
         Assert.AreEqual(((DimTargetPublic)v.Core).IntValue, 1);
     }
     //初期値代入
     {
         AppVar v = app.Dim(new DimTargetPublic(2));
         Assert.AreEqual(((DimTargetPublic)v.Core).IntValue, 2);
     }
 }