Exemplo n.º 1
0
 private void Browser_ObserveHttpModifyRequest(object sender, GeckoObserveHttpModifyRequestEventArgs e)
 {
     if (e.Uri.AbsoluteUri.Contains(Utils.Constants.SEARCH_RESPONSE_ENDPOINT))
     {
         foreach (KeyValuePair <string, string> header in e.RequestHeaders)
         {
             if (header.Key.Equals("Cookie"))
             {
                 this.lastCookie = header.Value;
             }
             else if (header.Key.Equals("User-Agent"))
             {
                 this.userAgent = header.Value;
             }
         }
     }
 }
Exemplo n.º 2
0
        private void UpdateUser(GeckoObserveHttpModifyRequestEventArgs e)
        {
            var parsedQuery = HttpUtility.ParseQueryString(e.Uri.Query);
            var user        = parsedQuery["user"];
            var project     = parsedQuery["project"];
            var avatarUri   = parsedQuery["avatarUri"];
            var name        = parsedQuery["name"];
            var uilang      = parsedQuery["uilang"];
            var font        = parsedQuery["font"];
            var fontsize    = parsedQuery["fontsize"];
            var playpause   = parsedQuery["playpause"];
            var back        = parsedQuery["back"];
            var forward     = parsedQuery["forward"];
            var slower      = parsedQuery["slower"];
            var faster      = parsedQuery["faster"];

            Debug.Print($"{user}:{project}:{avatarUri}:{name}:{uilang}:{font}:{fontsize}:{playpause}:{back}:{forward}:{slower}:{faster}");
            var usersDoc = LoadXmlData("users");
            var userNode = usersDoc.SelectSingleNode($"//user[username/@id = '{user}']");

            if (userNode == null)
            {
                return;
            }
            var usernameNode = userNode.SelectSingleNode("username") as XmlElement;

            Debug.Assert(usernameNode != null, nameof(usernameNode) + " != null");
            AddAvatarUri(avatarUri, usernameNode);
            AddUserName(name, usernameNode, usersDoc);
            AddUilang(uilang, userNode, usersDoc);
            AddFontInfo("fontfamily", font, userNode, project, usersDoc, user);
            AddFontInfo("fontsize", fontsize, userNode, project, usersDoc, user);
            AddHotkey("play-pause", playpause, userNode, usersDoc);
            AddHotkey("back", back, userNode, usersDoc);
            AddHotkey("forward", forward, userNode, usersDoc);
            AddHotkey("slower", slower, userNode, usersDoc);
            AddHotkey("faster", faster, userNode, usersDoc);
            using (var xw = XmlWriter.Create(XmlFullName("users"), new XmlWriterSettings {
                Indent = true
            }))
            {
                usersDoc.Save(xw);
            }
        }
Exemplo n.º 3
0
        protected override void OnObserveHttpModifyRequest(GeckoObserveHttpModifyRequestEventArgs e)
        {
            Debug.Print(e.Uri.AbsoluteUri);
            var method = e.Channel.RequestMethod;

            if (method == "GET")
            {
                if (e.Uri.Segments[1] != "api/")
                {
                    return;
                }
                switch (e.Uri.Segments[2])
                {
                case "GetUsers":
                    GetUsers();
                    break;

                case "GetTasks":
                    GetTasks(e.Uri.Query);
                    break;
                }
            }
            else if (method == "PUT")
            {
                if (e.Uri.Segments[1] != "api/")
                {
                    return;
                }
                switch (e.Uri.Segments[2])
                {
                case "TaskEvent":
                    TaskEvent(e);
                    break;

                case "UpdateUser":
                    UpdateUser(e);
                    break;
                }
            }
        }
Exemplo n.º 4
0
        private void TaskEvent(GeckoObserveHttpModifyRequestEventArgs e)
        {
            var parsedQuery = HttpUtility.ParseQueryString(e.Uri.Query);
            var action      = parsedQuery["action"];
            var task        = parsedQuery["task"];
            var user        = parsedQuery["user"];
            var tasksDoc    = LoadXmlData("tasks");
            var taskNode    = tasksDoc.SelectSingleNode($@"//task[@id=""{task}""]");

            if (taskNode == null)
            {
                return;
            }
            switch (action)
            {
            case "Assigned":
                var assignedTo = taskNode.SelectSingleNode("@assignedto");
                if (!string.IsNullOrEmpty(assignedTo?.InnerText))
                {
                    e.Cancel = true;
                    return;
                }
                NewAttr(taskNode, "assignedto", user);
                break;

            case "Unassigned":
                var assignedTo2 = taskNode.SelectSingleNode("@assignedto") as XmlAttribute;
                if (string.IsNullOrEmpty(assignedTo2?.InnerText) || assignedTo2.InnerText != user)
                {
                    e.Cancel = true;
                    return;
                }
                Debug.Assert(taskNode.Attributes != null, "taskNode.Attributes != null");
                taskNode.Attributes.Remove(assignedTo2);
                break;

            case "TranscribeStart": break;

            case "TranscribeEnd": break;

            case "ReviewStart": break;

            case "ReviewEnd": break;

            case "HoldStart": break;

            case "HoldEnd": break;

            case "Upload": break;

            case "Complete": break;
            }
            var historyNodes = taskNode.SelectNodes(".//history");

            Debug.Assert(historyNodes != null, nameof(historyNodes) + " != null");

            var historyNode = tasksDoc.CreateElement("history");

            NewAttr(historyNode, "id", historyNodes.Count.ToString());
            NewAttr(historyNode, "datetime", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"));
            NewAttr(historyNode, "action", action);
            NewAttr(historyNode, "userid", user);
            taskNode.AppendChild(historyNode);
            using (var xw = XmlWriter.Create(XmlFullName("tasks"), new XmlWriterSettings {
                Indent = true
            }))
            {
                tasksDoc.Save(xw);
            }
        }
Exemplo n.º 5
0
 private void Browser_ObserveHttpModifyRequest(object sender, GeckoObserveHttpModifyRequestEventArgs e)
 {
     //e.Channel.SetRequestHeader(name, value, merge: true);
 }
Exemplo n.º 6
0
        protected override void OnObserveHttpModifyRequest(GeckoObserveHttpModifyRequestEventArgs e)
        {
            Debug.Print(e.Uri.AbsoluteUri);
            var method = e.Channel.RequestMethod;

            if (method == "GET")
            {
                if (e.Uri.Segments.Length < 2 || e.Uri.Segments[1] != "api/")
                {
                    return;
                }
                var arg3 = e.Uri.Segments.Length > 3 ? e.Uri.Segments[3] : string.Empty;
                Logger.WriteEvent($"Get {e.Uri.Segments[2]} {e.Uri.Query} {arg3}");
                try
                {
                    switch (e.Uri.Segments[2])
                    {
                    case "GetUsers":
                        new GetUsers();
                        break;

                    case "GetTasks":
                        new GetTasks(e.Uri.Query);
                        break;

                    case "GetParatextProjects":
                        ForParatext.GetParatextProjects();
                        break;

                    case "GetDefaultUserHotKeys":
                        new GetDefaultUserHotKeys();
                        break;

                    case "GetZttProjectsCount":
                        new GetZttProjectsCount();
                        break;
                    }
                }
                catch (Exception err)
                {
                    Logger.WriteEvent($"{err.Message} in {e.Uri.Segments[2]}");
                }
            }
            else if (method == "PUT")
            {
                if (e.Uri.Segments.Length < 2 || e.Uri.Segments[1] != "api/")
                {
                    return;
                }
                Logger.WriteEvent($"Put {e.Uri.Segments[2]} {e.Uri.Query}");
                try
                {
                    switch (e.Uri.Segments[2])
                    {
                    case "TaskEvent":
                        var taskEvent = new TaskEvent();
                        if (taskEvent.Exec(e.Uri.Query, ForParatext.Upload))
                        {
                            e.Cancel = true;
                        }
                        break;

                    case "UpdateUser":
                        new UpdateUser(e.Uri.Query, e.RequestBody, SaveImage);
                        break;

                    case "UpdateProjectAvatar":
                        new UpdateProjectAvatar(e.Uri.Query, e.RequestBody, SaveImage);
                        break;

                    case "UpdateProject":
                        new UpdateProject(e.Uri.Query);
                        break;

                    case "ReportPosition":
                        new ReportPosition(e.Uri.Query);
                        break;

                    case "WriteTranscription":
                        new WriteTranscription(e.Uri.Query, e.RequestBody);
                        break;

                    case "DeleteUser":
                        new DeleteUser(e.Uri.Query);
                        break;

                    case "UpdateTask":
                        new UpdateTask(e.Uri.Query, e.RequestBody);
                        break;

                    case "DeleteTask":
                        new DeleteTask(e.Uri.Query);
                        break;

                    case "CopyToClipboard":
                        new CopyToClipboard(e.Uri.Query, ToClipboard);
                        break;

                    case "AddManyTasks":
                        new AddManyTasks(e.Uri.Query, SelectAudioFilesFolder);
                        break;

                    case "ShowHelp":
                        new ShowHelp(e.Uri.Query, ShowHelpTopic);
                        break;

                    case "GetMeta":
                        new GetMeta(e.Uri.Query, e.RequestBody);
                        break;

                    case "DeleteProject":
                        new DeleteProject(e.Uri.Query);
                        break;
                    }
                }
                catch (Exception err)
                {
                    Logger.WriteEvent($"{err.Message} in {e.Uri.Segments[2]}");
                }
            }
        }