Example #1
0
        void InitializeCommunicator(int rpHostProcessID)
        {
            r_Communicator = new MemoryMappedFileCommunicator($"Sakuno/HeavenlyWind({rpHostProcessID})", 4096);
            r_Communicator.ReadPosition  = 0;
            r_Communicator.WritePosition = 2048;

            r_Messages = r_Communicator.GetMessageObservable().ObserveOnDispatcher().Publish();
            r_Messages.Connect();

            r_Communicator.StartReader();

            r_Messages.Subscribe(CommunicatorMessages.ClearCache, _ => r_BrowserProvider?.ClearCache(false));
            r_Messages.Subscribe(CommunicatorMessages.ClearCacheAndCookie, _ => r_BrowserProvider?.ClearCache(true));

            r_Messages.Subscribe(CommunicatorMessages.GoBack, _ => r_Browser?.GoBack());
            r_Messages.Subscribe(CommunicatorMessages.GoForward, _ => r_Browser?.GoForward());
            r_Messages.Subscribe(CommunicatorMessages.Navigate, rpUrl => r_Browser?.Navigate(rpUrl));
            r_Messages.Subscribe(CommunicatorMessages.Refresh, _ => r_Browser?.Refresh());

            r_Messages.Subscribe(CommunicatorMessages.SetZoom, r =>
            {
                r_Zoom = double.Parse(r);
                r_Browser?.SetZoom(r_Zoom);
                r_Communicator.Write(CommunicatorMessages.InvalidateArrange);
            });

            r_Messages.Subscribe(CommunicatorMessages.ResizeBrowserToFitGame, _ =>
            {
                r_Container.Width  = GameConstants.GameWidth * r_Zoom / DpiUtil.ScaleX / DpiUtil.ScaleX;
                r_Container.Height = GameConstants.GameHeight * r_Zoom / DpiUtil.ScaleY / DpiUtil.ScaleY;
                r_Communicator.Write(CommunicatorMessages.InvalidateArrange);
            });

            InitializeScreenshotMessagesSubscription();
        }
		private Task BrowserInitialize(IBrowser browser, string icn, CancellationToken ct)
		{
			return Task.Run(async () =>
			{
				await browser.Navigate(ModuleConfiguration.Url, ct);
				do
				{
					var isJquery = (bool)await browser.ExecuteJs("return jQuery != null", ct);
					if (isJquery)
						break;

					await browser.Refresh(ct);
				} while (true);

				await browser.ExecuteJs(
					"window.fragma=window.fragma||{},fragma.modules=fragma.modules||{},void 0===fragma.modules.cities&&(fragma.modules.cities=new function(){var e=this,t=function(e,t,i,n,r){i.hide(),t.val(e),t.keydown();var a=[],o=function(){return i.is(':visible')?$.each(i.find('a'),function(e,t){var i=$(t);a.push(i.html())}):t.val()!=e&&a.push(t.val()),a.length>0?(n.waitHandler=null,void r(a)):void(n.waitHandler=setTimeout(o,100))};n.waitHandler=setTimeout(o,30)};e.senderContext={cities:[],waitHandler:null},e.receiverContext={cities:[],waitHandler:null},e.getSenderCity=function(i){e.senderContext.cities=[],e.senderContext.waitHandler&&(clearTimeout(e.senderContext.waitHandler),e.senderContext.waitHandler=null);var n=$('input[name=\"from_ship\"]'),r=$($('ul.ui-autocomplete')[0]);t(i,n,r,e.senderContext,function(t){e.senderContext.cities=t})},e.getReceiverCity=function(i){e.receiverContext.cities=[],e.receiverContext.waitHandler&&(clearTimeout(e.receiverContext.waitHandler),e.receiverContext.waitHandler=null);var n=$('input[name=\"to_send\"]'),r=$($('ul.ui-autocomplete')[1]);return t(i,n,r,e.receiverContext,function(t){e.receiverContext.cities=t})}});",
					ct);

				await browser.ExecuteJs(
					"window.fragma=window.fragma||{},fragma.modules=fragma.modules||{},void 0===fragma.modules.tariffs&&(fragma.modules.tariffs=new function(){var a=this;a.getTariffs=function(){for(var a=[],n=$('.style_table').find('tr'),r=1;r<n.length;++r){var f=$(n[r]);$columns=f.find('td');var s=$columns[0].innerHTML,m=$($columns[1]).find('b').html(),i=$columns[2].innerHTML;a.push(s),a.push(m),a.push(i)}return a}});",
					ct);

				if (!await browser.Select("input[name='login']", ct))
					throw new InvalidOperationException("Can't find login input");
				await browser.Input(ModuleConfiguration.Login, ct);

				if (!await browser.Select("input[name=pass]", ct))
					throw new InvalidOperationException("Can't find password input");
				await browser.Input(ModuleConfiguration.Password, ct);

				if (!await browser.WaitForAjax(5000, ct))
					throw new TimeoutException("Failed to wait for icn input to show");

				//await WaitFor("Failed to wait for icn input to show", 20, () =>
				//{
				//    return _browser.IsElementVisible("div#loginform input[name=icn]", ct);
				//}, ct);

				if (!await browser.Select("input[name=icn]", ct))
					throw new InvalidOperationException("Can't find icn input");
				await browser.Input(icn, ct);
				await browser.Select("#submit", ct);

				if (!await browser.WaitForAjax(10000, ct))
					throw new TimeoutException("Login operation proceeded too long");
			}, ct);
		}
Example #3
0
        private void _RunCommand(string cmd)
        {
            string vimpath      = @"C:\Program Files (x86)\Vim\vim73\gvim.exe";
            string explorerpath = @"C:\Windows\explorer.exe";
            string daemonpath   = @"C:\Program Files (x86)\DAEMON Tools Lite\DTLite.exe";

            switch (cmd)
            {
            case "edit this":
            {
                FileInfo     file = new FileInfo(vimpath);
                IBrowserItem item = getComponent <IBrowser>().Cursor;
                Win32.SHExecute(file, "\"" + item.FullPath + "\"", false);
                return;
            }

            case "sudo edit this":
            {
                FileInfo     file = new FileInfo(vimpath);
                IBrowserItem item = getComponent <IBrowser>().Cursor;
                Win32.SHExecute(file, "\"" + item.FullPath + "\"", true);
                return;
            }

            case "explore here":
            {
                FileInfo      file = new FileInfo(explorerpath);
                DirectoryInfo dir  = getComponent <IBrowser>().CurrentDir;

                Win32.SHExecute(file, dir.FullName, false);
                return;
            }

            case "select this":
            {
                IBrowser browser = getComponent <IBrowser>();
                browser.MarkItem(browser.Cursor);
                return;
            }

            case "select all":
            {
                IBrowser            browser = getComponent <IBrowser>();
                List <IBrowserItem> items   = browser.Items;
                Selection           sel     = browser.Selection;
                foreach (IBrowserItem item in items)
                {
                    sel.addItem(item);
                }
                return;
            }

            case "alt-u":
            {
                IBrowser browser = getComponent <IBrowser>();
                if (browser.Selection.Count > 0)
                {
                    browser.Selection.clear();
                }
                else
                {
                    RunCommand("select all");
                }
                return;
            }

            case "refresh":
            {
                getComponent <IBrowser>().Refresh();
                return;
            }

            case "delete silent":
            {
                DeleteFiles(true);
                return;
            }

            case "delete":
            {
                DeleteFiles(false);
                return;
            }

            case "mount this":
            {
                FileInfo     file = new FileInfo(daemonpath);
                IBrowserItem item = getComponent <IBrowser>().Cursor;
                Win32.SHExecute(file, "-mount 0," + item.FullPath, false);
                return;
            }

            case "!cmd":
            case "!":
            case "cmd":
            {
                Win32.SHExecute("cmd", "", false);
                return;
            }

            case "paste":
            {
                Paste();
                return;
            }

            case "cut selected":
            {
                SetDropFileList(true);
                return;
            }

            case "copy selected":
            {
                SetDropFileList(false);
                return;
            }

            case "goroot":
            {
                getComponent <IBrowser>().CurrentDir = getComponent <IBrowser>().CurrentDir.Root;
                return;
            }

            case "test":
            {
                var temp = UINotify;
                if (temp != null)
                {
                    temp(this, new Notification.NotifyArgs("Asdfnews"));
                }
                return;
            }

            case "gc":
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                return;
            }

            case "set":     // FIXME: temporary
            {
                getComponent <Components.Config.IConfig>()["Font"] = "FixedSys, 12pt";
                return;
            }

            default:
            {
                if (cmd.StartsWith("notify ", true, null))
                {
                    string msg = cmd.Substring(7);
                    throw new Exception(msg);
                }
                if (cmd.StartsWith("mkdir ", true, null))
                {
                    string dirName = cmd.Substring(6);
                    Directory.CreateDirectory(getComponent <IBrowser>().CurrentDir.FullName + "\\" + dirName);
                    getComponent <IBrowser>().Refresh();
                    return;
                }
                if (cmd.StartsWith("cd ", true, null))
                {
                    getComponent <IBrowser>().CurrentDir = new DirectoryInfo(cmd.Substring(3));
                    return;
                }
                if (cmd.StartsWith("open ", true, null))
                {
                    getComponent <IBrowser>().CurrentDir = new DirectoryInfo(cmd.Substring(5));
                    return;
                }
                if (cmd.StartsWith("select ", true, null))
                {
                    IBrowser     browser = getComponent <IBrowser>();
                    string       tmp     = cmd.Substring(7);
                    IBrowserItem selItem;
                    selItem = browser.Items.Find(delegate(IBrowserItem item)
                        {
                            return(item.showName == tmp);
                        });
                    if (selItem == null)
                    {
                        throw new FileNotFoundException();
                    }
                    browser.Selection.addItem(selItem);
                    return;
                }
                if (cmd.StartsWith("rename ", true, null))
                {
                    string   newFilename = cmd.Substring(7);
                    IBrowser browser     = getComponent <IBrowser>();
                    browser.Cursor.accept(new RenameVisitor(this, newFilename));
                    browser.Refresh();
                    return;
                }
                if (cmd.StartsWith("save"))
                {
                    string vv = cmd.Substring(4);
                    getComponent <Components.Config.IConfig>()["Bookmark" + vv] = getComponent <IBrowser>().CurrentDir.FullName;
                    return;
                }
                if (cmd.StartsWith("load"))
                {
                    string vv = cmd.Substring(4);
                    getComponent <IBrowser>().CurrentDir = new DirectoryInfo(getComponent <Components.Config.IConfig>()["Bookmark" + vv]);
                    return;
                }
                if (cmd.StartsWith("new "))
                {
                    string vv = cmd.Substring(4);
                    File.Create(getComponent <IBrowser>().CurrentDir.FullName + "\\" + vv).Close();
                    getComponent <IBrowser>().Refresh();
                    return;
                }
                throw new NotImplementedException("Operation " + cmd + " is not implemented");
            }
            }
        }