コード例 #1
0
        public static void ITEM_EXISTS <TId, TItem>(this HTTPServer HTTPServer,
                                                    HTTPPath UriTemplate,
                                                    ParseIdDelegate <TId> ParseIdDelegate,
                                                    Func <String, String> ParseIdError,
                                                    TryGetItemDelegate <TId, TItem> TryGetItemDelegate,
                                                    ItemFilterDelegate <TItem> ItemFilterDelegate,
                                                    Func <TId, String> TryGetItemError,
                                                    String HTTPServerName = HTTPServer.DefaultHTTPServerName)
        {
            HTTPServer.AddMethodCallback(HTTPHostname.Any,
                                         HTTPMethod.EXISTS,
                                         UriTemplate,
                                         HTTPContentType.JSON_UTF8,
                                         HTTPDelegate: async Request => {
                if (!ParseIdDelegate(Request.ParsedURLParameters[0], out TId Id))
                {
                    return new HTTPResponse.Builder(Request)
                    {
                        HTTPStatusCode            = HTTPStatusCode.BadRequest,
                        Server                    = HTTPServerName,
                        Date                      = Timestamp.Now,
                        AccessControlAllowOrigin  = "*",
                        AccessControlAllowMethods = "GET, EXISTS, COUNT",
                        AccessControlAllowHeaders = "Content-Type, Accept, Authorization",
                        ETag                      = "1",
                        ContentType               = HTTPContentType.JSON_UTF8,
                        Content                   = ErrorMessage(ParseIdError(Request.ParsedURLParameters[0])).ToUTF8Bytes(),
                        CacheControl              = "no-cache",
                        Connection                = "close"
                    }
                }
                ;

                if (!TryGetItemDelegate(Id, out TItem Item) || !ItemFilterDelegate(Item))
                {
                    return new HTTPResponse.Builder(Request)
                    {
                        HTTPStatusCode = HTTPStatusCode.NotFound,
                        Server         = HTTPServerName,
                        Date           = Timestamp.Now,
                        ContentType    = HTTPContentType.JSON_UTF8,
                        Content        = ErrorMessage(TryGetItemError(Id)).ToUTF8Bytes(),
                        CacheControl   = "no-cache",
                        Connection     = "close"
                    }
                }
                ;

                return(new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server = HTTPServerName,
                    Date = Timestamp.Now,
                    ETag = "1",
                    CacheControl = "public",
                    //Expires         = "Mon, 25 Jun 2015 21:31:12 GMT",
                    Connection = "close"
                });
            });
        }
コード例 #2
0
        public static void ITEM_GET <TId, TItem>(this HTTPServer HTTPServer,
                                                 HTTPPath UriTemplate,
                                                 ParseIdDelegate <TId> ParseIdDelegate,
                                                 Func <String, String> ParseIdError,
                                                 TryGetItemDelegate <TId, TItem> TryGetItemDelegate,
                                                 ItemFilterDelegate <TItem> ItemFilterDelegate,
                                                 Func <TId, String> TryGetItemError,
                                                 ItemToJSONDelegate <TItem> ToJSONDelegate)
        {
            HTTPServer.AddMethodCallback(HTTPHostname.Any,
                                         HTTPMethod.GET,
                                         UriTemplate,
                                         HTTPContentType.JSON_UTF8,
                                         HTTPDelegate: async Request => {
                TId Id;
                TItem Item;

                if (!ParseIdDelegate(Request.ParsedURLParameters[0], out Id))
                {
                    return new HTTPResponse.Builder(Request)
                    {
                        HTTPStatusCode = HTTPStatusCode.BadRequest,
                        Server         = HTTPServer.DefaultServerName,
                        ContentType    = HTTPContentType.JSON_UTF8,
                        Content        = ErrorMessage(ParseIdError(Request.ParsedURLParameters[0])).ToUTF8Bytes(),
                        CacheControl   = "no-cache",
                        Connection     = "close"
                    }
                }
                ;

                if (!TryGetItemDelegate(Id, out Item) || !ItemFilterDelegate(Item))
                {
                    return new HTTPResponse.Builder(Request)
                    {
                        HTTPStatusCode = HTTPStatusCode.NotFound,
                        Server         = HTTPServer.DefaultServerName,
                        ContentType    = HTTPContentType.JSON_UTF8,
                        Content        = ErrorMessage(TryGetItemError(Id)).ToUTF8Bytes(),
                        CacheControl   = "no-cache",
                        Connection     = "close"
                    }
                }
                ;

                return(new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server = HTTPServer.DefaultServerName,
                    ContentType = HTTPContentType.JSON_UTF8,
                    Content = ToJSONDelegate(Item).ToUTF8Bytes(),
                    ETag = "1",
                    CacheControl = "public",
                    //Expires         = "Mon, 25 Jun 2015 21:31:12 GMT",
                    Connection = "close"
                });
            });
        }
コード例 #3
0
 public static void ITEMS_GET <TId, TItem>(this HTTPServer HTTPServer,
                                           HTTPPath UriTemplate,
                                           Dictionary <TId, TItem> Dictionary,
                                           ItemFilterDelegate <TItem> Filter,
                                           ItemsToJSONDelegate <TItem> ToJSONDelegate)
 {
     GET_ITEMS(HTTPServer,
               UriTemplate,
               Dictionary.Select(kvp => kvp.Value),
               Filter,
               ToJSONDelegate);
 }
コード例 #4
0
        public GeckoAutoCompleteTextBox()
        {
            if (DesignMode)
            {
                return;
            }

            _formToObjectFinderDelegate = DefaultFormToObjectFinder;
            _itemFilterDelegate         = FilterList;

            Leave += Popup_Deactivate;

            _toolTip    = new ToolTip();
            MouseHover += OnMouseHover;

            // Create the list box that will hold matching items
            _listBox             = new GeckoListBox();
            _listBox.MaximumSize = new Size(800, 100);
            _listBox.Cursor      = Cursors.Hand;
            _listBox.BorderStyle = BorderStyle.FixedSingle;
            _listBox.MultiColumn = false;
            //_listBox.SelectedIndexChanged += List_SelectedIndexChanged;
            _listBox.UserClick      += List_Click;
            _listBox.ListLostFocus  += OnListLostFocus;
            _listBox.Enter          += List_Enter;
            _listBox.Leave          += List_Leave;
            _listBox.ItemHeight      = _listBox.Font.Height;
            _listBox.Visible         = false;
            _listBox.Sorted          = false;
            _listBox.HighlightSelect = true;

            // Add default triggers.
            triggers.Add(new TextLengthTrigger(2));
            triggers.Add(new ShortCutTrigger(Keys.Enter, TriggerState.Select));
            triggers.Add(new ShortCutTrigger(Keys.Tab, TriggerState.Select));
            triggers.Add(new ShortCutTrigger(Keys.Control | Keys.Space, TriggerState.ShowAndConsume));
            triggers.Add(new ShortCutTrigger(Keys.Escape, TriggerState.HideAndConsume));
        }
コード例 #5
0
        public static void GET_ITEMS <TItem>(this HTTPServer HTTPServer,
                                             HTTPPath UriTemplate,
                                             IEnumerable <TItem> Enumeration,
                                             ItemFilterDelegate <TItem> Filter,
                                             ItemsToJSONDelegate <TItem> ToJSONDelegate)
        {
            HTTPServer.AddMethodCallback(HTTPHostname.Any,
                                         HTTPMethod.GET,
                                         UriTemplate,
                                         HTTPContentType.JSON_UTF8,
                                         HTTPDelegate: async Request => {
                var skip = Request.QueryString.GetUInt32("skip");
                var take = Request.QueryString.GetUInt32("take");

                var AllItems = Enumeration.
                               Skip(skip.HasValue ? skip.Value : 0).
                               Where(item => Filter(item));

                if (take.HasValue)
                {
                    AllItems = AllItems.
                               Take(take.Value);
                }

                return(new HTTPResponse.Builder(Request)
                {
                    HTTPStatusCode = HTTPStatusCode.OK,
                    Server = HTTPServer.DefaultServerName,
                    ContentType = HTTPContentType.JSON_UTF8,
                    Content = ToJSONDelegate(AllItems).ToUTF8Bytes(),
                    ETag = "1",
                    CacheControl = "public",
                    //Expires         = "Mon, 25 Jun 2015 21:31:12 GMT",
                    Connection = "close"
                });
            });
        }
コード例 #6
0
ファイル: AutoCompleteTextBox.cs プロジェクト: bbriggs/wesay
		public WeSayAutoCompleteTextBox()
		{
			if (DesignMode)
			{
				return;
			}

			_formToObectFinderDelegate = DefaultFormToObjectFinder;
			_itemFilterDelegate = FilterList;

			Leave += Popup_Deactivate;

			_toolTip = new ToolTip();
			MouseHover += OnMouseHover;

			// Create the list box that will hold matching items
			_listBox = new ListBox();
			_listBox.MaximumSize = new Size(800, 100);
			_listBox.Cursor = Cursors.Hand;
			_listBox.BorderStyle = BorderStyle.FixedSingle;
			//_listBox.SelectedIndexChanged += List_SelectedIndexChanged;
			_listBox.Click += List_Click;
			_listBox.MouseMove += List_MouseMove;
			_listBox.ItemHeight = _listBox.Font.Height;
			_listBox.Visible = false;
			_listBox.Sorted = false;

			// Add default triggers.
			triggers.Add(new TextLengthTrigger(2));
			triggers.Add(new ShortCutTrigger(Keys.Enter, TriggerState.Select));
			triggers.Add(new ShortCutTrigger(Keys.Tab, TriggerState.Select));
			triggers.Add(new ShortCutTrigger(Keys.Control | Keys.Space, TriggerState.ShowAndConsume));
			triggers.Add(new ShortCutTrigger(Keys.Escape, TriggerState.HideAndConsume));
		}