예제 #1
0
        private void CheckForUpdateThread(object param)
        {
            Logger.Log("CheckForUpdate - thread started");

            Stopwatch sw = new Stopwatch();

            sw.Start();

            bool   succeed        = false;
            double version        = 0;
            bool   updateRequired = false;
            string url            = "";
            string message        = "";

            try
            {
                string requrl = param.ToString();

                using (HttpWebUtility http = new HttpWebUtility(5 * 1000, false, 0))
                {
                    Logger.Log("CheckForUpdate - open url: {0}", requrl);

                    ExceptionTester.Instance.Throw("checkforupdatethread");

                    http.OpenUrl(requrl, null);

                    string res = http.GetHtmlContent();

                    Logger.DLog("CheckForUpdate - http: {0}", res);

                    // parse file
                    string[] lines = res.Split('\n');

                    if (lines.Length == 4)
                    {
                        if (double.TryParse(lines[1], out version))
                        {
                            succeed = true;
                            url     = lines[2];
                            message = lines[3];

                            // check version
                            double curVersion = 0;

                            if (double.TryParse(About.Version, out curVersion))
                            {
                                if (version > curVersion)
                                {
                                    updateRequired = true;
                                }
                            }
                            else
                            {
                                Logger.Warn("cannot parse current version: {0}", version);
                            }
                        }
                        else
                        {
                            Logger.Warn("cannot parse version number: {0}", lines[1]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                Logger.Warn("CheckForUpdate - exception while http!");
            }

            CheckForUpdateResultHandler(succeed, updateRequired, version, url, message);

            sw.Stop();

            Logger.Log("CheckForUpdate - elapsed: {0}", sw.ElapsedMilliseconds);
        }
예제 #2
0
        private void RakerThread(object param)
        {
            int threadId = (int)param;

            Logger.Log("thread{0}: started", threadId);

            try
            {
                using(HttpWebUtility http = new HttpWebUtility())
                {
                    UrlPair urlpair = null;

                    while((urlpair = GetNextUrl()) != null)
                    {
                        string filepath = filePathMaker.MakeFilePath(urlpair.Url, fileNameMakingMethod);
                        bool reportSucceed = true;

                        urlpair.Filename = filepath;

                        Logger.Log("    thread{0}: saving url: {1} to file: {2} (referer: {3})", threadId, urlpair.Url, filepath, urlpair.RefererUrl);

                        if (!AllowOverwrite() && File.Exists(filepath))
                        {
                            // duplicated
                            Logger.Log("    thread{0}: file already exists! continue to next url.", threadId);

                            urlpair.Result = UrlPair.SaveResult.Duplicated;
                            numOfDuplicated++;
                            reportSucceed = false;
                        }
                        else
                        {
                            try
                            {
                                http.SaveContentToFile(urlpair.Url, filepath, urlpair.RefererUrl);

                                ExceptionTester.Instance.Throw("exception");
                            }
                            catch (ThreadAbortException ex)
                            {
                                Logger.Warn("	thread{0}: ThreadAbortException raised.", threadId);

                                throw;
                            }
                            catch (Exception ex)
                            {
                                Logger.Warn("	thread{0}: exception has occured during saving image. '{1}'. try again, using encoded refererurl",
                                    threadId, ex.Message);

                                // try again, using encoded refererurl
                                try
                                {
                                    // refererUrl에 한글이 포함되어있으면 exception이 발생하므로 인코딩 해줘야 함.
                                    http.SaveContentToFile(urlpair.Url, filepath, HttpUtility.UrlEncode(urlpair.RefererUrl));

                                    ExceptionTester.Instance.Throw("savecontenttofile");
                                }
                                catch (ThreadAbortException ex2)
                                {
                                    Logger.Warn("	thread{0}: ThreadAbortException raised.", threadId);

                                    throw;
                                }
                                catch (Exception ex2)
                                {
                                    Logger.Warn("	thread{0}: exception has occured during saving image. '{1}'", threadId, ex2.Message);

                                    reportSucceed = false;
                                }
                            }

                            if (reportSucceed)
                            {
                                Logger.Log("	thread{0}: {1} saved.", threadId, filepath);

                                urlpair.Result = UrlPair.SaveResult.Saved;

                                lock (lockThis)
                                {
                                    numOfSucceed++;
                                }
                            }
                            else
                            {
                                Logger.Warn("	thread{0}: {1} save failed.", threadId, filepath);

                                urlpair.Result = UrlPair.SaveResult.Failed;

                                lock (lockThis)
                                {
                                    numOfFailed++;
                                }
                            }
                        }

                        // notify
                        lock(lockThis)
                        {
                            if (Progress != null)
                            {
                                // this.currentUrlIndex를 사용하지 않는 이유는, 전부 다 돼서 current == url.length인데,
                                // 락에 걸려서 progressbar performstep은 아직 다 안됐을 경우 자연스럽게 보이기 위함.
                                Progress(urlpair.Url, reportSucceed, urls.Count);
                            }
                        }
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                Logger.Warn("thread{0}: ThreadAbortException raised. aborting thread.", threadId);
            }
            catch (Exception ex)
            {
                Logger.Warn("thread{0}: exception has occured in work thread. '{1}'", threadId, ex.Message);
            }
            finally
            {
                Logger.Log("thread{0}: terminated.", threadId);
                this.manualEvents[threadId].Set();
            }
        }
예제 #3
0
        private void RakerThread(object param)
        {
            int threadId = (int)param;

            Logger.Log("thread{0}: started", threadId);

            try
            {
                using (HttpWebUtility http = new HttpWebUtility())
                {
                    UrlPair urlpair = null;

                    while ((urlpair = GetNextUrl()) != null)
                    {
                        string filepath      = filePathMaker.MakeFilePath(urlpair.Url, fileNameMakingMethod);
                        bool   reportSucceed = true;

                        urlpair.Filename = filepath;

                        Logger.Log("    thread{0}: saving url: {1} to file: {2} (referer: {3})", threadId, urlpair.Url, filepath, urlpair.RefererUrl);

                        if (!AllowOverwrite() && File.Exists(filepath))
                        {
                            // duplicated
                            Logger.Log("    thread{0}: file already exists! continue to next url.", threadId);

                            urlpair.Result = UrlPair.SaveResult.Duplicated;
                            numOfDuplicated++;
                            reportSucceed = false;
                        }
                        else
                        {
                            try
                            {
                                http.SaveContentToFile(urlpair.Url, filepath, urlpair.RefererUrl);

                                ExceptionTester.Instance.Throw("exception");
                            }
                            catch (ThreadAbortException ex)
                            {
                                Logger.Warn("	thread{0}: ThreadAbortException raised.", threadId);

                                throw;
                            }
                            catch (Exception ex)
                            {
                                Logger.Warn("	thread{0}: exception has occured during saving image. '{1}'. try again, using encoded refererurl",
                                            threadId, ex.Message);

                                // try again, using encoded refererurl
                                try
                                {
                                    // refererUrl에 한글이 포함되어있으면 exception이 발생하므로 인코딩 해줘야 함.
                                    http.SaveContentToFile(urlpair.Url, filepath, HttpUtility.UrlEncode(urlpair.RefererUrl));

                                    ExceptionTester.Instance.Throw("savecontenttofile");
                                }
                                catch (ThreadAbortException ex2)
                                {
                                    Logger.Warn("	thread{0}: ThreadAbortException raised.", threadId);

                                    throw;
                                }
                                catch (Exception ex2)
                                {
                                    Logger.Warn("	thread{0}: exception has occured during saving image. '{1}'", threadId, ex2.Message);

                                    reportSucceed = false;
                                }
                            }

                            if (reportSucceed)
                            {
                                Logger.Log("	thread{0}: {1} saved.", threadId, filepath);

                                urlpair.Result = UrlPair.SaveResult.Saved;

                                lock (lockThis)
                                {
                                    numOfSucceed++;
                                }
                            }
                            else
                            {
                                Logger.Warn("	thread{0}: {1} save failed.", threadId, filepath);

                                urlpair.Result = UrlPair.SaveResult.Failed;

                                lock (lockThis)
                                {
                                    numOfFailed++;
                                }
                            }
                        }

                        // notify
                        lock (lockThis)
                        {
                            if (Progress != null)
                            {
                                // this.currentUrlIndex를 사용하지 않는 이유는, 전부 다 돼서 current == url.length인데,
                                // 락에 걸려서 progressbar performstep은 아직 다 안됐을 경우 자연스럽게 보이기 위함.
                                Progress(urlpair.Url, reportSucceed, urls.Count);
                            }
                        }
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                Logger.Warn("thread{0}: ThreadAbortException raised. aborting thread.", threadId);
            }
            catch (Exception ex)
            {
                Logger.Warn("thread{0}: exception has occured in work thread. '{1}'", threadId, ex.Message);
            }
            finally
            {
                Logger.Log("thread{0}: terminated.", threadId);
                this.manualEvents[threadId].Set();
            }
        }
예제 #4
0
        private void ReportThread(object param)
        {
            Logger.Log("UsageReporter - thread started");

            // send info to server
            Stopwatch sw = new Stopwatch();

            sw.Start();

            // make post string
            Pair <Dictionary <string, string>, string> pairparam = param as Pair <Dictionary <string, string>, string>;
            Dictionary <string, string> post = null;
            string reportUrl = null;

            if (pairparam != null)
            {
                post      = pairparam.First as Dictionary <string, string>;
                reportUrl = pairparam.Second as string;
            }

            if (post == null || reportUrl == null)
            {
                Logger.Warn("invalid report param");

                return;
            }

            string postString = "";

            int count = 0;

            foreach (KeyValuePair <string, string> kvp in post)
            {
                string key   = kvp.Key;
                string value = kvp.Value;

                postString += string.Format("{0}={1}", key, HttpUtility.UrlEncode(value));

                if (count != post.Count - 1)
                {
                    postString += "&";
                }

                count++;
            }

            //Logger.DLog("UsageReporter - url: {0}, poststring: {1}", reportUrl, postString);
            Logger.DLog("UsageReporter - url: {0}, post: {1}", reportUrl, postString);

            bool uploaded = false;

            // upload
            try
            {
                using (HttpWebUtility http = new HttpWebUtility(5 * 1000, false, 0))
                {
                    http.OpenUrl(reportUrl, null, postString);

                    ExceptionTester.Instance.Throw("reportthread");

                    string res = http.GetHtmlContent();

                    Logger.DLog("UsageReporter - http: {0}", res);

                    if (res.Contains("<OK>"))
                    {
                        uploaded = true;
                    }
                }
            }
            catch (Exception)
            {
                Logger.Warn("UsageReporter - cannot upload usage report!");
            }

            sw.Stop();

            Logger.Log("UsageReporter - report result: {0}, elapsed: {1}", uploaded, sw.ElapsedMilliseconds);
        }
예제 #5
0
        private void CheckForUpdateThread(object param)
        {
            Logger.Log("CheckForUpdate - thread started");

            Stopwatch sw = new Stopwatch();
            sw.Start();

            bool succeed = false;
            double version = 0;
            bool updateRequired = false;
            string url = "";
            string message = "";

            try
            {
                string requrl = param.ToString();

                using (HttpWebUtility http = new HttpWebUtility(5 * 1000, false, 0))
                {
                    Logger.Log("CheckForUpdate - open url: {0}", requrl);

                    ExceptionTester.Instance.Throw("checkforupdatethread");

                    http.OpenUrl(requrl, null);

                    string res = http.GetHtmlContent();

                    Logger.DLog("CheckForUpdate - http: {0}", res);

                    // parse file
                    string[] lines = res.Split('\n');

                    if (lines.Length == 4)
                    {
                        if (double.TryParse(lines[1], out version))
                        {
                            succeed = true;
                            url = lines[2];
                            message = lines[3];

                            // check version
                            double curVersion = 0;

                            if (double.TryParse(About.Version, out curVersion))
                            {
                                if (version > curVersion)
                                {
                                    updateRequired = true;
                                }
                            }
                            else
                            {
                                Logger.Warn("cannot parse current version: {0}", version);
                            }
                        }
                        else
                        {
                            Logger.Warn("cannot parse version number: {0}", lines[1]);
                        }
                    }

                }
            }
            catch (Exception)
            {
                Logger.Warn("CheckForUpdate - exception while http!");
            }

            CheckForUpdateResultHandler(succeed, updateRequired, version, url, message);

            sw.Stop();

            Logger.Log("CheckForUpdate - elapsed: {0}", sw.ElapsedMilliseconds);
        }
예제 #6
0
        private void ReportThread(object param)
        {
            Logger.Log("UsageReporter - thread started");

            // send info to server
            Stopwatch sw = new Stopwatch();
            sw.Start();

            // make post string
            Pair<Dictionary<string, string>, string> pairparam = param as Pair<Dictionary<string, string>, string>;
            Dictionary<string, string> post = null;
            string reportUrl = null;

            if(pairparam != null)
            {
                post = pairparam.First as Dictionary<string, string>;
                reportUrl = pairparam.Second as string;
            }

            if(post == null || reportUrl == null)
            {
                Logger.Warn("invalid report param");

                return;
            }

            string postString = "";

            int count = 0;
            foreach (KeyValuePair<string, string> kvp in post)
            {
                string key = kvp.Key;
                string value = kvp.Value;

                postString += string.Format("{0}={1}", key, HttpUtility.UrlEncode(value));

                if (count != post.Count - 1)
                {
                    postString += "&";
                }

                count++;
            }

            //Logger.DLog("UsageReporter - url: {0}, poststring: {1}", reportUrl, postString);
            Logger.DLog("UsageReporter - url: {0}, post: {1}", reportUrl, postString);

            bool uploaded = false;

            // upload
            try
            {
                using(HttpWebUtility http = new HttpWebUtility(5 * 1000, false, 0))
                {
                    http.OpenUrl(reportUrl, null, postString);

                    ExceptionTester.Instance.Throw("reportthread");

                    string res = http.GetHtmlContent();

                    Logger.DLog("UsageReporter - http: {0}", res);

                    if (res.Contains("<OK>"))
                    {
                        uploaded = true;
                    }
                }
            }
            catch (Exception)
            {
                Logger.Warn("UsageReporter - cannot upload usage report!");
            }

            sw.Stop();

            Logger.Log("UsageReporter - report result: {0}, elapsed: {1}", uploaded, sw.ElapsedMilliseconds);
        }