コード例 #1
0
ファイル: Core.cs プロジェクト: ReguMaster/CafeMaster
        public static void Initialize(bool force = true)
        {
            try
            {
                if (!Directory.Exists(GlobalVar.DATA_DIR))
                {
                    Directory.CreateDirectory(GlobalVar.DATA_DIR);
                }

                Notify.Initialize( );

                if (force)                   // 데이터 파일이 없을 시
                {
                    NaverRequest.New("http://cafe.naver.com/ArticleList.nhn?search.clubid=" + GlobalVar.CAFE_ID + "&search.boardtype=L&userDisplay=15", NaverRequest.RequestMethod.GET, Encoding.Default, (value) =>
                    {
                        DBProvider.SQLite sqliteProvider = new DBProvider.SQLite("core.db", GlobalVar.THREAD_DATA_CREATE_SQLITE);

                        List <TableDataTable> dataTable = Parse.TotalArticlePageCrawling(value);

                        foreach (TableDataTable i in dataTable)
                        {
                            sqliteProvider.ExecuteQuery("INSERT OR IGNORE INTO ThreadIDStored ( id ) VALUES ( " + i.number + " )");
                        }

                        sqliteProvider.Close( );

                        TopProgressMessage.End( );
                    }, ( Exception ex ) =>
                    {
                        NotifyBox.Show(null, "오류", "죄송합니다, 데이터를 불러오지 못했습니다.\n\n" + ex.Message + " (0x" + (ex.HResult > 0 ? ex.HResult : 0) + ")", NotifyBoxType.OK, NotifyBoxIcon.Error);
                    });
                }
            }
            catch (SQLiteException ex)
            {
                Utility.WriteErrorLog("SQLiteException - " + ex.Message, Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터를 불러오지 못했습니다, SQLite 오류입니다.\n\n" + ex.Message + " (0x" + (ex.ErrorCode > 0 ? ex.ErrorCode : 0) + ")", NotifyBoxType.OK, NotifyBoxIcon.Error);
            }
            catch (IOException ex)
            {
                Utility.WriteErrorLog("IOException - " + ex.Message, Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터를 불러오지 못했습니다, 파일 접근 오류가 발생했습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);
            }
            catch (Exception ex)
            {
                Utility.WriteErrorLog(ex.Message, Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터를 불러오지 못했습니다, 알 수 없는 오류가 발생했습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);
            }
        }
コード例 #2
0
ファイル: Core.cs プロジェクト: ReguMaster/CafeMaster
        private static async void RefreshAsync(object status)
        {
            if (WORKING)
            {
                return;
            }

            WORKING = true;

            bool ignoreBottomLine = false;

            try
            {
                int           currentArticlePage  = 1;      // 현재 게시판 페이지
                bool          newThreadFound      = false;
                List <string> newThreadNumberTemp = new List <string>( );
                string[]      savedDataTable      = ThreadDataStore.Get( ); // 최적화 필요;

                if (savedDataTable.Length <= 0)                             // Need to test
                {
                    Utility.WriteErrorLog("savedDataTable 길이가 0입니다, DB가 정상적으로 생성되지 않았을 수 있습니다.", Utility.LogSeverity.ERROR);
                    TopProgressMessage.Set("새로운 게시물을 확인하는 중 오류가 발생했습니다.");

                    WORKING = false;

                    ThreadDataStore.Initialize(true);

                    throw new FormatException("DB가 정상적으로 생성되지 않았습니다, 프로그램을 재시작하세요.");
                }

searchThreadPage:                                 // 페이지 루프를 위한 goto

                int newThreadCount = 0;

                TopProgressMessage.Set("새로운 게시물을 확인하고 있습니다 ... [" + currentArticlePage + " 페이지]");

                NaverRequest.New("http://cafe.naver.com/ArticleList.nhn?search.clubid=" + GlobalVar.CAFE_ID + "&search.boardtype=L&search.page=" + currentArticlePage, NaverRequest.RequestMethod.GET, Encoding.Default, (value) =>
                {
                    List <TableDataTable> newDataTable = Parse.TotalArticlePageCrawling(value);

                    for (int i = 0; i < newDataTable.Count; i++)
                    {
                        bool dataStoreFound = false;

                        for (int i2 = 0; i2 < savedDataTable.Length; i2++)
                        {
                            if (newDataTable[i].number == savedDataTable[i2])
                            {
                                dataStoreFound = true;
                                break;
                            }
                        }

                        if (!dataStoreFound)                           // 새로운 글
                        {
                            if (Notify.Exists(newDataTable[i].number))
                            {
                                continue;
                            }

                            if (!newThreadFound)
                            {
                                newThreadFound = true;
                            }

                            TopProgressMessage.Set("#" + newDataTable[i].number + " 게시글의 정보를 불러오고 있습니다 ... [1/3]");

                            newThreadNumberTemp.Add(newDataTable[i].number);

                            Notify.Add(newDataTable[i]);

                            newThreadCount++;
                        }
                    }
                }, ( Exception ex ) =>
                {
                    Utility.WriteErrorLog(ex.Message, Utility.LogSeverity.EXCEPTION);

                    if (ex is WebException)
                    {
                        if ((( WebException )ex).Response == null)
                        {
                            TopProgressMessage.Set("새로운 게시물을 불러올 수 없습니다, 컴퓨터가 네트워크에 연결되지 않았습니다.", true);
                            TopProgressMessage.SetType(Main.NetworkStatus.Error);
                        }
                        else
                        {
                            TopProgressMessage.Set("새로운 게시물을 불러올 수 없습니다, 네트워크 오류가 발생했습니다.", true);
                            TopProgressMessage.SetType(Main.NetworkStatus.Error);
                        }
                    }
                    else
                    {
                        TopProgressMessage.Set("새로운 게시물을 불러올 수 없습니다.", true);
                        TopProgressMessage.SetType(Main.NetworkStatus.Error);
                    }

                    ignoreBottomLine = true;
                });

                if (ignoreBottomLine)
                {
                    WORKING = false;
                    return;
                }

                if (newThreadCount >= 15)                   // 기본 설정으로 게시판 한 페이지 당 15개의 글이 있음, 이상으로 글이 있을 시 새로운 글이 다음 페이지에 있을 수 있으므로 다음 페이지도 검색
                {
                    currentArticlePage++;
                    goto searchThreadPage;
                }

                if (newThreadFound)
                {
                    ThreadDataStore.Add(newThreadNumberTemp);
                    Notify.Sort( );

                    Utility.FlashWindow.Flash( );                     // 작업표시줄 하이라이트 처리

                    if (Config.Get("SoundEnable", "1") == "1")
                    {
                        SoundNotify.PlayNotify( );
                    }
                }

                await Task.Delay(1000);

                TopProgressMessage.End( );

                WORKING = false;
            }
            catch (FormatException ex)
            {
                Utility.WriteErrorLog(ex.Message, Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터를 불러오지 못했습니다.\n\n" + ex.Message + " (0x" + (ex.HResult > 0 ? ex.HResult : 0) + ")", NotifyBoxType.OK, NotifyBoxIcon.Error);
                System.Windows.Forms.Application.Exit( );
            }
            catch (Exception ex)
            {
                Utility.WriteErrorLog(ex.Message, Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터를 불러오지 못했습니다.\n\n" + ex.Message + " (0x" + (ex.HResult > 0 ? ex.HResult : 0) + ")", NotifyBoxType.OK, NotifyBoxIcon.Error);
            }
        }
コード例 #3
0
        public static void Add(TableDataTable table)
        {
            string threadID = table.number;

            NotifyData data = new NotifyData( );

            data.threadTitle = HttpUtility.HtmlDecode(table.title);
            data.threadID    = table.number;
            data.threadURL   = table.url;
            data.threadHit   = table.hit;
            data.focused     = false;

            TopProgressMessage.Set("#" + threadID + " 게시글의 정보를 불러오고 있습니다 ... [2/3]");

            ThreadDetailStruct?detailStruct = NaverRequest.GetSpecificThreadDetail(threadID);

            if (detailStruct.HasValue)
            {
                data.threadAuthor  = detailStruct.Value.threadAuthor;
                data.threadTime    = detailStruct.Value.threadTime;
                data.personaconURL = detailStruct.Value.personaconURL;
                data.articleName   = detailStruct.Value.articleName;
                data.authorRank    = detailStruct.Value.authorRank;
            }
            else
            {
                data.threadAuthor  = "NULL(NULL)";
                data.threadTime    = "00:00";
                data.personaconURL = "";
                data.articleName   = "알 수 없음";
                data.authorRank    = "새싹멤버";
            }

            LISTS.Insert(0, data);

            //await Task.Run( new Action( ( ) => Advice.CheckThread( data ) ) );
            //Advice.CheckThread( data );

            if (Config.Get("CaptureEnable", "1") == "1")
            {
                TopProgressMessage.Set("#" + threadID + " 게시글을 캡처하고 있습니다 ... [3/3]");

                Main mainForm = Utility.GetMainForm( );

                if (mainForm != null)
                {
                    if (mainForm.InvokeRequired)
                    {
                        mainForm.Invoke(new Action(() => BrowserCapture.Capture(threadID)));
                    }
                    else
                    {
                        BrowserCapture.Capture(threadID);
                    }
                }
            }
            else
            {
                TopProgressMessage.Set("#" + threadID + " 게시글을 설정에 의해 캡처하지 않습니다. [3/3]");
            }
        }