Example #1
0
        void thread_Main()
        {
            irrDevice.Logger.Log(Thread.CurrentThread.Name, "Started", LogLevel.Information);

            while (true)
            {
                ThreadCommand cmd = thread_GetNextCommand();

                if (cmd == null)
                {
                    Thread.Sleep(1);
                    continue;
                }

                switch (cmd.Type)
                {
                case ThreadCommandType.Stop:
                    irrDevice.Logger.Log(Thread.CurrentThread.Name, "Finished", LogLevel.Information);
                    return;

                case ThreadCommandType.LoadTexture:
                    irrDevice.Logger.Log(Thread.CurrentThread.Name, "Loading " + (cmd.Params[1] as string) + "|" + (cmd.Params[2] as Dimension2Di), LogLevel.Information);
                    thread_LoadTexture(cmd.Params[0] as SceneNode, cmd.Params[1] as string, cmd.Params[2] as Dimension2Di);
                    break;

                case ThreadCommandType.UnloadTexture:
                    irrDevice.Logger.Log(Thread.CurrentThread.Name, "Unloading " + (cmd.Params[0] as string), LogLevel.Information);
                    thread_UnloadTexture(cmd.Params[0] as string);
                    break;
                }
            }
        }
Example #2
0
 /// <summary>
 /// Executes the command on specified thread.
 /// </summary>
 /// <param name="command">The command.</param>
 public static void ExecuteThreadCommand(ThreadCommand command)
 {
     if (command.Command == "Abort")
     {
         Abort(command.ID);
     }
 }
Example #3
0
        ThreadCommand thread_GetNextCommand()
        {
            ThreadCommand cmd = null;

            lock (threadCommands)
            {
                if (threadCommands.Count > 0)
                {
                    // We do first Peek and only then Dequeue, because we do not want Stop command to be processed only by one thread (so other will not get this command)

                    cmd = threadCommands.Peek();

                    if (cmd.Type != ThreadCommandType.Stop)
                    {
                        threadCommands.Dequeue();
                    }
                }
            }

            return(cmd);
        }
Example #4
0
        void addThreadCommand(ThreadCommandType command, bool topPriority, params object[] args)
        {
            ThreadCommand cmd = new ThreadCommand();

            cmd.Type   = command;
            cmd.Params = args;

            lock (threadCommands)
            {
                if (cmd.Type == ThreadCommandType.Stop)
                {
                    foreach (ThreadCommand c in threadCommands)
                    {
                        if (c.Type == ThreadCommandType.LoadTexture)
                        {
                            (c.Params[0] as SceneNode).Drop();
                        }
                    }

                    threadCommands.Clear();
                }

                if (topPriority && threadCommands.Count > 0)
                {
                    ThreadCommand[] a = threadCommands.ToArray();
                    threadCommands.Clear();
                    threadCommands.Enqueue(cmd);
                    for (int i = 0; i < a.Length; i++)
                    {
                        threadCommands.Enqueue(a[i]);
                    }
                }
                else
                {
                    threadCommands.Enqueue(cmd);
                }
            }
        }
Example #5
0
		void addThreadCommand(ThreadCommandType command, bool topPriority, params object[] args)
		{
			ThreadCommand cmd = new ThreadCommand();
			cmd.Type = command;
			cmd.Params = args;

			lock (threadCommands)
			{
				if (cmd.Type == ThreadCommandType.Stop)
				{
					foreach (ThreadCommand c in threadCommands)
						if (c.Type == ThreadCommandType.LoadTexture)
							(c.Params[0] as SceneNode).Drop();

					threadCommands.Clear();
				}

				if (topPriority && threadCommands.Count > 0)
				{
					ThreadCommand[] a = threadCommands.ToArray();
					threadCommands.Clear();
					threadCommands.Enqueue(cmd);
					for (int i = 0; i < a.Length; i++)
						threadCommands.Enqueue(a[i]);
				}
				else
				{
					threadCommands.Enqueue(cmd);
				}
			}
		}
Example #6
0
        private async void WebView_ScriptNotify(object sender, NotifyEventArgs e)
        {
            if (_vm.ForumThreadEntity == null)
            {
                return;
            }
            if (e == null)
            {
                return;
            }
            string        stringJson = e.Value;
            ThreadCommand command    = null;

            try
            {
                command = JsonConvert.DeserializeObject <ThreadCommand>(stringJson);
            }
            catch (Exception ex)
            {
                AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
            }
            if (command == null)
            {
                return;
            }
            switch (command.Command)
            {
            case "quote":
                Frame.Navigate(typeof(ReplyPage), command.Id);
                break;

            case "edit":
                Frame.Navigate(typeof(EditPage), command.Id);
                break;

            case "setFont":
                SetFontSize();
                break;

            case "scrollToPost":
                if (!string.IsNullOrEmpty(_vm.ForumThreadEntity.ScrollToPostString))
                {
                    try
                    {
                        await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { _vm.ForumThreadEntity.ScrollToPostString });
                    }
                    catch (Exception ex)
                    {
                        AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                    }
                }
                break;

            case "markAsLastRead":
                await _threadManager.MarkPostAsLastRead(_forumThread, Convert.ToInt32(command.Id));

                int nextPost = Convert.ToInt32(command.Id) + 1;

                try
                {
                    await ThreadWebView.InvokeScriptAsync("ScrollToDiv", new[] { string.Concat("#postId", nextPost.ToString()) });
                }
                catch (Exception ex)
                {
                    AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                    return;
                }
                var message = new MessageDialog("Post marked as last read! Now go on and live your life!")
                {
                    DefaultCommandIndex = 1
                };
                await message.ShowAsync();

                break;

            case "openThread":
                var query = Extensions.ParseQueryString(command.Id);
                if (query.ContainsKey("action") && query["action"].Equals("showPost"))
                {
                    var postManager = new PostManager();
                    try
                    {
                        var html = await postManager.GetPost(Convert.ToInt32(query["postid"]));
                    }
                    catch (Exception ex)
                    {
                        AwfulDebugger.SendMessageDialogAsync("A thread javascript command failed", ex);
                        return;
                    }
                    return;
                }
                var threadManager = new ThreadManager();
                var threadEntity  = new ForumThreadEntity();
                var thread        = await threadManager.GetThread(threadEntity, command.Id);

                if (thread == null)
                {
                    var error = new MessageDialog("Specified post was not found in the live forums.")
                    {
                        DefaultCommandIndex = 1
                    };
                    await error.ShowAsync();

                    break;
                }
                string jsonObjectString = JsonConvert.SerializeObject(threadEntity);
                Frame.Navigate(typeof(ThreadPage), jsonObjectString);
                break;

            default:
                var msgDlg = new MessageDialog("Not working yet!")
                {
                    DefaultCommandIndex = 1
                };
                await msgDlg.ShowAsync();

                break;
            }
        }