Пример #1
0
        public override bool GetUrlElement()
        {
            mResponseData = null;

            CTS    cts      = CTS.CTS_Default;
            int    iCTS     = 0;
            string jsonStr  = string.Empty;
            ushort response = 0;

            if (!actionGetter.GetInt("cts", ref iCTS) ||
                !actionGetter.GetString("json", ref jsonStr) ||
                !actionGetter.GetWord("response", ref response))
            {
                return(false);
            }
            cts = (CTS)iCTS;
            JsonData json = JsonMapper.ToObject(jsonStr);

            Action <JsonData, Action5002> callback;

            if (!NetWork.mRegsterJsonCTS.TryGetValue(cts, out callback))
            {
                return(false);
            }
            callback(json, this);

            bool rst = response > 0;

            if (mResponseData == null)
            {
                return(false);
            }

            return(rst);
        }
        protected override Task BuildSelectedValue(bool withNotifyPropertyChanged = true)
        {
            if (CTS != null)
            {
                CTS.Cancel(false);
            }

            CTS = new CancellationTokenSource();

            return(Task.Run(() =>
            {
                _selectedValue = new ApplyedProductParameter
                {
                    Id = this.Id,
                    DataType = this.DataType,
                    Values = Items.Where(x => x.Selected).Select(y => new ApplyedProductParameterValue {
                        Id = y.Id
                    }).ToList()
                };

                if (withNotifyPropertyChanged)
                {
                    RaisePropertyChanged(() => SelectedValue);
                }
            }, CTS.Token));
        }
Пример #3
0
 public static void RegisterMessage(CTS cts, Action <JsonData, Action5002> callBack)
 {
     if (mRegsterJsonCTS.ContainsKey(cts))
     {
         return;
     }
     mRegsterJsonCTS.Add(cts, callBack);
 }
Пример #4
0
 public static void RegisterMessage(CTS cts, Action <byte[], Action5001> callBack)
 {
     if (mRegsterBytesCTS.ContainsKey(cts))
     {
         return;
     }
     mRegsterBytesCTS.Add(cts, callBack);
 }
Пример #5
0
 public void Cancel()
 {
     if (State == TransferStates.CANCELED)
     {
         return;
     }
     State = TransferStates.CANCELED;
     CTS?.Cancel();
     Message = "Upload was canceled";
 }
Пример #6
0
 /// <summary>
 /// 開放処理。
 /// </summary>
 public void Dispose()
 {
     if (CTS == null)
     {
         return;
     }
     CTS.Cancel();
     CTS.Dispose();
     CTS = null;
 }
Пример #7
0
        public static void RegisterMessage(CTS cts, Action <JsonData, Action5002> callBack)
        {
            Action <JsonData, Action5002> action;

            if (mRegsterJsonCTS.TryGetValue(cts, out action))
            {
                action += callBack;
                return;
            }
            mRegsterJsonCTS.Add(cts, callBack);
        }
Пример #8
0
        public static void RegisterMessage(CTS cts, Action <byte[], Action5001> callBack)
        {
            Action <byte[], Action5001> action;

            if (mRegsterBytesCTS.TryGetValue(cts, out action))
            {
                action += callBack;
                return;
            }
            mRegsterBytesCTS.Add(cts, callBack);
        }
        public MainPageViewModel(INavigationService navigationService,
                                 IPageDialogService dialogService)
        {
            _navigationService = navigationService;
            _dialogService     = dialogService;
            GetLocationCommand = new DelegateCommand(async() =>
            {
                if (GeolocationAccuracySelected == null)
                {
                    await _dialogService.DisplayAlertAsync("錯誤", "請選擇GPS定位精確度", "確定");
                    return;
                }
                CTS         = new CancellationTokenSource();
                Token       = CTS.Token;
                GetLocation = true;

                try
                {
                    var request  = new GeolocationRequest(GeolocationAccuracySelected.Item, TimeSpan.FromSeconds(10));
                    var location = await Geolocation.GetLocationAsync(request, Token);

                    if (location != null)
                    {
                        YourLocation = $"Latitude 緯度 : {location.Latitude}, Longitude 經度 : {location.Longitude}";
                    }
                }
                catch (FeatureNotSupportedException fnsEx)
                {
                    // 處理裝置不支援這項功能的例外異常
                }
                catch (PermissionException pEx)
                {
                    // 處理關於權限上的例外異常
                }
                catch (AggregateException ae)
                {
                    // 處理取消的例外異常
                }
                catch (Exception ex)
                {
                    // 無法取得該GPS位置之例外異常
                }

                GetLocation = false;
            });
            CancelLocationCommand = new DelegateCommand(() =>
            {
                GetLocation = false;
                CTS.Cancel();
            });
        }
Пример #10
0
        /// Release any unmanaged resources
        public virtual void Dispose()
        {
            Source?.Dispose();
            Dest?.Dispose();

            CTS?.Dispose();
            Client?.Dispose();

            try
            {
                Worker?.Dispose();
            }
            catch (InvalidOperationException)
            {
                return;
            }
        }
Пример #11
0
        public async Task DisconnectAsync()
        {
            if (WS is null)
            {
                return;
            }
            // TODO: requests cleanup code, sub-protocol dependent.
            if (WS.State == WebSocketState.Open)
            {
                CTS.CancelAfter(TimeSpan.FromSeconds(2));
                await WS.CloseOutputAsync(WebSocketCloseStatus.Empty, "", CancellationToken.None);

                await WS.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);
            }
            WS.Dispose();
            WS = null;
            CTS.Dispose();
            CTS = null;
        }
Пример #12
0
        public override bool GetUrlElement()
        {
            mResponseData = null;

            byte[] data     = (byte[])actionGetter.GetMessage();
            byte[] ctsBytes = new byte[4];
            int    len      = data.Length - ctsBytes.Length - 1;

            byte[] d        = new byte[len];
            byte[] response = new byte[1];

            int pos = 0;

            Buffer.BlockCopy(data, pos, ctsBytes, 0, ctsBytes.Length);
            pos += ctsBytes.Length;
            Buffer.BlockCopy(data, pos, response, 0, 1);
            pos += 1;
            Buffer.BlockCopy(data, pos, d, 0, d.Length);

            CTS  cts = (CTS)BitConverter.ToInt32(ctsBytes, 0);
            bool rst = response[0] > 0 ? true : false;

            Action <byte[], Action5001> callback;

            if (!NetWork.mRegsterBytesCTS.TryGetValue(cts, out callback))
            {
                return(true);
            }
            callback(d, this);

            if (mResponseData == null)
            {
                return(true);
            }
            if (!rst)
            {
                mResponseData = null;
            }

            return(rst);
        }
Пример #13
0
        protected Task BuildSelectedValue()
        {
            if (CTS != null)
            {
                CTS.Cancel(false);
            }

            CTS = new CancellationTokenSource();

            return(Task.Run(() =>
            {
                SelectedValue = new ApplyedFilter
                {
                    Id = this.Id,
                    DataType = this.DataType,
                    Values = Items.Where(x => x.Selected).Select(y => new ApplyedFilterValue {
                        Id = y.Id
                    }).ToList()
                };
            }, CTS.Token));
        }
Пример #14
0
        public async Task ConnectAsync(string url)
        {
            if (WS != null)
            {
                if (WS.State == WebSocketState.Open)
                {
                    return;
                }
                else
                {
                    WS.Dispose();
                }
            }
            WS = new ClientWebSocket();
            if (CTS != null)
            {
                CTS.Dispose();
            }
            CTS = new CancellationTokenSource();
            await WS.ConnectAsync(new Uri(url), CTS.Token);

            await Task.Factory.StartNew(ReceiveLoop, CTS.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
Пример #15
0
    public static void SendPacket <T>(CTS cts, T obj, Action <byte[]> callback)
    {
        if (GameApp.Instance.directGame)
        {
            return;
        }
        ActionParam param = new ActionParam();

        param["obj"]      = obj;
        param["cts"]      = (int)cts;
        param["response"] = (callback != null);
        Net.Instance.Send((int)ActionType.BytesPackage, (result) => {
            if (result == null)
            {
                return;
            }
            byte[] data = result.Get <byte[]>("data");
            if (callback != null)
            {
                callback(data);
            }
        }, param);
    }
Пример #16
0
        protected Task BuildSelectedValue(PickerCollectionItemVM item)
        {
            if (CTS != null)
            {
                CTS.Cancel(false);
            }

            CTS = new CancellationTokenSource();

            return(Task.Run(() =>
            {
                SelectedValue = new ApplyedProductParameter
                {
                    Id = this.Id,
                    DataType = this.DataType,
                    Values = new List <ApplyedProductParameterValue> {
                        new ApplyedProductParameterValue {
                            Id = item.Id
                        }
                    }
                };
            }, CTS.Token));
        }
Пример #17
0
    public static void SendJsonPacket(CTS cts, JsonData json, Action <JsonData> callback)
    {
        if (GameApp.Instance.directGame)
        {
            return;
        }
        ActionParam param = new ActionParam();

        param["json"]     = json;
        param["cts"]      = (int)cts;
        param["response"] = (callback != null);
        Net.Instance.Send((int)ActionType.BytesPackage, (result) =>
        {
            if (result == null)
            {
                return;
            }
            string data = result.Get <string>("json");
            if (callback != null)
            {
                callback(JsonMapper.ToObject(data));
            }
        }, param);
    }
Пример #18
0
 /// Cancel communication throughout pipe
 public virtual void Disconnect()
 {
     Connected = false;
     CTS?.Cancel();
 }
Пример #19
0
 private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
 {
     CTS.Cancel();
 }
Пример #20
0
        //In case of false return, operation shall be cancelled with an internal error.
        public bool GetClearanceForDBOperation(WebServiceBaseTimeoutableProcessor _ServiceProcessor, string _DBTableName, string _Identifier, Action <string> _ErrorMessageAction = null)
        {
            if (!_ServiceProcessor.IsDoNotGetDBClearanceSet())
            {
                return(true);
            }

            var CreatedAction = new Action_OperationTimeout(_DBTableName, _Identifier);

            lock (_ServiceProcessor.RelevantTimeoutStructures)
            {
                bool bFound = false;
                foreach (var CTS in _ServiceProcessor.RelevantTimeoutStructures)
                {
                    if (CTS.Equals(CreatedAction))
                    {
                        CreatedAction = CTS;
                        bFound        = true;
                        break;
                    }
                }
                if (!bFound)
                {
                    _ServiceProcessor.RelevantTimeoutStructures.Add(CreatedAction);
                }
            }

            var MemoryEntryValue = ATOMIC_DB_OP_CTRL_MEM_PREFIX + _DBTableName + "-" + _Identifier;

            if (_ServiceProcessor.IsUseQueueSetClearanceActionsSet() &&
                _ServiceProcessor.TryRemoveSetClearanceAwaitItem(MemoryEntryValue))
            {
                return(true);
            }

            int TrialCounter = 0;

            bool bResult;

            do
            {
                bResult = MemoryService.SetKeyValueConditionally(
                    QueryParameters,
                    new Tuple <string, BPrimitiveType>(MemoryEntryValue, new BPrimitiveType("busy")),
                    _ErrorMessageAction);

                if (!bResult)
                {
                    Thread.Sleep(1000);
                }
            }while (!bResult && TrialCounter++ < TIMEOUT_TRIAL_SECONDS);

            if (TrialCounter >= TIMEOUT_TRIAL_SECONDS)
            {
                _ErrorMessageAction?.Invoke("Atomic DB Operation Controller->GetClearanceForDBOperation: A timeout has occured for operation type " + _DBTableName + ", for ID " + _Identifier + ", existing operation has been overriden by the new request.");

                Manager_PubSubService.Get().PublishAction(Actions.EAction.ACTION_OPERATION_TIMEOUT, JsonConvert.SerializeObject(new Action_OperationTimeout()
                {
                    TableName = _DBTableName,
                    EntryKey  = _Identifier
                }),
                                                          _ErrorMessageAction);

                //Timeout for other operation has occured.
                return(MemoryService.SetKeyValue(QueryParameters, new Tuple <string, BPrimitiveType>[]
                {
                    new Tuple <string, BPrimitiveType>(MemoryEntryValue, new BPrimitiveType("busy"))
                },
                                                 _ErrorMessageAction));
            }

            return(true);
        }
Пример #21
0
        public void LoadRom(string romFile, bool prompt)
        {
            try
            {
                CTS?.Cancel();
                Emulator?.Stop();
                DisplayTask?.Wait();

                if (prompt)
                {
                    OpenFileDialog dialog = new OpenFileDialog();

                    dialog.Title = Resources.OpenTitle;
                    if (File.Exists(romFile))
                    {
                        dialog.InitialDirectory = Path.GetDirectoryName(romFile);
                        dialog.FileName         = Path.GetFileName(romFile);
                    }

                    romFile = dialog.ShowDialog() == DialogResult.OK ? dialog.FileName : "";
                }

                if (!string.IsNullOrWhiteSpace(romFile) && File.Exists(romFile))
                {
                    LastRomFile = romFile;

                    Log($"Loading ROM: {romFile}", LogLevel.Info);

                    byte[] romData = File.ReadAllBytes(romFile);
                    Emulator = new Chip8Emu(this, romData);

                    DisplayBuffer = new bool[Chip8Emu.DisplayColumns, Chip8Emu.DisplayRows];

                    Emulator.TryConfigureQuirks();

                    Log("Ready.", LogLevel.Info);
                }

                CTS = new CancellationTokenSource();

                Emulator?.Start(CTS);
                DisplayTask = Task.Factory.StartNew(() =>
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();

                    while (!CTS.Token.IsCancellationRequested)
                    {
                        if (sw.Elapsed >= ViewDelay)
                        {
                            DrawDisplay();
                            sw.Restart();
                        }
                        Thread.Yield();
                    }
                });
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                UpdateConfig();
            }
        }
Пример #22
0
 public Move PlayerMove(Coordinate shootingCoord)
 {
     Player.ShotsTaken.Add(shootingCoord);
     return(new Move(shootingCoord, CTS.Translate(shootingCoord)));
 }
Пример #23
0
        public Move ComputerMove()
        {
            var shootingCoord = RSS.Shoot();

            return(new Move(shootingCoord, CTS.Translate(shootingCoord)));
        }
Пример #24
0
 public static void UnregisterMessage(CTS cts)
 {
     mRegsterBytesCTS.Remove(cts);
     mRegsterJsonCTS.Remove(cts);
 }
Пример #25
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     CTS?.Cancel();
     Emulator?.Stop();
     DisplayTask?.Wait();
 }