Example #1
0
        public void Resume()
        {
            var cts   = new CancellationTokenSource();
            var count = 0;

            using (var src = new WakeableTimer())
            {
                src.Interval = TimeSpan.FromSeconds(1);
                src.Start(TimeSpan.FromMilliseconds(100));
                _ = src.Subscribe(Synchronous.AsTask(() =>
                {
                    ++count;
                    src.Stop();
                    cts.Cancel();
                }));
                src.Start();
                src.Suspend();

                Assert.That(count, Is.EqualTo(0));
                Task.Delay(300).Wait();
                Assert.That(count, Is.EqualTo(0));
                Assert.That(Execute(src, 0, cts), "Timeout");
                Assert.That(count, Is.EqualTo(1));
            }
        }
Example #2
0
        /// <summary>
        /// Tells to the actor the message.
        /// </summary>
        /// <param name="message">The emit message.</param>
        /// <typeparam name="TI">The in type.</typeparam>
        /// <typeparam name="TO">The out type.</typeparam>
        /// <returns>The response of the object.</returns>
        public IObservable <TO> Send <TI, TO>(TI message)
        {
            var future = new Synchronous(message);

            this.mailBox.Add(future);
            return(future.ToObservable <TO>());
        }
Example #3
0
        public void Transition_PowerMode()
        {
            var pmc   = new PowerModeContext(Power.Mode);
            var count = 0;
            var dummy = 0;

            Power.Configure(pmc);

            using (var src = new WakeableTimer())
                using (src.Subscribe(Synchronous.AsTask(() => ++ dummy)))
                {
                    src.PowerModeChanged += (s, e) => ++ count;
                    src.Start();

                    pmc.Mode = PowerModes.Suspend;
                    Assert.That(Power.Mode, Is.EqualTo(PowerModes.Suspend));
                    Assert.That(src.State, Is.EqualTo(TimerState.Suspend));

                    pmc.Mode = PowerModes.Resume;
                    Assert.That(Power.Mode, Is.EqualTo(PowerModes.Resume));
                    Assert.That(src.State, Is.EqualTo(TimerState.Run));

                    src.Stop();
                    Assert.That(Power.Mode, Is.EqualTo(PowerModes.Resume));
                    Assert.That(src.State, Is.EqualTo(TimerState.Stop));
                }
        }
        private void Example1_Click(object sender, RoutedEventArgs e)
        {
            var synchronous = new Synchronous();
            int result      = synchronous.LongRunningTask(5);

            MessageBox.Show($"Result was: {result}");
        }
Example #5
0
 internal void Validate()
 {
     if (string.IsNullOrEmpty(ConnectionString))
     {
         throw new ArgumentNullException(nameof(ConnectionString));
     }
     Asynchronous.Validate();
     Synchronous.Validate();
     Error.Validate();
 }
 /// <summary>
 ///     在UI线程中执行
 /// </summary>
 /// <param name="action"></param>
 /// <param name="args"></param>
 private void InvokeInUiThread <T>(Action <T> action, T args)
 {
     if (Synchronous == null)
     {
         action(args);
     }
     else
     {
         Synchronous.BeginInvokeInUiThread(action, args);
     }
 }
Example #7
0
        /* ----------------------------------------------------------------- */
        ///
        /// Execute
        ///
        /// <summary>
        /// Waits for the timer to execute the specified number of callbacks.
        /// </summary>
        ///
        /// <param name="src">Timer object.</param>
        /// <param name="msec">Initial delay.</param>
        /// <param name="count">
        /// Number of callbacks that the timer waits.
        /// </param>
        ///
        /// <returns>true for success.</returns>
        ///
        /* ----------------------------------------------------------------- */
        private bool Execute(WakeableTimer src, int msec, int count)
        {
            var n   = 0;
            var cts = new CancellationTokenSource();

            using (src.Subscribe(Synchronous.AsTask(() =>
            {
                if (++n >= count)
                {
                    src.Stop();
                    cts.Cancel();
                }
            }))) return(Execute(src, msec, cts));
        }
Example #8
0
        /* ----------------------------------------------------------------- */
        ///
        /// UpdateChecker
        ///
        /// <summary>
        /// オブジェクトを初期化します。
        /// </summary>
        ///
        /// <param name="src">設定用オブジェクト</param>
        ///
        /* ----------------------------------------------------------------- */
        public UpdateChecker(SettingFolder src)
        {
            var io  = src.IO;
            var dir = Assembly.GetExecutingAssembly().GetDirectoryName();

            FileName = io.Combine(dir, "UpdateChecker.exe");
            Setting  = src;

            _timer.Interval = TimeSpan.FromDays(1);
            _timer.Subscribe(Synchronous.AsTask(WhenTick));

            if (Setting.Shared.CheckUpdate)
            {
                Start();
            }
        }
Example #9
0
 /// <summary>
 /// 把总后台一至两天所有的需调拔的单子的状态弄到分后台去
 /// </summary>
 public void SyncGoodsOrderRedploy()
 {
     if (DateTime.Now.Hour == shortagesTime && shortagesDate.ToString("yyyyMMdd") != DateTime.Now.ToString("yyyyMMdd"))
     {
         shortagesDate = DateTime.Now;
         int i = 0;
         IList <GoodsOrderInfo> goodsOrderList = goodOrderDal.GetGoodsOrderList(OrderState.Redeploy, 2, 1); //需拔调,两至三天的单子
         foreach (GoodsOrderInfo goodsOrderInfo in goodsOrderList)
         {
             using (var syn = new Synchronous(goodsOrderInfo.FromSourceId))
             {
                 syn.UpdateOrderState(goodsOrderInfo.OrderId, OrderState.Redeploy);
             }
             i++;
         }
     }
 }
Example #10
0
        private void OnEnd(Task <TResult> task)
        {
            _task = null;
            switch (task.Status)
            {
            case TaskStatus.Faulted:
                //LogRecorder.Exception(task.Exception);
                Status = CommandStatus.Faulted;
                break;

            default:
                Status = CommandStatus.Succeed;
                break;
            }
            try
            {
                if (_endAction == null)
                {
                    return;
                }
                if (Synchronous == null)
                {
                    _endAction(Status, task.IsFaulted ? task.Exception : null, !task.IsFaulted ? task.Result : default(TResult));
                }
                else
                {
                    Synchronous.BeginInvokeInUiThread(_endAction, Status, task.IsFaulted ? task.Exception : null, !task.IsFaulted ? task.Result : default(TResult));
                }
            }
            catch (Exception ex)
            {
                LogRecorder.Exception(ex);
                Status = CommandStatus.Faulted;
            }
            finally
            {
                OnCanExecuteChanged();
            }
        }
Example #11
0
        /// <summary>
        /// Save profile values
        /// </summary>
        public void SaveProfileSettings()
        {
            if (Temperature > TempMax)
            {
                Temperature = TempMax;
            }
            if (Temperature < TempMin)
            {
                Temperature = TempMin;
            }
            if (_position > MaxPosition)
            {
                _position = MaxPosition;
            }

            //ascom items
            Profile.WriteValue(sCsDriverId, "FilterNames", String.Join(",", Names).ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Absolute", Absolute.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "MaxIncrement", MaxIncrement.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "MaxPosition", MaxPosition.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Position", _position.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "MotorSpeed", MotorSpeed.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "StepSize", stepSize.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempComp", tempComp.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempCompAvailable", TempCompAvailable.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Temperature", Temperature.ToString(CultureInfo.InvariantCulture));
            //extended FilterWheel items
            Profile.WriteValue(sCsDriverId, "CanHalt", CanHalt.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "CanStepSize", CanStepSize.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Synchronous", Synchronous.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempMax", TempMax.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempMin", TempMin.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempPeriod", TempPeriod.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempProbe", TempProbe.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "TempSteps", TempSteps.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "SettleTime", settleTime.ToString(CultureInfo.InvariantCulture));
            Profile.WriteValue(sCsDriverId, "Logging", TL.Enabled.ToString(CultureInfo.InvariantCulture));
        }
Example #12
0
    /// <summary>
    /// 交互命令
    /// </summary>
    private void HandleExceptionExchange(ref CommandInfo commdInfo, params object[] prms)
    {
        try
        {
            var arrayList    = new ArrayList(prms);
            int count        = prms.Length;
            var fromSourceId = (Guid)prms[count - 2];

            MIS.WCF.Contract.ServiceMethodName misType = 0;
            EyeseeMethodName eyeType = 0;
            if (fromSourceId.ToString().ToUpper() == "65070EB0-F9ED-4028-AEA2-6E2BA200F85A")
            {
                misType = (ServiceMethodName)Enum.Parse(typeof(ServiceMethodName), commdInfo.CommandMethod, true);
            }
            else
            {
                eyeType = (EyeseeMethodName)Enum.Parse(typeof(EyeseeMethodName), commdInfo.CommandMethod, true);
            }

            arrayList.RemoveAt(count - 1);
            arrayList.RemoveAt(count - 2);

            if (typeof(Guid) == prms[0].GetType())        //判断是不是最后一个参数
            {
                if ((Guid)prms[0] != commdInfo.CommandID) //如果最后已经插入GUID
                {
                    arrayList.Add(commdInfo.CommandID);
                }
            }
            else
            {
                arrayList.Add(commdInfo.CommandID);
            }

            prms = arrayList.ToArray();
            if (commdInfo.CommandMethod == "UpdateOrderState")
            {
                var psm = prms[1] as object[];
                if (psm != null && psm.Length > 1)
                {
                    var pps = new[] { prms[0], psm[0], psm[1] };
                    prms = pps;
                }
            }

            object returnInfo;
            if (fromSourceId.ToString().ToUpper() == "65070EB0-F9ED-4028-AEA2-6E2BA200F85A")
            {
                using (var syn = new MISSynchronous(fromSourceId))
                {
                    returnInfo = syn.SyncFunc(misType, prms); //发送请求并返回结果
                }
            }
            else
            {
                using (var syn = new Synchronous(fromSourceId))
                {
                    returnInfo = syn.SyncFunc(eyeType, prms); //发送请求并返回结果
                }
            }
            var wInfo = returnInfo as WCFReturnInfo;

            //1.如果处理失败,
            if (wInfo == null || !wInfo.IsSuccess)
            {
                commdInfo.Exception = wInfo == null ? "请求服务超时!" : wInfo.ErrorMessage.Length >= 1000 ? wInfo.ErrorMessage.Substring(0, 999) : wInfo.ErrorMessage;
                com.UpdateExceptionCount(commdInfo); //改变发送次数
            }
            else //2.如果处理成功,删除这条数据..
            {
                com.DeleteCommand(commdInfo.CommandID);
            }
        }
        catch (System.ServiceModel.FaultException <WcfException> fe)
        {
            commdInfo.Exception = fe.Detail.Message.Length >= 1000
                                      ? fe.Detail.Message.Substring(0, 999)
                                      : fe.Detail.Message;
            com.UpdateExceptionCount(commdInfo); //改变发送次数
        }
        catch (Exception ex)
        {
            commdInfo.Exception = ex.Message.Length >= 1000
                                      ? ex.Message.Substring(0, 999)
                                      : ex.Message;
            com.UpdateExceptionCount(commdInfo); //改变发送次数
        }
    }