示例#1
0
        /// <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
        /// <summary>
        /// Reads in the AMT secret and key from the amazon.xml file so that HITs can be submitted.
        /// </summary>
        public static void AskForAmazonKeys(TurKit.startTaskDelegate success, TurKit.noKeysDelegate cancel)
        {
            AmazonKeys keys = LoadAmazonKeys();

            if (keys == null)
            {
                Globals.Ribbons.Ribbon.AskForKeys(success, cancel);
            }
            else
            {
                success(keys);
            }
        }
示例#3
0
        public static AmazonKeys LoadAmazonKeys()
        {
            string rootDirectory = Soylent.GetDataDirectory();
            string keyFile       = rootDirectory + @"\amazon.xml";


            if (!File.Exists(keyFile))
            {
                return(null);
            }
            else
            {
                AmazonKeys keys = getKeysFromFile(keyFile);
                return(keys);
            }
        }
示例#4
0
 private void fillTextField(AmazonKeys keys)
 {
     accessKey.Text = keys.amazonID;
     secretKey.Text = keys.secretKey;
 }
示例#5
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);
            }
        }
示例#6
0
 // called if we couldn't get keys
 public void startShortnTask(AmazonKeys keys)
 {
     startFindFixVerifyTask("shortn", keys);
 }
示例#7
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
        }
示例#8
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
        }
示例#9
0
 public void startCrowdproofTask(AmazonKeys keys)
 {
     startFindFixVerifyTask("crowdproof", keys);
 }