コード例 #1
0
        private static string REMOVE_TEXT = "Cut";       //This is the text for the context menu option that replaces the selection with the empty string.

        /// <summary>
        /// The dialog window that opens when a user wants to interact with returned Shortn data.
        /// </summary>
        /// <param name="data">The Model for this Shortn job</param>
        public ShortnDialog(ShortnData data)
        {
            InitializeComponent();
            this.data = data;
            updateParagraphs(1);
            initSliderTicks();
        }
コード例 #2
0
ファイル: ShortnView.cs プロジェクト: tummykung/soylent
        /// <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 ShortnView(string workType, ShortnData data, int job) : base(workType, data, job)
        {
            //Globals.Soylent.soylent.Controls.Add(new System.Windows.Forms.Button());
            ShortnButton         = new Button();
            ShortnButton.Content = "Shortn";
            ShortnButton.Name    = "Shortn";
            ShortnButton.Height  = 23;
            //ShortnButton.Width = 80;
            ShortnButton.IsEnabled = false;
            ShortnButton.Click    += new RoutedEventHandler(Shortn_Clicked);

            data.register(this);
            //ShortnButton.
            //ShortnButton.Click = Shortn_Clicked;
            //stages.Children.Add(ShortnButton);
            StackPanel buttonPanel = new StackPanel();

            buttonPanel.Margin = new Thickness(5.0, 0.0, 5.0, 0.0);

            buttonPanel.Children.Add(ShortnButton);

            stages.Children.Add(buttonPanel);
        }
コード例 #3
0
ファイル: ShortnView.cs プロジェクト: tummykung/soylent
        /// <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 static void openShortnDialog(ShortnData data)
        {
            System.Windows.Forms.Form newForm = new System.Windows.Forms.Form();
            newForm.Width     = 1200;
            newForm.Height    = int.MaxValue;
            newForm.BackColor = System.Drawing.Color.White;

            // Create the ElementHost control for hosting the
            // WPF UserControl.
            ElementHost host = new ElementHost();

            host.Dock = System.Windows.Forms.DockStyle.Fill;

            // Create the WPF UserControl.
            ShortnDialog sd = new ShortnDialog(data);

            // Assign the WPF UserControl to the ElementHost control's
            // Child property.
            host.Child = sd;

            newForm.Visible = false;
            // Add the ElementHost control to the form's
            // collection of child controls.
            newForm.Controls.Add(host);
            newForm.Show();

            // set the form's height based on what the textbox wants to be
            int dialogHeight = (int)sd.grid.DesiredSize.Height;

            newForm.Height          = (int)(sd.DesiredSize.Height + newForm.Padding.Vertical + System.Windows.Forms.SystemInformation.CaptionHeight + System.Windows.SystemParameters.ScrollWidth);
            sd.grid.Height          = sd.grid.DesiredSize.Height;
            newForm.Width           = 1200;
            host.MaximumSize        = new System.Drawing.Size(1200, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
            newForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;

            newForm.Visible = true;
        }
コード例 #4
0
ファイル: SoylentRibbon.cs プロジェクト: tummykung/soylent
        private void button2_Click(object sender, RibbonControlEventArgs e)
        {
            //I is trying to learn how to write gooder.
            TurKitSocKit.TurKitFindFixVerifyPatch p1 = new TurKitSocKit.TurKitFindFixVerifyPatch();
            p1.start   = 4; p1.end = 24;
            p1.options = new List <TurKitSocKit.TurKitFindFixVerifyOption>();
            TurKitSocKit.TurKitFindFixVerifyOption option = new TurKitSocKit.TurKitFindFixVerifyOption();
            option.editsText    = true;
            option.field        = "revision";
            option.alternatives = new List <TurKitSocKit.TurKitFindFixVerifyAlternative>();
            p1.options.Add(option);

            TurKitSocKit.TurKitFindFixVerifyAlternative p1a = new TurKitSocKit.TurKitFindFixVerifyAlternative();
            TurKitSocKit.TurKitFindFixVerifyAlternative p1b = new TurKitSocKit.TurKitFindFixVerifyAlternative();
            TurKitSocKit.TurKitFindFixVerifyAlternative p1c = new TurKitSocKit.TurKitFindFixVerifyAlternative();
            p1a.text = "figuring"; p1b.text = "trying to figure"; p1c.text = "working out";

            option.alternatives.Add(p1a); option.alternatives.Add(p1b); option.alternatives.Add(p1c);

            TurKitSocKit.TurKitFindFixVerifyPatch p2 = new TurKitSocKit.TurKitFindFixVerifyPatch();
            p2.start = 64; p2.end = 70;

            TurKitSocKit.TurKitFindFixVerifyOption option2 = new TurKitSocKit.TurKitFindFixVerifyOption();
            option2.editsText    = true;
            option2.field        = "revision";
            option2.alternatives = new List <TurKitSocKit.TurKitFindFixVerifyAlternative>();

            TurKitSocKit.TurKitFindFixVerifyAlternative p2a = new TurKitSocKit.TurKitFindFixVerifyAlternative();
            TurKitSocKit.TurKitFindFixVerifyAlternative p2b = new TurKitSocKit.TurKitFindFixVerifyAlternative();
            TurKitSocKit.TurKitFindFixVerifyAlternative p2c = new TurKitSocKit.TurKitFindFixVerifyAlternative();
            p2a.text = "proper"; p2b.text = "right"; p2c.text = "yes";
            option2.alternatives.Add(p2a); option2.alternatives.Add(p2b); option2.alternatives.Add(p2c);

            TurKitSocKit.TurKitFindFixVerify tks = new TurKitSocKit.TurKitFindFixVerify();
            tks.job = 1; tks.paragraph = 1; tks.patches = new List <TurKitSocKit.TurKitFindFixVerifyPatch>();
            tks.patches.Add(p1); tks.patches.Add(p2);

            ShortnData shortenData = Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[tks.job] as ShortnData;

            shortenData.processSocKitMessage(tks);


            System.Windows.Forms.Form newForm = new System.Windows.Forms.Form();
            //newForm.Width = 1195;
            //newForm.Height = 380;
            newForm.BackColor = System.Drawing.Color.White;

            // Create the ElementHost control for hosting the
            // WPF UserControl.
            ElementHost host = new ElementHost();

            host.Width  = newForm.Width;
            host.Height = newForm.Height;

            // Create the WPF UserControl.
            //Word.Range toShorten = Globals.Soylent.Application.Selection.Range;
            ShortnDialog sd = new ShortnDialog(Globals.Soylent.soylentMap[Globals.Soylent.Application.ActiveDocument].jobMap[1] as ShortnData);

            // Assign the WPF UserControl to the ElementHost control's
            // Child property.

            host.Child = sd;

            // Add the ElementHost control to the form's
            // collection of child controls.
            newForm.Controls.Add(host);
            newForm.Show();
        }
コード例 #5
0
ファイル: SoylentRibbon.cs プロジェクト: tummykung/soylent
 private void directManipulate_Click(object sender, RibbonControlEventArgs e)
 {
     ShortnView.openShortnDialog(ShortnData.getCannedData());
 }
コード例 #6
0
ファイル: TurKitSocKit.cs プロジェクト: tummykung/soylent
        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!");
        }
コード例 #7
0
ファイル: Soylent.cs プロジェクト: tummykung/soylent
        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);
                    }
                }
            }
        }
コード例 #8
0
ファイル: Soylent.cs プロジェクト: tummykung/soylent
        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);
                    }
                }
            }
        }