Пример #1
0
        public void SaveCate(EP_POSTS EP_POSTS)
        {
            IEnumerable <EP_METAS> metas = db.EP_META.ToList().Where(c => c.UserID == User.Identity.GetUserId());

            if (metas != null)
            {
                foreach (EP_METAS meta in metas)
                {
                    String Publish_BLOGID  = meta.Publish_BLOGID;
                    String service         = meta.publish;
                    String publish_SITE    = meta.publish_SITE;
                    String Publish_ID      = meta.Publish_ID;
                    String Publish_BLOGKEY = meta.Publish_BLOGKEY;
                    String Publish_PW      = meta.Publish_PW;
                    if (meta.publish == "Tistory")
                    {
                        Category[]    category;
                        List <string> categorylist = new List <string>();
                        try
                        {
                            MetaWeblog api = new MetaWeblog(publish_SITE + "/api");
                            //api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, true);
                            category = api.getCategories(Publish_BLOGID, Publish_ID, Publish_BLOGKEY);
                            foreach (Category cate in category)
                            {
                                categorylist.Add(cate.title);
                            }
                        }
                        catch
                        {
                            ModelState.AddModelError("", "실패했습니다.");
                        }
                        string catstring = categorylist.ToArray().Aggregate((cur, next) => cur + "|" + next);

                        EP_POSTS.Title     = publish_SITE;
                        EP_POSTS.GUID      = Guid.NewGuid().ToString();
                        EP_POSTS.UserID    = User.Identity.GetUserId();
                        EP_POSTS.Date      = DateTime.Now;
                        EP_POSTS.Type      = "Categories";
                        EP_POSTS.Mime_type = service;
                        EP_POSTS.Category  = catstring;
                        db.EP_POST.Add(EP_POSTS);
                        db.SaveChanges();
                    }

                    if (meta.publish == "Naver")
                    {
                        Category[]    category;
                        List <string> categorylist = new List <string>();
                        try
                        {
                            MetaWeblog api = new MetaWeblog("https://api.blog.naver.com/xmlrpc");
                            //api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, true);
                            category = api.getCategories(Publish_BLOGID, Publish_ID, Publish_BLOGKEY);
                            foreach (Category cate in category)
                            {
                                categorylist.Add(cate.title);
                            }
                        }
                        catch
                        {
                            ModelState.AddModelError("", "실패했습니다.");
                        }
                        string catstring = categorylist.ToArray().Aggregate((cur, next) => cur + "|" + next);

                        EP_POSTS.Title     = publish_SITE;
                        EP_POSTS.GUID      = Guid.NewGuid().ToString();
                        EP_POSTS.UserID    = User.Identity.GetUserId();
                        EP_POSTS.Date      = DateTime.Now;
                        EP_POSTS.Type      = "Categories";
                        EP_POSTS.Mime_type = service;
                        EP_POSTS.Category  = catstring;
                        db.EP_POST.Add(EP_POSTS);
                        db.SaveChanges();
                    }
                    if (meta.publish == "WordPress")
                    {
                        Category[]    category;
                        List <string> categorylist = new List <string>();
                        try
                        {
                            MetaWeblog api = new MetaWeblog(publish_SITE + "/xmlrpc.php");
                            //api.newPost("", Publish_ID, Publish_PW, post, true);
                            category = api.getCategories("1", Publish_ID, Publish_PW);
                            foreach (Category cate in category)
                            {
                                categorylist.Add(cate.title);
                            }
                        }
                        catch
                        {
                            ModelState.AddModelError("", "실패했습니다.");
                        }
                        string catstring = categorylist.ToArray().Aggregate((cur, next) => cur + "|" + next);

                        EP_POSTS.Title     = publish_SITE;
                        EP_POSTS.GUID      = Guid.NewGuid().ToString();
                        EP_POSTS.UserID    = User.Identity.GetUserId();
                        EP_POSTS.Date      = DateTime.Now;
                        EP_POSTS.Type      = "Categories";
                        EP_POSTS.Mime_type = service;
                        EP_POSTS.Category  = catstring;
                        db.EP_POST.Add(EP_POSTS);
                        db.SaveChanges();
                    }
                }
            }
        }
Пример #2
0
        public ActionResult Posting(int?id, string[] BlogService, string[] category, int?[] size, int[] pub)
        {
            Post post = new Post();

            EP_POSTS EP_POST = db.EP_POST.Find(id);

            bool post_private = true;

            for (int i = 0; i < BlogService.Count(s => s != null); i++)
            {
                int reali = Convert.ToInt32(BlogService[i].Substring(0, 1));

                char     sp       = '|';
                string[] spstring = BlogService[i].Split(sp);
                string   realsite = spstring[1];
                string   realcate = category[reali];
                int?     realsize = size[reali];

                if (pub[reali] == 0)
                {
                    post_private = false;
                }

                IEnumerable <EP_METAS> metas = db.EP_META.ToList().Where(c => c.publish_SITE == realsite && c.UserID == User.Identity.GetUserId());
                foreach (var meta in metas)
                {
                    String Publish_BLOGID  = meta.Publish_BLOGID;
                    String service         = meta.publish;
                    String publish_SITE    = meta.publish_SITE;
                    String Publish_ID      = meta.Publish_ID;
                    String Publish_BLOGKEY = meta.Publish_BLOGKEY;
                    String Publish_PW      = meta.Publish_PW;
                    if (service == "Tistory")
                    {
                        try
                        {
                            MetaWeblog api = new MetaWeblog(publish_SITE + "/api");
                            //EP_POST.Body 545가 있다면
                            if (realsize == null)
                            {
                                post.description = EP_POST.Body;
                                post.title       = EP_POST.Title;
                                post.mt_keywords = EP_POST.Slug;
                                post.categories  = new string[] { realcate };
                                post.dateCreated = DateTime.UtcNow;
                                api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, post_private);
                            }
                            else if (realsize != null)
                            {
                                string des = EP_POST.Body.Replace(@"width='545'", @"width='" + realsize + @"'");
                                post.description = des;
                                post.title       = EP_POST.Title;
                                post.mt_keywords = EP_POST.Slug;
                                post.categories  = new string[] { realcate };
                                post.dateCreated = DateTime.UtcNow;
                                api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, post_private);
                            }
                        }
                        catch
                        {
                            ModelState.AddModelError("", "실패했습니다.");
                        }
                    }

                    if (service == "Naver")
                    {
                        try
                        {
                            MetaWeblog api = new MetaWeblog("https://api.blog.naver.com/xmlrpc");
                            if (realsize == null)
                            {
                                string des = EP_POST.Body.Replace(@"width='545'", @"width='730'");
                                post.description = des;
                                post.title       = EP_POST.Title;
                                post.tags        = EP_POST.Slug;
                                post.dateCreated = DateTime.UtcNow;
                                post.categories  = new string[] { realcate };
                                api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, post_private);
                            }
                            else if (realsize != null)
                            {
                                string des = EP_POST.Body.Replace(@"width='545'", @"width='" + realsize + @"'");
                                post.description = des;
                                post.title       = EP_POST.Title;
                                post.mt_keywords = EP_POST.Slug;
                                post.categories  = new string[] { realcate };
                                post.dateCreated = DateTime.UtcNow;
                                api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, post_private);
                            }
                        }
                        catch
                        {
                            ModelState.AddModelError("", "실패했습니다.");
                        }
                    }
                    if (service == "WordPress")
                    {
                        try
                        {
                            MetaWeblog api = new MetaWeblog(publish_SITE + "/xmlrpc.php");
                            if (realsize != null)
                            {
                                string des = EP_POST.Body.Replace(@"width='545'", @"width='" + realsize + @"'");
                                post.description = des;
                                post.title       = EP_POST.Title;
                                post.mt_keywords = EP_POST.Slug;
                                post.categories  = new string[] { realcate };
                                post.dateCreated = DateTime.UtcNow;
                                api.newPost(Publish_BLOGID, Publish_ID, Publish_BLOGKEY, post, post_private);
                            }
                            else
                            {
                                post.description = EP_POST.Body;
                                post.title       = EP_POST.Title;
                                post.mt_keywords = EP_POST.Slug;
                                post.dateCreated = DateTime.UtcNow;
                                post.categories  = new string[] { realcate };
                                api.newPost("", Publish_ID, Publish_PW, post, post_private);
                            }
                        }
                        catch
                        {
                            ModelState.AddModelError("", "실패했습니다.");
                        }
                    }

                    if (EP_POST.Publish1 != null)
                    {
                        EP_POST.Publish2      = EP_POST.Publish1;
                        EP_POST.Publish2_time = EP_POST.Publish1_time;
                        EP_POST.Publish2_site = EP_POST.Publish1_site;
                        EP_POST.Publish1      = service;
                        EP_POST.Publish1_time = DateTime.Now;
                        EP_POST.Publish1_site = publish_SITE;
                    }
                    else if (EP_POST.Publish1 == null)
                    {
                        EP_POST.Publish1      = service;
                        EP_POST.Publish1_time = DateTime.Now;
                        EP_POST.Publish1_site = publish_SITE;
                    }
                    db.Entry(EP_POST).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult Create([Bind(Include = "ID,UserID,publish,publish_SITE,Publish_ID,Publish_PW,Publish_BLOGID,Publish_BLOGKEY")] EP_METAS eP_METAS, string SERVICE)
        {
            if (ModelState.IsValid)
            {
                if (SERVICE == "Tistory")
                {
                    try
                    {
                        string[]   strarray    = eP_METAS.publish_SITE.Split('/');
                        MetaWeblog api         = new MetaWeblog("http://" + strarray[2] + "/api");
                        Post[]     check_login = new Post[1];
                        check_login = api.getRecentPosts(eP_METAS.Publish_BLOGID, eP_METAS.Publish_ID, eP_METAS.Publish_PW, 1);
                    }
                    catch
                    {
                        ModelState.AddModelError("", "사용자 이름 또는 암호가 잘못되었습니다.");
                        return(View());
                    }
                }
                if (SERVICE == "Naver")
                {
                    try
                    {
                        string[]   strarray    = eP_METAS.publish_SITE.Split('/');
                        MetaWeblog api         = new MetaWeblog("https://api.blog.naver.com/xmlrpc");
                        Post[]     check_login = new Post[1];
                        check_login = api.getRecentPosts(eP_METAS.Publish_BLOGID, eP_METAS.Publish_ID, eP_METAS.Publish_BLOGKEY, 1);
                    }
                    catch
                    {
                        ModelState.AddModelError("", "사용자 이름 또는 암호가 잘못되었습니다.");
                        return(View());
                    }
                }
                if (SERVICE == "WordPress")
                {
                    try
                    {
                        string[]   strarray    = eP_METAS.publish_SITE.Split('/');
                        MetaWeblog api         = new MetaWeblog(eP_METAS.publish_SITE + "/xmlrpc.php");
                        Post[]     check_login = new Post[1];
                        check_login = api.getRecentPosts("", eP_METAS.Publish_ID, eP_METAS.Publish_PW, 1);
                    }
                    catch
                    {
                        ModelState.AddModelError("", "사용자 이름 또는 암호가 잘못되었습니다.");
                        //return View();
                        return(RedirectToAction("Create", "BlogAPI", new { SERVICE = "WordPress" }));
                    }
                }
                //if (SERVICE == "Blogger")
                //{
                //    try
                //    {
                //        string[] strarray = eP_METAS.publish_SITE.Split('/');
                //        MetaWeblog api = new MetaWeblog("http://www.blogger.com/feeds/" + eP_METAS.ID +"/posts/default");

                //        Post[] check_login = new Post[1];
                //        check_login = api.getRecentPosts("", eP_METAS.Publish_ID, eP_METAS.Publish_PW, 1);
                //    }
                //    catch
                //    {
                //        ModelState.AddModelError("", "사용자 이름 또는 암호가 잘못되었습니다.");
                //        return View();

                //    }
                //}
                eP_METAS.publish = SERVICE;
                eP_METAS.UserID  = User.Identity.GetUserId();
                //eP_METAS.publish = ViewData["Metaservice"].ToString;
                db.EP_META.Add(eP_METAS);
                db.SaveChanges();
                return(RedirectToAction("Manage", "Account"));
            }

            return(View(eP_METAS));
        }