Пример #1
0
    private void fillGridView()
    {
        //搜尋條件
        Dictionary <string, string> conditions = new Dictionary <string, string>();

        conditions.Add("Flag", "1");
        conditions.Add("KeyWord", txtSearchKeyword.Text.Trim());
        conditions.Add("Type", ddlSearchType.SelectedValue);
        if (!string.IsNullOrEmpty(txtSearchShowDateStart.Text.Trim()))
        {
            conditions.Add("ShowDateStart", txtSearchShowDateStart.Text.Trim());
        }

        if (!string.IsNullOrEmpty(txtSearchShowDateEnd.Text.Trim()))
        {
            conditions.Add("ShowDateEnd", txtSearchShowDateEnd.Text.Trim());
        }

        //分頁
        AspNetPager1.RecordCount = m_PostFileService.GetFileCount(conditions);
        lblTotalCount.Text       = string.Format("共查出 {0} 筆資料", AspNetPager1.RecordCount.ToString());
        if (AspNetPager1.RecordCount > 0)
        {
            btnSearchExport.Visible = true;
        }
        else
        {
            btnSearchExport.Visible = false;
        }
        int pageIndex = (AspNetPager1.CurrentPageIndex - 1);
        int pageSize  = AspNetPager1.PageSize;

        conditions.Add("PageIndex", pageIndex.ToString());
        conditions.Add("PageSize", pageSize.ToString());
        //conditions.Add("Order", string.Format("order by {0}", ddlSearchOrder.SelectedValue));
        //conditions.Add("Order", "order by p.CloseDate desc, p.ShowDate desc, p.Title");

        gvList.DataSource = m_PostFileService.GetFileList(conditions);
        gvList.DataBind();
    }
        //private WebLogService m_WebLogService;
        //private HttpHelper m_HttpHelper;

        // GET api/<controller>
        public HttpResponseMessage Get()
        {
            IList <FileDto> result = new List <FileDto>();

            Dictionary <string, string> conditions = new Dictionary <string, string>();

            conditions.Add("Flag", "1");
            conditions.Add("PageIndex", "0");
            conditions.Add("PageSize", "10");
            //conditions.Add("Order", "order by f.FileId");

            IList <FileVO> fileVOList = m_PostFileService.GetFileList(conditions);

            if (fileVOList != null && fileVOList.Count > 0)
            {
                foreach (FileVO vo in fileVOList)
                {
                    result.Add(new FileDto(vo));
                }
            }

            return(Request.CreateResponse <IList <FileDto> >(HttpStatusCode.OK, result));
        }
Пример #3
0
    /// <summary>
    /// 同步到Server
    /// </summary>
    public static void UpdateFileToServer(string filePath)
    {
        PostFactory      m_PostFactory     = new PostFactory();
        IPostFileService m_PostFileService = m_PostFactory.GetPostFileService();
        ConfigHelper     m_ConfigHelper    = new ConfigHelper();
        WebUtility       m_WebUtility      = new WebUtility();

        if (string.IsNullOrEmpty(m_ConfigHelper.PostFileApiUrl))
        {
            return;
        }

        Dictionary <string, string> conditions = new Dictionary <string, string>();

        conditions.Add("NeedUpdate", "true");
        IList <FileVO> list = m_PostFileService.GetFileList(conditions);

        if (list != null && list.Count > 0)
        {
            foreach (FileVO vo in list)
            {
                try
                {
                    FileVO fileVO = m_PostFileService.GetFileById(vo.FileId);
                    if (fileVO.IsUpdatingToServer)
                    {
                        continue;
                    }

                    FileDto dto = new FileDto(vo);

                    //狀態為刪除
                    if (dto.Flag == 0)
                    {
                        vo.IsUpdatingToServer = true;
                        m_PostFileService.UpdateFile(vo);

                        if (dto.ServerId > 0)
                        {
                            //有serverId就去server刪除
                            string     url     = m_ConfigHelper.PostFileApiUrl + "/" + dto.ServerId.ToString();
                            WebRequest request = ApiUtil.Post(url, "DELETE", "");

                            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                            {
                                if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Gone || response.StatusCode == HttpStatusCode.NoContent)
                                {
                                    vo.NeedUpdate         = false;
                                    vo.IsUpdatingToServer = false;
                                    m_PostFileService.UpdateFile(vo);
                                }
                            }
                        }
                        else
                        {
                            //沒有serverId就直接標記已更新
                            vo.NeedUpdate         = false;
                            vo.IsUpdatingToServer = false;
                            m_PostFileService.UpdateFile(vo);
                        }
                    }
                    else
                    {
                        vo.IsUpdatingToServer = true;
                        m_PostFileService.UpdateFile(vo);

                        WebRequest request = ApiUtil.Post <FileDto>(m_ConfigHelper.PostFileApiUrl, "POST", dto);

                        string responseInfo = string.Empty;
                        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                        {
                            if (response.StatusCode == HttpStatusCode.Created)
                            {
                                using (Stream stream = response.GetResponseStream())
                                {
                                    responseInfo = (new StreamReader(stream)).ReadToEnd().Trim();

                                    FileDto newFileDto = JsonConvert.DeserializeObject <FileDto>(responseInfo);

                                    vo.IsUpdatingToServer = false;
                                    vo.NeedUpdate         = false;
                                    vo.ServerId           = newFileDto.FileId;
                                    m_PostFileService.UpdateFile(vo);

                                    //成功的話在ftp檔案
                                    m_WebUtility.UploadFileToFTP(Path.Combine(filePath, vo.FileName));
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    vo.IsUpdatingToServer = false;
                    m_PostFileService.UpdateFile(vo);
                    string error = ex.ToString();
                }
            }
        }
    }