Beispiel #1
0
        public void AsyncTranslate(string i_Text, OnCompleted i_Callback)
        {
            var key = getKey(i_Text);
            if (r_TranslationCache.ContainsKey(key))
            {
                i_Callback(r_TranslationCache[key]);
                return;
            }

            r_RealTranslator.AsyncTranslate(
                i_Text,
                (result) =>
                {
                    if (!r_TranslationCache.ContainsKey(key))
                    {
                        r_TranslationCache.TryAdd(key, result);
                    }

                    i_Callback(r_TranslationCache[key]);
                });
        }
 public MNWSInfoRequestCurrentUserInfo(OnCompleted onCompleted)
     : base()
 {
     this.OnCompletedDelegate = onCompleted;
 }
 public MNWSInfoRequestAnyUser(long userId,OnCompleted onCompleted)
     : base()
 {
     this.Parameters["userId"] = userId;
       this.OnCompletedDelegate = onCompleted;
 }
 public MNWSInfoRequestSystemGameNetStats(OnCompleted onCompleted)
     : base()
 {
     this.OnCompletedDelegate = onCompleted;
 }
 public MNWSInfoRequestLeaderboard(LeaderboardMode mode,OnCompleted onCompleted)
     : base()
 {
     this.Parameters["LeaderboardMode"] = mode.GetParametersDictionary();
       this.OnCompletedDelegate = onCompleted;
 }
 public MNWSInfoRequestCurrUserBuddyList(OnCompleted onCompleted)
     : base()
 {
     this.OnCompletedDelegate = onCompleted;
 }
Beispiel #7
0
 public void AsyncTranslate(string i_Text, OnCompleted i_Callback)
 {
     ThreadPool.QueueUserWorkItem(doTranslate, new Tuple<string, OnCompleted>(i_Text, i_Callback));
 }
Beispiel #8
0
 public void AsyncTranslate(string i_Text, OnCompleted i_Callback)
 {
     ThreadPool.QueueUserWorkItem(doTranslate, new Tuple <string, OnCompleted>(i_Text, i_Callback));
 }
Beispiel #9
0
 protected virtual void HandleOnCompleted()
 {
     coroutine = null;
     completionSource.TrySetResult(this);
     OnCompleted?.Invoke();
 }
Beispiel #10
0
 private void FireOnComplete()
 {
     Status = QuestStatus.Completed;
     OnCompleted?.Invoke();
 }
Beispiel #11
0
        public async Task Initialize(IServiceProvider builder,
                                     RecoverabilityComponent recoverabilityComponent,
                                     MessageOperations messageOperations,
                                     PipelineComponent pipelineComponent,
                                     IPipelineCache pipelineCache,
                                     TransportInfrastructure transportInfrastructure,
                                     CancellationToken cancellationToken = default)
        {
            if (configuration.IsSendOnlyEndpoint)
            {
                return;
            }

            var mainPump = transportInfrastructure.Receivers[MainReceiverId];

            var receivePipeline               = pipelineComponent.CreatePipeline <ITransportReceiveContext>(builder);
            var mainPipelineExecutor          = new MainPipelineExecutor(builder, pipelineCache, messageOperations, configuration.PipelineCompletedSubscribers, receivePipeline);
            var recoverabilityExecutorFactory = recoverabilityComponent.GetRecoverabilityExecutorFactory(builder);
            var recoverability = recoverabilityExecutorFactory
                                 .CreateDefault(configuration.LocalAddress);

            var onCompleted = new OnCompleted((completeContext, token) =>
                                              ((INotificationSubscriptions <ReceiveCompleted>)configuration.ReceiveCompletedSubscribers)
                                              .Raise(new ReceiveCompleted(completeContext.NativeMessageId, completeContext.WasAcknowledged, completeContext.Headers, completeContext.StartedAt, completeContext.CompletedAt, completeContext.OnMessageFailed), token));

            await mainPump.Initialize(configuration.PushRuntimeSettings, mainPipelineExecutor.Invoke,
                                      recoverability.Invoke, onCompleted, cancellationToken).ConfigureAwait(false);

            receivers.Add(mainPump);

            if (transportInfrastructure.Receivers.TryGetValue(InstanceSpecificReceiverId, out var instanceSpecificPump))
            {
                var instanceSpecificRecoverabilityExecutor = recoverabilityExecutorFactory.CreateDefault(configuration.InstanceSpecificQueue);

                await instanceSpecificPump.Initialize(configuration.PushRuntimeSettings, mainPipelineExecutor.Invoke,
                                                      instanceSpecificRecoverabilityExecutor.Invoke, onCompleted, cancellationToken).ConfigureAwait(false);

                receivers.Add(instanceSpecificPump);
            }

            foreach (var satellite in configuration.SatelliteDefinitions)
            {
                try
                {
                    var satellitePump = transportInfrastructure.Receivers[satellite.Name];

                    var satellitePipeline = new SatellitePipelineExecutor(builder, satellite);
                    var satelliteRecoverabilityExecutor = recoverabilityExecutorFactory.Create(satellite.RecoverabilityPolicy, satellite.ReceiveAddress);

                    await satellitePump.Initialize(satellite.RuntimeSettings, satellitePipeline.Invoke,
                                                   satelliteRecoverabilityExecutor.Invoke, (_, __) => Task.CompletedTask, cancellationToken).ConfigureAwait(false);

                    receivers.Add(satellitePump);
                }
                catch (Exception ex)
                {
                    Logger.Fatal("Satellite failed to start.", ex);
                    throw;
                }
            }
        }
Beispiel #12
0
        private void DuringDecompress()
        {
            if (!IsCompleted)
            {
                try
                {
                    int    size;
                    int    fixSize = 2048;
                    byte[] data;
                    string fileName;
                    while ((mEnt = mZipInputStream.GetNextEntry()) != null)
                    {
                        if (!string.IsNullOrEmpty(mEnt.Name))
                        {
                            fileName = Path.Combine(SavePath, mEnt.Name);

                            #region Android
                            fileName = fileName.Replace('\\', '/');

                            "log:Start uncompress zip, file name is {0}".Log(fileName);

                            if (fileName.EndsWith(StringUtils.PATH_SYMBOL))
                            {
                                Directory.CreateDirectory(fileName);
                                continue;
                            }
                            else
                            {
                            }
                            #endregion

                            FileStream = File.Create(fileName);

                            size = fixSize;
                            data = new byte[size];
                            while (true)
                            {
                                size = mZipInputStream.Read(data, 0, data.Length);

#if LOG_UNPRESS_ZIP
                                bool isReadAll = size <= 0;
                                if (isReadAll)
                                {
                                    "log:File {0} uncompress end.".Log(fileName);
                                }
                                else
                                {
                                    "log:Zip stream read size {0}".Log(size.ToString());
                                }
#endif
                                if (size > 0)
                                {
                                    FileStream.Write(data, 0, size);//解决读取不完整情况
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            "error".Log("Next Entry name is empty..");
                        }
                    }
                }
                catch (Exception e)
                {
                    "error:Zip exception {0}".Log(e.ToString());
                }
                finally
                {
                    if (FileStream != null)
                    {
                        FileStream.Close();
                        FileStream.Dispose();
                    }
                    else
                    {
                    }

                    if (mZipInputStream != null)
                    {
                        mZipInputStream.Close();
                        mZipInputStream.Dispose();
                    }
                    else
                    {
                    }

                    if (mEnt != null)
                    {
                        mEnt = null;
                    }
                    else
                    {
                    }

                    GC.Collect();
                    GC.Collect(1);

                    IsCompleted = true;
                    Operation   = ZipOperation.None;
                    UpdaterNotice.SceneCallLater((t) => { OnCompleted?.Invoke(); });
                }
            }
            else
            {
            }
        }
        public Task Initialize(PushRuntimeSettings limitations, OnMessage onMessage, OnError onError, OnCompleted onCompleted, CancellationToken cancellationToken = default)
        {
            this.onMessage   = onMessage;
            this.onError     = onError;
            this.onCompleted = onCompleted;

            Init();

            // use concurrency 1 if the user hasn't explicitly configured a concurrency value
            maxConcurrency     = limitations == PushRuntimeSettings.Default ? 1 : limitations.MaxConcurrency;
            concurrencyLimiter = new SemaphoreSlim(maxConcurrency);

            RecoverPendingTransactions();

            EnsureDirectoriesExists();

            return(Task.CompletedTask);
        }
Beispiel #14
0
 protected void Complete()
 {
     OnCompleted.Invoke();
 }
Beispiel #15
0
 /// <summary>
 /// 异步创建爬虫
 /// </summary>
 /// <param name="uri"></param>
 /// <param name="proxy"></param>
 /// <returns></returns>
 public async Task <string> Start(Uri uri, WebProxy proxy = null)
 {
     return(await Task.Run(() =>
     {
         var pageSource = string.Empty;
         try
         {
             OnStart?.Invoke(this, new OnStartEventArgs(uri));
             Stopwatch watch = new Stopwatch();
             watch.Start();
             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
             request.Accept = "*/*";
             //定义文档类型及编码
             request.ContentType = "application/x-www-form-urlencoded";
             request.AllowAutoRedirect = false;//禁止自动跳转
             request.UserAgent = UAString;
             //定义请求超时事件为5s
             request.Timeout = 5000;
             //长连接
             request.KeepAlive = true;
             request.Method = "GET";
             //设置代理服务器IP,伪装请求地址
             if (proxy != null)
             {
                 request.Proxy = proxy;
             }
             //附加Cookie容器
             request.CookieContainer = this.CookieContainer;
             //定义最大链接数
             request.ServicePoint.ConnectionLimit = int.MaxValue;
             //获取请求响应
             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
             //将Cookie加入容器,保持登录状态
             foreach (Cookie cookie in response.Cookies)
             {
                 this.CookieContainer.Add(cookie);
             }
             //获取响应流
             Stream stream = response.GetResponseStream();
             //以UTF8的方式读取流
             StreamReader reader = new StreamReader(stream, Encoding.UTF8);
             //获取网站资源
             pageSource = reader.ReadToEnd();
             watch.Stop();
             //获取当前任务线程ID
             var threadID = Thread.CurrentThread.ManagedThreadId;
             //获取请求执行时间
             var milliseconds = watch.ElapsedMilliseconds;
             reader.Close();
             stream.Close();
             request.Abort();
             response.Close();
             OnCompleted?.Invoke(this, new OnCompletedEventArgs(uri, threadID, milliseconds, pageSource));
         }
         catch (Exception ex)
         {
             OnError?.Invoke(this, ex);
         }
         return pageSource;
     }));
 }
Beispiel #16
0
 public Task Initialize(PushRuntimeSettings limitations, OnMessage onMessage, OnError onError, OnCompleted onCompleted, CancellationToken cancellationToken = default)
 {
     startupSequence.Add($"{nameof(IMessageReceiver)}.{nameof(Initialize)} for receiver {Id}");
     return(Task.CompletedTask);
 }
Beispiel #17
0
 private void OnStoryboardCompleted(object sender, EventArgs e)
 {
     isAnimating = false;
     OnCompleted?.Invoke();
 }
Beispiel #18
0
 public virtual Task Completed(IUnitOfWork context) => OnCompleted?.Invoke(context);
 public void FireOnCompleted()
 {
     OnCompleted?.Invoke();
 }
 private void OnSequenceCompleted(EventArgs args)
 {
     OnCompleted?.Invoke(this, args);
 }
 public MNWSInfoRequestCurrGameRoomUserList(int roomSFId,OnCompleted onCompleted)
     : base()
 {
     this.Parameters["roomSFId"] = roomSFId;
       this.OnCompletedDelegate = onCompleted;
 }
Beispiel #22
0
        public async Task <string> Start(Uri uri, string proxy = null)
        {
            return(await Task.Run(() =>
            {
                var pageSource = string.Empty;

                try
                {
                    // Sent a satet event.
                    OnStart?.Invoke(this, new OnStartEventArgs(uri));

                    //
                    var watch = new Stopwatch();
                    watch.Start();

                    var request = (HttpWebRequest)WebRequest.Create(uri);
                    request.Accept = "*/*";
                    request.ServicePoint.Expect100Continue = false;                        //加快载入速度
                    request.ServicePoint.UseNagleAlgorithm = false;                        //禁止Nagle算法加快载入速度
                    request.AllowWriteStreamBuffering = false;                             //禁止缓冲加快载入速度
                    request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); //定义gzip压缩页面支持
                    request.ContentType = "application/x-www-form-urlencoded";             //定义文档类型及编码
                    request.AllowAutoRedirect = false;                                     //禁止自动跳转
                    //设置User-Agent,伪装成Google Chrome浏览器
                    request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36";
                    request.Timeout = 5000;   //定义请求超时时间为5秒
                    request.KeepAlive = true; //启用长连接
                    request.Method = "GET";   //定义请求方式为GET
                    if (proxy != null)
                    {
                        request.Proxy = new WebProxy(proxy);             //设置代理服务器IP,伪装请求地址
                    }
                    request.CookieContainer = this.CookiesContainer;     //附加Cookie容器
                    request.ServicePoint.ConnectionLimit = int.MaxValue; //定义最大连接数

                    using (var response = (HttpWebResponse)request.GetResponse())
                    {
                        // Save cookies.
                        CookiesContainer.Add(response.Cookies);

                        // Parse the response.
                        if (response.ContentEncoding.ToLower().Contains("gzip")) // decompress
                        {
                            using (GZipStream stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress))
                            {
                                using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("Big5")))
                                {
                                    pageSource = reader.ReadToEnd();
                                }
                            }
                        }
                        else if (response.ContentEncoding.ToLower().Contains("deflate")) // decompress
                        {
                            using (DeflateStream stream = new DeflateStream(response.GetResponseStream(), CompressionMode.Decompress))
                            {
                                using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("Big5")))
                                {
                                    pageSource = reader.ReadToEnd();
                                }
                            }
                        }
                        else // not compressed.
                        {
                            using (Stream stream = response.GetResponseStream())//原始
                            {
                                using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("Big5")))
                                {
                                    pageSource = reader.ReadToEnd();
                                }
                            }
                        }
                    }

                    // Abort the request.
                    request.Abort();
                    watch.Stop();

                    // Fetch the current thread id.
                    var threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;

                    // Calculate the spent time.
                    var milliseconds = watch.ElapsedMilliseconds;

                    // Sent a completed event.
                    OnCompleted?.Invoke(this, new OnCompletedEventArgs(uri, threadId, pageSource, milliseconds));
                }
                catch (Exception ex)
                {
                    // Sent a error event.
                    OnError?.Invoke(this, new OnErrorEventArgs(uri, ex));
                }

                return pageSource;
            }));
        }
 public MNWSInfoRequestCurrUserSubscriptionStatus(OnCompleted onCompleted)
     : base()
 {
     this.OnCompletedDelegate = onCompleted;
 }
Beispiel #24
0
 public Task Initialize(PushRuntimeSettings limitations, OnMessage onMessage, OnError onError, OnCompleted onCompleted, CancellationToken cancellationToken = default)
 {
     pushSettings = limitations;
     return(Task.CompletedTask);
 }
 public MNWSInfoRequestSessionSignedClientToken(string payload,OnCompleted onCompleted)
     : base()
 {
     this.Parameters["payload"] = payload;
       this.OnCompletedDelegate = onCompleted;
 }
Beispiel #26
0
 protected virtual void RaiseOnCompleted() => OnCompleted?.Invoke(this, new EventArgs());
 public MNWSInfoRequestAnyGame(int gameId,OnCompleted onCompleted)
     : base()
 {
     this.Parameters["gameId"] = gameId;
       this.OnCompletedDelegate = onCompleted;
 }
 private void Complete(CompletedArgs args)
 {
     OnCompleted?.Invoke(args);
 }
 public MNWSInfoRequestAnyUserGameCookies(long[] userIdList,int[] cookieKeyList,OnCompleted onCompleted)
     : base()
 {
     this.Parameters["userIdList"   ] = userIdList;
       this.Parameters["cookieKeyList"] = cookieKeyList;
       this.OnCompletedDelegate = onCompleted;
 }
Beispiel #30
0
 private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     OnCompleted?.Invoke();
 }
 public MNWSInfoRequestCurrGameRoomList(OnCompleted onCompleted)
     : base()
 {
     this.OnCompletedDelegate = onCompleted;
 }
Beispiel #32
0
 public void Hide()
 {
     Visibility = Visibility.Collapsed;
     HideEditor();
     OnCompleted?.Invoke(this, new EventArgs());
 }