private void handleRequest(HttpListenerContext context)
        {
            var eventArgs = new HttpEventArgs(context.Request, context.Response);
            var method    = context.Request.HttpMethod;

            try
            {
                if (method == HttpMethod.Get.Method)
                {
                    OnGet?.Invoke(this, eventArgs);
                }
                else if (method == HttpMethod.Post.Method)
                {
                    OnPost?.Invoke(this, eventArgs);
                }
                else if (method == HttpMethod.Put.Method)
                {
                    OnPut?.Invoke(this, eventArgs);
                }
            }
            catch (NotImplementedException)
            {
                context.Response.Abort();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of the object pool and initializes it.
 /// </summary>
 /// <param name="maxPoolSize">The maximum amount of objects that should be pooled maximum.</param>
 public ObjectPool(Constructor constructor, int maxPoolSize = 1000, OnReturn onReturn = null, OnGet onGet = null)
 {
     this.constructor = constructor;
     this.onReturn    = onReturn;
     this.onGet       = onGet;
     this.maxPoolSize = maxPoolSize;
 }
Exemplo n.º 3
0
 public BarResponse Get(string id)
 {
     OnGet?.Invoke(this, id);
     return(new BarResponse {
         Data = _testData
     });
 }
Exemplo n.º 4
0
 protected void InvokeOnGet(T item)
 {
     if (OnGet != null)
     {
         OnGet.Invoke(item);
     }
 }
Exemplo n.º 5
0
    public void GetData <T>(string path, OnGet <T> callback)
    {
        string url = String.Format("{0}{1}.json", databaseRoot, path);

        RestClient.Get(url).Then(response => {
            Debug.Log(String.Format("Response code:{0}", response.StatusCode));
            callback(JsonUtility.FromJson <T>(response.Text));
        });
    }
Exemplo n.º 6
0
        public void OnPoolGet()
        {
            if (lifecycleHandlers != null)
            {
                for (var i = 0; i < lifecycleHandlers.Length; i++)
                {
                    var handler = lifecycleHandlers[i];
                    handler.OnPoolGet();
                }
            }

            OnGet?.Invoke();
        }
Exemplo n.º 7
0
        public T Get()
        {
            if (unused.Count <= 0)
            {
                Expand();
            }

            T item = unused.Pop();

            used.Add(item);

            item.OnGet(this);

            OnGet?.Invoke(item);

            return(item);
        }
Exemplo n.º 8
0
        public virtual async Task<T> Get<T>(string resource,
                                    CancellationToken cancelToken,
                                    string taskTitle,
                                    string successMsg,
                                    params Func<T, object>[] successMsgArgs
                                    ) where T : new()
        {
            if (!IsLoggedIn)
                throw Error.BadAct($"‹{this.GetType().Name}› is not logged in.");

            var req = _auth.Req.GET(resource);
            try
            {
                return await _client.Send<T>(req, cancelToken, taskTitle, successMsg, successMsgArgs);
            }
            catch (RestServiceException ex) { OnGet.Err(this, ex); }
            catch (Exception ex) { OnUnhandled.Err(this, ex); }
            return default(T);
        }
Exemplo n.º 9
0
        public PoolableObject Get(object id)
        {
            if (id == null)
            {
                Debug.LogError("Get >>> id cannot be null!");
                return(null);
            }

            Pool pool;

            if (pools.ContainsKey(id))
            {
                pool = pools[id];
            }
            else
            {
                Debug.LogError($"Pool doesn't exist for id {id}!");
                return(null);
            }

            OnGet?.Invoke();
            return(pool.Get());
        }
Exemplo n.º 10
0
 protected virtual void OnGetAction(GetEventArgs e)
 {
     OnGet?.Invoke(this, e);
 }
Exemplo n.º 11
0
 private void TriggerOnGet(string key, string region, CacheActionEventArgOrigin origin = CacheActionEventArgOrigin.Local)
 {
     OnGet?.Invoke(this, new CacheActionEventArgs(key, region, origin));
 }
Exemplo n.º 12
0
        private void onRequest(HttpListenerContext context)
        {
            var req       = context.Request;
            var res       = context.Response;
            var eventArgs = new HttpRequestEventArgs(context);

            if (req.HttpMethod == "GET" && !OnGet.IsNull())
            {
                OnGet(this, eventArgs);
                return;
            }

            if (req.HttpMethod == "HEAD" && !OnHead.IsNull())
            {
                OnHead(this, eventArgs);
                return;
            }

            if (req.HttpMethod == "POST" && !OnPost.IsNull())
            {
                OnPost(this, eventArgs);
                return;
            }

            if (req.HttpMethod == "PUT" && !OnPut.IsNull())
            {
                OnPut(this, eventArgs);
                return;
            }

            if (req.HttpMethod == "DELETE" && !OnDelete.IsNull())
            {
                OnDelete(this, eventArgs);
                return;
            }

            if (req.HttpMethod == "OPTIONS" && !OnOptions.IsNull())
            {
                OnOptions(this, eventArgs);
                return;
            }

            if (req.HttpMethod == "TRACE" && !OnTrace.IsNull())
            {
                OnTrace(this, eventArgs);
                return;
            }

            if (req.HttpMethod == "CONNECT" && !OnConnect.IsNull())
            {
                OnConnect(this, eventArgs);
                return;
            }

            if (req.HttpMethod == "PATCH" && !OnPatch.IsNull())
            {
                OnPatch(this, eventArgs);
                return;
            }

            res.StatusCode = (int)HttpStatusCode.NotImplemented;
        }
Exemplo n.º 13
0
 private void TriggerOnGet(TKey key, CacheActionEventArgOrigin origin = CacheActionEventArgOrigin.Local)
 {
     OnGet?.Invoke(this, new CacheActionEventArgs <TKey>(key, origin));
 }
Exemplo n.º 14
0
 public T this[int index]
 {
     get { OnGet.Invoke(InternalList[index], index); return(InternalList[index]); }
     set { OnSet.Invoke(value, index); InternalList[index] = value; }
 }
Exemplo n.º 15
0
 public T2 this[T1 index]
 {
     get { OnGet.Invoke(index, InternalDict[index]); return(InternalDict[index]); }
     set { InternalDict[index] = value; OnSet.Invoke(index, value); }
 }