예제 #1
0
 /// <summary>
 /// 服务启动时执行一次
 /// </summary>
 /// <param name="args"></param>
 protected override void OnStart(string[] args)
 {
     StageTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
     int nValue;
     if (Int32.TryParse(ConfigHelper.GlobalConst.GetSetting("DelayTime"), out nValue))
         nDelayTime = nValue;
     if (Int32.TryParse(ConfigHelper.GlobalConst.GetSetting("Interval"), out nValue))
         StageTimer.Interval = nValue * 1000;
     EventBLL oEventBLL = new EventBLL();
     oEventBLL.WriteEvent(String.Format("OnStart 服务启动,延迟{0}周期启动连接", nDelayTime), this.ToString());
     StageTimer.Enabled = true;
     oSemaphore = LiveSemaphore.GREED;              // 设置绿灯
 }
예제 #2
0
        public void TestOld()
        {
            LiveEntities dbEntity = new LiveEntities(ConfigHelper.LiveConnection.Connection);

            CultureInfo oCulture1 = new CultureInfo("zh-CN");
            CultureInfo oCulture2 = new CultureInfo("zh-TW");
            CultureInfo oCulture = new CultureInfo("ja-JP");
            decimal dm = 123894.56m;
            string s1 = oCulture.NumberFormat.CurrencySymbol + dm.ToString(oCulture.NumberFormat);
            Debug.WriteLine(s1);

            string symbolRMB = (new CultureInfo("zh-CN")).NumberFormat.CurrencySymbol;
            string symbolUSD = (new CultureInfo("en-US")).NumberFormat.CurrencySymbol;
            string symbolEUR = (new CultureInfo("fr-FR")).NumberFormat.CurrencySymbol;
            Guid? oUnitRMB = (from m in dbEntity.GeneralMeasureUnits
                              where m.Code == symbolRMB
                              select m.Gid).FirstOrDefault();
            Guid? oUnitUSD = (from m in dbEntity.GeneralMeasureUnits
                              where m.Code == symbolUSD
                              select m.Gid).FirstOrDefault();
            Guid? oUnitEUR = (from m in dbEntity.GeneralMeasureUnits
                              where m.Code == symbolEUR
                              select m.Gid).FirstOrDefault();

            GeneralResource oMoney = new GeneralResource
            {
                Rtype = (byte)ModelEnum.ResourceType.MONEY,
                Currency = oUnitRMB,
                Cash = 123.56m,
                ResourceItems = new List<GeneralResItem>
                {
                    new GeneralResItem { Currency = oUnitUSD, Cash = 34.67m },
                    new GeneralResItem { Currency = oUnitEUR, Cash = 31.69m }
                }
            };
            dbEntity.GeneralResources.Add(oMoney);
            dbEntity.SaveChanges();

            GeneralBLL oGeneralBLL = new GeneralBLL(dbEntity);
            string sm = oGeneralBLL.GetMoneyString(oMoney.Gid, oUnitRMB);

            string sMoneyCode1 = oMoney.GetCurrencyUnit(dbEntity).Code;
            string sMoneyCode2 = oMoney.GetCurrencyUnit(dbEntity, oUnitUSD.Value).Code;

            GeneralProgNode oProgNode = new GeneralProgNode
            {
                Program = dbEntity.GeneralPrograms.Where(p => p.Code == "ConfigIndex").FirstOrDefault(),
                Code = "EnableModify",
                Name = new GeneralResource
                {
                    Culture = 1033,
                    Matter = "Modify",
                    ResourceItems = new List<GeneralResItem>
                    {
                        new GeneralResItem { Culture = 2052, Matter = "允许修改" }
                    }
                },
                InputMode = (byte)ModelEnum.OptionalInputMode.COMBOBOX,
                Optional = new GeneralResource
                {
                    Culture = 1033,
                    Matter = "{0|No},{1|Yes}",
                    ResourceItems = new List<GeneralResItem>
                    {
                        new GeneralResItem { Culture = 2052, Matter = "{0|否},{1|是}" }
                    }
                }
            };
            dbEntity.GeneralProgNodes.Add(oProgNode);
            dbEntity.SaveChanges();

            MemberPrivilege oPrivilege = new MemberPrivilege
            {
                User = dbEntity.MemberUsers.Where(u => u.LoginName == "test").FirstOrDefault(),
                Ptype = (byte)ModelEnum.UserPrivType.PROGRAM_NODE,
                PrivilegeItems = new List<MemberPrivItem>
                {
                     new MemberPrivItem
                     {
                         RefID = oProgNode.Gid,
                         NodeCode = "EnableModify",
                         NodeValue = "1"
                     }
                }
            };
            dbEntity.MemberPrivileges.Add(oPrivilege);
            dbEntity.SaveChanges();

            Dictionary<string, string> oProgramNodes = new Dictionary<string, string>();
            oProgramNodes.Add("Supervisor", "1");
            if (oProgramNodes.ContainsKey("Supervisor") && (oProgramNodes["Supervisor"] == "1"))
            {
                Debug.WriteLine(oProgramNodes["Supervisor"]);
            }
            if (oProgramNodes.ContainsKey("Key") && (oProgramNodes["Key"] == "1"))
            {
                string s = oProgramNodes["Key"];
                Debug.WriteLine(s);
            }

            TimeSpan oTimeSpan = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
            DateTimeOffset oLocalTime1 = new DateTimeOffset(2011, 8, 24, 13, 45, 24, oTimeSpan);

            DateTime oLocalTime2 = DateTime.Now;
            oLocalTime2 = DateTime.SpecifyKind(oLocalTime2, DateTimeKind.Utc);
            DateTimeOffset oLocalTime3 = oLocalTime2;
            DateTimeOffset oLocalTime4 = oLocalTime1;

            GeneralConfig oConfig1 = new GeneralConfig
            {
                Code = "Test11",
                DateValue = oLocalTime1
            };
            GeneralConfig oConfig2 = new GeneralConfig
            {
                Code = "Test21",
                DateValue = oLocalTime3
            };
            GeneralConfig oConfig3 = new GeneralConfig
            {
                Code = "Test31",
                DateValue = oLocalTime4
            };

            dbEntity.GeneralConfigs.Add(oConfig1);
            dbEntity.GeneralConfigs.Add(oConfig2);
            dbEntity.GeneralConfigs.Add(oConfig3);
            dbEntity.SaveChanges();

            GeneralTodoList oTodo2 = (from t in dbEntity.GeneralTodoLists
                                      where t.Gid == new Guid("3429BF77-1ECE-E011-A3A0-60EB69D65AE8")
                                      select t).FirstOrDefault();

            // string strSQL = String.Format("SELECT * FROM dbo.fn_FindTest('{0}')", Guid.Empty);
            // string strSQL = String.Format("EXECUTE sp_FindTest '{0}'", Guid.Empty);

            var fnFindTest = dbEntity.Database.SqlQuery<ShipList>("SELECT * FROM fn_FindTest({0})", Guid.Empty);

            foreach (ShipList fnItem in fnFindTest)
            {
                Debug.WriteLine(fnItem.ShipID);
                Debug.WriteLine(fnItem.ShipWeight);
            }

            Guid og = Guid.Empty;
            Guid? og1 = null;
            Guid? og2 = Guid.NewGuid();
            Guid? og3 = Guid.Empty;
            if (og == Guid.Empty)
                Debug.WriteLine(og);
            if (og1.HasValue)
                Debug.WriteLine(og1.Value);
            if (og2.HasValue)
                Debug.WriteLine(og2.Value);
            if (og3.HasValue)
                Debug.WriteLine(og3.Value);

            var list = from c in dbEntity.WarehouseInformations
                       where c.Deleted == false
                       select c.Parent;
            foreach (var v in list)
            {
                Debug.WriteLine(v.FullName.Matter);

                //Debug.WriteLine(v.Key);
                //foreach (var item in v)
                //{
                //    Debug.WriteLine(item.FullName.Matter);
                //}
                //if (v.FullName == null)
                //    Debug.WriteLine("is null");
                //foreach (var v2 in v.FullName.ResourceItems)
                //    Debug.WriteLine(v2.Matter);
            }

            EventBLL oEventBLL = new EventBLL(dbEntity);
            oEventBLL.WriteEvent("系统启动", ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString());

            GeneralConfig oConfig = dbEntity.GeneralConfigs.Where(c => c.Code == "SessionName").FirstOrDefault();

            List<ListItem> oList2 = oConfig.SelectEnumList(typeof(ModelEnum.ActionSource), 2);
            string oListName = oConfig.SelectEnumName(typeof(ModelEnum.ActionSource), 2);
        }
예제 #3
0
        /// <summary>
        /// 时间触发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            if (oSemaphore == LiveSemaphore.RED)           // 红灯冲突,终止执行
                return;
            if (nDelayTime > 0)                            // 延迟一个周期
            {
                nDelayTime--;
                return;
            }

            // 开始执行事件
            oSemaphore = LiveSemaphore.RED;
            LiveEntities dbEntity = new LiveEntities(ConfigHelper.LiveConnection.Connection);
            EventBLL oEventBLL = new EventBLL(dbEntity);
            try
            {
                oEventBLL.WriteEvent("OnTimedEvent 执行事件", this.ToString());

                // 淘宝接口同步
                Section.TaobaoDaemon oTaobao = new Section.TaobaoDaemon(dbEntity, oEventBLL);
                oTaobao.Main();

                // 消息服务
                Section.MessageDaemon oMessage = new Section.MessageDaemon(dbEntity, oEventBLL);
                oMessage.Main();

                // 同步分布式数据库
                Section.SynchroDaemon oSynchro = new Section.SynchroDaemon(dbEntity, oEventBLL);
                oSynchro.Main();

                oEventBLL.WriteEvent("OnTimedEvent 执行结束", this.ToString());
            }
            catch (Exception ex)
            {
                oEventBLL.WriteEvent("OnTimedEvent " + ex.Message,
                    ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString());
            }
            finally
            {
                try
                {
                    dbEntity.Dispose();
                }
                catch { }
            }
            oSemaphore = LiveSemaphore.GREED;
        }
예제 #4
0
 protected override void OnStop()
 {
     EventBLL oEventBLL = new EventBLL();
     oEventBLL.WriteEvent("OnStop 服务停止", this.ToString());
 }