Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        m_ConfigHelper    = new ConfigHelper();
        m_WebLogService   = new WebLogService();
        m_PostFactory     = new PostFactory();
        m_AuthFactory     = new AuthFactory();
        m_CommonFactory   = new CommonFactory();
        m_SessionHelper   = new SessionHelper();
        m_WebUtility      = new WebUtility();
        m_AuthService     = m_AuthFactory.GetAuthService();
        m_PostFileService = m_PostFactory.GetPostFileService();
        m_CommonService   = m_CommonFactory.GetCommonService();
        m_PostService     = m_PostFactory.GetPostService();

        if (!IsPostBack)
        {
            pnlContent.Visible = false;
            fillGridView();
            ShowMode();
        }
    }
Exemple #2
0
 public PostController(IPostService postService, ICategoryService categoryService, IPostFileService postFileService) : base()
 {
     this.postService     = postService;
     this.categoryService = categoryService;
     this.postFileService = postFileService;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        m_ConfigHelper = new ConfigHelper();
        m_WebLogService = new WebLogService();
        m_PostFactory = new PostFactory();
        m_AuthFactory = new AuthFactory();
        m_CommonFactory = new CommonFactory();
        m_SessionHelper = new SessionHelper();
        m_WebUtility = new WebUtility();
        m_AuthService = m_AuthFactory.GetAuthService();
        m_PostFileService = m_PostFactory.GetPostFileService();
        m_CommonService = m_CommonFactory.GetCommonService();
        m_PostService = m_PostFactory.GetPostService();

        if (!IsPostBack)
        {
            pnlContent.Visible = false;
            fillGridView();
            ShowMode();
        }
    }
Exemple #4
0
 public UserPostsController(IUserPostService userPostService, IPostFileService postFileService)
 {
     _postFileService = postFileService;
     _userPostService = userPostService;
 }
    /// <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();
                }
            }
        }
    }