public void AddArticlesTest()
        {
            // Acts

            // products

            string[] colors = new string[] { "Blue", "Red", "Green" };

            for (int i = 1; i <= 10; i++)
            {
                var product = new Product($"Product {i}", 10.00m, colors[i % 3]);
                articlesService.Add(product);
            }

            // services
            for (int i = 1; i <= 3; i++)
            {
                var service = new Service($"Service {i}", 100);
                articlesService.Add(service);
            }

            // Assets

            var products = articlesService.Get();

            Assert.IsTrue(products.Count >= 10);
        }
Exemplo n.º 2
0
        public string Save()
        {
            string saveData = Request.Params["saveData"];

            saveData = saveData.Replace("\r\n", "<br/>").Replace("\\n", "<br/>").Replace(" ", "&nbsp;");
            articles entity = JsonConvert.DeserializeObject <articles>(saveData);
            bool     isSave = _articlesService.Add(entity);

            return(isSave ? "1" : "0");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 保存HTML
        /// </summary>
        /// <param name="args"></param>
        private static void SaveHtmlEvent(DataReceivedEventArgs args)
        {
            Regex  reg     = new Regex(@"(?m)<title[^>]*>(?<title>(?:\w|\W)*?)</title[^>]*>", RegexOptions.Multiline | RegexOptions.IgnoreCase);
            Match  mc      = reg.Match(args.Html);
            string m_title = String.Empty;

            if (mc.Success)
            {
                m_title = mc.Groups["title"].Value.Trim();
            }

            Regex urlRegex = new Regex(@"(?i)http://(\w+\.){1,3}(com(\.cn)?|cn|net)\b");

            //去除域名后
            var shtml = urlRegex.Replace(args.Html, "/File");

            try
            {
                lock (syncRoot)
                {
                    //更新数据库
                    Articles article = new Articles();
                    article.Id       = PrimaryKeyGen.GuidToLongId();
                    article.IsDelete = false;
                    article.Url      = args.Url;
                    article.Title    = m_title;
                    article.Summary  = m_title;
                    article.Content  = shtml;
                    article.AddTime  = DateTime.Now.ToString("yyyyMMdd hh:mm:ss");
                    var saveResult = _IArticlesService.Add(article);

                    if (saveResult)
                    {
                        // 更新索引库
                        IndexTask task = new IndexTask();
                        task.TaskId = article.Id;
                        task.Title  = m_title;
                        //去除回车,空格,换行
                        task.Content = HtmlConverts.ConvertHtml(shtml).Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");;
                        task.Summary = m_title;
                        IndexManager.Instance.AddArticle(task);
                    }
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Url:{0};\r\n错误信息{1}", args.Url, ex.InnerException.Message);
            }
        }
        public void Add()
        {
            Task task1 = Task.Run(() =>
            {
                for (var i = 0; i < 99999; i++)
                {
                    Articles article = new Articles();
                    article.Id       = PrimaryKeyGen.GuidToLongId();
                    article.IsDelete = false;
                    article.Url      = "http://codego.net/10158933/" + PrimaryKeyGen.GuidToLongId();
                    article.Title    = "cs";
                    article.Content  = "测试添加";
                    article.AddTime  = DateTime.Now.ToString("yyyyMMddhhmmss");
                    var saveResult   = _IArticlesService.Add(article);
                }
            });


            Task.WaitAll(task1);
        }
Exemplo n.º 5
0
        public IResult AddArticle([FromBody] Articles model)
        {
            AutUserInfo userInfo      = _httpContext.HttpContext.Session.GetObject <AutUserInfo>("UserInfo");
            string      resultmessage = StaticValues.ErrorMessage;
            int         resultcode    = StaticValues.ErrorCode;
            bool        resultval     = false;

            try
            {
                _logs.Add(userInfo.SessId, string.Format("Makale ekleme işlemi ekli parametreler ile başlamıştır.{0}", Reflections.GetModelPropertyValues <Articles>(model)), "AddArticle", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
                var result = _article.Add(model, userInfo);
                resultcode    = result.ResultCode;
                resultmessage = result.Message;
                resultval     = result.IsSuccess;
                _logs.Add(userInfo.SessId, string.Format("Makale ekleme işlemi tamamlanmıştır.Sonuç={0}", (resultval ? "Başarılı" : "Hatalı")), "AddArticle", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
            }
            catch (Exception ex)
            {
                _logs.Add(userInfo.SessId, ex.ToString(), "AddArticle", "ArticleController", Enum.GetName(typeof(LayerInfo), 1), "", userInfo.ClientIp, userInfo.UsrId);
            }
            return(new Result(resultval, resultmessage, resultcode));
        }