Beispiel #1
0
        private static void RunInsert(IDataProvider provider)
        {
            ResetDB(provider);

            var repo = new SimpleRepository(provider);

            Console.WriteLine("Inserting 1000 rows using Simple Repo: " + DateTime.Now + " using " + provider.Client);
            DateTime start = DateTime.Now;

            for (int i = 1; i < 1000; i++)
            {
                SubSonic.Tests.TestClasses.Product p = new SubSonic.Tests.TestClasses.Product();
                p.CategoryID   = 1;
                p.Discontinued = false;
                p.ProductName  = "Product" + i;
                p.Sku          = Guid.NewGuid();
                p.UnitPrice    = 1000;
                repo.Add(p);
                //Console.WriteLine(i);
            }
            DateTime end = DateTime.Now;
            TimeSpan ts  = end.Subtract(start);

            Console.WriteLine("End: " + DateTime.Now + " (" + ts.Seconds + ":" + ts.Milliseconds + ")");
        }
        public string Order(string imsi, string targetContentId, string productCode, string orderNo, float price = 0)
        {
            if (price <= 0)
            {
                return(null);
            }
            Order order = new Order();

            order.Imsi            = imsi;
            order.ProductCode     = productCode;
            order.Status          = OrderStatus.Created;
            order.TargetContentID = targetContentId;
            order.CreateDate      = DateTime.Now;
            order.Price           = price;
            try
            {
                order.OrderNo = orderNo;
                SimpleRepository.Add <Order>(order);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("ErrorLogger").Error(string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace));
                return(null);
            }
            return(order.OrderNo);
        }
Beispiel #3
0
        private static void TestSubSonic()
        {
            var p = ProviderFactory.GetProvider(@"Data Source=C:\dd\temp.sdf",
                                                "System.Data.SQLite");
            var rep  = new SimpleRepository(p, SimpleRepositoryOptions.RunMigrations);
            var item = new Post {
                Body = "test", Title = "test"
            };

            rep.Add(item);
            var item2 = rep.Single <Post>(item.ID);
        }
Beispiel #4
0
        public T Post(T item)
        {
            var repo = new SimpleRepository <T>(connectionFactory);

            item = repo.Add(item);

            if (item != null)
            {
                return(item);
            }
            else
            {
                throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
            }
        }
        public void SimpleRepository_Add_test()
        {
            SimpleRepository repository = new SimpleRepository("ConnectionStringOracleGeneral", SimpleRepositoryOptions.RunMigrations);
            int result = repository.Add <GeneralUser>(new GeneralUser {
                Email       = "*****@*****.**",
                Password    = "******",
                PhoneNumber = "136487979797"
            });

            var id = repository.NewAdd <GeneralUser>(new GeneralUser
            {
                Email       = "*****@*****.**",
                Password    = "******",
                PhoneNumber = "136487979797"
            });

            Console.WriteLine(id);
        }
Beispiel #6
0
        private static void RunInsert(IDataProvider provider)
        {
            ResetDB(provider);

            var repo = new SimpleRepository(provider);

            Console.WriteLine("Inserting 1000 rows using Simple Repo: " + DateTime.Now + " using " + provider.Name);
            DateTime start = DateTime.Now;

            for (int i = 1; i < 1000; i++)
            {
                SubSonic.Tests.TestClasses.Product p = new SubSonic.Tests.TestClasses.Product();
                p.CategoryID   = 1;
                p.Discontinued = false;
                p.ProductName  = "Product" + i;
                p.Sku          = Guid.NewGuid();
                p.UnitPrice    = 1000;
                repo.Add(p);
                //Console.Write(i + ",");
            }
            WriteResult(start);
        }
Beispiel #7
0
		private static void RunInsert(IDataProvider provider)
		{
			ResetDB(provider);

			var repo = new SimpleRepository(provider);
			Console.WriteLine("Inserting 1000 rows using Simple Repo: " + DateTime.Now + " using " + provider.Name);
			DateTime start = DateTime.Now;
			for (int i = 1; i < 1000; i++)
			{
				SubSonic.Tests.TestClasses.Product p = new SubSonic.Tests.TestClasses.Product();
				p.CategoryID = 1;
				p.Discontinued = false;
				p.ProductName = "Product" + i;
				p.Sku = Guid.NewGuid();
				p.UnitPrice = 1000;
				repo.Add(p);
				//Console.Write(i + ",");
			}
			WriteResult(start);
		}
Beispiel #8
0
        static void Main(string[] args)
        {
            EGT_OTA.Models.Repository.UpdateDB();
            SimpleRepository db = Repository.GetRepo();

            try
            {
                var MusicStartIndex = Tools.SafeInt(System.Web.Configuration.WebConfigurationManager.AppSettings["MusicStartIndex"]);
                var MusicEndIndex   = Tools.SafeInt(System.Web.Configuration.WebConfigurationManager.AppSettings["MusicEndIndex"]);
                var LineCount       = Tools.SafeInt(System.Web.Configuration.WebConfigurationManager.AppSettings["LineCount"]);

                for (var i = 0; i < LineCount; i++)
                {
                    Thread thread = new Thread(delegate()
                    {
                        while (MusicStartIndex < MusicEndIndex)
                        {
                            lock (locker)
                            {
                                try
                                {
                                    var json = HttpHelper.Get("http://music.163.com/api/song/detail?ids=%5B" + MusicStartIndex + "%5D");

                                    JArray array = JArray.Parse(JObject.Parse(json)["songs"].ToString());
                                    if (array.Count > 0)
                                    {
                                        JObject model = JObject.Parse(array[0].ToString());
                                        var musicId   = model["id"].ToString();
                                        var musicName = model["name"].ToString();
                                        if (!string.IsNullOrWhiteSpace(musicName))
                                        {
                                            var musicUrl     = model["mp3Url"].ToString();
                                            var artistsArray = JArray.Parse(model["artists"].ToString());
                                            var artists      = JObject.Parse(artistsArray[0].ToString());
                                            var artistsName  = artists["name"].ToString();
                                            var album        = JObject.Parse(model["album"].ToString());
                                            var albumName    = album["name"].ToString();
                                            var musicPicUrl  = album["picUrl"].ToString();

                                            if (!string.IsNullOrWhiteSpace(musicUrl))
                                            {
                                                var result = true;
                                                try
                                                {
                                                    HttpWebRequest wbRequest   = (HttpWebRequest)WebRequest.Create(musicUrl);
                                                    wbRequest.Method           = "GET";
                                                    wbRequest.Timeout          = 2000;
                                                    HttpWebResponse wbResponse = (HttpWebResponse)wbRequest.GetResponse();
                                                    result = (wbResponse.StatusCode == System.Net.HttpStatusCode.OK);

                                                    if (wbResponse != null)
                                                    {
                                                        wbResponse.Close();
                                                    }
                                                    if (wbRequest != null)
                                                    {
                                                        wbRequest.Abort();
                                                    }
                                                    Music music   = new Music();
                                                    music.Author  = artistsName;
                                                    music.Cover   = musicPicUrl;
                                                    music.FileUrl = musicUrl;
                                                    music.Name    = musicName;
                                                    music.Number  = musicId;
                                                    db.Add <Music>(music);
                                                    Console.WriteLine(MusicStartIndex + ":成功");
                                                }
                                                catch (Exception ex)
                                                {
                                                    result = false;
                                                    Console.WriteLine("失败:" + musicName + "," + ex.Message);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine(MusicStartIndex + ":失败");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine(MusicStartIndex);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(MusicStartIndex + ":" + ex.Message);
                                }

                                MusicStartIndex += 1;
                            }
                            Thread.Sleep(1000);
                        }
                    });
                    thread.IsBackground = true;
                    thread.Name         = "同步音乐接口线程" + i;
                    thread.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }
 public virtual void Insert <T>(T data) where T : class, new()
 {
     dataRespository.Add <T>(data);
 }
        public static void Main(string[] args)
        {
            try
            {
                // generate database schema
                Repository.Single <ArticleCategory>(entity => entity.Name == "Schema Update");
                Repository.Single <ArticleComment>(entity => entity.Name == "Schema Update");
                Repository.Single <Article>(entity => entity.Name == "Schema Update");

                var category1 = new ArticleCategory {
                    Name = "ArticleCategory 1"
                };
                var category2 = new ArticleCategory {
                    Name = "ArticleCategory 2"
                };
                var category3 = new ArticleCategory {
                    Name = "ArticleCategory 3"
                };

                // clear/populate the database
                Repository.DeleteMany((ArticleCategory entity) => true);
                var cat1Id = Convert.ToInt32(Repository.Add(category1));
                var cat2Id = Convert.ToInt32(Repository.Add(category2));
                var cat3Id = Convert.ToInt32(Repository.Add(category3));

                Repository.DeleteMany((Article entity) => true);
                var article1 = new Article {
                    Name = "Article 1", ArticleCategoryId = cat1Id
                };
                var article2 = new Article {
                    Name = "Article 2", ArticleCategoryId = cat2Id
                };
                var article3 = new Article {
                    Name = "Article 3", ArticleCategoryId = cat3Id
                };

                var art1Id = Convert.ToInt32(Repository.Add(article1));
                var art2Id = Convert.ToInt32(Repository.Add(article2));
                var art3Id = Convert.ToInt32(Repository.Add(article3));

                Repository.DeleteMany((ArticleComment entity) => true);
                var comment1 = new ArticleComment {
                    Body = "This is comment 1", Name = "Comment1", ArticleId = art1Id
                };
                var comment2 = new ArticleComment {
                    Body = "This is comment 2", Name = "Comment2", ArticleId = art1Id
                };
                var comment3 = new ArticleComment {
                    Body = "This is comment 3", Name = "Comment3", ArticleId = art1Id
                };
                var comment4 = new ArticleComment {
                    Body = "This is comment 4", Name = "Comment4", ArticleId = art2Id
                };
                var comment5 = new ArticleComment {
                    Body = "This is comment 5", Name = "Comment5", ArticleId = art2Id
                };
                var comment6 = new ArticleComment {
                    Body = "This is comment 6", Name = "Comment6", ArticleId = art2Id
                };
                var comment7 = new ArticleComment {
                    Body = "This is comment 7", Name = "Comment7", ArticleId = art3Id
                };
                var comment8 = new ArticleComment {
                    Body = "This is comment 8", Name = "Comment8", ArticleId = art3Id
                };
                var comment9 = new ArticleComment {
                    Body = "This is comment 9", Name = "Comment9", ArticleId = art3Id
                };
                Repository.Add(comment1);
                Repository.Add(comment2);
                Repository.Add(comment3);
                Repository.Add(comment4);
                Repository.Add(comment5);
                Repository.Add(comment6);
                Repository.Add(comment7);
                Repository.Add(comment8);
                Repository.Add(comment9);

                // verify the database generation
                Debug.Assert(Repository.All <Article>().Count() == 3);
                Debug.Assert(Repository.All <ArticleCategory>().Count() == 3);
                Debug.Assert(Repository.All <ArticleComment>().Count() == 9);

                // fetch a master list of articles from the database
                var articles =
                    (from article in Repository.All <Article>()
                     join category in Repository.All <ArticleCategory>()
                     on article.ArticleCategoryId equals category.Id
                     join comment in Repository.All <ArticleComment>()
                     on article.Id equals comment.ArticleId
                     select article)
                    .Distinct()
                    .ToList();

                foreach (var article in articles)
                {
                    Console.WriteLine(article.Name + " ID " + article.Id);
                    Console.WriteLine("\t" + article.Category.Name + " ID " + article.Category.Id);

                    foreach (var articleComment in article.Comments)
                    {
                        Console.WriteLine("\t\t" + articleComment.Name + " ID " + articleComment.Id);
                        Console.WriteLine("\t\t\t" + articleComment.Body);
                    }
                }

                // OUTPUT (ID will vary as autoincrement SQL index

                //Article 1 ID 28
                //        ArticleCategory 1 ID 41
                //                Comment1 ID 100
                //                        This is comment 1
                //                Comment2 ID 101
                //                        This is comment 2
                //                Comment3 ID 102
                //                        This is comment 3
                //Article 2 ID 29
                //        ArticleCategory 2 ID 42
                //                Comment4 ID 103
                //                        This is comment 4
                //                Comment5 ID 104
                //                        This is comment 5
                //                Comment6 ID 105
                //                        This is comment 6
                //Article 3 ID 30
                //        ArticleCategory 3 ID 43
                //                Comment7 ID 106
                //                        This is comment 7
                //                Comment8 ID 107
                //                        This is comment 8
                //                Comment9 ID 108
                //                        This is comment 9

                Console.ReadLine();

                // BETTER WAY (imho)...(joins aren't needed thus freeing up SQL overhead)

                // fetch a master list of articles from the database
                articles = Repository.All <Article>().ToList();

                foreach (var article in articles)
                {
                    Console.WriteLine(article.Name + " ID " + article.Id);
                    Console.WriteLine("\t" + article.Category.Name + " ID " + article.Category.Id);

                    foreach (var articleComment in article.Comments)
                    {
                        Console.WriteLine("\t\t" + articleComment.Name + " ID " + articleComment.Id);
                        Console.WriteLine("\t\t\t" + articleComment.Body);
                    }
                }

                Console.ReadLine();

                // OUTPUT should be identicle
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadLine();
            }
        }
Beispiel #11
0
        private static void RunInsert(IDataProvider provider)
        {
            ResetDB(provider);

            var repo = new SimpleRepository(provider);
            Console.WriteLine("Inserting 1000 rows using Simple Repo: " + DateTime.Now + " using " + provider.Client);
            DateTime start = DateTime.Now;
            for(int i = 1; i < 1000; i++)
            {
                SubSonic.Tests.TestClasses.Product p = new SubSonic.Tests.TestClasses.Product();
                p.CategoryID = 1;
                p.Discontinued = false;
                p.ProductName = "Product" + i;
                p.Sku = Guid.NewGuid();
                p.UnitPrice = 1000;
                repo.Add(p);
                //Console.WriteLine(i);
            }
            DateTime end = DateTime.Now;
            TimeSpan ts = end.Subtract(start);
            Console.WriteLine("End: " + DateTime.Now + " (" + ts.Seconds + ":" + ts.Milliseconds + ")");
        }
Beispiel #12
0
 public int AddCalendar(Calendar data)
 {
     _rep.Add(data);
     return(data.Id);
 }
Beispiel #13
0
        /// <summary>
        /// 推送
        /// </summary>
        /// <param name="usernumber">推送目标用户编号</param>
        /// <param name="id">对象ID(文章ID)</param>
        /// <param name="number">对象Number</param>
        /// <param name="name">用户名称/文章标题</param>
        /// <param name="pushtype">推送类型</param>
        /// <param name="ispush">是否推送</param>
        public void Push(string usernumber, int id, string number, string name, int pushtype, bool ispush = true)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(usernumber))
                {
                    return;
                }
                var user = db.Single <User>(x => x.Number == usernumber);
                if (user == null)
                {
                    return;
                }

                var result = "";
                if (ispush)
                {
                    if (user.ShowPush == 0)
                    {
                        return;
                    }
                    if (string.IsNullOrWhiteSpace(user.ClientID))
                    {
                        return;
                    }
                    PushHelper message = new PushHelper(new List <string>()
                    {
                        user.ClientID
                    });

                    var beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    var endTime   = DateTime.Now.AddHours(12).ToString("yyyy-MM-dd HH:mm:ss");

                    var url = System.Web.Configuration.WebConfigurationManager.AppSettings["base_url"];

                    switch (pushtype)
                    {
                    case Enum_PushType.Article:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇文章推荐啦", name, "", url + "Images/push.png", Enum_PushType.Article + "|" + id, beginTime, endTime);
                        break;

                    case Enum_PushType.Comment:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友评论啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Comment + "|" + id + "|" + number, beginTime, endTime);
                        break;

                    case Enum_PushType.Money:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友打赏啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Money.ToString(), beginTime, endTime);
                        break;

                    case Enum_PushType.Red:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "小微篇送您一个红包,快去看看吧", "", url + "Images/push.png", Enum_PushType.Red.ToString(), beginTime, endTime);
                        break;

                    case Enum_PushType.Fan:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有新的粉丝啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.Fan.ToString(), beginTime, endTime);
                        break;

                    case Enum_PushType.FanArticle:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇提醒您", "有好友发文啦,快去看看吧", "", url + "Images/push.png", Enum_PushType.FanArticle + "|" + id, beginTime, endTime);
                        break;

                    case Enum_PushType.Update:
                        result = message.PushTemplate(Enum_Push.Single, "小微篇更新啦", "更新内容", "", url + "Images/push.png", "10", beginTime, endTime);
                        break;

                    default:
                        break;
                    }
                }
                //推送记录
                PushLog log = new PushLog();
                log.Number       = usernumber;
                log.ObjectID     = id;
                log.ObjectName   = name;
                log.ObjectNumber = number;
                log.PushResult   = result;
                log.PushType     = pushtype;
                log.CreateTime   = DateTime.Now;
                logdb.Add <PushLog>(log);
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLoger.Error("推送失败:" + ex.Message);
            }
        }
        public string LabelPrintProductAddWithDetail(string branchCode, string createdBy, string remark, string labelType, List <LabelPrintProductDetail> details)
        {
            string docno = string.Empty;

            using (DbManager db = new DbManager(branchCode))
            {
                docno = db.SetCommand(GetSql(79)).ExecuteScalar <string>();
            }

            var culture = new System.Globalization.CultureInfo("th-TH");
            int index   = 1;

            if (!string.IsNullOrEmpty(docno))
            {
                index = Convert.ToInt32(docno) + 1;
            }

            docno = string.Format("PR{0}-{1:0000}", DateTime.Now.Date.ToString("yyMMdd", culture), index);

            var master = new LabelPrintProduct();

            master.Branchcode     = branchCode;
            master.Createuser     = createdBy;
            master.Createdate     = DateTime.Now;
            master.Computername   = "PDA";
            master.Docno          = docno;
            master.Docdate        = DateTime.Now.Date;
            master.Remark         = remark;
            master.Printlabeltype = labelType;

            //var labelPrintProduct = repo.Single<LabelPrintProduct>(docno);

            var          displayOrder = 0;
            ProductPrice productPrice = null;

            foreach (var item in details)
            {
                item.Docno    = docno;
                item.Docdate  = DateTime.Now.Date;
                item.Roworder = displayOrder.ToString();
                //item.PrintLabelTypeCode = labelPrintProduct.Printlabeltype;

                productPrice = ProductPriceGetCurrentPrice(branchCode, item.Productcode, item.Unitcode);
                if (productPrice != null)
                {
                    item.Sellprice = productPrice.Saleprice;
                    item.Pricedate = productPrice.Begindate;
                    //item.OthUnitprice = item.Sellprice;
                    item.OthUnitprice = 0;
                    item.OthUnitcode  = "";
                    item.OthUnitname  = "";
                    var UnitOther = ProductPriceGetUnitOther(branchCode, item.Productcode, item.Unitcode);
                    if (UnitOther != null)
                    {
                        item.OthUnitcode = UnitOther.UnitCode;
                        item.OthUnitname = UnitOther.UnitName;
                        var OthPrice = ProductPriceGetCurrentPrice(branchCode, item.Productcode, item.OthUnitcode);
                        if (OthPrice != null)
                        {
                            item.OthUnitprice = OthPrice.Saleprice;
                        }
                        else
                        {
                            item.OthUnitprice = 0;
                            item.OthUnitcode  = "";
                            item.OthUnitname  = "";
                        }
                    }
                }

                displayOrder++;
            }
            var provider = ProviderFactory.GetProvider(branchCode);
            var repo     = new SimpleRepository(provider);

            using (System.Transactions.TransactionScope ts = new TransactionScope())
            {
                using (SharedDbConnectionScope scs = new SharedDbConnectionScope(provider))
                {
                    repo.Add <LabelPrintProduct>(master);
                    repo.AddMany <LabelPrintProductDetail>(details);
                    ts.Complete();
                }
            }
            return(docno);
        }