Пример #1
0
        private bool OnGetSetResponse(HttpRequest request, HttpResponse response)
        {
            RequestURLInfo = new RequestURL(request.RawURL);
            if (!RequestURLInfo.IsValid)
            {
                return(false);
            }

            if (RequestURLInfo.RequestType == RequestURL.RequestTypeEnum.FILE)
            {
                string requestURL = request.URL.TrimStart(new char[] { '/' });
                Match  match      = iconRegex.Match(requestURL);
                if (match.Success && (!string.IsNullOrWhiteSpace(match.Groups[1].Value)))
                {
                    string strTemp   = string.Format("*.{0}", match.Groups[1].Value);
                    byte[] iconBytes = null;
                    if (ImageBytesDic.ContainsKey(strTemp))
                    {
                        iconBytes = ImageBytesDic[strTemp];
                    }
                    else
                    {
                        try
                        {
                            iconBytes = Helper.IconToBytes(IconReader.GetFileIcon(
                                                               strTemp, IconReader.IconSize.Small, false));
                            response.Content_Type = ContentTypeDic[".ico"];
                        }
                        catch
                        {
                            iconBytes             = ExistResourcesBytesDic["warn.png"];
                            response.Content_Type = ContentTypeDic[".png"];
                        }
                        ImageBytesDic.Add(strTemp, iconBytes);
                    }

                    response.SetContent(iconBytes);
                }
                else if (ExistResourcesBytesDic.ContainsKey(requestURL))
                {
                    response.SetContent(ExistResourcesBytesDic[requestURL]);
                    response.Content_Type = ContentTypeDic[Path.GetExtension(requestURL)];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                TotalItemCount = 0;
                PageCount      = 0;
                PageIndex      = -1;
                ItemIndex      = -1;

                UpFolderId        = -2;
                CurrentFolderId   = -2;
                CurrentFolderPath = "";

                if (RequestURLInfo.Offset >= 0)
                {
                    PageIndex = RequestURLInfo.Offset / PageItemCount;
                    ItemIndex = RequestURLInfo.Offset % PageItemCount;
                }

                string    strTitle          = RequestURLInfo.SearchKeyWord;
                int[]     idList            = null;
                DataTable dt                = null;
                DataTable diskRootDataTable = sqlData.DiskRootDataTable;

                SelectAllDisk = string.Format("全部(共 {0} 磁盘)",
                                              diskRootDataTable.Rows.Count);
                DiskDescList.Clear();
                DiskDescList.Add(SelectAllDisk);
                foreach (DataRow dr in diskRootDataTable.Rows)
                {
                    DiskDescList.Add(dr["disk_desc"].ToString());
                }

                if (RequestURLInfo.DiskDescribe != "")
                {
                    if (!DiskDescList.Contains(RequestURLInfo.DiskDescribe))
                    {
                        return(false);
                    }
                }
                else
                {
                    RequestURLInfo.DiskDescribe = SelectAllDisk;
                }

                switch (RequestURLInfo.QueryType)
                {
                case RequestURL.QueryTypeEnum.DISK_ROOT:
                {
                    TotalItemCount = diskRootDataTable.Rows.Count;
                    strTitle       = string.Format("INDEX[{0}]", TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.DATABASE_ID:
                {
                    dt = sqlData.GetDataByIdFromFilmInfo(RequestURLInfo.DataBaseId);
                    if (dt != null && dt.Rows.Count == 1)
                    {
                        TotalItemCount = 1;
                        strTitle       = string.Format("ID[{0}][{1}]", RequestURLInfo.DataBaseId, TotalItemCount);

                        CurrentFolderId = Convert.ToInt32(dt.Rows[0]["pid"]);
                        if (CurrentFolderId >= 0)
                        {
                            DataTable folderDt = sqlData.GetDataByIdFromFilmInfo(CurrentFolderId);
                            if (folderDt != null && folderDt.Rows.Count == 1)
                            {
                                UpFolderId        = Convert.ToInt32(folderDt.Rows[0]["pid"]);
                                CurrentFolderPath = folderDt.Rows[0]["path"].ToString();
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                break;

                case RequestURL.QueryTypeEnum.DATABASE_PID:
                {
                    CurrentFolderId = RequestURLInfo.DataBasePid;
                    if (CurrentFolderId >= 0)
                    {
                        dt = sqlData.GetDataByIdFromFilmInfo(CurrentFolderId);
                        if (dt != null && dt.Rows.Count == 1)
                        {
                            UpFolderId        = Convert.ToInt32(dt.Rows[0]["pid"]);
                            CurrentFolderPath = dt.Rows[0]["path"].ToString();
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    idList = sqlData.GetDataByPidFromFilmInfo(RequestURLInfo.DataBasePid);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    strTitle = string.Format("PID[{0}][{1}]", RequestURLInfo.DataBasePid, TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.SEARCH:
                {
                    idList = sqlData.SearchKeyWordFromFilmInfo(
                        RequestURLInfo.SearchKeyWord,
                        RequestURLInfo.DiskDescribe == SelectAllDisk ? null : RequestURLInfo.DiskDescribe);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    sqlData.InsertDataToSearchLog(
                        RequestURLInfo.SearchKeyWord, TotalItemCount, DateTime.Now);

                    strTitle = string.Format("SEARCH[{0}][1]", RequestURLInfo.SearchKeyWord, TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.TO_DELETE_BY_TIME:
                {
                    idList = sqlData.GetDeleteDataFromFilmInfo(
                        RequestURLInfo.DiskDescribe == SelectAllDisk ? null : RequestURLInfo.DiskDescribe);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    strTitle = string.Format("TO_DELETE_TIME[{0}][1]", RequestURLInfo.SearchKeyWord, TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.TO_DELETE_BY_DISK:
                {
                    idList = sqlData.GetDeleteDataFromFilmInfoGroupByDisk(
                        RequestURLInfo.DiskDescribe == SelectAllDisk ? null : RequestURLInfo.DiskDescribe);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    strTitle = string.Format("TO_DELETE_DISK[{0}][1]", RequestURLInfo.SearchKeyWord, TotalItemCount);
                }
                break;

                case RequestURL.QueryTypeEnum.TO_WATCH:
                {
                    idList = sqlData.GetWatchDataFromFilmInfo(
                        RequestURLInfo.DiskDescribe == SelectAllDisk ? null : RequestURLInfo.DiskDescribe);
                    if (idList != null)
                    {
                        TotalItemCount = idList.Length;
                    }

                    strTitle = string.Format("TO_WATCH[{0}][1]", RequestURLInfo.SearchKeyWord, TotalItemCount);
                }
                break;

                default:
                    return(false);
                }

                if (RequestURLInfo.Offset == 0 && TotalItemCount == 0)
                {
                    gridData = diskRootDataTable.Clone();
                }
                else if (RequestURLInfo.Offset >= 0 && RequestURLInfo.Offset < TotalItemCount)
                {
                    switch (RequestURLInfo.QueryType)
                    {
                    case RequestURL.QueryTypeEnum.DISK_ROOT:
                        gridData = diskRootDataTable
                                   .AsEnumerable()
                                   .Where((row, index) => index >= PageIndex * PageItemCount && index < (PageIndex + 1) * PageItemCount)
                                   .CopyToDataTable();
                        break;

                    case RequestURL.QueryTypeEnum.DATABASE_ID:
                        gridData = CommonDataTable.ConvertFilmInfoToGrid(dt);
                        break;

                    case RequestURL.QueryTypeEnum.DATABASE_PID:
                    case RequestURL.QueryTypeEnum.SEARCH:
                    case RequestURL.QueryTypeEnum.TO_DELETE_BY_TIME:
                    case RequestURL.QueryTypeEnum.TO_DELETE_BY_DISK:
                    case RequestURL.QueryTypeEnum.TO_WATCH:
                        dt = sqlData.SelectDataByIDList(
                            Helper.ArraySlice(idList, PageIndex * PageItemCount, PageItemCount));
                        gridData = CommonDataTable.ConvertFilmInfoToGrid(dt);
                        break;

                    default:
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                PageCount = TotalItemCount / PageItemCount +
                            (TotalItemCount % PageItemCount == 0 ? 0 : 1);

                string strResponse = Properties.Resources.main_html.Replace("${title}",
                                                                            string.Format("{0} - {1}", strTitle, TitleSuffix));
                strResponse = strResponse.Replace("${title_app}", TitleSuffix);
                strResponse = strResponse.Replace("${select_items}", GetSelectBoxHtmlString());
                strResponse = strResponse.Replace("${search_keyword}", RequestURLInfo.SearchKeyWord);
                strResponse = strResponse.Replace("${table_content}", GetTableHtmlString());
                strResponse = strResponse.Replace("${cut_page_index}", GetCutPageHtmlString());

                response.SetContent(strResponse);
                response.Content_Type = ContentTypeDic[".html"];
            }

            response.StatusCode = "200";
            return(true);
        }