Esempio n. 1
0
 /// <summary>
 /// 接收短信
 /// </summary>
 /// <returns>接收到的短信数量</returns>
 public int ReceiveSms()
 {
     EucpHelper oEucpHelper = new EucpHelper(ConfigHelper.EucpConfig.SerialNumber, ConfigHelper.EucpConfig.Password);
     List<object> oList = oEucpHelper.ReceiveSms();
     int nCount = 0;
     foreach (Dictionary<string, object> oMessage in oList)
     {
         GeneralMessageReceive oReceive = new GeneralMessageReceive
         {
             SendFrom = oMessage["Mobile"].ToString(),
             Matter = oMessage["Content"].ToString(),
             SentTime = (DateTimeOffset)oMessage["SentTime"],
             GetFrom = oMessage["Channel"].ToString()
         };
         dbEntity.GeneralMessageReceives.Add(oReceive);
         dbEntity.SaveChanges();
         nCount++;
     }
     return nCount;
 }
Esempio n. 2
0
        public void GeneralTest()
        {
            try
            {
                // 创建数据库事务
                using (var scope = new TransactionScope())
                {
                    // 创建EF实体
                    using (var oLiveEntities = new LiveEntities(ConfigHelper.LiveConnection.Connection))
                    {
                        GeneralResource oResource = new GeneralResource
                        {
                            Code = "Test",
                            Culture = 0,
                            Matter = "名称"
                        };
                        string culturename = oResource.CultureName;

                        CultureInfo oCultureCN = new CultureInfo("zh-CN");
                        CultureInfo oCultureGB = new CultureInfo("en-GB");
                        CultureInfo oCultureUS = new CultureInfo("en-US");
                        CultureInfo oCultureFR = new CultureInfo("fr-FR");
                        CultureInfo oCultureDE = new CultureInfo("de-DE");

                        GeneralMessageReceive oMessageReceive = new GeneralMessageReceive
                        {
                            SendFrom = "13816626660",
                            Matter = "Hello World",
                            GetFrom = "EUCP",
                            SentTime = new DateTime(2010, 2, 10, 12, 35, 09)
                        };

                        oLiveEntities.GeneralMessageReceives.Add(oMessageReceive);
                        // 此处,数据库中事实上没有保存
                        oLiveEntities.SaveChanges();

                        GeneralProgram oProgram = new GeneralProgram
                        {
                            Code = "Main"
                        };
                        GeneralProgNode oNode = new GeneralProgNode
                        {
                            Program = oProgram,
                            Code = "Test"
                        };
                        oLiveEntities.GeneralProgNodes.Add(oNode);
                        oLiveEntities.SaveChanges();
                    }
                    // 提交事务,数据库物理写入
                    scope.Complete();
                    Debug.WriteLine("Submit Completed");
                }
            }
            catch (TransactionAbortedException ex)
            {
                Console.WriteLine("TransactionAbortedException Message: {0}", ex.Message);
            }
            catch (ApplicationException ex)
            {
                Console.WriteLine("ApplicationException Message: {0}", ex.Message);
            }
            GC.Collect();
        }