Exemple #1
0
 public void Modify(long id, string title, bool top, string tag, long category, string sourceUrl, string content,
                    string summary)
 {
     DBModules.Blog item;
     if (id > 0)
     {
         item = DBContext.Load <DBModules.Blog>(id);
     }
     else
     {
         item = new DBModules.Blog();
     }
     if (item != null)
     {
         item.Title      = title;
         item.Top        = top;
         item.Tags       = tag;
         item.CategoryID = category;
         Category cate = DBContext.Load <Category>(category);
         if (cate != null)
         {
             item.Category = cate.Name;
         }
         item.SourceUrl = sourceUrl;
         item.Content   = content;
         item.Summary   = summary;
         item.Save();
         RefreshBlog refreshBlog = new RefreshBlog();
         refreshBlog.BlogID = item.ID;
         refreshBlog.Status = 1;
         refreshBlog.Save();
     }
 }
Exemple #2
0
 public object GetBlog(long id, HttpResponse response)
 {
     DBModules.Blog blog = DBContext.Load <DBModules.Blog>(id);
     if (blog != null)
     {
         string token = Units.MD5Encrypt(id.ToString() + DateTime.Now.Date);
         response.SetCookie(COMMINT_TOKEN, token, DateTime.Now.AddMinutes(10));
         return(new
         {
             blog.ID,
             blog.Title,
             blog.Category,
             blog.CategoryID,
             blog.Content,
             Tags = string.IsNullOrEmpty(blog.Tags) ? new string[0] : blog.Tags.Split(' ', StringSplitOptions.RemoveEmptyEntries),
             blog.SourceUrl,
             CreateTime = blog.CreateTime.ToString(),
         });
     }
     return(new object());
 }
Exemple #3
0
        private static void OnSyncData(object state)
        {
            BeetleX.FastHttpApi.HttpApiServer server = (BeetleX.FastHttpApi.HttpApiServer)state;
            if (!Available)
            {
                return;
            }
            mSyncTimer.Change(-1, -1);
            try
            {
                foreach (var item in new Peanut.Expression().List <DBModules.RefreshBlog>())
                {
                    if (item.Status == 1)
                    {
                        DBModules.Blog blog = Peanut.DBContext.Load <DBModules.Blog>(item.BlogID);
                        if (blog != null)
                        {
                            ES.ESBlog eSBlog = new ESBlog();
                            eSBlog.ID         = blog.ID.ToString();
                            eSBlog.CategoryID = blog.CategoryID;
                            eSBlog.Content    = blog.Content;
                            eSBlog.CreateTime = blog.CreateTime;
                            eSBlog.SourceUrl  = blog.SourceUrl;
                            eSBlog.Summary    = blog.Summary;
                            eSBlog.Category   = blog.Category;
                            eSBlog.Tags       = blog.Tags;
                            eSBlog.Title      = blog.Title;
                            eSBlog.Top        = blog.Top;
                            Blog.Put(eSBlog);

                            (DBModules.RefreshBlog.blogID == blog.ID).Delete <DBModules.RefreshBlog>();
                            if (server.EnableLog(EventArgs.LogType.Info))
                            {
                                server.Log(EventArgs.LogType.Info, $"update blog {blog.Title} sync to elasticsearch  success");
                            }
                        }
                    }
                    else
                    {
                        (DBModules.RefreshBlog.blogID == item.BlogID).Delete <DBModules.RefreshBlog>();
                        try
                        {
                            Blog.Delete <ESBlog>(item.BlogID.ToString());
                            if (server.EnableLog(EventArgs.LogType.Info))
                            {
                                server.Log(EventArgs.LogType.Info, $"delete blog {item.BlogID} sync to elasticsearch  success");
                            }
                        }
                        catch (Exception e_)
                        {
                            if (server.EnableLog(EventArgs.LogType.Error))
                            {
                                server.Log(EventArgs.LogType.Error, $"delete blog {item.BlogID} sync to elasticsearch  error {e_.Message}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (server.EnableLog(EventArgs.LogType.Error))
                {
                    server.Log(EventArgs.LogType.Error, $"blog sync to elasticsearch error {e.Message}");
                }
            }
            finally
            {
                mSyncTimer.Change(5000, 5000);
            }
        }