Exemplo n.º 1
0
        private void Save()
        {
            int    imgErr          = 0;
            string CnBlogsUserName = Request.Form["CnBlogsUserName"];
            string CnBlogsPassWord = Request.Form["CnBlogsPassWord"];
            string ApiAddress      = Request.Form["ApiAddress"];

            CnBlogsUserName = Decrypt(CnBlogsUserName);
            CnBlogsPassWord = Decrypt(CnBlogsPassWord);
            ApiAddress      = Decrypt(ApiAddress);
            string[]    picRes     = Request.Form["PicRes"].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            IgetCatList categories = (IgetCatList)XmlRpcProxyGen.Create(typeof(IgetCatList));

            ((XmlRpcClientProtocol)categories).Url = ApiAddress;
            BlogEntity BlogInfo = default(BlogEntity);

            BlogInfo.title       = Request.Form["BlogTitle"];
            BlogInfo.description = Request.Form["BlogBody"];
            BlogInfo.dateCreated = DateTime.Now;
            BlogInfo.postid      = Request.Form["BlogId"];
            for (int i = 0; i < picRes.Length; i++)
            {
                FileData fd      = default(FileData);
                string   picPath = base.Server.MapPath(picRes[i]);
                fd.bits = File.ReadAllBytes(picPath);
                fd.name = Path.GetExtension(picPath);
                fd.type = string.Format("image/{0}", fd.name.Substring(1));
                try
                {
                    FileData obj = categories.newMediaObject(CnBlogsUserName, CnBlogsUserName, CnBlogsPassWord, fd);
                    BlogInfo.description = BlogInfo.description.Replace(picRes[i], obj.url);
                }
                catch
                {
                    imgErr++;
                }
            }
            try
            {
                if (string.IsNullOrWhiteSpace(BlogInfo.postid))
                {
                    categories.newPost(string.Empty, CnBlogsUserName, CnBlogsPassWord, BlogInfo, false);
                }
                else
                {
                    categories.editPost(BlogInfo.postid, CnBlogsUserName, CnBlogsPassWord, BlogInfo, false);
                }
            }
            catch (Exception)
            {
                Response.Write("博客发送失败");
                return;
            }
            if (imgErr < 1)
            {
                Response.Write("博客发送成功");
                return;
            }
            Response.Write(string.Format("博客虽然发送成功了,但是有{0}张图片发送失败了", imgErr));
        }