Ejemplo n.º 1
0
        public void LoadCompanies(decimal percentage)
        {
            var count = _symbolLoader.GetSymbols().Count();
            int index = 0;

            foreach (var symbol in _symbolLoader.GetSymbols())
            {
                try
                {
                    index++;
                    var company = _downloader.GetQuote(symbol.Symbol);
                    _companies.Add(new CompanyVM(company));
                }
                catch (Exception s)
                {
                }
                finally
                {
                    ProgressChangedHandler?.Invoke(this, new ProgressChangedEventArgs()
                    {
                        Progress = (int)((float)index / count * 100.0)
                    });
                }
            }

            var filtered = FilterCompanies(percentage);

            _companies.Clear();
            _companies.AddRange(filtered.ToList());

            CompaniesUpdatedHandler?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 2
0
        public ProgressCounter(Thread workerThread, int maximumValue, int initialValue = 0, int incrementBy = 1)
        {
            _workerThread = workerThread;

            _childProgressChangedHandler = new ProgressChangedHandler(_childCounter_ProgressChanged);
            _childStatusChangedHandler   = new StatusChangedHandler(_childCounter_StatusChanged);
            _value       = initialValue;
            _incrementBy = incrementBy;
            _maximum     = maximumValue;

            ProgressCounter parentCounter = Top;

            if (parentCounter == null)
            {
                // Set top level counter
                Top = this;
            }
            else
            {
                // Add to stack
                while (parentCounter._childCounter != null)
                {
                    parentCounter = parentCounter._childCounter;
                }

                if (parentCounter != null)
                {
                    parentCounter.AddChild(this);
                }
            }
        }
Ejemplo n.º 3
0
        }//end method

        /// <summary>
        /// 以异步的形式发起HTTP请求并返回类型为泛型的API响应对象。
        /// </summary>
        /// <typeparam name="T">定义结果的泛型。</typeparam>
        /// <param name="successCallback">调用成功的方法回调。</param>
        /// <param name="progressCallback">调用过程中进度变化的方法回调。</param>
        /// <param name="failCallback">调用失败的方法回调。</param>
        /// <param name="timeout">HTTP超时时间,以秒为单位。</param>
        /// <param name="reportInterval">HTTP异步执行中反馈进度的时间间隔,以秒为单位。</param>
        /// <returns>返回HTTP异步任务。</returns>
        public virtual KdHttpTask <T> ToAPIResponseAsync <T>(
            Action <APIResponse <T> > successCallback = null,
            ProgressChangedHandler progressCallback   = null,
            Action <APIResponse <T> > failCallback    = null,
            int timeout        = 0,
            int reportInterval = 5)
        {
            var task = new KdHttpTask <T>();

            task.KdRequest        = this;
            task.SuccessCallBack  = successCallback;
            task.ProgressCallBack = progressCallback;
            task.FailCallBack     = failCallback;
            //task.BeginApiClientExecute();
            return(task);
        }//end method
Ejemplo n.º 4
0
        // Token: 0x060000DC RID: 220 RVA: 0x00004458 File Offset: 0x00002658
        private ProgressReporter(ApiClient client, ApiRequest request, ProgressChangedHandler progressCallback, int interval)
        {
            string text = request.RequestId;

            if (interval < 0 || interval > 30)
            {
                interval = 5;
            }
            int num = 1000 * interval;

            this.timer            = new Timer(new TimerCallback(this.TimerCallback), null, num, num);
            this.requestId        = text;
            this.progressCallback = progressCallback;
            this.client           = client;
            this.getLastAuto      = request.AutoGetLastProgress;
        }
Ejemplo n.º 5
0
        }//end method

        /// <summary>
        /// 以异步的形式发起HTTP请求并返回执行结果。
        /// </summary>
        /// <typeparam name="T">泛型对象。</typeparam>
        /// <param name="successCallback">执行成功的方法委托。</param>
        /// <param name="progressCallback">执行中的方法委托。</param>
        /// <param name="failCallback">执行失败的方法委托。</param>
        /// <param name="timeout">超时时间,默认0秒。</param>
        /// <param name="reportInterval">执行汇报进程间隔,默认5秒。</param>
        /// <returns>返回ApiRequest对象。</returns>
        public virtual ApiRequest ExecuteAsync <T>(
            Action <T> successCallback = null,
            ProgressChangedHandler progressCallback = null,
            FailCallbackHandler failCallback        = null,
            int timeout        = 0,
            int reportInterval = 5)
        {
            this.CreateApiClientInstance();

            var paramatersArray = JsonConvert.DeserializeObject <object[]>(this.Operation.RequestParameters);

            return(_client.ExecuteAsync <T>(this.Operation.ServiceName,
                                            successCallback,
                                            paramatersArray,
                                            progressCallback,
                                            failCallback,
                                            timeout,
                                            reportInterval));
        }//end method
Ejemplo n.º 6
0
 // Token: 0x06000016 RID: 22 RVA: 0x00002568 File Offset: 0x00000768
 public void CallAsync <T>(ApiRequest request, Action <AsyncResult <T> > callback, ProgressChangedHandler progressCallback = null, int timeout = 0, int reportInterval = 5)
 {
     this.httpClient.SendAysnc(request, delegate(AsyncResult <string> ret)
     {
         ProgressReporter.Finish(request.RequestId);
         callback(ret.Cast <T>());
     }, null);
     if (progressCallback != null)
     {
         ProgressReporter reporter = ProgressReporter.Create(this, request, progressCallback, reportInterval);
         if (reportInterval > 0)
         {
             new DelayInvoker <ApiRequest>(delegate(ApiRequest r)
             {
                 try
                 {
                     reporter.TimerCallback(null);
                 }
                 catch (WebException ex)
                 {
                     if (ex.Status == WebExceptionStatus.RequestCanceled)
                     {
                         throw new TimeoutException(string.Format("请求超时{0}秒,请求被终止", timeout));
                     }
                 }
             }, request, timeout).Invoke();
         }
     }
 }
Ejemplo n.º 7
0
        // Token: 0x06000013 RID: 19 RVA: 0x000023B8 File Offset: 0x000005B8
        private ApiRequest ExecuteAsyncInternal <T>(string servicename, Action <AsyncResult <T> > callback, object[] parameters = null, ProgressChangedHandler progressCallback = null, int timeout = 0, int reportInterval = 5)
        {
            ApiRequest apiRequest = this.CreateAsyncRequest(servicename, parameters);

            apiRequest.HttpRequest.Timeout = timeout * 1000;
            this.CallAsync <T>(apiRequest, callback, progressCallback, timeout, reportInterval);
            return(apiRequest);
        }
Ejemplo n.º 8
0
 // Token: 0x06000012 RID: 18 RVA: 0x00002374 File Offset: 0x00000574
 public ApiRequest ExecuteAsync <T>(string servicename, Action <T> successCallback, object[] parameters = null, ProgressChangedHandler progressCallback = null, FailCallbackHandler failcallback = null, int timeout = 0, int reportInterval = 5)
 {
     return(this.ExecuteAsyncInternal <T>(servicename, delegate(AsyncResult <T> ret)
     {
         if (ret.Successful)
         {
             successCallback(ret.ReturnValue);
             return;
         }
         FailCallbackHandler reallyFailCallback = this.GetReallyFailCallback(failcallback);
         if (reallyFailCallback != null)
         {
             reallyFailCallback(ret.Exception);
             return;
         }
         ret.ThrowEx();
     }, parameters, progressCallback, timeout, reportInterval));
 }
Ejemplo n.º 9
0
        // Token: 0x060000DB RID: 219 RVA: 0x00004424 File Offset: 0x00002624
        internal static ProgressReporter Create(ApiClient client, ApiRequest request, ProgressChangedHandler progressCallback, int interval)
        {
            string key = request.RequestId;

            ProgressReporter.reporters[key] = new ProgressReporter(client, request, progressCallback, interval);
            return(ProgressReporter.reporters[key]);
        }
Ejemplo n.º 10
0
 // Token: 0x060000BC RID: 188 RVA: 0x000041B8 File Offset: 0x000023B8
 public void GroupSaveSync(string formId, string data, Action <string> SuccResultHandler, FailCallbackHandler failcallback = null, ProgressChangedHandler progressCallback = null, int reportInterval = 5)
 {
     base.ExecuteAsync <string>("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.GroupSave", SuccResultHandler, new object[]
     {
         formId,
         data
     }, progressCallback, failcallback, 10, reportInterval);
 }
Ejemplo n.º 11
0
 // Token: 0x060000B6 RID: 182 RVA: 0x00004088 File Offset: 0x00002288
 public void ExecuteBillQuerySync(string data, Action <List <List <object> > > SuccResultHandler, FailCallbackHandler failcallback = null, ProgressChangedHandler progressCallback = null, int reportInterval = 5)
 {
     base.ExecuteAsync <List <List <object> > >("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery", SuccResultHandler, new object[]
     {
         data
     }, progressCallback, failcallback, 10, reportInterval);
 }
Ejemplo n.º 12
0
 // Token: 0x060000AD RID: 173 RVA: 0x00003EC8 File Offset: 0x000020C8
 public void GetDataCentersSync(Action <List <DataCenter> > SuccResultHandler, FailCallbackHandler failcallback = null, ProgressChangedHandler progressCallback = null, int reportInterval = 5)
 {
     base.ExecuteAsync <List <DataCenter> >("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.GetDataCenterList", SuccResultHandler, new object[0], progressCallback, failcallback, 10, reportInterval);
 }