示例#1
0
 private void InitComms()
 {
     //_comms = new Bootlegger(WhiteLabelConfig.SERVER, WhiteLabelConfig.PORT, this.FilesDir.AbsolutePath, WhiteLabelConfig.APIKEY, WhiteLabelConfig.CBID);
     Bootlegger.Create(WhiteLabelConfig.SERVER, WhiteLabelConfig.PORT, this.FilesDir.AbsolutePath, WhiteLabelConfig.APIKEY, WhiteLabelConfig.CBID, GetExternalPath(), WhiteLabelConfig.LOCAL_LOGIN);
     Bootlegger.BootleggerClient.Language = Resources.Configuration.Locale.Language;
     _cache = new Square.OkHttp3.Cache(FilesDir, 300 * 1024 * 1024);
 }
        internal void Get(string path)
        {
            if (Bootlegger.DEBUGMODE)
            {
                sw.Reset();
                sw.Start();
            }

            if (socket != null && socket.IsConnected)
            {
                socket.Emit("get", new SailsArgs()
                {
                    url = path, data = new ApiKeyArgs()
                    {
                        apikey = Bootlegger.API_KEY
                    }
                }, callback: (oe) =>
                {
                    //Console.WriteLine(oe);
                    if (Bootlegger.DEBUGMODE)
                    {
                        sw.Stop();
                        Bootlegger.FireDebug("get " + path + ": " + sw.ElapsedMilliseconds);
                    }
                });
            }
        }
        internal Task <bool> Get(string path, object d = null)
        {
            if (Bootlegger.DEBUGMODE)
            {
                sw.Reset();
                sw.Start();
            }
            var tcs = new TaskCompletionSource <bool>();

            const int timeoutMs = 5000;
            var       ct        = new CancellationTokenSource(timeoutMs);

            ct.Token.Register(() => tcs.TrySetCanceled(), useSynchronizationContext: false);
            if (d == null)
            {
                d = new ApiKeyArgs();
            }
            (d as ApiKeyArgs).apikey = Bootlegger.API_KEY;

            if (socket != null && socket.IsConnected)
            {
                socket.Emit("get", new SailsArgs()
                {
                    url = path, data = d
                }, callback: (oe) =>
                {
                    if (Bootlegger.DEBUGMODE)
                    {
                        sw.Stop();
                        Bootlegger.FireDebug("get " + path + ": " + sw.ElapsedMilliseconds);
                    }
                    tcs.TrySetResult(true);
                });

                //Timer t = new Timer(new TimerCallback((o)=>{
                //    tcs.TrySetResult(true);
                //}),null,0,2000);
            }
            else
            {
                tcs.TrySetResult(true);
            }
            return(tcs.Task);
        }