Ejemplo n.º 1
0
        private async void GetRevisionData()
        {
            await Task.Run(async() =>
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    RevisionProgressBar.Visibility = Visibility.Visible;
                });

                const string URL = @"https://costudio1122.blogspot.com/p/standard-korean-dictionary-revisions.html";

                HtmlWeb client        = new HtmlWeb();
                HtmlDocument document = client.Load(URL);

                HtmlNodeCollection revisions = document.DocumentNode.SelectNodes("//revision");
                HtmlNode versionTarget       = null;

                foreach (HtmlNode revisionNode in revisions)
                {
                    if (revisionNode.Attributes["version"].Value == "1")
                    {
                        versionTarget = revisionNode;
                        break;
                    }
                }

                if (versionTarget == null)
                {
                    throw new Exception("올바른 versionTarget이 없습니다.");
                }

                HtmlNodeCollection years = versionTarget.SelectNodes("./year");
                foreach (HtmlNode yearNode in years)
                {
                    RevisionCollection year = new RevisionCollection(yearNode.Attributes["year"].Value);

                    HtmlNodeCollection articles = yearNode.SelectNodes("./a");
                    foreach (HtmlNode articleNode in articles)
                    {
                        year.Add(articleNode.InnerText, articleNode.Attributes["href"].Value);
                    }

                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        collections.Add(year);
                    });
                }

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    RevisionProgressBar.Visibility = Visibility.Collapsed;
                    RevisionPivot.Visibility       = Visibility.Visible;
                });
            }).ContinueWith(async(t) =>
            {
                if (t.IsFaulted)
                {
                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        RevisionProgressBar.Visibility = Visibility.Collapsed;
                        NetNoticeGrid.Visibility       = Visibility.Visible;
                    });
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes the SQL statment over the Data Base connected
        /// </summary>
        /// <param name="onSql">This parameter has the current SQL statment</param>
        /// <param name="onFilterList">List of filters to check</param>
        /// <param name="comparer">This parameter has all the information refering to the order criteria to add to SQL statment</param>
        /// <param name="startRowOid">This parameter has the OID necessary to start the search</param>
        /// <param name="blockSize">This parameter represents the number of instances to be returned</param>
        public override ONCollection ExecuteSql(ONSql onSql, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria orderCriteria, ONOid startRowOid, int blockSize)
        {
            RevisionCollection lQuery = null;
            bool lWithStartRow        = (startRowOid != null).TypedValue;
            long lCount = -1;

            if (!lWithStartRow)
            {
                lCount = 0;
            }

            IDataReader     lDataReader      = null;
            ONSQLConnection lOnSQLConnection = null;

            try
            {
                lDataReader = Execute(onSql) as IDataReader;

                RevisionInstance lInstance    = null;
                RevisionInstance lAntInstance = null;
                if (lDataReader != null)
                {
                    object[] lColumns;
                    if (displaySet == null)
                    {
                        lColumns = new object[6];
                    }
                    else
                    {
                        lColumns = new object[displaySet.ElementsInData];
                    }

                    lQuery = new RevisionCollection(OnContext);
                    bool lFoundStartRow = false;
                    while (lDataReader.Read())
                    {
                        lAntInstance = lInstance;

                        // Read Columns
                        lDataReader.GetValues(lColumns);

                        // Read Instance
                        int lIndex = 0;
                        lInstance = LoadFacet(OnContext, displaySet, lColumns, ref lIndex);

                        // Read related attributes
                        if (displaySet != null)
                        {
                            LoadRelated(OnContext, displaySet, lColumns, lIndex, lInstance);
                        }

                        if (lCount >= 0)                         // Add the load instance
                        {
                            if ((onFilterList == null) || (!onFilterList.InMemory))
                            {
                                // Add to the Instance list
                                lQuery.Add(lInstance);
                                lCount++;
                            }
                            else
                            {
                                ONSQLConnection lSQLConnectionOld = (ONSQLConnection)lInstance.OnContext.SqlConnection;

                                // Set another connection because it is imposible to use
                                // the same connection that is used in the DataReader
                                if (lOnSQLConnection == null)
                                {
                                    lOnSQLConnection = GetConnection();
                                }
                                lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                if (onFilterList.FilterInMemory(lInstance))
                                {
                                    // Add to the Instance list
                                    lQuery.Add(lInstance);
                                    lCount++;
                                }

                                lInstance.OnContext.SqlConnection = lSQLConnectionOld;
                            }
                        }
                        else
                        {
                            if ((orderCriteria != null) && (orderCriteria.InMemory))                             // Need to load for ordering in memory after loading
                            {
                                if (lAntInstance != null)
                                {
                                    // Set another connection because it is imposible to use
                                    // the same connection that is used in the DataReader
                                    ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection;
                                    if (lOnSQLConnection == null)
                                    {
                                        lOnSQLConnection = GetConnection();
                                    }
                                    lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                    int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance);
                                    if (lCompare != 0)
                                    {
                                        if (lFoundStartRow)
                                        {
                                            lCount = 1;
                                        }
                                        else
                                        {
                                            lQuery.Clear();
                                        }
                                    }

                                    // Restores the old connection
                                    lInstance.OnContext.SqlConnection = lOnSQLConnectionOld;
                                }

                                if ((onFilterList == null) || (!onFilterList.InMemory))
                                {
                                    // Add to the Instance list
                                    lQuery.Add(lInstance);
                                }
                                else
                                {
                                    ONSQLConnection lSQLConnectionOld = (ONSQLConnection)lInstance.OnContext.SqlConnection;

                                    // Set another connection because it is imposible to use
                                    // the same connection that is used in the DataReader
                                    if (lOnSQLConnection == null)
                                    {
                                        lOnSQLConnection = GetConnection();
                                    }
                                    lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                    if (onFilterList.FilterInMemory(lInstance))
                                    {
                                        // Add to the Instance list
                                        lQuery.Add(lInstance);
                                    }
                                    else
                                    {
                                        lCount--;
                                    }

                                    lInstance.OnContext.SqlConnection = lSQLConnectionOld;
                                }

                                if (lInstance.Oid.Equals(startRowOid))
                                {
                                    lFoundStartRow = true;
                                }
                            }

                            else if (lInstance.Oid.Equals(startRowOid))                             // Search the start row
                            {
                                lCount = 0;
                            }
                        }

                        // Stop loading
                        if ((blockSize != 0) && (lCount > blockSize))
                        {
                            if (orderCriteria == null)
                            {
                                break;
                            }
                            else
                            {
                                // Set another connection because it is imposible to use
                                // the same connection that is used in the DataReader
                                ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection;
                                if (lOnSQLConnection == null)
                                {
                                    lOnSQLConnection = GetConnection();
                                }
                                lInstance.OnContext.SqlConnection = lOnSQLConnection;

                                int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance);

                                // Restores the old connection
                                lInstance.OnContext.SqlConnection = lOnSQLConnectionOld;

                                if (lCompare > 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string ltraceItem = "Method: ExecuteSql, Component: RevisionData";
                if (e is ONSystemException)
                {
                    ONSystemException lException = e as ONSystemException;
                    lException.addTraceInformation(ltraceItem);
                    throw lException;
                }
                throw new ONSystemException(e, ltraceItem);
            }
            finally
            {
                if (lOnSQLConnection != null)
                {
                    ONDBData.CloseConnection(lOnSQLConnection);
                }
                if (lDataReader != null)
                {
                    if (mSqlCommand != null)
                    {
                        mSqlCommand.Cancel();
                    }
                    lDataReader.Close();
                }
                Close();
                if ((onFilterList != null) && (onFilterList.InMemory) && !lWithStartRow && (lCount <= blockSize))
                {
                    lQuery.totalNumInstances = lQuery.Count;
                }
            }

            return(lQuery);
        }