示例#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);
            }
        }
示例#2
0
    // Use this for initialization
    private void Start()
    {
        // Initialise variables
        GameOptions.LoadOptions();
        challengeGenerator = GetComponent <ChallengeGenerator>();
        challengeGenerator.GenerateChallenges();
        audioManager = GetComponent <AudioManager>();
        menu         = FindObjectOfType <Menu>();

        dictData = new DictData(dict);
        dictData.Setup();
        letterList = new DictData(challengesFile);
        letterList.CleanLetterCombos();
        letters = new char[3];
        scores  = new Scores();
        answers = new List <string>();
        word    = new Word();
        input.onEndEdit.AddListener(CheckInput);
        gameState      = GameState.Pregame;
        IncreasePoints = new IntEvent();
        IncreaseTime   = new IntEvent();

        bannedWords = bannedWordsAsset.ToString().Split('\n').ToList();
        for (int i = 0; i < bannedWords.Count(); ++i)
        {
            bannedWords[i] = bannedWords[i].TrimEnd('\r');
        }

        // Check if this is the first time the game has been played
        bool playedBefore = false;

        for (int mode = 1; mode < 3; ++mode)
        {
            // For each game mode
            for (int diff = 1; diff < 4; ++diff)
            {
                // For each difficulty
                if (scores.GetBestScore((GameMode)mode, (Difficulty)diff) > 0)
                {
                    // If high score > 0 then played before
                    playedBefore = true;
                    break;
                }
            }

            if (playedBefore)
            {
                break;
            }
        }

        // Finished initialising variables

        // If not played before then start with the tutorial
        if (!playedBefore)
        {
            FindObjectOfType <LogoOpening>().SetNotPlayedBefore();
            GameInfo.SetGameMode(GameMode.Welcome);
        }

#if UNITY_IOS || UNITY_ANDROID
        // Initialise ads on mobile
        Ads.AdFinished.AddListener(AdCompleted);
        Ads.AdSkipped.AddListener(AdCompleted);
        Ads.AdFailed.AddListener(GoToMenu);
#endif
    }
示例#3
0
        /// <summary>
        /// 新建厂家资料目录
        /// </summary>
        public static JObject EDITSystem(string sid, string ProjectKeyword, string projectAttrJson)
        {
            ExReJObject reJo = new ExReJObject();

            try
            {
                User curUser = DBSourceController.GetCurrentUser(sid);
                if (curUser == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                DBSource dbsource = curUser.dBSource;
                if (dbsource == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                Project m_prj = dbsource.GetProjectByKeyWord(ProjectKeyword);
                if (m_prj == null)
                {
                    reJo.msg = "参数错误,目录不存在!";
                    return(reJo.Value);
                }


                #region 获取传递过来的属性参数
                //获取传递过来的属性参数
                JArray jaAttr = (JArray)JsonConvert.DeserializeObject(projectAttrJson);

                string strSystemId = "", strSystemCode = "", strSystemDesc = "",
                       strSystemEngDesc = "", strSystemChinese = "",
                       strAddress = "", strProvince = "",
                       strPostCode = "", strEMail = "",
                       strReceiver = "", strFaxNo = "", strPhone = "";

                foreach (JObject joAttr in jaAttr)
                {
                    string strName  = joAttr["name"].ToString();
                    string strValue = joAttr["value"].ToString();

                    switch (strName)
                    {
                    case "systemId":
                        strSystemId = strValue;
                        break;

                    case "systemCode":
                        strSystemCode = strValue;
                        break;

                    case "systemDesc":
                        strSystemDesc = strValue;
                        break;

                    case "systemEngDesc":
                        strSystemEngDesc = strValue;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(strSystemCode))
                {
                    reJo.msg = "请输入项目编号!";
                    return(reJo.Value);
                }
                if (string.IsNullOrEmpty(strSystemDesc))
                {
                    reJo.msg = "请输入项目名称!";
                    return(reJo.Value);
                }
                #endregion

                Project prjProject = CommonFunction.getParentProjectByTempDefn(m_prj, "HXNY_DOCUMENTSYSTEM");

                if (prjProject == null)
                {
                    reJo.msg = "获取项目目录失败!";
                    return(reJo.Value);
                }


                int systemId = Convert.ToInt32(strSystemId);
                //获取项目代码
                string strProjCode = prjProject.Code;//.GetAttrDataByKeyWord("COMPANY").ToString;


                JArray  jaData   = new JArray();
                JObject joSystem = new JObject();

                List <DictData> dictDataList = dbsource.GetDictDataList("System");
                //[o_Code]:公司编码,[o_Desc]:公司描述,[o_sValue1]:项目代码

                foreach (DictData data6 in dictDataList)
                {
                    if (!string.IsNullOrEmpty(data6.O_sValue2) && data6.O_sValue2 == strProjCode &&
                        data6.O_Code == strSystemCode && data6.O_ID != systemId)
                    {
                        reJo.msg = "已经存在相同的参建单位,请返回重试!";
                        return(reJo.Value);
                    }
                }

                #region 添加到数据字典

                DictData dictData = null;

                foreach (DictData data6 in dictDataList)
                {
                    if (data6.O_ID == systemId)
                    {
                        dictData = data6;
                    }
                }

                if (dictData == null)
                {
                    reJo.msg = "参建单位ID不存在,请返回重试!";
                    return(reJo.Value);
                }

                dictData.O_Code    = strSystemCode;
                dictData.O_Desc    = strSystemDesc;
                dictData.O_sValue2 = strProjCode;
                dictData.O_sValue1 = strSystemEngDesc;
                dictData.Modify();

                DBSourceController.refreshDBSource(sid);

                #endregion

                reJo.success = true;
                return(reJo.Value);
            }
            catch (Exception e)
            {
                reJo.msg = e.Message;
                CommonController.WebWriteLog(reJo.msg);
            }

            return(reJo.Value);
        }
示例#4
0
        /// <summary>
        /// 新建厂家资料目录
        /// </summary>
        public static JObject EditDepartment(string sid, string ProjectKeyword, string projectAttrJson)
        {
            ExReJObject reJo = new ExReJObject();

            try
            {
                User curUser = DBSourceController.GetCurrentUser(sid);
                if (curUser == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                DBSource dbsource = curUser.dBSource;
                if (dbsource == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                Project m_prj = dbsource.GetProjectByKeyWord(ProjectKeyword);
                if (m_prj == null)
                {
                    reJo.msg = "参数错误,目录不存在!";
                    return(reJo.Value);
                }


                #region 获取传递过来的属性参数
                //获取传递过来的属性参数
                JArray jaAttr = (JArray)JsonConvert.DeserializeObject(projectAttrJson);

                string strDepartmentId = "", strDepartmentCode = "", strDepartmentDesc = "",
                       strSecretarilman = "";

                foreach (JObject joAttr in jaAttr)
                {
                    string strName  = joAttr["name"].ToString();
                    string strValue = joAttr["value"].ToString();

                    switch (strName)
                    {
                    case "departmentId":
                        strDepartmentId = strValue;
                        break;

                    case "departmentCode":
                        strDepartmentCode = strValue;
                        break;

                    case "departmentDesc":
                        strDepartmentDesc = strValue;
                        break;

                    case "secretarilman":
                        strSecretarilman = strValue;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(strDepartmentCode))
                {
                    reJo.msg = "请输入部门编号!";
                    return(reJo.Value);
                }
                if (string.IsNullOrEmpty(strDepartmentDesc))
                {
                    reJo.msg = "请输入部门名称!";
                    return(reJo.Value);
                }
                #endregion

                //Project prjProject = CommonFunction.getParentProjectByTempDefn(m_prj, "HXNY_DOCUMENTSYSTEM");

                //if (prjProject == null)
                //{
                //    reJo.msg = "获取项目目录失败!";
                //    return reJo.Value;
                //}



                //获取项目代码
                //string strProjCode = prjProject.Code;//.GetAttrDataByKeyWord("COMPANY").ToString;

                int departmentId = Convert.ToInt32(strDepartmentId);

                JArray  jaData       = new JArray();
                JObject joDepartment = new JObject();

                List <DictData> dictDataList = dbsource.GetDictDataList("Communication");
                //[o_Code]:公司编码,[o_Desc]:公司描述,[o_sValue1]:项目代码

                foreach (DictData data6 in dictDataList)
                {
                    //if (!string.IsNullOrEmpty(data6.O_sValue1) && data6.O_sValue1 == strProjCode
                    if (data6.O_sValue1 == strDepartmentCode && data6.O_ID != departmentId)
                    {
                        reJo.msg = "已经存在相同的项目部门,请返回重试!";
                        return(reJo.Value);
                    }
                }
                //dbsource.NewDictData
                #region 添加到数据字典
                //添加到数据字典

                DictData dictData = null;

                foreach (DictData data6 in dictDataList)
                {
                    if (data6.O_ID == departmentId)
                    {
                        dictData = data6;
                    }
                }

                if (dictData == null)
                {
                    reJo.msg = "项目部门ID不存在,请返回重试!";
                    return(reJo.Value);
                }

                dictData.O_sValue1 = strDepartmentCode;
                dictData.O_Desc    = strDepartmentDesc;
                //dictData.O_sValue1 = strProjCode;
                dictData.O_sValue4 = strSecretarilman;// secretarilman.ToString;//
                dictData.Modify();

                DBSourceController.refreshDBSource(sid);

                #endregion


                reJo.success = true;
                return(reJo.Value);
            }
            catch (Exception e)
            {
                reJo.msg = e.Message;
                CommonController.WebWriteLog(reJo.msg);
            }

            return(reJo.Value);
        }
示例#5
0
        /// <summary>
        /// 新建厂家资料目录
        /// </summary>
        public static JObject EditCompany(string sid, string ProjectKeyword, string projectAttrJson)
        {
            ExReJObject reJo = new ExReJObject();

            try
            {
                User curUser = DBSourceController.GetCurrentUser(sid);
                if (curUser == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                DBSource dbsource = curUser.dBSource;
                if (dbsource == null)
                {
                    reJo.msg = "登录验证失败!请尝试重新登录!";
                    return(reJo.Value);
                }

                Project m_prj = dbsource.GetProjectByKeyWord(ProjectKeyword);
                if (m_prj == null)
                {
                    reJo.msg = "参数错误,目录不存在!";
                    return(reJo.Value);
                }


                #region 获取传递过来的属性参数
                //获取传递过来的属性参数
                JArray jaAttr = (JArray)JsonConvert.DeserializeObject(projectAttrJson);

                string strCompanyId = "", strCompanyCode = "", strCompanyDesc = "",
                       strSecretarilman = "", strCompanyChinese = "",
                       strAddress = "", strProvince = "",
                       strPostCode = "", strEMail = "",
                       strReceiver = "", strFaxNo = "", strPhone = "";

                foreach (JObject joAttr in jaAttr)
                {
                    string strName  = joAttr["name"].ToString();
                    string strValue = joAttr["value"].ToString();

                    switch (strName)
                    {
                    case "companyId":
                        strCompanyId = strValue;
                        break;

                    case "companyCode":
                        strCompanyCode = strValue;
                        break;

                    case "companyDesc":
                        strCompanyDesc = strValue;
                        break;

                    case "secretarilman":
                        strSecretarilman = strValue;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(strCompanyCode))
                {
                    reJo.msg = "请输入项目编号!";
                    return(reJo.Value);
                }
                if (string.IsNullOrEmpty(strCompanyDesc))
                {
                    reJo.msg = "请输入项目名称!";
                    return(reJo.Value);
                }
                #endregion

                Project prjProject = CommonFunction.getParentProjectByTempDefn(m_prj, "HXNY_DOCUMENTSYSTEM");

                if (prjProject == null)
                {
                    reJo.msg = "获取项目目录失败!";
                    return(reJo.Value);
                }

                //User secretarilman = dbsource.GetUserByKeyWord(strSecretarilman);
                //if (secretarilman == null)
                //{
                //    reJo.msg = "参数错误!文控角色所选择的用户不存在!";
                //    return reJo.Value;
                //}

                int companyId = Convert.ToInt32(strCompanyId);
                //获取项目代码
                string strProjCode = prjProject.Code;//.GetAttrDataByKeyWord("COMPANY").ToString;


                JArray  jaData    = new JArray();
                JObject joCompany = new JObject();

                List <DictData> dictDataList = dbsource.GetDictDataList("Unit");
                //[o_Code]:公司编码,[o_Desc]:公司描述,[o_sValue1]:项目代码

                foreach (DictData data6 in dictDataList)
                {
                    if (!string.IsNullOrEmpty(data6.O_sValue1) && data6.O_sValue1 == strProjCode &&
                        data6.O_Code == strCompanyCode && data6.O_ID != companyId)
                    {
                        reJo.msg = "已经存在相同的参建单位,请返回重试!";
                        return(reJo.Value);
                    }
                }
                //dbsource.NewDictData


                #region 添加到数据字典
                //添加到数据字典

                //DictData dictdata = new DictData();
                //dictdata.StatusNew = true;
                //dictdata.O_skey = "Unit";
                //dictdata.O_datatype = (int)enDictDataType.TableHead;
                //dictdata.O_Code = strCompanyCode;
                //dictdata.O_Desc = strCompanyDesc;
                //dictdata.O_sValue1 = strProjCode;

                ////设置属性的值
                //SetDictDataPropertyValue(dictdata, 0);

                //dictdata.Modify();
                DictData dictData = null;

                foreach (DictData data6 in dictDataList)
                {
                    if (data6.O_ID == companyId)
                    {
                        dictData = data6;
                    }
                }

                if (dictData == null)
                {
                    reJo.msg = "参建单位ID不存在,请返回重试!";
                    return(reJo.Value);
                }

                //自动设置文控,如果没有与单位代码一样的用户,就自动添加用户
                SetUnitSecUser(sid, dbsource, prjProject, strCompanyCode, strCompanyDesc, ref strSecretarilman);
                //#region 自动设置文控,如果没有与单位代码一样的用户,就自动添加用户
                //User secUser = null;
                //if (string.IsNullOrEmpty(strSecretarilman))
                //{
                //    secUser = dbsource.GetUserByCode(strCompanyCode);
                //    if (secUser == null)
                //    {
                //        ////UserController. CreateUser(sid, strCompanyCode, strCompanyDesc + "文控", "", "0",
                //        ////            "0", "", strCompanyCode, strCompanyCode);
                //        ////secUser = dbsource.GetUserByCode(strCompanyCode);
                //        secUser = dbsource.NewUser(
                //                            enUserFlage.OnLine,
                //                            enUserType.Default,
                //                                "",
                //                               strCompanyCode,
                //                                strCompanyDesc + "文控",
                //                                strCompanyCode,
                //                                "",
                //                                null
                //                                );

                //        if (secUser != null)
                //        {

                //            User m_user = secUser;
                //            m_user.O_suser1 = m_user.dBSource.GUID;

                //            m_user.Modify();



                //            // 强制刷新共享数据源
                //            //
                //            //DBSourceController.RefreshShareDBManager();
                //            DBSourceController.RefreshDBSource(sid);
                //            strSecretarilman = secUser.ToString;
                //        }
                //    }
                //    else
                //    {
                //        strSecretarilman = secUser.ToString;
                //    }


                //}

                //if (secUser != null)
                //{
                //    //把用户添加到项目管理类里面的项目单位用户组
                //    Group group = dbsource.GetGroupByName(prjProject.Code + "_ALLUnit");


                //    if (group != null)
                //    {
                //        group.AddUser(secUser);
                //        group.Modify();
                //    }
                //}
                //    #endregion

                dictData.O_Code    = strCompanyCode;
                dictData.O_Desc    = strCompanyDesc;
                dictData.O_sValue1 = strProjCode;
                dictData.O_sValue3 = strSecretarilman;// secretarilman.ToString;//
                dictData.Modify();

                DBSourceController.refreshDBSource(sid);

                ////通过以上的dictdata新建一个DictData
                //DictData newDictData = CreateNewDictData(dbsource, dictdata, enDictDataType.TableHead);

                //if (!newDictData.Write())
                //{
                //    //MessageBox.Show("创建失败!", "提示", MessageBoxButtons.OK);
                //    reJo.msg = "创建失败!";
                //    return reJo.Value;
                //}
                #endregion

                //自动创建通信类下的单位目录
                CreateUnitProject(dbsource, prjProject, strCompanyCode, strCompanyDesc, strSecretarilman);

                ////自动创建通信类下的单位目录
                //#region 自动创建通信类下的单位目录
                //try
                //{
                //    TempDefn mTempDefn = Company.GetTempDefn(dbsource, "COM_UNIT");
                //    if (mTempDefn != null)
                //    {
                //        Project cdProject = CommonFunction.GetProjectByDesc(prjProject, "存档管理");
                //        if (cdProject != null)
                //        {
                //            Project txProject = CommonFunction.GetProjectByDesc(cdProject, "通信类");
                //            if (txProject != null)
                //            {
                //                Project project = txProject.NewProject(strCompanyCode, strCompanyDesc, m_prj.Storage, mTempDefn);

                //                if (project != null)
                //                {
                //                    //增加附加属性
                //                    try
                //                    {
                //                        project.GetAttrDataByKeyWord("UN_SECRETAARECTOR").SetCodeDesc(strSecretarilman);             //文控
                //                        project.AttrDataList.SaveData();
                //                    }
                //                    catch (Exception ex)
                //                    {
                //                        //MessageBox.Show("获取厂家模板失败,请联系管理员!");
                //                        reJo.msg = "获取厂家模板失败,请联系管理员!";
                //                        return reJo.Value;
                //                    }

                //                    TempDefn sfwTempDefn = Company.GetTempDefn(dbsource, "STO_SUBDOCUMENT");
                //                    if (sfwTempDefn != null)
                //                    {
                //                        Project swProject = project.NewProject("收文", "", m_prj.Storage, sfwTempDefn);
                //                        Project fwProject = project.NewProject("发文", "", m_prj.Storage, sfwTempDefn);

                //                        TempDefn typeTempDefn = Company.GetTempDefn(dbsource, "STO_COMTYPE");
                //                        if (typeTempDefn != null)
                //                        {
                //                            if (swProject != null)
                //                            {
                //                                swProject.NewProject("红头文", "", m_prj.Storage, typeTempDefn);
                //                                swProject.NewProject("会议纪要", "", m_prj.Storage, typeTempDefn);
                //                                swProject.NewProject("文件传递单", "", m_prj.Storage, typeTempDefn);
                //                                swProject.NewProject("信函", "", m_prj.Storage, typeTempDefn);
                //                            }

                //                            if (fwProject != null)
                //                            {
                //                                fwProject.NewProject("红头文", "", m_prj.Storage, typeTempDefn);
                //                                fwProject.NewProject("会议纪要", "", m_prj.Storage, typeTempDefn);
                //                                fwProject.NewProject("文件传递单", "", m_prj.Storage, typeTempDefn);
                //                                fwProject.NewProject("信函", "", m_prj.Storage, typeTempDefn);
                //                            }
                //                        }
                //                    }
                //                }
                //            }
                //        }
                //    }
                //}
                //catch
                //{

                //}
                //#endregion

                //prjProject.GetProjectByName();


                //    reJo.msg = "获取参建单位模板失败,请联系管理员!";
                //    return reJo.Value;
                //}

                //Project project = m_prj.NewProject(strCompanyCode, strCompanyDesc, m_prj.Storage, mTempDefn);
                //if (project == null)
                //{
                //    reJo.msg = "新建版本目录失败,请联系管理员!";
                //    return reJo.Value;
                //}

                //增加附加属性
                try
                {
                    //project.GetAttrDataByKeyWord("FC_COMPANYCODE").SetCodeDesc(strCompanyCode);       //厂家编码
                    //project.GetAttrDataByKeyWord("FC_COMPANYCHINESE").SetCodeDesc(strCompanyChinese);    //厂家名称
                    //project.GetAttrDataByKeyWord("FC_ADDRESS").SetCodeDesc(strAddress);           //厂家地址
                    //project.GetAttrDataByKeyWord("FC_PROVINCE").SetCodeDesc(strProvince);          //厂家省份
                    //project.GetAttrDataByKeyWord("FC_POSTCODE").SetCodeDesc(strPostCode);          //厂家邮政
                    //project.GetAttrDataByKeyWord("FC_EMAIL").SetCodeDesc(strEMail);             //厂家邮箱
                    //project.GetAttrDataByKeyWord("FC_RECEIVER").SetCodeDesc(strReceiver);          //厂家收件人
                    //project.GetAttrDataByKeyWord("FC_FAXNO").SetCodeDesc(strFaxNo);             //厂家传真号
                    //project.GetAttrDataByKeyWord("FC_PHONE").SetCodeDesc(strPhone);             //收件人电话
                    //project.AttrDataList.SaveData();
                }
                catch (Exception ex)
                {
                    //MessageBox.Show("获取厂家模板失败,请联系管理员!");
                    reJo.msg = "获取厂家模板失败,请联系管理员!";
                    return(reJo.Value);
                }

                //reJo.data = new JArray(new JObject(new JProperty("ProjectKeyword", project.KeyWord)));

                reJo.success = true;
                return(reJo.Value);
            }
            catch (Exception e)
            {
                reJo.msg = e.Message;
                CommonController.WebWriteLog(reJo.msg);
            }

            return(reJo.Value);
        }
        /// <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;
        }
 /// <summary>
 /// Build the final byte array of the compressed file.
 /// </summary>
 /// <param name="oldByteArray">The original byte array used to change the bytes into the new bytes.</param>
 /// <param name="binaryDictByte">The Dictionary containing the information used to compare the old bytes.</param>
 /// <returns>The new byte array used for the compressed file.</returns>
 protected byte[] BuildNewByteArray(byte[] oldByteArray, DictData binaryDictByte)
 {
     int i = 0;
     // StringBuilder used to negate the speed lost from adding to a very long string.
     StringBuilder sb = new StringBuilder();
     sb.Append(binaryDictByte.FileHeader);
     // Go through the old byte array to create the new bytes.
     while (i < oldByteArray.Length)
     {
         sb.Append(binaryDictByte[oldByteArray[i]]);
         i++;
     }
     string currentByteString = sb.ToString();
     int numOfExtraBits = currentByteString.Length % 8;
     if(numOfExtraBits > 0)
         currentByteString = currentByteString.PadLeft(currentByteString.Length + 8 - numOfExtraBits, '0');
     int numOfBytes = currentByteString.Length / 8;
     byte[] newByteArray = new byte[numOfBytes];
     for (int ii = 0; ii < numOfBytes; ii++)
     {
         newByteArray[ii] = Convert.ToByte(currentByteString.Substring(8 * ii, 8), 2);
     }
     return newByteArray;
 }
示例#8
0
 public DictDataCaller() : base(BLLFactory <DictData> .Instance)
 {
     bll = baseBLL as DictData;
 }