예제 #1
0
        private static void Main(string[] p_Args)
        {
            Startup.Start();

            s_HttpDownloader = new HttpDownloader();
            s_Configuration  = new Configuration();
            s_Response       = new G2CoveoResponse();

            //First of all, we load the connector configuration file.
            if (!File.Exists(m_ConfigFilePath))
            {
                //We cannot work without a configuration file.
                m_Logger.Fatal("ConnectorConfig.json file not found, closing now.");
                return;
            }
            else if (!UpdateAndValidateConfig())
            {
                //Something is not right with the configuration file.
                m_Logger.Fatal("ConnectorConfig.json file has definition error(s), closing now.");
                return;
            }

            // Only create a new log file if one hasn't been created today
            m_Logger = new SimpleLogger(s_Configuration, true);

            string ListeningRecordsUrl = "http://" + s_Configuration.ListeningHost + ":" + s_Configuration.ListeningPort + "/xmlfeed/";
            string ListeningGroupsUrl  = "http://" + s_Configuration.ListeningHost + ":" + s_Configuration.ListeningPort + "/xmlgroups/";

            //Make sure the TEMP_FOLDER has been created before we start
            try
            {
                Directory.CreateDirectory(s_Configuration.TempFolder);
            } catch
            {
                m_Logger.Fatal("Not able to create TEMP_FOLDER.");
                return;
            }

            WebServer webServer = new WebServer(ProcessRequestForFeed, ProcessFeed, ListeningRecordsUrl);

            webServer.Run();
            WebServer webServerGroups = new WebServer(ProcessRequestForGroups, ProcessGroups, ListeningGroupsUrl);

            webServerGroups.Run();

            Console.ReadKey();

            s_HttpDownloader.Dispose();
            webServer.Stop();
            webServerGroups.Stop();
        }
예제 #2
0
        private void Download()
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("Download Url is empty");
                return;
            }

            var dlg = new SaveFileDialog();

            dlg.FileName    = "download.dat";
            dlg.Filter      = "Download File(*.dat)|*.dat|*|*.*";
            dlg.FilterIndex = 1;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                dlg.Dispose();
                return;
            }
            var file = dlg.FileName;

            dlg.Dispose();

            if (string.IsNullOrEmpty(file))
            {
                return;
            }

            downloader_ = new HttpDownloader();
            downloader_.download_url  = textBox1.Text;
            downloader_.savefilepath  = dlg.FileName;
            downloader_.update_event += (msg, s, c, t, r) =>
            {
                if (s == HttpDownloader.Status.kDownloading)
                {
                    progressBar1.Value = (int)(c * progressBar1.Maximum / t);
                    label2.Text        = progressBar1.Value.ToString() + "%";
                    if (t > 0)
                    {
                        label3.Text = c.ToString() + " / " + t.ToString();
                    }
                    else
                    {
                        label3.Text = c.ToString();
                    }
                    label3.Text = label3.Text + "  " + r.ToString();
                }
                else if (s == HttpDownloader.Status.kComplete)
                {
                    progressBar1.Value = progressBar1.Maximum;
                    label2.Text        = "Finish";

                    if (t > 0)
                    {
                        c           = t;
                        label3.Text = c.ToString() + " / " + t.ToString();
                    }
                    else
                    {
                        label3.Text = c.ToString();
                    }

                    button1.Text = "Download";
                    downloader_.Dispose();
                    downloader_ = null;
                }
                else if (s >= HttpDownloader.Status.kAborted)
                {
                    label2.Text = s.ToString();
                }
            };

            button1.Text = "Abort";
            downloader_.Start();
        }