Exemplo n.º 1
0
        public void RunMacro_Click(object sender, RoutedEventArgs e)
        {
            HumanMacroData.Separator separator = HumanMacroData.Separator.Sentence;
            if (separatorBox.SelectedItem == item2)
            {
                separator = HumanMacroData.Separator.Sentence;
            }
            else if (separatorBox.SelectedItem == item1)
            {
                separator = HumanMacroData.Separator.Paragraph;
            }

            double reward; int redundancy; string localtitle; string localsubtitle; string localinstructions;

            /*
             * if (Soylent.DEBUG == true)
             * {
             *  reward = 0.05;
             *  redundancy = 2;
             *  localtitle = "\"Make my novel present tense\"";
             *  localsubtitle = "\"I need to change some prose from past to present tense\"";
             *  localinstructions = "'I am changing this section of my novel from the past tense to the present tense. Please read and fix to make everything present tense, e.g., \"Susan swerved and aimed the gun at her assailant. The man recoiled, realizing that his prey had now caught on to the scheme.\" becomes \"Susan swerves and aims the gun at her assailant. The man recoils, realizing that his prey had now caught on to the scheme.\"'";
             * }
             * else
             * {
             */
            reward            = payment;
            redundancy        = numRepetitions;
            localtitle        = title;
            localsubtitle     = subtitle;
            localinstructions = instructions;
            //}

            HumanMacroData.ReturnType type = HumanMacroData.ReturnType.Comment;
            if (returnTypeBox.SelectedItem == returnAsComments)
            {
                type = HumanMacroData.ReturnType.Comment;
            }
            else if (returnTypeBox.SelectedItem == returnAsInline)
            {
                type = HumanMacroData.ReturnType.SmartTag;
            }


            //Debug.WriteLine("########################");
            //Debug.WriteLine("Reward: " + reward + " || Redundancy: "+redundancy+" || Title: "+localtitle+" || Subtitle: "+localsubtitle+" || Instructions: "+localinstructions);
            //Debug.WriteLine(separatorBox.SelectedValue.ToString() + " 1 " + (item2 == separatorBox.SelectedValue) + " 2 " + (item2 == separatorBox.SelectionBoxItem) + " 3 " + (item2 == separatorBox.SelectedItem) + " 4 " + (item2.Content == separatorBox.SelectedValuePath));

            //HumanMacroData data = new HumanMacroData(text, jobNumber, separator, reward, redundancy, localtitle, localsubtitle, localinstructions, type, HumanMacroData.TestOrReal.Real);

            //HumanMacroJob job = new HumanMacroJob(data, jobNumber);
            HumanMacroJob job = new HumanMacroJob(text, jobNumber, separator, reward, redundancy, localtitle, localsubtitle, localinstructions, type, HumanMacroData.TestOrReal.Real);

            HwndSource source = (HwndSource)PresentationSource.FromVisual(sender as Button);

            System.Windows.Forms.Control ctl = System.Windows.Forms.Control.FromChildHandle(source.Handle);
            ctl.FindForm().Close();
        }
Exemplo n.º 2
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);
                    }
                }
            }
        }