コード例 #1
0
ファイル: Form.cs プロジェクト: m2pathan/SemantAPI
        private void btProcess_Click(object sender, EventArgs e)
        {
            if (CancelIfNecessary() || !VerifyInput())
            {
                return;
            }

            try
            {
                ReadTheSource(tbSource.Text, int.Parse(tbDocSize.Text));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            btProcess.Text  = "Cancel";
            btClose.Enabled = false;
            _cancelFlag     = false;

            if (cbSemantria.Checked)
            {
                WriteDebugInfo("Semantria service is checked. Preparing the context...");

                AnalysisExecutionContext semContext = new AnalysisExecutionContext(_documents);
                semContext.ExecutionProgress += ExecutionProgress;
                semContext.Key            = tbSemantriaKey.Text;
                semContext.Secret         = tbSemantriaSecret.Text;
                semContext.Language       = cbLanguage.Text;
                semContext.Format         = DataFormat.JSON;
                semContext.DocumentLength = int.Parse(tbDocSize.Text);
                if (UseDebugMode && Benchmark.Contains("Semantria"))
                {
                    semContext.UseDebugMode = true;
                }
                SemantriaExecutor semExecutor = new SemantriaExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Semantria context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        semExecutor.Execute(semContext);
                        return(null);
                    }), null, out time);

                    WriteDebugInfo("Semantria thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbAlchemy.Checked)
            {
                WriteDebugInfo("Alchemy service is checked. Preparing the context...");

                AnalysisExecutionContext alcContext = new AnalysisExecutionContext(_documents);
                alcContext.ExecutionProgress += ExecutionProgress;
                alcContext.Key = tbAlchemyKey.Text;
                if (UseDebugMode && Benchmark.Contains("Alchemy"))
                {
                    alcContext.UseDebugMode = true;
                }
                AlchemyExecutor alcExecutor = new AlchemyExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Alchemy context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        alcExecutor.Execute(alcContext);
                        return(null);
                    }), null, out time);

                    WriteDebugInfo("Alchemy thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbRepustate.Checked)
            {
                WriteDebugInfo("Repustate service is checked. Preparing the context...");

                AnalysisExecutionContext rsContext = new AnalysisExecutionContext(_documents);
                rsContext.ExecutionProgress += ExecutionProgress;
                rsContext.Key      = tbRepustateKey.Text;
                rsContext.Language = cbLanguage.Text;
                if (UseDebugMode && Benchmark.Contains("Repustate"))
                {
                    rsContext.UseDebugMode = true;
                }
                RepustateExecutor rsExecutor = new RepustateExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Repustate context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        rsExecutor.Execute(rsContext);
                        return(null);
                    }), null, out time);

                    WriteDebugInfo("Repustate thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbChatterbox.Checked)
            {
                WriteDebugInfo("Chatterbox service is checked. Preparing the context...");

                AnalysisExecutionContext cbContext = new AnalysisExecutionContext(_documents);
                cbContext.ExecutionProgress += ExecutionProgress;
                cbContext.Key            = tbChatterboxKey.Text;
                cbContext.Language       = cbLanguage.Text;
                cbContext.DocumentLength = int.Parse(tbDocSize.Text);
                if (UseDebugMode && Benchmark.Contains("Chatterbox"))
                {
                    cbContext.UseDebugMode = true;
                }
                ChatterboxExecutor cbExecutor = new ChatterboxExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Chatterbox context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        cbExecutor.Execute(cbContext);
                        return(null);
                    }), null, out time);

                    WriteDebugInfo("Chatterbox thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbViralheat.Checked)
            {
                WriteDebugInfo("Viralheat service is checked. Preparing the context...");

                AnalysisExecutionContext vhContext = new AnalysisExecutionContext(_documents);
                vhContext.ExecutionProgress += ExecutionProgress;
                vhContext.Key            = tbViralheatKey.Text;
                vhContext.Language       = cbLanguage.Text;
                vhContext.DocumentLength = int.Parse(tbDocSize.Text);
                if (UseDebugMode && Benchmark.Contains("Viralheat"))
                {
                    vhContext.UseDebugMode = true;
                }
                ViralheatExecutor vhExecutor = new ViralheatExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Viralheat context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        vhExecutor.Execute(vhContext);
                        return(null);
                    }), null, out time);

                    WriteDebugInfo("Viralheat thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbBitext.Checked)
            {
                WriteDebugInfo("Bitext service is checked. Preparing the context...");

                AnalysisExecutionContext btContext = new AnalysisExecutionContext(_documents);
                btContext.ExecutionProgress += ExecutionProgress;
                btContext.Key            = tbBitextLogin.Text;
                btContext.Secret         = tbBitextPassword.Text;
                btContext.Language       = cbLanguage.Text;
                btContext.Format         = DataFormat.XML;
                btContext.DocumentLength = int.Parse(tbDocSize.Text);
                if (UseDebugMode && Benchmark.Contains("Bitext"))
                {
                    btContext.UseDebugMode = true;
                }
                BitextExecutor btExecutor = new BitextExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Bitext context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        btExecutor.Execute(btContext);
                        return(null);
                    }), null, out time);

                    WriteDebugInfo("Bitext thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbSkyttle.Checked)
            {
                WriteDebugInfo("Skyttle service is checked. Preparing the context...");

                AnalysisExecutionContext skContext = new AnalysisExecutionContext(_documents);
                skContext.ExecutionProgress += ExecutionProgress;
                skContext.Key      = tbSkyttleKey.Text;
                skContext.Language = cbLanguage.Text;
                if (UseDebugMode && Benchmark.Contains("Skyttle"))
                {
                    skContext.UseDebugMode = true;
                }
                SkyttleExecutor skExecutor = new SkyttleExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Skyttle context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        skExecutor.Execute(skContext);
                        return(null);
                    }), null, out time);

                    WriteDebugInfo("Skyttle thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }
        }
コード例 #2
0
ファイル: Form.cs プロジェクト: RavenB/SemantAPI
        private void btProcess_Click(object sender, EventArgs e)
        {
            if (CancelIfNecessary() || !VerifyInput())
                return;

            try
            {
                ReadTheSource(tbSource.Text, int.Parse(tbDocSize.Text));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            btProcess.Text = "Cancel";
            btClose.Enabled = false;
            _cancelFlag = false;

            if (cbSemantria.Checked)
            {
                WriteDebugInfo("Semantria service is checked. Preparing the context...");

                AnalysisExecutionContext semContext = new AnalysisExecutionContext(_documents);
                semContext.ExecutionProgress += ExecutionProgress;
                semContext.Key = tbSemantriaKey.Text;
                semContext.Secret = tbSemantriaSecret.Text;
                semContext.Language = cbLanguage.Text;
                semContext.Format = DataFormat.JSON;
                semContext.DocumentLength = int.Parse(tbDocSize.Text);
                if (UseDebugMode && Benchmark.Contains("Semantria"))
                    semContext.UseDebugMode = true;
                SemantriaExecutor semExecutor = new SemantriaExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Semantria context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        semExecutor.Execute(semContext);
                        return null;
                    }), null, out time);

                    WriteDebugInfo("Semantria thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbAlchemy.Checked)
            {
                WriteDebugInfo("Alchemy service is checked. Preparing the context...");

                AnalysisExecutionContext alcContext = new AnalysisExecutionContext(_documents);
                alcContext.ExecutionProgress += ExecutionProgress;
                alcContext.Key = tbAlchemyKey.Text;
                if (UseDebugMode && Benchmark.Contains("Alchemy"))
                    alcContext.UseDebugMode = true;
                AlchemyExecutor alcExecutor = new AlchemyExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Alchemy context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        alcExecutor.Execute(alcContext);
                        return null;
                    }), null, out time);

                    WriteDebugInfo("Alchemy thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbRepustate.Checked)
            {
                WriteDebugInfo("Repustate service is checked. Preparing the context...");

                AnalysisExecutionContext rsContext = new AnalysisExecutionContext(_documents);
                rsContext.ExecutionProgress += ExecutionProgress;
                rsContext.Key = tbRepustateKey.Text;
                rsContext.Language = cbLanguage.Text;
                if (UseDebugMode && Benchmark.Contains("Repustate"))
                    rsContext.UseDebugMode = true;
                RepustateExecutor rsExecutor = new RepustateExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Repustate context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        rsExecutor.Execute(rsContext);
                        return null;
                    }), null, out time);

                    WriteDebugInfo("Repustate thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbChatterbox.Checked)
            {
                WriteDebugInfo("Chatterbox service is checked. Preparing the context...");

                AnalysisExecutionContext cbContext = new AnalysisExecutionContext(_documents);
                cbContext.ExecutionProgress += ExecutionProgress;
                cbContext.Key = tbChatterboxKey.Text;
                cbContext.Language = cbLanguage.Text;
                cbContext.DocumentLength = int.Parse(tbDocSize.Text);
                if (UseDebugMode && Benchmark.Contains("Chatterbox"))
                    cbContext.UseDebugMode = true;
                ChatterboxExecutor cbExecutor = new ChatterboxExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Chatterbox context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        cbExecutor.Execute(cbContext);
                        return null;
                    }), null, out time);

                    WriteDebugInfo("Chatterbox thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbViralheat.Checked)
            {
                WriteDebugInfo("Viralheat service is checked. Preparing the context...");

                AnalysisExecutionContext vhContext = new AnalysisExecutionContext(_documents);
                vhContext.ExecutionProgress += ExecutionProgress;
                vhContext.Key = tbViralheatKey.Text;
                vhContext.Language = cbLanguage.Text;
                vhContext.DocumentLength = int.Parse(tbDocSize.Text);
                if (UseDebugMode && Benchmark.Contains("Viralheat"))
                    vhContext.UseDebugMode = true;
                ViralheatExecutor vhExecutor = new ViralheatExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Viralheat context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        vhExecutor.Execute(vhContext);
                        return null;
                    }), null, out time);

                    WriteDebugInfo("Viralheat thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbBitext.Checked)
            {
                WriteDebugInfo("Bitext service is checked. Preparing the context...");

                AnalysisExecutionContext btContext = new AnalysisExecutionContext(_documents);
                btContext.ExecutionProgress += ExecutionProgress;
                btContext.Key = tbBitextLogin.Text;
                btContext.Secret = tbBitextPassword.Text;
                btContext.Language = cbLanguage.Text;
                btContext.Format = DataFormat.XML;
                btContext.DocumentLength = int.Parse(tbDocSize.Text);
                if (UseDebugMode && Benchmark.Contains("Bitext"))
                    btContext.UseDebugMode = true;
                BitextExecutor btExecutor = new BitextExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Bitext context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        btExecutor.Execute(btContext);
                        return null;
                    }), null, out time);

                    WriteDebugInfo("Bitext thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }

            if (cbSkyttle.Checked)
            {
                WriteDebugInfo("Skyttle service is checked. Preparing the context...");

                AnalysisExecutionContext skContext = new AnalysisExecutionContext(_documents);
                skContext.ExecutionProgress += ExecutionProgress;
                skContext.Key = tbSkyttleKey.Text;
                skContext.Language = cbLanguage.Text;
                if (UseDebugMode && Benchmark.Contains("Skyttle"))
                    skContext.UseDebugMode = true;
                SkyttleExecutor skExecutor = new SkyttleExecutor();

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object obj)
                {
                    WriteDebugInfo("Running the dedicated thread for Skyttle context serving...");

                    TimeSpan time = TimeSpan.Zero;
                    BenchmarkHelper.Invoke(new InvokeBenchmarkHandler(delegate(object state)
                    {
                        skExecutor.Execute(skContext);
                        return null;
                    }), null, out time);

                    WriteDebugInfo("Skyttle thread execution time: {0} milliseconds.", time.TotalMilliseconds);
                }), null);
            }
        }