Beispiel #1
0
        public void Close()
        {
            if (m_onClose == null)
            {
                return;
            }
            if (m_socket == null)
            {
                return;
            }

            foreach (ChannelDelegate @d in m_onClose)
            {
                CompleteEvent e = new CompleteEvent();
                e.@delegate = @d;
                e.channel   = this;
                e.message   = null;
                m_queue.Add(e);
            }
            SCommunity msg = new SCommunity();

            Backend.Game.Player p = this.GetContent() as Backend.Game.Player;
            p.online = false;
            msg.name = p.user;
            Console.WriteLine(string.Format("Channel {0} remove", p.user));
            msg.id    = 0;
            msg.enter = false;
            Database.Instance.playerExit(p.dbid);
            Backend.Game.World.Instance.Broundcast(msg);
        }
Beispiel #2
0
        public void AcceptCallback(IAsyncResult ar)
        {
            // Signal the main thread to continue.
            allDone.Set();
            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;
            Socket handler  = listener.EndAccept(ar);
            // Create the state object.
            Channel channel = new Channel(handler);

            channel.RegisterOnMessageRecv(onMessageRecv);
            channel.RegisterOnClose(onClose);
            channel.CompleteQueue = CompleteQueue;
            //channel.workSocket = handler;
            listener.BeginAccept(
                new AsyncCallback(AcceptCallback),
                listener);
            foreach (ChannelDelegate d in onAccept)
            {
                //d.Invoke(channel);
                CompleteEvent e = new CompleteEvent()
                {
                    @delegate = d,
                    channel   = channel,
                    message   = null
                };
                CompleteQueue.Add(e);
            }

            Console.WriteLine("Accept connection from {0}", handler.RemoteEndPoint.ToString());
            // Issue the firest receive command
            channel.BeginRecv();
            // Issue a new accept command
        }
Beispiel #3
0
    /// <summary>
    /// 开始计时
    /// </summary>
    /// <param name="time_">计时时长</param>
    /// <param name="onStartCompleted_">开始计时调用方法</param>
    /// <param name="onEndCompleted_">结束计时调用方法</param>
    /// <param name="update">计时线程方法</param>
    /// <param name="isIgnoreTimeScale_">是否忽略时间速率</param>
    /// <param name="isRepeate_"></param>
    /// <param name="isDestory_"></param>
    public void StartTiming(float time_, CompleteEvent onStartCompleted_, CompleteEvent onEndCompleted_, UpdateEvent update = null, bool isIgnoreTimeScale_ = true, bool isRepeate_ = false, bool isDestory_ = true)
    {
        timeTarget = time_;
        if (onEndCompleted_ != null)
        {
            onEndCompleted = onEndCompleted_;
        }
        if (onStartCompleted_ != null)
        {
            onStartCompleted = onStartCompleted_;
        }
        if (update != null)
        {
            updateEvent = update;
        }
        isDestory         = isDestory_;
        isIgnoreTimeScale = isIgnoreTimeScale_;
        isRepeate         = isRepeate_;

        if (onStartCompleted != null)
        {
            onStartCompleted();
        }
        timeStart  = Time_;
        offsetTime = 0;
        isEnd      = false;
        isTimer    = true;
    }
        public void Should_receive_a_response_from_a_valid_request()
        {
            bool responseHandled = false;
            bool faultHandled    = false;

            CompleteEvent.WaitOne(TimeSpan.FromSeconds(2), true);

            LocalBus.PublishRequest(new ValidRequest(), x =>
            {
                x.Handle <Replay>(r =>
                {
                    responseHandled = true;
                    CompleteEvent.Set();
                });
                x.HandleFault((c, f) =>
                {
                    faultHandled = true;
                    CompleteEvent.Set();
                });
            });

            CompleteEvent.WaitOne(TimeSpan.FromSeconds(20), true);

            Assert.That(responseHandled, Is.True);
            Assert.That(faultHandled, Is.False);
        }
Beispiel #5
0
        void NotifyComplete()
        {
            if (_completed)
            {
                return;
            }

            lock (_lock)
            {
                _completed = true;

                CompleteEvent.Set();
            }

            lock (_completionCallbacks)
            {
                _completionCallbacks.Each(callback =>
                {
                    try
                    {
                        if (callback != null)
                        {
                            callback(this);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error("The request callback threw an exception", ex);
                    }
                });
            }
        }
        public void Should_receive_a_fault_from_a_failed_request()
        {
            bool responedHendeled = false;
            bool faultHendeled    = false;

            CompleteEvent.WaitOne(TimeSpan.FromSeconds(2), true);

            LocalBus.PublishRequest(new InvalidRequest(), x =>
            {
                x.Handle <Replay>(r =>
                {
                    responedHendeled = true;
                    CompleteEvent.Set();
                });
                x.HandleFault((c, f) =>
                {
                    faultHendeled = true;
                    CompleteEvent.Set();
                });
            });

            CompleteEvent.WaitOne(Debugger.IsAttached ? 5.Minutes() : 20.Seconds(), true);

            Assert.That(responedHendeled, Is.False);
            Assert.That(faultHendeled, Is.True);
        }
Beispiel #7
0
        public void Close()
        {
            if (m_onClose == null)
            {
                return;
            }
            if (m_socket == null)
            {
                return;
            }
            if (timer != null)
            {
                timer.Stop();
            }
            else
            {
                return;
            }
            // Broundcast to all players

            Player player = (Player)GetContent();

            World.Instance.RemovePlayer(player);
            m_player = null;

            foreach (ChannelDelegate @d in m_onClose)
            {
                CompleteEvent e = new CompleteEvent();
                e.@delegate = @d;
                e.channel   = this;
                e.message   = null;
                m_queue.Add(e);
            }
        }
        private void Complete()
        {
            foreach (var tween in _tweeners)
            {
                // 終了時のいちに
                tween.Eval(_totalTime, _isReverse);
                tween.Reset();
            }

            _loopCount++;

            if (_loopType == LoopType.PingPongOnce && _loopCount >= 2)
            {
            }
            else if (_loopType != LoopType.None)
            {
                _time = 0f;
                if (_loopType == LoopType.PingPong || _loopType == LoopType.PingPongOnce)
                {
                    _isReverse = !_isReverse;
                }

                return;
            }

            _isPlaying = false;
            CompleteEvent?.Invoke();
        }
Beispiel #9
0
 private void InternalComplete(bool result)
 {
     if (_Cancel == false)
     {
         Complete(result);
         CompleteEvent?.Invoke(this, new BackgroundTaskEventArgs(result));
     }
 }
Beispiel #10
0
        public static void Initialize()
        {
            worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                List <Package> paks = (List <Package>)args.Argument;

                CleanUpTempFiles(paks[0].list);  //TODO

                foreach (Package pak in paks)
                {
                    float progressChunk = (paks.IndexOf(pak) + 1) * progressChunksPerPackage;

                    worker.ReportProgress((int)progressChunk - 4, string.Format("Downloading {0}...", pak.name));
                    System.Threading.Thread.Sleep(10);
                    DownloadPackage(pak);

                    if (doFullInstall)
                    {
                        worker.ReportProgress((int)progressChunk - 3, "Unpacking archive...");
                        System.Threading.Thread.Sleep(10);
                        Unpack(pak);
                        worker.ReportProgress((int)progressChunk - 2, string.Format("Installing {0}...", pak.name));
                        System.Threading.Thread.Sleep(10);
                        InstallPackage(pak);
                        worker.ReportProgress((int)progressChunk - 1, "Cleaning up...");
                        System.Threading.Thread.Sleep(10);
                        DeleteArchive(pak);
                    }
                }

                worker.ReportProgress(GetProgressBarLength(paks.Count), "Done!");
            };

            worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                ProgressEvent.Invoke(null, new object[] { args.ProgressPercentage, args.UserState });
            };

            worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (args.Error != null)
                {
                    Log.Write(args.Error);
                    if (args.Error.InnerException != null)
                    {
                        Log.Write(args.Error.InnerException);
                    }

                    CompleteEvent.Invoke(null, false);
                    return;
                }
                else
                {
                    CompleteEvent.Invoke(null, true);
                }
            };
        }
        public void Setup()
        {
            LocalBus  = CreateBus("local", x => { });
            RemoteBus = CreateBus("remote", x => x.Consumer <SomeConsumer>());

            Assert.IsTrue(LocalBus.HasSubscription <InvalidRequest>().Any());
            Assert.IsTrue(LocalBus.HasSubscription <ValidRequest>().Any());

            CompleteEvent.Reset();
        }
Beispiel #12
0
        private void BtnNext_Click(object sender, EventArgs e)
        {
            if (dgvMain.Rows.Count > 0)
            {
                CompleteEvent?.Invoke(dgvMain.Rows);
                return;
            }

            MessageBox.Show("Введите значения!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
Beispiel #13
0
        public async void IncreaseInRandom()
        {
            while (this.Progress < 100)
            {
                await Task.Delay(Seconds * 1000);

                Progress = random.Next(Progress + 1, Progress + 10 <= 100 ? Progress + 10
                    : 100);
            }
            await Task.Delay(5000);

            CompleteEvent?.Invoke();
        }
        public string Generate(int Appid, String game_path, String Description)
        {
            string path = Directory.GetCurrentDirectory();

            string filePath = path + @"\Tools\Steamcmd\Scripts\app_build_" + Appid + ".vpf";

            app_build_script_path = filePath;
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            read_filestream  = new FileStream(path + @"\Tools\Steamcmd\Scripts\Template\app_build_[].vpf", FileMode.Open);
            write_filestream = new FileStream(filePath, FileMode.CreateNew);
            stream_writer    = new StreamWriter(write_filestream);
            stream_reader    = new StreamReader(read_filestream);
            string app_build_script = stream_reader.ReadToEnd();

            app_build_script = app_build_script.Replace("[Appid]", Appid.ToString());
            app_build_script = app_build_script.Replace("[Appid1]", (Appid + 1).ToString());
            app_build_script = app_build_script.Replace("[Description]", Description);
            stream_writer.WriteLine(app_build_script);
            stream_writer.Close();
            stream_reader.Close();
            write_filestream.Close();
            read_filestream.Close();

            filePath = path + @"\Tools\Steamcmd\Scripts\depot_build_" + (Appid + 1) + ".vdf";
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            read_filestream  = new FileStream(path + @"\Tools\Steamcmd\Scripts\Template\depot_build_[].vdf", FileMode.Open);
            write_filestream = new FileStream(filePath, FileMode.CreateNew);
            stream_writer    = new StreamWriter(write_filestream);
            stream_reader    = new StreamReader(read_filestream);
            string depot_build_script = stream_reader.ReadToEnd();

            depot_build_script = depot_build_script.Replace("[Appid]", (Appid + 1).ToString());
            depot_build_script = depot_build_script.Replace("[P_Game_path]", Directory.GetParent(game_path).FullName + @"\");
            depot_build_script = depot_build_script.Replace("[Game_path]", ".\\" + game_path + @"\*");
            stream_writer.WriteLine(depot_build_script);
            stream_writer.Close();
            stream_reader.Close();
            write_filestream.Close();
            read_filestream.Close();

            CompleteEvent.Invoke();
            return(app_build_script_path);
        }
Beispiel #15
0
        /// <inheritdoc />
        public async Task <CompleteEvent> GetCompleteEvent(int eventId)
        {
            CompleteEvent completeEvent = new CompleteEvent();

            completeEvent.EventDetails = _context.Events.Find(eventId);

            completeEvent.Guests = GetGuestsForEvent(eventId);

            completeEvent.ClaimedItems = GetClaimedItemsForEvent(eventId);
            //completeEvent.Attendees = _context.EventAttendees.Where(x => x.event_id == eventId).ToList();

            //completeEvent.Items = _context.Items.Where(x => x.event_id == eventId).ToList();

            return(completeEvent);
        }
Beispiel #16
0
        public UcFile()
        {
            InitializeComponent();

            btnNext.Click += (s, e) =>
            {
                if (!string.IsNullOrEmpty(uploader1.FileName) || !string.IsNullOrEmpty(uploader2.FileName))
                {
                    CompleteEvent?.Invoke(uploader1.FileName, uploader2.FileName);
                    return;
                }

                MessageBox.Show("Сначала загрузите файлы!!!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            };
        }
Beispiel #17
0
        public void Dispose()
        {
            Loaded = 0;
            Utils.Reclaim(mLoader);

            ResList.Clear();
            mDepsSigned?.Clear();

            CompleteEvent?.RemoveAllListeners();
            RemoteAssetUpdated?.RemoveAllListeners();

            CompleteEvent      = default;
            RemoteAssetUpdated = default;
            mLoader            = default;
            mDepsSigned        = default;
        }
 public GameFrameStory ReadStory(GameFrameStory story, CompleteEvent completeEvent)
 {
     story.BindFunction("battle", (string scriptName) =>
     {
         var battleMode = new BattleGameMode(this, TopDownRpgScene.ClickEvent)
         {
             CompleteEvent = victory =>
             {
                 _gameModeController.PopGameMode();
                 completeEvent?.Invoke(victory);
             }
         };
         battleMode.StartStory(scriptName);
         _gameModeController.PushGameModeDelegate(battleMode);
     });
     return(story);
 }
Beispiel #19
0
 public override GameFrameStory Interact()
 {
     if (!Flags.MasterDefeated)
     {
         _gameStory = ReadStory("dojo_master_hideout.ink");
         CompleteEvent completeEvent = win =>
         {
             Flags.MasterDefeated = true;
         };
         ReadStory(_gameStory, completeEvent);
     }
     else
     {
         _gameStory = ReadStory("dojo_master_defeated.ink");
     }
     return(_gameStory);
 }
Beispiel #20
0
        private void Bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            AsynEventArgs msg = new AsynEventArgs();

            if (e.Result is MType)
            {
                msg.Result = true;
                msg.MType  = (MType)e.Result;
            }
            else
            {
                msg.Result  = false;
                msg.MType   = this.type;
                msg.Message = e.Result.ToString();
            }
            CompleteEvent?.Invoke(msg);
        }
Beispiel #21
0
        private void downloadThread()
        {
            try
            {
                Uri            URL            = new Uri(httpUrl);
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);
                httpWebRequest.Timeout = 120 * 1000;
                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();


                long totalBytes = httpWebResponse.ContentLength;
                //更新文件大小
                StartEvent?.Invoke(this, totalBytes);
                Stream st = httpWebResponse.GetResponseStream();
                Stream so = new FileStream(savePath, FileMode.Create);

                long   totalDownloadedByte = 0;
                byte[] by    = new byte[1024];
                int    osize = st.Read(by, 0, (int)by.Length);
                while (osize > 0)
                {
                    totalDownloadedByte = osize + totalDownloadedByte;
                    so.Write(by, 0, osize);

                    osize = st.Read(by, 0, (int)by.Length);

                    //进度计算
                    double process = double.Parse(String.Format("{0:F}",
                                                                ((double)totalDownloadedByte / (double)totalBytes * 100)));
                    ProcessUpdateEvent?.Invoke(this, process);
                }
                //关闭资源
                httpWebResponse.Close();
                so.Close();
                st.Close();
                CompleteEvent?.Invoke(this, null);
            }
            catch (Exception ec)
            {
                LogHelper.Warning(ec.ToString());

                //下载发生异常
                ErrorEvent?.Invoke(this, ec.Message);
            }
        }
Beispiel #22
0
        public async Task Handle(CompleteEvent notification, CancellationToken cancellationToken)
        {
            //var partnerId = notification.Model.TradingPartnerId;
            //var participant = _db.Get<InvoiceParticipant.InvoiceParticipant>().FirstOrDefault(x => x.ReferenceId == partnerId);

            //var _db.Get<AccountingInvoice.AccountingInvoice>().FirstOrDefault(x => x.ToId == participant);
//            await _mediator.Send(new ShipmentStatusUpdateRequest()
//            {
//                Id = notification.ServiceModel.Id,
//                ServiceModel = new ShipmentStatusUpdateServiceModel()
//                {
//                    StatusDate = DateTime.UtcNow,
//                    StatusCodeId = "CD",
//                }
//            }, cancellationToken);

            //var invoice = new LoadTenderInvoice();
        }
Beispiel #23
0
 /// <summary>
 /// 启动加载
 /// </summary>
 /// <param name="statu"></param>
 public void Load(out int statu)
 {
     statu = 0;
     if (mCurrentOption == default)
     {
         StartLoad(out statu);
     }
     else
     {
         statu = 1;
     }
     if (statu == 2)
     {
         CompleteEvent?.Invoke(true, this);
     }
     else
     {
     }
 }
Beispiel #24
0
        /// <summary>
        /// 开始计时 :
        /// </summary>
        public void StartTiming(float time, CompleteEvent onCompleted, UpdateEvent update = null, bool isIgnoreTimeScale = true, bool isRepeate = false, bool isDestory = true)
        {
            timeTarget = time;
            if (onCompleted != null)
            {
                this.onCompleted = onCompleted;
            }
            if (update != null)
            {
                updateEvent = update;
            }
            this.isDestory         = isDestory;
            this.isIgnoreTimeScale = isIgnoreTimeScale;
            this.isRepeate         = isRepeate;

            timeStart  = Time;
            offsetTime = 0;
            isEnd      = false;
            isTimer    = true;
        }
Beispiel #25
0
        public void Dispose()
        {
            LoaderKey = string.Empty;
            CompleteEvent.RemoveAllListeners();

            Abort();
            Url = string.Empty;

            AfterCheckResult();

            ApplyAssetBundleVersion = false;
            Asyncer    = default;
            mRequester = default;

            AudioClip  = default;
            ResultData = default;
            TextData   = default;
            Assets     = default;
            TextData   = string.Empty;
        }
Beispiel #26
0
        /// <summary>
        /// 开始计时
        /// </summary>
        /// <param name="time">倒计时时间</param>
        /// <param name="onCompleredEvent">计时完成回调</param>
        /// <param name="update">更新事件</param>
        /// <param name="m_IsIgnoreTimeScale">是否忽略时间速率</param>
        /// <param name="m_IsRepeate">是否重复</param>
        /// <param name="m_IsDestory">倒计时完成后是否删除</param>
        public void StartTiming(float time, CompleteEvent onCompleredEvent, UpdateEvent update = null, bool m_IsIgnoreTimeScale = true, bool m_IsRepeate = false, bool m_IsDestory = true)
        {
            m_TimeTarget = time;
            if (onCompleredEvent != null)
            {
                m_OnCompleted = onCompleredEvent;
            }
            if (update != null)
            {
                m_UpdateEvent = update;
            }
            this.m_IsDestory         = m_IsDestory;
            this.m_IsIgnoreTimeScale = m_IsIgnoreTimeScale;
            this.m_IsRepeate         = m_IsRepeate;

            m_TimeStart  = m_GetTime;
            m_OffsetTime = 0;
            m_IsEnd      = false;
            m_IsTimer    = true;
        }
Beispiel #27
0
        public void Close()
        {
            if (m_onClose == null)
            {
                return;
            }
            if (m_socket == null)
            {
                return;
            }

            foreach (ChannelDelegate @d in m_onClose)
            {
                CompleteEvent e = new CompleteEvent();
                e.@delegate = @d;
                e.channel   = this;
                e.message   = null;
                m_queue.Add(e);
            }
        }
        public void GenerateJsonHashes(LoadingFileDto[] loadedData, string filename, int hashIndex)
        {
            for (int i = 0; i < loadedData.Length; i++)
            {
                byte[] _4bytes = new byte[4];

                ResultJsonModel[] jsonModel =
                    new ResultJsonModel[loadedData[i].LoadedData.Length / 4];

                var len = loadedData[i].LoadedData.Length;
                for (int j = 0; j < len; j += 4)
                {
                    Array.Copy(loadedData[i].LoadedData, j, _4bytes, 0, 4);
                    var result = HashManager.ShortCutMessageBySpecificFunction(_4bytes, hashIndex);
                    jsonModel[j / 4] = new ResultJsonModel()
                    {
                        HexInput = Helpers.ByteArrayToHex(_4bytes),
                        HexHash  = result
                    };

                    if (j % 1000 == 0)
                    {
                        if (UpdateEvent != null)
                        {
                            UpdateEvent.Invoke(j, len);
                        }
                    }
                }
                var serializer = new JavaScriptSerializer();
                serializer.MaxJsonLength = int.MaxValue;
                var jsonString = serializer.Serialize(jsonModel);

                File.WriteAllText(filename + "_" + i, jsonString);

                if (CompleteEvent != null)
                {
                    CompleteEvent.Invoke();
                }
            }
        }
Beispiel #29
0
    /// <summary>
    /// 开始计时
    /// </summary>
    /// <param name="time_">总时间</param>
    /// <param name="onCompleted_">计时结束时回调</param>
    /// <param name="updateEvent_">每帧的回调</param>
    /// <param name="repateRate_">updateEvent_调用速率 默认每帧一次</param>
    /// <param name="isIgnoreTimeScale_">是否忽略时间缩放</param>
    /// <param name="isRepeate_">是否重复</param>
    /// <param name="isDestory_">执行完是否销毁</param>
    public void StartTiming(float time_, CompleteEvent onCompleted_, UpdateEvent updateEvent_ = null
                            , float repateRate_ = 0, bool isIgnoreTimeScale_ = true, bool isRepeate_ = false, bool isDestory_ = true)
    {
        timeTarget = time_;
        if (onCompleted_ != null)
        {
            onCompleted = onCompleted_;
        }
        if (updateEvent_ != null)
        {
            updateEvent = updateEvent_;
        }
        repateRate        = repateRate_;
        isDestory         = isDestory_;
        isIgnoreTimeScale = isIgnoreTimeScale_;
        isRepeate         = isRepeate_;

        timeStart  = Time_;
        offestTime = 0;
        isEnd      = false;
        isTimer    = true;
    }
Beispiel #30
0
        public bool Wait()
        {
            bool alreadyCompleted;

            lock (_lock)
                alreadyCompleted = _completed;

            bool result = alreadyCompleted || CompleteEvent.WaitOne(_timeout == TimeSpan.MaxValue ? Int32.MaxValue : (int)_timeout.TotalMilliseconds, true);

            if (!result)
            {
                Fail(RequestTimeoutException.FromCorrelationId(_requestId));
            }

            Close();

            if (_exception != null)
            {
                throw _exception;
            }

            return(result);
        }
Beispiel #31
0
 private void GetListCompleted(object sender, CompleteEvent e)
 {
     listLayers.layersListCompleted -= GetListCompleted;
     if (e.LayerList != null)
     {
         if (e.LayerList.Count > 0)
         {
             // Show window with the possible layers
             listView = new LayerListView();
             LayerListViewModel listViewModel = new LayerListViewModel(e.LayerList);
             modalDialogService.ShowDialog(listView, listViewModel, EndOfLayerSelection);
         }
         else
         {
             ShowMessagebox.Raise(new Notification
             {
                 Content = Silverlight.UI.Esri.JTToolbarCommon.Resources.ToolbarCommon.NoLayersAvailable,
                 Title = Silverlight.UI.Esri.JTToolbarCommon.Resources.ToolbarCommon.Warning
             });
         }
     }
     else
     {
         // Error occurred
         ShowErrorMessagebox.Raise(new Notification
         {
             Content = String.Format("GetListCompleted-{0}[{1}]", e.ErrorMessage, ""),
             Title = "System error"
         });
     }
 }