示例#1
0
        void Application_DocumentChange()
        {
            Word.Document doc = this.Application.ActiveDocument;
            // If the document is already open, don't worry about it.  If not (e.g. created a new document, loaded old), set up its panel
            if (!soylentMap.Keys.Contains <Word.Document>(doc))
            {
                SoylentPanel soylent = new SoylentPanel();

                HITView = this.CustomTaskPanes.Add(soylent, "Soylent");
                HITView.VisibleChanged += new EventHandler(hitviewVisibleChanged);
                //HITView.Visible = true;

                addDocToMap(soylent);
            }
        }
示例#2
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!");
        }
示例#3
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);
                    }
                }
            }
        }
示例#4
0
 public void addDocToMap(SoylentPanel sp)
 {
     Word.Document doc = this.Application.ActiveDocument;
     soylentMap[doc] = sp;
 }