Ejemplo n.º 1
0
        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            /*
             * Globals.Soylent.Application.ActiveDocument.ShowRevisions = true;//!Globals.Soylent.Application.ActiveDocument.ShowRevisions;
             * Globals.Soylent.Application.ActiveDocument.TrackRevisions = !Globals.Soylent.Application.ActiveDocument.TrackRevisions;
             * Word.Range range = Globals.Soylent.Application.ActiveDocument.Range(0, 4);
             * range.Text = Globals.Soylent.Application.ActiveDocument.TrackRevisions.ToString();
             * */

            CrowdproofData data = CrowdproofData.getCannedData();
            //CrowdproofView.insertTrackChanges(data);

            //Globals.Soylent.Application.ActiveDocument.TrackRevisions = true;

            /*
             * TurKitSocKit tksc = new TurKitSocKit();
             * tksc.Listen();
             */
        }
Ejemplo n.º 2
0
        /// <summary>
        /// HITView subclass specific to Shortn tasks.  This adds the Shortn button and additional necessary functionality.
        /// </summary>
        /// <param name="workType"></param>
        /// <param name="data"></param>
        public CrowdproofView(string workType, CrowdproofData data, int job) : base(workType, data, job)
        {
            //Globals.Soylent.soylent.Controls.Add(new System.Windows.Forms.Button());
            CrowdproofButton         = new Button();
            CrowdproofButton.Content = "View Revisions";
            CrowdproofButton.Name    = "Crowdproof";
            CrowdproofButton.Height  = 23;
            //CrowdproofButton.Width = 90;
            CrowdproofButton.IsEnabled = false;
            CrowdproofButton.Click    += new RoutedEventHandler(Crowdproof_Clicked);

            AcceptRevisions           = new Button();
            AcceptRevisions.Content   = "Accept All";
            AcceptRevisions.Name      = "AcceptRevisions";
            AcceptRevisions.Height    = 23;
            AcceptRevisions.Width     = 100;
            AcceptRevisions.IsEnabled = false;
            AcceptRevisions.Click    += new RoutedEventHandler(AcceptRevisions_Clicked);

            RejectRevisions           = new Button();
            RejectRevisions.Content   = "Reject All";
            RejectRevisions.Name      = "RejectRevisions";
            RejectRevisions.Height    = 23;
            RejectRevisions.Width     = 100;
            RejectRevisions.IsEnabled = false;
            RejectRevisions.Click    += new RoutedEventHandler(RejectRevisions_Clicked);

            buttons             = new StackPanel();
            buttons.Orientation = System.Windows.Controls.Orientation.Horizontal;
            buttons.Children.Add(AcceptRevisions);
            buttons.Children.Add(RejectRevisions);

            stages.Children.Add(CrowdproofButton);
            stages.Children.Add(buttons);

            this.data = data;
            data.register(this);

            jobTurkerName = turkerName + job;
        }
Ejemplo n.º 3
0
        private void button6_Click(object sender, RibbonControlEventArgs e)
        {
            string s = "";

            foreach (Microsoft.Office.Core.CustomXMLPart cus in Globals.Soylent.Application.ActiveDocument.CustomXMLParts)
            {
                s = cus.XML;
            }

            XmlSerializer y = new XmlSerializer(typeof(CrowdproofData));

            //StringReader sr = new StringReader(a);
            StringReader sr = new StringReader(s);

            XmlReader z   = XmlReader.Create(sr);
            object    obj = y.Deserialize(z);

            CrowdproofData q = obj as CrowdproofData;

            Word.Bookmark a = Globals.Soylent.Application.ActiveDocument.Bookmarks["Soylent" + q.job];
            q.range = a.Range;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Open the Shortn dialog window.  Used internally after the Shortn button is pressed, and by Ribbon for the debugging
        /// </summary>
        /// <param name="data"></param>

        public void insertTrackChanges(CrowdproofData data)
        {
            Globals.Soylent.Application.ActiveDocument.TrackRevisions = true;
            Globals.Soylent.Application.ActiveDocument.ShowRevisions  = true;

            Microsoft.Office.Core.DocumentProperties properties;

            properties = (Microsoft.Office.Core.DocumentProperties)Globals.Soylent.Application.ActiveDocument.BuiltInDocumentProperties;
            string defaultAuthor = properties["Author"].Value as string;

            if (defaultAuthor == turkerName)
            {
                turkerName = turkerName + "B";
            }

            foreach (CrowdproofPatch patch in data.patches)
            {
                string comment = "";
                foreach (string reason in patch.reasons)
                {
                    if (patch.reasons.IndexOf(reason) == 0)
                    {
                        comment += reason;
                    }
                    else if (patch.reasons.IndexOf(reason) == 1)
                    {
                        comment += "\n\nOther Explanations:";
                        comment += "\n - ";
                        comment += reason;
                    }
                    else
                    {
                        comment += "\n - ";
                        comment += reason;
                    }
                }
                foreach (string suggestion in patch.replacements)
                {
                    if (patch.replacements.IndexOf(suggestion) == 0)
                    {
                        if (patch.replacements.Count > 1)
                        {
                            comment += "\n\nOther Suggestions:";
                        }
                    }
                    else
                    {
                        comment += "\n - ";
                        comment += suggestion;
                    }
                }
                object commentText = comment;
                Microsoft.Office.Interop.Word.Comment c = Globals.Soylent.Application.ActiveDocument.Comments.Add(patch.range, commentText);
                c.Author = jobTurkerName;

                Globals.Soylent.Application.UserName = jobTurkerName;
                patch.range.Text = patch.replacements[0];
                Globals.Soylent.Application.UserName = defaultAuthor;
            }

            /*
             * foreach (Microsoft.Office.Interop.Word.Comment c in Globals.Soylent.Application.ActiveDocument.Comments)
             * {
             *  c.Author = jobTurkerName;
             *  c.Initial = jobTurkerName;
             * }
             */

            //this.AcceptRevisions.IsEnabled = true;
            //this.stages.Children.Remove(CrowdproofButton);
            //this.stages.Children.Add(buttons);
            AcceptRevisions.IsEnabled  = true;
            RejectRevisions.IsEnabled  = true;
            CrowdproofButton.IsEnabled = false;

            stub.AcceptRevisions.IsEnabled  = true;
            stub.RejectRevisions.IsEnabled  = true;
            stub.CrowdproofButton.IsEnabled = false;

            Globals.Soylent.Application.ActiveDocument.TrackRevisions = false;
        }
Ejemplo n.º 5
0
        public static void HandleSocketMessage(string incomingString)
        {
            Regex  typeRegex   = new Regex("\"__type__\"\\s*:\\s*\"(?<messageType>.*)\"");
            Match  regexResult = typeRegex.Match(incomingString);
            string messageType = regexResult.Groups["messageType"].Value;

            Regex  jobtypeRegex   = new Regex("\"__jobType__\"\\s*:\\s*\"(?<jobType>.*)\"");
            Match  jobregexResult = jobtypeRegex.Match(incomingString);
            string jobType        = jobregexResult.Groups["jobType"].Value;


            JavaScriptSerializer serializer = new JavaScriptSerializer();

            if (messageType == "status")
            {
                TurKitStatus receivedObject = serializer.Deserialize <TurKitStatus>(incomingString);

                Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                HITData concernedHIT = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job];    //Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job];

                Debug.WriteLine(receivedObject.hitURL);

                //if (concernedHIT is ShortnData)
                if (jobType == "shortn")
                {
                    Debug.WriteLine("Status update for Shortn");
                    ShortnData shortenData = concernedHIT as ShortnData;
                    shortenData.updateStatus(receivedObject);
                }
                //else if (concernedHIT is CrowdproofData)
                else if (jobType == "crowdproof")
                {
                    CrowdproofData crowdproofData = concernedHIT as CrowdproofData;
                    crowdproofData.updateStatus(receivedObject);
                }
                if (jobType == "human-macro")
                {
                    Debug.WriteLine("Status update for human-macro");
                    HumanMacroData humanMacro = concernedHIT as HumanMacroData;
                    humanMacro.updateStatus(receivedObject);
                }
            }
            else if (messageType == "stageComplete")
            {
                Debug.WriteLine("Stage complete message");
                TurKitStageComplete receivedObject = serializer.Deserialize <TurKitStageComplete>(incomingString);

                if (jobType == "shortn")
                {
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    ShortnData shortenData = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as ShortnData;
                    //Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as ShortnData;
                    shortenData.stageCompleted(receivedObject);
                }
                else if (jobType == "crowdproof")
                {
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    CrowdproofData crowdproofData = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as CrowdproofData;
                    //CrowdproofData crowdproofData = fixthis;//Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as CrowdproofData;
                    crowdproofData.stageCompleted(receivedObject);
                }
            }
            else if (messageType == "complete")
            {
                if (jobType == "human-macro")
                {
                    TurKitHumanMacroResult receivedObject = serializer.Deserialize <TurKitHumanMacroResult>(incomingString);
                    Debug.WriteLine("\nHUMAN MACRO COMPLEEETE******");
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    HumanMacroData humanMacro = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as HumanMacroData;
                    //HumanMacroData humanMacro = fixthis;//Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as HumanMacroData;
                    humanMacro.processSocKitMessage(receivedObject);
                }
                else if (jobType == "shortn")
                {
                    TurKitFindFixVerify receivedObject         = serializer.Deserialize <TurKitFindFixVerify>(incomingString);
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    ShortnData shortenData = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as ShortnData;    //Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as ShortnData;
                    shortenData.processSocKitMessage(receivedObject);
                }
                else if (jobType == "crowdproof")
                {
                    TurKitFindFixVerify receivedObject         = serializer.Deserialize <TurKitFindFixVerify>(incomingString);
                    Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                    CrowdproofData crowdproofData = Globals.Soylent.soylentMap[doc].jobMap[receivedObject.job] as CrowdproofData;
                    //CrowdproofData crowdproofData = fixthis;//Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[receivedObject.job] as CrowdproofData;
                    crowdproofData.processSocKitMessage(receivedObject);
                }
            }
            else if (messageType == "exception")
            {
                Debug.WriteLine("TurKit exception thrown:");
                TurKitException receivedObject = serializer.Deserialize <TurKitException>(incomingString);
                Debug.WriteLine(receivedObject.exceptionString);

                Microsoft.Office.Interop.Word.Document doc = Globals.Soylent.jobToDoc[receivedObject.job];
                SoylentPanel panel        = Globals.Soylent.soylentMap[doc];
                HITData      concernedHIT = panel.jobMap[receivedObject.job];

                panel.Invoke(new HITData.showErrorDelegate(concernedHIT.showError), new object[] { receivedObject.exceptionString });
                //concernedHIT.showError(receivedObject.exceptionCode);
            }
            //Debug.WriteLine("got it!");
        }
Ejemplo n.º 6
0
        void Application_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
        {
            foreach (Microsoft.Office.Core.CustomXMLPart xmlPart in Globals.Soylent.Application.ActiveDocument.CustomXMLParts)
            {
                if (!(xmlPart.BuiltIn))
                {
                    xmlPart.Delete();
                }
            }
            foreach (object obj in soylentMap[Doc].sidebar.jobs.Children)
            {
                if (!(obj is StackPanel))
                {
                    continue;
                }
                StackPanel elem = obj as StackPanel;
                foreach (object elem2 in elem.Children)
                {
                    HITData raw;
                    if (elem2 is HITView)
                    {
                        raw = (elem2 as HITView).data;
                    }
                    else
                    {
                        raw = (elem2 as HITViewStub).data;
                    }

                    if (raw is ShortnData)
                    {
                        ShortnData hit = raw as ShortnData;

                        XmlSerializer x  = new XmlSerializer(hit.GetType());
                        StringWriter  sw = new StringWriter();
                        x.Serialize(sw, hit);
                        string xml = sw.ToString();
                        Microsoft.Office.Core.CustomXMLPart xmlPart = Globals.Soylent.Application.ActiveDocument.CustomXMLParts.Add(xml);
                    }
                    else if (raw is CrowdproofData)
                    {
                        CrowdproofData hit = raw as CrowdproofData;

                        XmlSerializer x  = new XmlSerializer(hit.GetType());
                        StringWriter  sw = new StringWriter();
                        x.Serialize(sw, hit);
                        string xml = sw.ToString();
                        Microsoft.Office.Core.CustomXMLPart xmlPart = Globals.Soylent.Application.ActiveDocument.CustomXMLParts.Add(xml);
                    }
                    else if (raw is HumanMacroData)
                    {
                        HumanMacroData hit = raw as HumanMacroData;

                        XmlSerializer x  = new XmlSerializer(hit.GetType());
                        StringWriter  sw = new StringWriter();
                        x.Serialize(sw, hit);
                        string xml = sw.ToString();
                        Microsoft.Office.Core.CustomXMLPart xmlPart = Globals.Soylent.Application.ActiveDocument.CustomXMLParts.Add(xml);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        void Application_DocumentOpen(Word.Document doc)
        {
            SoylentPanel  soylent = soylentMap[doc];
            List <string> rawHITs = new List <string>();

            //One problem: loads jobs in reverse order.  This is easy to fix.  But is either correct?
            foreach (Microsoft.Office.Core.CustomXMLPart xmlPart in Globals.Soylent.Application.ActiveDocument.CustomXMLParts)
            {
                string xml         = xmlPart.XML;
                Regex  typeRegex   = new Regex("<job>(.*?)</job>"); //To filter out Soylent jobs from the xml parts Word automatically saves
                Match  regexResult = typeRegex.Match(xml);
                string jobString   = regexResult.ToString();
                if (jobString.Length < 6)
                {
                    continue;
                }

                int job = Int32.Parse(jobString.Substring(5, jobString.Length - 11));

                jobToDoc[job] = doc;
                rawHITs.Add(xml);
            }
            rawHITs.Reverse();

            foreach (string xml in rawHITs)
            {
                StringReader sr = new StringReader(xml);
                XmlReader    xr = XmlReader.Create(sr);

                if (new Regex("</ShortnData>").Match(xml).Length > 0)
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ShortnData));
                    object        raw        = serializer.Deserialize(xr);

                    ShortnData hit = raw as ShortnData;

                    // HACK: have to do this after deserialization because numParagraphs is 0 when the object is deserialized
                    foreach (StageData stage in hit.stages)
                    {
                        stage.FixParagraphNumber(hit.numParagraphs);
                    }

                    Word.Bookmark a = Globals.Soylent.Application.ActiveDocument.Bookmarks["Soylent" + hit.job];
                    hit.range = a.Range;

                    if (hit.jobDone)
                    {
                        ShortnJob s = new ShortnJob(hit, hit.job, false);
                        //Use saved TurKit messages to recreate the results.
                        foreach (TurKitSocKit.TurKitStageComplete message in hit.stageCompletes)
                        {
                            hit.terminateStage(message);
                        }
                        foreach (TurKitSocKit.TurKitFindFixVerify message in hit.findFixVerifies)
                        {
                            hit.postProcessSocKitMessage(message);
                        }
                    }
                    else
                    {
                        // This will work if you are restarting it on the same machine, where the
                        // TurKit javascript file still sits. Otherwise, it will restart the job.
                        ShortnJob s = new ShortnJob(hit, hit.job, true);
                    }
                }

                else if (new Regex("</CrowdproofData>").Match(xml).Length > 0)
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(CrowdproofData));
                    object        raw        = serializer.Deserialize(xr);

                    CrowdproofData hit = raw as CrowdproofData;

                    foreach (StageData stage in hit.stages)
                    {
                        stage.FixParagraphNumber(hit.numParagraphs);
                    }

                    Word.Bookmark a = Globals.Soylent.Application.ActiveDocument.Bookmarks["Soylent" + hit.job];
                    hit.range = a.Range;

                    //SoylentRibbon.setLastJob(hit.job);

                    if (hit.jobDone)
                    {
                        CrowdproofJob s = new CrowdproofJob(hit, hit.job, false);
                        //Use saved TurKit messages to recreate the results.
                        foreach (TurKitSocKit.TurKitStageComplete message in hit.stageCompletes)
                        {
                            hit.terminateStage(message);
                        }
                        foreach (TurKitSocKit.TurKitFindFixVerify message in hit.findFixVerifies)
                        {
                            hit.postProcessSocKitMessage(message);
                        }
                    }
                    else
                    {
                        CrowdproofJob s = new CrowdproofJob(hit, hit.job, true);
                    }
                }

                else if (new Regex("</HumanMacroData>").Match(xml).Length > 0)
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(HumanMacroData));
                    object        raw        = serializer.Deserialize(xr);

                    HumanMacroData hit = raw as HumanMacroData;

                    foreach (StageData stage in hit.stages)
                    {
                        stage.FixParagraphNumber(hit.numParagraphs);
                    }

                    Word.Bookmark a = Globals.Soylent.Application.ActiveDocument.Bookmarks["Soylent" + hit.job];
                    hit.range = a.Range;

                    //SoylentRibbon.setLastJob(hit.job);

                    if (hit.jobDone)
                    {
                        HumanMacroJob s = new HumanMacroJob(hit, hit.job, false);
                        //Use saved TurKit messages to recreate the results.
                        foreach (TurKitSocKit.TurKitHumanMacroResult message in hit.messages)
                        {
                            hit.postProcessSocKitMessage(message);
                        }
                        hit.finishStageData();
                    }
                    else
                    {
                        HumanMacroJob s = new HumanMacroJob(hit, hit.job, true);
                    }
                }
            }
        }