コード例 #1
0
ファイル: SoylentRibbon.cs プロジェクト: tummykung/soylent
        /// <summary>
        /// Prompt for the Amazon Keys
        /// </summary>
        /// <param name="callback">A callback if we got keys</param>
        /// <param name="cancel">A callback if the user didn't provide keys</param>
        public void AskForKeys(TurKit.startTaskDelegate callback, TurKit.noKeysDelegate cancel)
        {
            Amazon amazon       = new Amazon();
            Window amazonWindow = new Window
            {
                Title         = "Amazon Keys",
                Content       = amazon,
                SizeToContent = SizeToContent.WidthAndHeight,
                ResizeMode    = ResizeMode.NoResize
            };

            amazon.okButton.Click += (sender, e) => {
                AmazonKeys keys = new AmazonKeys();
                keys.amazonID  = amazon.accessKey.Text;
                keys.secretKey = amazon.secretKey.Text;

                if (callback != null)
                {
                    callback(keys);
                }
                amazonWindow.Close();
            };

            amazon.cancelButton.Click += (sender, e) =>
            {
                if (cancel != null)
                {
                    cancel();
                }
            };

            amazonWindow.ShowDialog();
        }
コード例 #2
0
 private void cancelBtn_Click(object sender, RoutedEventArgs e)
 {
     AmazonKeys.AskForAmazonKeys((AmazonKeys keys) =>
     {
         data.tk.cancelTask(keys);
         RemoveHITVIew();
     }, null);
 }
コード例 #3
0
        public Amazon()
        {
            InitializeComponent();

            AmazonKeys keys = AmazonKeys.LoadAmazonKeys();

            if (keys != null)
            {
                fillTextField(keys);
            }
        }
コード例 #4
0
        public void startFindFixVerifyTask(string tasktype, AmazonKeys keys)
        {
            string[][] pgraphs = new string[hdata.range.Paragraphs.Count][];
            // Range.Paragraphs and Range.Sentences are 1 INDEXED
            for (int i = 0; i < hdata.range.Paragraphs.Count; i++)
            {
                Word.Paragraph paragraph = hdata.range.Paragraphs[i + 1];
                pgraphs[i] = new string[paragraph.Range.Sentences.Count];
                for (int j = 0; j < paragraph.Range.Sentences.Count; j++)
                {
                    Word.Range sentence = paragraph.Range.Sentences[j + 1];
                    string     temp     = sentence.Text;

                    // Whitespace characters in the middle of sentences will not be removed
                    temp          = temp.Trim();
                    pgraphs[i][j] = temp;
                }
            }
            JavaScriptSerializer js = new JavaScriptSerializer();
            string paragraphs       = js.Serialize(pgraphs);

            //string paragraphs = JsonConvert.SerializeObject(pgraphs);

            paragraphs = "var paragraphs = " + paragraphs + ";";

            // figure out whether there are one or two spaces between sentences
            string firstSentence          = hdata.range.Paragraphs[1].Range.Sentences[1].Text;
            string spacesBetweenSentences = " ";

            if (firstSentence.EndsWith("  "))
            {
                spacesBetweenSentences = "  ";
            }
            string numSpaces = "var sentence_separator = '" + spacesBetweenSentences + "';";

            int    request       = hdata.job;
            string requestLine   = "var soylentJob = " + request + ";";
            string debug         = "var debug = " + (Soylent.DEBUG ? "true" : "false") + ";";
            string fileDirectory = "var fileDirectory = " + js.Serialize(Soylent.GetAppDirectory() + @"turkit");

            string[] script = File.ReadAllLines(Soylent.GetAppDirectory() + @"turkit\templates\"
                                                + tasktype + @"\" + tasktype + @".data.js");

            int new_lines = 5;

            string[] newScript = new string[new_lines + script.Length];
            newScript[0] = requestLine;
            newScript[1] = paragraphs;
            newScript[2] = debug;
            newScript[3] = numSpaces;
            newScript[4] = fileDirectory;
            Array.Copy(script, 0, newScript, new_lines, script.Length);

            string requestFile = Soylent.GetDataDirectory() + @"active-hits\" + tasktype + @"." + request + ".data.js";

            File.WriteAllLines(requestFile, newScript, Encoding.UTF8);

            string arguments = " -jar " + TURKIT_VERSION + " -f \"" + requestFile + "\" -a " + keys.amazonID + " -s " + keys.secretKey + " -o 100 -h 1000";

            if (Soylent.DEBUG)
            {
                arguments += " -m sandbox";
            }
            else
            {
                arguments += " -m real";
            }

            info = new ProcessInformation("java", arguments, Soylent.GetAppDirectory() + @"\turkit", SHOW_WINDOW);

            TimerCallback callback = ExecuteProcess;
            int           timer    = 60 * 1000;

            if (Soylent.DEBUG)
            {
                timer = 30 * 1000;
            }
            turkitLoopTimer = new Timer(callback, info, 0, timer);  // starts the timer every 60 seconds
        }
コード例 #5
0
 public void startCrowdproofTask(AmazonKeys keys)
 {
     startFindFixVerifyTask("crowdproof", keys);
 }
コード例 #6
0
        public delegate void noKeysDelegate();  // called if we couldn't get keys

        public void startShortnTask(AmazonKeys keys)
        {
            startFindFixVerifyTask("shortn", keys);
        }
コード例 #7
0
 /// <summary>
 /// Asks for Amazon Keys if necessary and then executes the task
 /// </summary>
 /// <param name="taskDelegate"></param>
 public void GetKeysAndExecute(startTaskDelegate taskDelegate, noKeysDelegate cancelDelegate)
 {
     AmazonKeys.AskForAmazonKeys(taskDelegate, cancelDelegate);
 }
コード例 #8
0
        public void cancelTask(AmazonKeys keys)
        {
            // Stop TurKit timer
            stopTurKitTimer();

            // Call the cancelTask() method
            int    request    = hdata.job;
            string cancelLine = "\n" + "cancelTask();";

            if (hdata is ShortnData)
            {
                string requestFile = Soylent.GetAppDirectory() + @"\turkit\active-hits\shortn." + request + ".data.js";
                File.AppendAllText(requestFile, cancelLine);

                string arguments = " -jar " + TURKIT_VERSION + " -f \"" + requestFile + "\" -a " + keys.amazonID + " -s " + keys.secretKey + " -o 100 -h 1000";
                if (Soylent.DEBUG)
                {
                    arguments += " -m sandbox";
                }
                else
                {
                    arguments += " -m real";
                }

                ProcessInformation cancel_info = new ProcessInformation("java", arguments, Soylent.GetAppDirectory() + @"\turkit", SHOW_WINDOW);
                ExecuteProcess(cancel_info);
            }
            else if (hdata is CrowdproofData)
            {
                string requestFile = Soylent.GetDataDirectory() + @"\active-hits\crowdproof." + request + ".data.js";
                File.AppendAllText(requestFile, cancelLine);

                string arguments = " -jar " + TURKIT_VERSION + " -f \"" + requestFile + "\" -a " + keys.amazonID + " -s " + keys.secretKey + " -o 100 -h 1000";
                if (Soylent.DEBUG)
                {
                    arguments += " -m sandbox";
                }
                else
                {
                    arguments += " -m real";
                }

                ProcessInformation cancel_info = new ProcessInformation("java", arguments, Soylent.GetAppDirectory() + @"\turkit", SHOW_WINDOW);
                ExecuteProcess(cancel_info);
            }
            else if (hdata is HumanMacroData)
            {
                string requestFile = Soylent.GetDataDirectory() + @"\active-hits\macro." + request + ".data.js";
                File.AppendAllText(requestFile, cancelLine);

                string arguments = " -jar " + TURKIT_VERSION + " -f \"" + requestFile + "\" -a " + keys.amazonID + " -s " + keys.secretKey + " -o 100 -h 1000";
                if (Soylent.DEBUG)
                {
                    arguments += " -m sandbox";
                }
                else
                {
                    arguments += " -m real";
                }

                ProcessInformation cancel_info = new ProcessInformation("java", arguments, Soylent.GetAppDirectory() + @"\turkit", SHOW_WINDOW);
                ExecuteProcess(cancel_info);
            }
        }
コード例 #9
0
        public void startHumanMacroTask(AmazonKeys keys)
        {
            HumanMacroData data = hdata as HumanMacroData;

            JavaScriptSerializer js = new JavaScriptSerializer();
            string inputs;

            if (data.separator == HumanMacroData.Separator.Paragraph)
            {
                string[] pgraphs;

                if (data.test == HumanMacroData.TestOrReal.Test)
                {
                    pgraphs = new string[1];
                }
                else
                {
                    pgraphs = new string[data.range.Paragraphs.Count];
                }
                for (int i = 0; i < data.range.Paragraphs.Count; i++)
                {
                    Word.Paragraph paragraph = data.range.Paragraphs[i + 1];
                    string         temp      = paragraph.Range.Text;
                    temp       = temp.Trim();
                    pgraphs[i] = temp;

                    /*
                     * Patch patch = new Patch(paragraph.Range, new List<string>());
                     * patch.original = paragraph.Range.Text;
                     */
                    HumanMacroPatch patch = new HumanMacroPatch(paragraph.Range, paragraph.Range.Start - data.range.Start, paragraph.Range.End - data.range.Start);
                    patch.original = paragraph.Range.Text;
                    data.patches.Add(patch);
                    if (data.test == HumanMacroData.TestOrReal.Test)
                    {
                        break;
                    }
                }
                inputs = js.Serialize(pgraphs);
            }
            else
            {
                string[] pgraphs;

                if (data.test == HumanMacroData.TestOrReal.Test)
                {
                    pgraphs = new string[1];
                }
                else
                {
                    pgraphs = new string[data.range.Sentences.Count];
                }
                for (int i = 0; i < data.range.Sentences.Count; i++)
                {
                    Word.Range range = data.range.Sentences[i + 1];

                    string temp = range.Text;
                    // Whitespace characters in the middle of sentences will not be removed
                    temp       = temp.Trim();
                    pgraphs[i] = temp;

                    //Patch patch = new Patch(range, new List<string>());
                    HumanMacroPatch patch = new HumanMacroPatch(range, range.Start - data.range.Start, range.End - data.range.Start);
                    patch.original = range.Text;
                    data.patches.Add(patch);

                    if (data.test == HumanMacroData.TestOrReal.Test)
                    {
                        break;
                    }
                }
                inputs = js.Serialize(pgraphs);
            }

            inputs = "var inputs = " + inputs + ";";

            // figure out whether there are one or two spaces between sentences
            string firstSentence          = data.range.Paragraphs[1].Range.Sentences[1].Text;
            string spacesBetweenSentences = " ";

            if (firstSentence.EndsWith("  "))
            {
                spacesBetweenSentences = "  ";
            }
            data.patchesFound(spacesBetweenSentences);

            string numSpaces = "var sentence_separator = '" + spacesBetweenSentences + "';";

            int request = hdata.job;

            string requestLine = "var soylentJob = " + request + ";";
            string debug       = "var debug = " + (Soylent.DEBUG ? "true" : "false") + ";";

            string reward       = "var reward = " + data.reward + ";";
            string redundancy   = "var redundancy = " + data.redundancy + ";";
            string title        = "var title = '" + data.title + "';";
            string subtitle     = "var subtitle = '" + data.subtitle + "';";
            string instructions = "var instructions = '" + data.instructions + "';";

            string[] script = File.ReadAllLines(Soylent.GetAppDirectory() + @"\turkit\templates\human-macro\macro.data.js");

            int new_lines = 9;

            string[] newScript = new string[new_lines + script.Length];
            newScript[0] = requestLine;
            newScript[1] = inputs;
            newScript[2] = debug;
            newScript[3] = numSpaces;
            newScript[4] = reward;
            newScript[5] = redundancy;
            newScript[6] = title;
            newScript[7] = subtitle;
            newScript[8] = instructions;
            Array.Copy(script, 0, newScript, new_lines, script.Length);

            string requestFile = Soylent.GetDataDirectory() + @"\active-hits\macro." + request + ".data.js";

            File.WriteAllLines(requestFile, newScript, Encoding.UTF8);

            string arguments = " -jar " + TURKIT_VERSION + " -f \"" + requestFile + "\" -a " + keys.amazonID + " -s " + keys.secretKey + " -o 100 -h 1000";

            if (Soylent.DEBUG)
            {
                arguments += " -m sandbox";
            }
            else
            {
                arguments += " -m real";
            }

            //ProcessInformation info = new ProcessInformation("java", arguments, rootDirectory + @"\turkit", Soylent.DEBUG);
            info = new ProcessInformation("java", arguments, Soylent.GetAppDirectory() + @"\turkit", SHOW_WINDOW);

            TimerCallback callback = ExecuteProcess;
            int           timer    = 60 * 1000;

            if (Soylent.DEBUG)
            {
                timer = 30 * 1000;
            }
            turkitLoopTimer = new Timer(callback, info, 0, timer);  // starts the timer every 60 seconds
        }
コード例 #10
0
 private void fillTextField(AmazonKeys keys)
 {
     accessKey.Text = keys.amazonID;
     secretKey.Text = keys.secretKey;
 }