示例#1
0
        private async void RefreshMeal(string date)
        {
            string[] menu = new string[4];

            try {
                for (int i = 1; i <= 3; i++)
                {
                    menu[i] = "";

                    string url = string.Format(
                        "http://emenu.ourhome.co.kr/meal/list.action?tempcd=8c2ea4cdbe74d231b29b4c69f4c90328&offerdt={0}&up_yn=&up_busiplcd=8c2ea4cdbe74d231b29b4c69f4c90328&busiord=&mealclass={1}"
                        , date, i);

                    Task <string> httpTask = GetHTML(url, "UTF-8");
                    string        strHTML  = await httpTask;

                    int lastIndex = 0, endIndex = 0, openIndex = 0, closeIndex = 0;

                    for (int j = 0; j < 2; j++)
                    {
                        lastIndex = strHTML.IndexOf("메뉴정보박스시작", lastIndex);
                        if (lastIndex < 0)
                        {
                            break;
                        }
                        endIndex = strHTML.IndexOf("메뉴정보박스끝", lastIndex);

                        if (j == 1)
                        {
                            menu[i] += "\n";
                        }

                        openIndex = lastIndex;
                        for (; ;)
                        {
                            openIndex = strHTML.IndexOf("<span class=\"MAR5\">", openIndex);
                            if (openIndex < 0 || openIndex > endIndex)
                            {
                                break;
                            }
                            closeIndex = strHTML.IndexOf("</td>", openIndex);

                            menu[i] += strHTML.Substring(openIndex, closeIndex + 5 - openIndex)
                                       .Replace("<span class=\"MAR5\">·</span>", "")
                                       .Replace("</td>", "") + " ";

                            openIndex++;
                        }

                        lastIndex++;
                    }

                    try {
                        if (DictData.ContainsKey(string.Format("{0}{1}", date, i)))
                        {
                            DictData[string.Format("{0}{1}", date, i)] = menu[i];
                        }
                        else
                        {
                            DictData.Add(string.Format("{0}{1}", date, i), menu[i]);
                        }
                    } catch { }
                }

                await this.Dispatcher.BeginInvoke(new Action(() => {
                    for (int i = 1; i <= 3; i++)
                    {
                        if (menu[i] == "")
                        {
                            (FindName(string.Format("stackMeal{0}", i)) as StackPanel).Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            (FindName(string.Format("stackMeal{0}", i)) as StackPanel).Visibility = Visibility.Visible;
                            (FindName(string.Format("textMeal{0}", i)) as TextBlock).Text = menu[i];
                            (FindName(string.Format("textMeal{0}", i)) as TextBlock).ToolTip = menu[i];
                        }
                    }

                    stackContent.BeginAnimation(StackPanel.OpacityProperty,
                                                new DoubleAnimation(1, TimeSpan.FromMilliseconds(300)));
                }));
            } catch (Exception ex) {
                //MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// Build the linked list containing each dictionary pair with their new binary code in a descending order.
        /// </summary>
        /// <param name="binaryTree">Binary tree to use.</param>
        /// <returns>The linked list containing the dictionary pair and their binary code in a descending order.</returns>
        protected DictData BuildBinaryDict(BinaryTree<CharData> binaryTree)
        {
            string headerTree = "";
            // The header is used to rebuild the binary tree when decompressing.
            // Example...
            //      o
            //    /  \
            //   o    o
            //  / \  / \
            // o  o  o  o
            //     \   / \
            //      o  o  o
            // This binary tree would be made like this (If right = 01, left = 10 and parent = 11. 00 would mean the end of the binary tree creation)
            // 01 01 01 11 10 11 11 10 11 11 10 01 01 11 11 10 11 11 11 00

            string currentBinaryCode = "";
            DictData dictTmp = new DictData();
            BinaryTreeNode<CharData> currentNode = binaryTree.Root;
            bool isParent = false;
            while (currentNode != null)
            {
                if (currentNode.Right != null)
                {
                    // Has a right node
                    currentNode = currentNode.Right;
                    headerTree += "01";
                    currentBinaryCode += "1";
                    isParent = false;
                }
                else if (currentNode.Left != null)
                {
                    // Has a left node but not right
                    currentNode = currentNode.Left;
                    headerTree += "10";
                    currentBinaryCode += "0";
                    isParent = false;
                }
                else
                {
                    headerTree += "11";
                    // Is a Leaf
                    if (!isParent)
                    {
                        currentNode.Value.BinaryCode = currentBinaryCode;
                        headerTree += Convert.ToString(Convert.ToByte(currentNode.Value.Pair.Key), 2).PadLeft(8, '0');
                        dictTmp.Add(currentNode.Value.Pair.Key, currentNode.Value.BinaryCode);
                    }
                    currentNode = currentNode.Parent;
                    isParent = true;
                    if (currentNode != null)
                    {
                        currentBinaryCode = currentBinaryCode.Remove(currentBinaryCode.Length - 1);
                        if (currentNode.Right != null)
                            currentNode.Right = null;
                        else currentNode.Left = null;
                    }
                }
            }
            headerTree += "00";
            dictTmp.FileHeader = headerTree;
            return dictTmp;
        }