예제 #1
0
        public static void Add(List <string> threadIDList)
        {
            try
            {
                DBProvider.SQLite sqliteProvider = new DBProvider.SQLite("core.db", GlobalVar.THREAD_DATA_CREATE_SQLITE);

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

                sqliteProvider.Close( );
            }
            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);
            }
            catch (Exception ex)
            {
                Utility.WriteErrorLog(ex.Message, Utility.LogSeverity.EXCEPTION);
            }
        }
예제 #2
0
        public static bool RemoveAll( )
        {
            try
            {
                DBProvider.SQLite sqliteProvider = new DBProvider.SQLite("core.db", GlobalVar.NOTIFY_ARTICLE_CREATE_SQLITE);

                sqliteProvider.ExecuteQuery("DELETE FROM ArticleNotification");

                sqliteProvider.Close( );

                return(true);
            }
            catch (System.Data.SQLite.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);

                return(false);
            }
            catch (Exception ex)
            {
                Utility.WriteErrorLog(ex.Message, Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터를 삭제하지 못했습니다, 알 수 없는 오류가 발생했습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);

                return(false);
            }
        }
예제 #3
0
        public static void Save( )
        {
            Main mainForm = Utility.GetMainForm( );

            if (mainForm != null)
            {
                mainForm.MaskShow( );
            }

            try
            {
                DBProvider.SQLite sqliteProvider = new DBProvider.SQLite("core.db", GlobalVar.NOTIFY_ARTICLE_CREATE_SQLITE);

                sqliteProvider.ExecuteQuery("DELETE FROM ArticleNotification");

                foreach (NotifyData i in LISTS)
                {
                    sqliteProvider.ExecuteQuery(
                        string.Format("INSERT INTO ArticleNotification VALUES ( {0}, '{1}', '{2}', '{3}', '{4}', {5}, {6}, '{7}', '{8}', '{9}' )",
                                      i.threadID,
                                      i.threadTitle.Replace("'", "''"),
                                      i.threadAuthor,
                                      i.threadURL,
                                      i.threadTime,
                                      i.threadHit,
                                      i.focused == true ? 1 : 0,
                                      i.personaconURL,
                                      i.articleName,
                                      i.authorRank
                                      )
                        );


                    Application.DoEvents( );
                }

                sqliteProvider.Close( );
            }
            catch (System.Data.SQLite.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 (Exception ex)
            {
                Utility.WriteErrorLog(ex.Message, Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터를 저장하지 못했습니다, 알 수 없는 오류가 발생했습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);
            }
            finally
            {
                if (mainForm != null)
                {
                    mainForm.MaskClose( );
                }
            }
        }
예제 #4
0
 public static void OpenWebPage(string url, Form parent = null)
 {
     try
     {
         Process.Start(url);
     }
     catch (Exception ex)
     {
         WriteErrorLog("WebPageOpenFailed - " + url + " - " + ex.Message, LogSeverity.EXCEPTION);
         NotifyBox.Show(parent, "오류", "죄송합니다, 웹 페이지를 여는 도중 오류가 발생했습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);
     }
 }
예제 #5
0
        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);
            }
        }
예제 #6
0
 public static void OpenImage(string threadNumber)
 {
     if (File.Exists(GlobalVar.CAPTURE_DIR + "\\" + threadNumber + ".png"))
     {
         try
         {
             System.Diagnostics.Process.Start(GlobalVar.CAPTURE_DIR + "\\" + threadNumber + ".png");
         }
         catch (Exception ex)
         {
             Utility.WriteErrorLog(ex.Message, Utility.LogSeverity.EXCEPTION);
             NotifyBox.Show(null, "오류", "죄송합니다, 이미지 파일을 여는 도중 오류가 발생했습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);
         }
     }
     else
     {
         Utility.WriteErrorLog("CaptureImageNotFound", Utility.LogSeverity.ERROR);
         NotifyBox.Show(null, "오류", "죄송합니다, 이 게시물에 대한 캡처된 이미지가 없습니다.", NotifyBoxType.OK, NotifyBoxIcon.Warning);
     }
 }
예제 #7
0
        public static void SetFocused(string threadID, bool newFocusValue)
        {
            //Predicate<NotifyData> finder = ( NotifyData data ) => { return data.threadID == threadNumber; };
            int index = LISTS.FindIndex(( NotifyData data ) =>
            {
                return(data.threadID == threadID);
            });

            if (index > -1 && LISTS?[index] != null)
            {
                NotifyData oldData = LISTS[index];
                oldData.focused = newFocusValue;
                LISTS[index]    = oldData;

                Save( );
            }
            else
            {
                Utility.WriteErrorLog("NotifyIndexError", Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터 조작 중 오류가 발생했습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);
            }
        }
예제 #8
0
        public static void SetData(string threadID, DataSettingDelegate setCallBack)
        {
            int index = LISTS.FindIndex(( NotifyData data ) =>
            {
                return(data.threadID == threadID);
            });

            if (index > -1 && LISTS?[index] != null)
            {
                NotifyData oldData = LISTS[index];

                setCallBack.Invoke(ref oldData);

                LISTS[index] = oldData;

                Save( );
            }
            else
            {
                Utility.WriteErrorLog("NotifyIndexError", Utility.LogSeverity.EXCEPTION);
                NotifyBox.Show(null, "오류", "죄송합니다, 데이터 조작 중 오류가 발생했습니다.", NotifyBoxType.OK, NotifyBoxIcon.Error);
            }
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        public static void Initialize( )
        {
            try
            {
                DBProvider.SQLite sqliteProvider = new DBProvider.SQLite("core.db", GlobalVar.NOTIFY_ARTICLE_CREATE_SQLITE);

                sqliteProvider.ExecuteDataReader("SELECT * FROM ArticleNotification ORDER BY threadID DESC", (System.Data.SQLite.SQLiteDataReader reader) =>
                {
                    LISTS.Add(new NotifyData( )
                    {
                        threadID      = reader["threadID"].ToString( ),
                        threadTitle   = HttpUtility.HtmlDecode(reader["threadTitle"].ToString( )),
                        threadURL     = reader["threadURL"].ToString( ),
                        threadHit     = int.Parse(reader["threadHit"].ToString( )),
                        threadTime    = reader["threadTime"].ToString( ),
                        threadAuthor  = HttpUtility.HtmlDecode(reader["threadAuthor"].ToString( )),
                        personaconURL = reader["personaconURL"].ToString( ),
                        articleName   = reader["articleName"].ToString( ),
                        authorRank    = reader["authorRank"].ToString( ),
                        focused       = reader["focused"].ToString( ) == "1" ? true : false
                    });

                    //newNotifyData.threadID = reader[ "threadID" ].ToString( );
                    //newNotifyData.threadTitle = HttpUtility.HtmlDecode( reader[ "threadTitle" ].ToString( ) );
                    //newNotifyData.threadURL = reader[ "threadURL" ].ToString( );
                    //newNotifyData.threadHit = int.Parse( reader[ "threadHit" ].ToString( ) );

                    //newNotifyData.threadTime = reader[ "threadTime" ].ToString( );
                    //newNotifyData.threadAuthor = reader[ "threadAuthor" ].ToString( );
                    //newNotifyData.personaconURL = reader[ "personaconURL" ].ToString( );
                    //newNotifyData.articleName = reader[ "articleName" ].ToString( );
                    //newNotifyData.authorRank = reader[ "authorRank" ].ToString( );

                    //if ( reader[ "focused" ] != null )
                    //	newNotifyData.focused = reader[ "focused" ].ToString( ) == "1" ? true : false;
                    //else
                    //	newNotifyData.focused = false;

                    return(true);
                });

                sqliteProvider.Close( );
                RefreshMainNotifyPanel( );
                //foreach( JsonObjectCollection i in collection )
                //{
                //	NotifyData newNotifyData = new NotifyData( );
                //	newNotifyData.threadID = i[ "threadID" ].GetValue( ).ToString( );
                //	newNotifyData.threadTitle = HttpUtility.HtmlDecode( i[ "threadTitle" ].GetValue( ).ToString( ) );
                //	newNotifyData.threadURL = i[ "threadURL" ].GetValue( ).ToString( );
                //	newNotifyData.threadHit = int.Parse( i[ "threadHit" ].GetValue( ).ToString( ) );

                //	newNotifyData.threadTime = i[ "threadTime" ].GetValue( ).ToString( );
                //	newNotifyData.threadAuthor = i[ "threadAuthor" ].GetValue( ).ToString( );
                //	newNotifyData.personaconURL = i[ "personaconURL" ].GetValue( ).ToString( );
                //	newNotifyData.articleName = i[ "articleName" ].GetValue( ).ToString( );
                //	newNotifyData.authorRank = i[ "authorRank" ].GetValue( ).ToString( );

                //	if ( i[ "focused" ] != null )
                //		newNotifyData.focused = bool.Parse( i[ "focused" ].GetValue( ).ToString( ) );
                //	else
                //		newNotifyData.focused = false;

                //	LISTS.Add( newNotifyData );
                //}
            }
            catch (System.Data.SQLite.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 ( FormatException ex )
            //{
            //	Utility.WriteErrorLog( "FormatException - " + 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);
            }
        }