Beispiel #1
0
        /// <summary>
        /// 延时调用某些行为。
        /// </summary>
        /// <param name="millisecond">延迟的事件ms</param>
        /// <param name="act">要执行的行为</param>
        public void Run(int millisecond, Action act)
        {
            DelayInfo delayInfo = new DelayInfo(act, millisecond);
            Thread    thread    = new Thread(OnThreadProcess);

            thread.IsBackground = true;
            thread.Start(delayInfo);
        }
Beispiel #2
0
 public DelayInfoViewModel(DelayInfo Delay)
     : base()
 {
     CurrentDelay    = Delay;
     SaveCommand     = new CommandHandler(__Save, false);
     m_LiveDataBll   = new LiveDataBLL();
     AllDelayReasons = DelayReason.GetAllDelayReasons();
 }
        public void InitDateChecker(PlatformApiInfo platformInfo, CityPlatformInfo cityInfo, OperationInfo operationInfo, DelayInfo delayInfo)
        {
            PlatformInfo  = platformInfo;
            CityInfo      = cityInfo;
            OperationInfo = operationInfo;
            DelayInfo     = delayInfo;

            ApiClient = new RestClient(CityInfo.AltApiUrl ?? PlatformInfo.ApiUrl);

            Init();
        }
Beispiel #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDelayedTime.Text != string.Empty && !DataValidation.IsNaturalNumber(txtDelayedTime.Text))
                {
                    MessageBox.Show("延迟时间必须为整数!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtDelayedTime.Select();
                    return;
                }

                if (DataValidation.IsNullOrEmpty(txtTimeOut.Text) || !DataValidation.IsNaturalNumber(txtTimeOut.Text))
                {
                    MessageBox.Show("超时时间不能为空且必须是整数!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTimeOut.Select();
                    return;
                }

                if (DataValidation.IsNullOrEmpty(txtTryTimes.Text) || !DataValidation.IsNaturalNumber(txtTryTimes.Text) || DataConvert.GetInt32(txtTryTimes.Text) < 1)
                {
                    MessageBox.Show("尝试次数必须为大于1的整数!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTryTimes.Select();
                    return;
                }

                DelayInfo delay = new DelayInfo();

                if (txtDelayedTime.Text != string.Empty)
                {
                    delay.DelayedTime = DataConvert.GetInt32(txtDelayedTime.Text);
                }
                else
                {
                    delay.DelayedTime = null;
                }

                delay.TimeOut  = DataConvert.GetInt32(txtTimeOut.Text);
                delay.TryTimes = DataConvert.GetInt32(txtTryTimes.Text);

                if (!ConfigCtrl.SetDelay(delay))
                {
                    MessageBox.Show("保存失败!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                Program.ShowMessageBox("DlgDelaySetting", ex);
            }
        }
Beispiel #5
0
        private void AosDelay_Callback(DelayInfo info)
        {
            Mobile target   = info.Target;
            Mobile defender = info.Defender;
            int    damage   = info.Damage;

            if (Caster.HarmfulCheck(defender))
            {
                SpellHelper.Damage(this, target, Utility.Random(damage, 5), 0, 0, 100, 0, 0, info.OrigTarget);

                target.FixedParticles(0x374A, 10, 15, 5038, 1181, 2, EffectLayer.Head);
                target.PlaySound(0x213);
            }
        }
Beispiel #6
0
        public DelayInfoForm(DelayInfo delayInfo)
        {
            DelayInfo = delayInfo;

            InitializeComponent();

            ActionResultDelay.Value         = DelayInfo.ActionResultDelay;
            RefreshSessionUpdateDelay.Value = DelayInfo.RefreshSessionUpdateDelay;
            DiscreteWaitDelay.Value         = DelayInfo.DiscreteWaitDelay;
            ManualReactionWaitDelay.Value   = DelayInfo.ManualReactionWaitDelay;
            PostInputDelay.Value            = DelayInfo.PostInputDelay;
            DateCheckDelay.Value            = DelayInfo.DateCheckDelay;
            RequestTimeout.Value            = DelayInfo.RequestTimeout;
        }
Beispiel #7
0
        private void OnThreadProcess(object obj)
        {
            DelayInfo delayInfo = (DelayInfo)obj;

            Thread.Sleep(delayInfo.Millisecond);
            if (BeginInvoke != null)
            {
                BeginInvoke(delayInfo.Act);
            }
            else
            {
                delayInfo.Act();
            }
        }
Beispiel #8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtDelayedTime.Text != string.Empty && !DataValidation.IsNaturalNumber(txtDelayedTime.Text))
                {
                    MessageBox.Show("延迟时间必须为整数!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtDelayedTime.Select();
                    return;
                }

                if (DataValidation.IsNullOrEmpty(txtTimeOut.Text) || !DataValidation.IsNaturalNumber(txtTimeOut.Text))
                {
                    MessageBox.Show("超时时间不能为空且必须是整数!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTimeOut.Select();
                    return;
                }

                if (DataValidation.IsNullOrEmpty(txtTryTimes.Text) || !DataValidation.IsNaturalNumber(txtTryTimes.Text) || DataConvert.GetInt32(txtTryTimes.Text) < 1)
                {
                    MessageBox.Show("尝试次数必须为大于1的整数!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTryTimes.Select();
                    return;
                }

                DelayInfo delay = new DelayInfo();

                if (txtDelayedTime.Text != string.Empty)
                    delay.DelayedTime = DataConvert.GetInt32(txtDelayedTime.Text);
                else
                    delay.DelayedTime = null;

                delay.TimeOut = DataConvert.GetInt32(txtTimeOut.Text);
                delay.TryTimes = DataConvert.GetInt32(txtTryTimes.Text);

                if (!ConfigCtrl.SetDelay(delay))
                {
                    MessageBox.Show("保存失败!", MainConstants.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                Program.ShowMessageBox("DlgDelaySetting", ex);
            }
        }
 public static Dictionary <string, Dictionary <string, T[]> > CreateFromPlatformInfos <T>(
     PlatformApiInfo[] platforms, DelayInfo delayInfo,
     EventHandler <DateCheckerErrorEventArgs> onRequestErrorHandler,
     EventHandler <DateCheckerOkEventArgs> onRequestOkHandler
     ) where T : DateChecker, new()
 {
     return(platforms.ToDictionary(
                platform => platform.Name,
                platform => CreateFromPlatformInfo <T>(
                    platform, delayInfo,
                    onRequestErrorHandler,
                    onRequestOkHandler
                    )
                ));
 }
 public static Dictionary <string, T[]> CreateFromPlatformInfo <T>(
     PlatformApiInfo platform, DelayInfo delayInfo,
     EventHandler <DateCheckerErrorEventArgs> onRequestErrorHandler,
     EventHandler <DateCheckerOkEventArgs> onRequestOkHandler
     ) where T : DateChecker, new()
 {
     return(platform.CityPlatforms.ToDictionary(
                city => city.Name,
                city => CreateFromCityPlatformInfo <T>(
                    platform, city, delayInfo,
                    onRequestErrorHandler,
                    onRequestOkHandler
                    )
                ));
 }
Beispiel #11
0
 private bool IsThrottleDelayNeeded(out TimeSpan delay)
 {
     delay = TimeSpan.Zero;
     if (this.performanceCounter.CurrentIoOperations >= this.workLoadSize)
     {
         this.performanceCounter.CurrentIoOperations = 0;
         DelayInfo delay2 = this.resourceMonitor.GetDelay();
         if (delay2.Delay > TimeSpan.Zero)
         {
             delay = delay2.Delay;
             return(true);
         }
     }
     return(false);
 }
Beispiel #12
0
		private void AosDelay_Callback(DelayInfo info)
		{
			Mobile m = info.Target;
			int mana = info.ToDrain;

			if (m.Alive && !m.IsDeadBondedPet)
			{
				m.Mana += mana;

				m.FixedEffect(0x3779, 10, 25);
				m.PlaySound(0x28E);
			}

			m_Table.Remove(m);
		}
Beispiel #13
0
        private void AosDelay_Callback(DelayInfo info)
        {
            Mobile m    = info.Target;
            int    mana = info.ToDrain;

            if (m.Alive && !m.IsDeadBondedPet)
            {
                m.Mana += mana;

                m.FixedEffect(0x3779, 10, 25);
                m.PlaySound(0x28E);
            }

            m_Table.Remove(m);
        }
        public DelayInfoViewModel(DelayInfo Delay)
            : base()
        {
            CurrentDelay  = Delay;
            SaveCommand   = new CommandHandler(__Save, false);
            m_LiveDataBll = new LiveDataBLL();

            if (Delay.Schedule.Schedule.Station.ESTW.InfrastructureManager == eInfrastructureManager.DB)
            {
                AllDelayReasons = DelayReason.GetDBDelayReasons();
            }
            else if (Delay.Schedule.Schedule.Station.ESTW.InfrastructureManager == eInfrastructureManager.OEBB)
            {
                AllDelayReasons = DelayReason.GetOEBBDelayReasons();
            }
        }
Beispiel #15
0
        public OperationResult <bool> JustifyDelay(DelayInfo delay, string reason, int?causedBy)
        {
            try
            {
                if (reason.IsNullOrWhiteSpace())
                {
                    return new OperationResult <bool> {
                               Message = "Bitte Grund angeben!"
                    }
                }
                ;

                var SettingsResult = SettingsBLL.GetSettings();
                ValidateResult(SettingsResult);
                var Settings = SettingsResult.Result;

                if (Settings.CheckPlausibility)
                {
                    __CheckDelayJustificationPlausibility(delay, causedBy);
                }

                delay.Reason   = reason;
                delay.CausedBy = causedBy;

                if (delay.Type == eDelayType.Arrival && delay.Schedule.Schedule.TwinScheduleArrival != null)
                {
                    __SynchronizeDelayToTwinSchedule(delay, delay.Schedule.Schedule.TwinScheduleArrival);
                }

                if (delay.Type == eDelayType.Departure && delay.Schedule.Schedule.TwinScheduleDeparture != null)
                {
                    __SynchronizeDelayToTwinSchedule(delay, delay.Schedule.Schedule.TwinScheduleDeparture);
                }

                var Result = new OperationResult <bool>();
                Result.Result    = true;
                Result.Succeeded = true;
                return(Result);
            }
            catch (Exception ex)
            {
                return(new OperationResult <bool> {
                    Message = ex.Message
                });
            }
        }
        public DelayInfoViewModel(TBy byData, StationViewModel station, TrainViewModel train,
                                  DateTime date, string from, string destination,
                                  TimeSpan?plannedArrival, TimeSpan?arrivalDelay,
                                  TimeSpan?plannedDeparture, TimeSpan?departureDelay)
        {
            Station = station;
            Train   = train;

            delayInfo = new DelayInfo <TBy>()
            {
                ByData           = byData,
                Station          = new Station(station.StationName, station.StationID),
                Train            = new Train(train.Name, train.ID, train.Host),
                Date             = date, From = from, Destination = destination,
                PlannedArrival   = plannedArrival, ArrivalDelay = arrivalDelay,
                PlannedDeparture = plannedDeparture, DepartureDelay = departureDelay
            };
        }
Beispiel #17
0
        private void __CheckDelayJustificationPlausibility(DelayInfo delay, int?causedBy)
        {
            var validationMessages = new List <string>();

            if (causedBy.HasValue)
            {
                var area = delay.Schedule.Schedule.Station.ESTW.Area;

                if (area.LiveTrains.ContainsKey(causedBy.Value))
                {
                    var train     = area.LiveTrains[causedBy.Value];
                    var schedules = train.Schedules.Where(s => s.Schedule.Station.ShortSymbol == delay.Schedule.Schedule.Station.ShortSymbol);

                    if (!schedules.Any())
                    {
                        validationMessages.Add($"Zug {causedBy.Value} hat die Betriebsstelle '{delay.Schedule.Schedule.Station.Name}' nicht durchfahren");
                    }
                    else if (delay.Type == eDelayType.Arrival && !schedules.Any(s => __AreTimesClose(delay.Schedule.LiveArrival, s.LiveArrival) ||
                                                                                __AreTimesClose(delay.Schedule.LiveArrival, s.ExpectedArrival) ||
                                                                                __AreTimesClose(delay.Schedule.LiveArrival, s.LiveDeparture)))
                    {
                        validationMessages.Add($"Zug {causedBy.Value} hat die Betriebsstelle '{delay.Schedule.Schedule.Station.Name}' zu einer anderen Zeit durchfahren als {delay.Schedule.Train.Train.Number}");
                    }
                    else if (delay.Type == eDelayType.Departure && !schedules.Any(s => __AreTimesClose(delay.Schedule.LiveDeparture, s.LiveArrival) ||
                                                                                  __AreTimesClose(delay.Schedule.LiveDeparture, s.ExpectedArrival) ||
                                                                                  __AreTimesClose(delay.Schedule.LiveDeparture, s.LiveDeparture)))
                    {
                        validationMessages.Add($"Zug {causedBy.Value} hat die Betriebsstelle '{delay.Schedule.Schedule.Station.Name}' zu einer anderen Zeit durchfahren als {delay.Schedule.Train.Train.Number}");
                    }
                }
                else
                {
                    validationMessages.Add($"Zug {causedBy.Value} nicht gefunden");
                }
            }

            if (validationMessages.Any())
            {
                validationMessages.Insert(0, "Plausibilitätsprüfung fehlgeschlagen");
                var message = string.Join(Environment.NewLine, validationMessages);
                throw new InvalidOperationException(message);
            }
        }
Beispiel #18
0
        private void __SynchronizeDelayToTwinSchedule(DelayInfo delay, Schedule twinSchedule)
        {
            var twinTrainNumber  = twinSchedule.Train.Number;
            var twinTrain        = __GetOrCreateLiveTrainInformation(twinTrainNumber, delay.Schedule.Schedule.Station.ESTW);
            var twinLiveSchedule = twinTrain.Schedules.FirstOrDefault(s => s.Schedule == twinSchedule);

            if (twinLiveSchedule != null && !twinLiveSchedule.IsCancelled)
            {
                var twinDelay = twinLiveSchedule.Delays.FirstOrDefault(d => d.Type == delay.Type);

                if (twinDelay == null)
                {
                    twinDelay = twinLiveSchedule.AddDelay(delay.Minutes, delay.Type);
                }

                twinDelay.Reason   = delay.Reason;
                twinDelay.CausedBy = delay.CausedBy;
            }
        }
        public static T[] CreateFromCityPlatformInfo <T>(
            PlatformApiInfo apiInfo, CityPlatformInfo cityInfo, DelayInfo delayInfo,
            EventHandler <DateCheckerErrorEventArgs> onRequestErrorHandler,
            EventHandler <DateCheckerOkEventArgs> onRequestOkHandler
            ) where T : DateChecker, new()
        {
            T[] checkers = new T[cityInfo.Operations.Length];

            for (int i = 0; i < cityInfo.Operations.Length; ++i)
            {
                checkers[i] = new T();
                checkers[i].InitDateChecker(apiInfo, cityInfo, cityInfo.Operations[i], delayInfo);

                checkers[i].OnRequestError += onRequestErrorHandler;
                checkers[i].OnRequestOK    += onRequestOkHandler;
            }

            return(checkers);
        }
Beispiel #20
0
        private void DlgDelaySetting_Load(object sender, EventArgs e)
        {
            try
            {
                //load config info
                DelayInfo delay = ConfigCtrl.GetDelay();
                if (delay != null)
                {
                    txtDelayedTime.Text = delay.DelayedTime.ToString();
                    txtTimeOut.Text     = delay.TimeOut.ToString();
                    txtTryTimes.Text    = delay.TryTimes.ToString();
                }

                txtDelayedTime.Select();
            }
            catch (Exception ex)
            {
                Program.ShowMessageBox("DlgDelaySetting", ex);
                this.Close();
            }
        }
Beispiel #21
0
        public bool OnBeforeDelay(DelayInfo delayInfo)
        {
            LocalizedString warningMessage = LocalizedString.Empty;

            if (delayInfo is UserQuotaDelayInfo)
            {
                UserQuotaDelayInfo userQuotaDelayInfo = (UserQuotaDelayInfo)delayInfo;
                if (userQuotaDelayInfo.OverBudgetException != null)
                {
                    warningMessage = Strings.WarningCmdletTarpittingByUserQuota(userQuotaDelayInfo.OverBudgetException.PolicyPart, delayInfo.Delay.TotalSeconds.ToString(), ThrottlingModule <T> .computerName);
                }
                else
                {
                    warningMessage = Strings.WarningCmdletMicroDelay(delayInfo.Delay.TotalMilliseconds.ToString());
                }
            }
            else if (delayInfo is ResourceLoadDelayInfo && ((ResourceLoadDelayInfo)delayInfo).ResourceKey != null)
            {
                warningMessage = Strings.WarningCmdletTarpittingByResourceLoad(((ResourceLoadDelayInfo)delayInfo).ResourceKey.ToString(), delayInfo.Delay.TotalSeconds.ToString());
            }
            this.WriteCmdletMicroDelayMessage(warningMessage, delayInfo.Delay.TotalSeconds);
            return(true);
        }
Beispiel #22
0
        private TimeSpan GetResourceMonitorDelay()
        {
            DelayInfo delay = ResourceLoadDelayInfo.GetDelay(this.budget, PublicFolderSynchronizer.WorkloadSettings, this.resourcesToAccess, true);

            if (delay != null)
            {
                PublicFolderSynchronizer.Tracer.TraceDebug <TimeSpan>((long)this.GetHashCode(), "Resource load provided delay info: {0}", delay.Delay);
                if (delay.Delay > this.maximumAllowedDelay)
                {
                    string text = string.Format("Delay suggested by ResourceMonitor of {0} ms has exceeded the maximum allowed delay of {1} ms", delay.Delay.TotalMilliseconds, this.maximumAllowedDelay.TotalMilliseconds);
                    if (this.syncContext.IsHierarchyReady)
                    {
                        throw new StorageTransientException(new LocalizedString(text));
                    }
                    PublicFolderSynchronizerLogger.LogOnServer(text, LogEventType.Warning, new Guid?(this.syncContext.CorrelationId));
                    return(this.maximumAllowedDelay);
                }
            }
            if (delay == null)
            {
                return(TimeSpan.Zero);
            }
            return(delay.Delay);
        }
Beispiel #23
0
        public OperationResult <bool> JustifyDelay(DelayInfo delay, string reason, int?causedBy)
        {
            try
            {
                if (reason.IsNullOrWhiteSpace())
                {
                    return new OperationResult <bool> {
                               Message = "Bitte Grund angeben!"
                    }
                }
                ;

                var SettingsResult = SettingsBLL.GetSettings();
                ValidateResult(SettingsResult);
                var Settings = SettingsResult.Result;

                if (Settings.CheckPlausibility)
                {
                    __CheckDelayJustificationPlausibility(delay, causedBy);
                }

                delay.Reason   = reason;
                delay.CausedBy = causedBy;

                var Result = new OperationResult <bool>();
                Result.Result    = true;
                Result.Succeeded = true;
                return(Result);
            }
            catch (Exception ex)
            {
                return(new OperationResult <bool> {
                    Message = ex.Message
                });
            }
        }
Beispiel #24
0
    public override void CopyInfo(SerializedClass info)
    {
        DelayInfo i = (DelayInfo)info;

        duration = i.Duration;
    }
Beispiel #25
0
        public static DelayInfo GetDelay()
        {
            try
            {
                XmlDocument objXmlDoc = GetAssistantConfigFile();
                if (objXmlDoc == null)
                    return null;

                DelayInfo delay = new DelayInfo();

                XmlNode objNode = objXmlDoc.SelectSingleNode(Constants.CONFIG_ROOT + Constants.CHAR_SLASH + Constants.DELAY_DELAY);
                if (objNode == null)
                    return null;

                if (objNode.SelectSingleNode(Constants.DELAY_DELAYEDTIME).InnerText == string.Empty)
                    delay.DelayedTime = null;
                else
                    delay.DelayedTime = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.DELAY_DELAYEDTIME).InnerText);
                if (objNode.SelectSingleNode(Constants.DELAY_TIMEOUT).InnerText == string.Empty)
                    delay.TimeOut = null;
                else
                    delay.TimeOut = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.DELAY_TIMEOUT).InnerText);
                if (objNode.SelectSingleNode(Constants.DELAY_TRYTIMES).InnerText == string.Empty)
                    delay.TryTimes = null;
                else
                    delay.TryTimes = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.DELAY_TRYTIMES).InnerText);
                return delay;
            }
            catch (Exception ex)
            {
                LogHelper.Write("读取延迟设置", ex);
                throw;
            }
        }
Beispiel #26
0
        public static bool SetDelay(DelayInfo delay)
        {
            try
            {
                XmlDocument objXmlDoc = GetAssistantConfigFile();
                if (objXmlDoc == null)
                    return false;

                XmlNode objNode = objXmlDoc.SelectSingleNode(Constants.CONFIG_ROOT + Constants.CHAR_SLASH + Constants.DELAY_DELAY);
                if (objNode == null)
                    return false;

                objNode.SelectSingleNode(Constants.DELAY_DELAYEDTIME).InnerText = delay.DelayedTime.ToString();
                objNode.SelectSingleNode(Constants.DELAY_TIMEOUT).InnerText = delay.TimeOut.ToString();
                objNode.SelectSingleNode(Constants.DELAY_TRYTIMES).InnerText = delay.TryTimes.ToString();

                return SetAssistantConfigFile(objXmlDoc);
            }
            catch (Exception ex)
            {
                LogHelper.Write("保存延迟设置", ex);   
                return false;
            }
        }