protected override void Initialize() { collection = new CollectionHandler { Handler = this }; var col = new NSTableColumn(); col.ResizingMask = NSTableColumnResizing.Autoresizing; col.Editable = false; cell = new MacImageListItemCell(); cell.Wraps = false; col.DataCell = cell; Control.AddColumn(col); Control.DoubleClick += HandleDoubleClick; Control.DataSource = new EtoDataSource { Handler = this }; Control.Delegate = new EtoDelegate { Handler = this }; scroll = new EtoScrollView { Handler = this }; scroll.AutoresizesSubviews = true; scroll.DocumentView = Control; scroll.HasVerticalScroller = true; scroll.HasHorizontalScroller = true; scroll.AutohidesScrollers = true; scroll.BorderType = NSBorderType.BezelBorder; base.Initialize(); HandleEvent(Eto.Forms.Control.KeyDownEvent); }
private Test CreateCopyToTest() { return(new TestCase("CopyTo", () => { AssertDistinctIntancesNotEmpty(); var collection = GetSafeDefaultInstance(); var handler = new CollectionHandler <TCollection, TItem>(collection, Context); var initialContent = new ReadOnlyCollection <TItem>(new List <TItem>(collection)); foreach (var item in DistinctInstances) { if (!IsReadOnly && !initialContent.Contains(item)) { handler.AddSingleItemOk(item); } } const int extension = 5; int count = collection.Count; var target = new TItem[count + extension]; AssertCopyToThrowException(() => collection.CopyTo(null, 0), "when called with a null argument.", "Argument Name", "array"); AssertCopyToThrowException(() => collection.CopyTo(target, -1), "when called with a negative index.", "Argument Name", "arrayIndex"); for (int i = 0; i <= extension; i++) { AssertCopyToNotThrowException(() => collection.CopyTo(target, i), "Expected the method to not throw an exception."); var clone = new TItem[count]; Array.Copy(target, i, clone, 0, count); Assert.AreElementsEqual(collection, clone); } AssertCopyToThrowException(() => collection.CopyTo(target, extension + 1), "when called with a too large array index.", "Argument Name", "arrayIndex"); })); }
/// <summary>method <c>ReadLocales</c> Reads locales from app.config file.</summary><returns>Nothing</returns> private string[] ReadLocales() { CollectionHandler collectionHandler = new CollectionHandler(); string series = collectionHandler.GetLocales(); return(series.Split(",")); }
/// <summary> /// Save button functionality. /// Calls methods ValidatePost() and BuildData() /// Asks user confirmation to validate saving or chance to back out. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void SaveNewPost(object sender, RoutedEventArgs e) { if (this.ValidatePost()) { MessageBoxResult wannaInsert = MessageBox.Show("Are you sure you want to add post?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (wannaInsert == MessageBoxResult.Yes) { CollectionHandler collectionHandler = new CollectionHandler(); FirebaseHandler firebaseHandler = new FirebaseHandler(); string[] response = await firebaseHandler.SaveToDb(this.BuildData(), collectionHandler.GetBlogCollection(localesDrobdown.Text)); if (response[0].Equals("200")) { _ = MessageBox.Show("Blog post added", "Info", MessageBoxButton.OK, MessageBoxImage.Information); } else { _ = MessageBox.Show(response[1], "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { _ = MessageBox.Show("Inserting cancelled!", "Info", MessageBoxButton.OK, MessageBoxImage.Information); } } else { _ = MessageBox.Show("Some fields are empty", "Info", MessageBoxButton.OK, MessageBoxImage.Information); } }
public OpexController(ILogger <OpexController> logger, IOptions <AppSettings> settings, IHubContext <PreingestEventHub> eventHub, CollectionHandler preingestCollection) { _logger = logger; _settings = settings.Value; _preingestCollection = preingestCollection; _eventHub = eventHub; }
/* class functions */ // gets data from db List<Dic<string, object>> and sets it to private variable private async void SetData() { // dummy text for user messageHeader.Text = "Loading messages, please wait!"; // change mouse cursor to load Mouse.OverrideCursor = Cursors.Wait; try { FirebaseHandler fbh = new FirebaseHandler(); CollectionHandler collectionHandler = new CollectionHandler(); this.data = await fbh.GetCollection(collectionHandler.GetMessageCollection()); //release mouse cursor to normal Mouse.OverrideCursor = null; if (this.data[0] != null) { // insert messages to "DOM" or ui this.InsertToDom(this.data[0]); } } catch (Exception e) { messageHeader.Text = "Error occured: " + e.Message; } }
private Test CreateAddItemsTest() { return(new TestCase("AddItems", () => { AssertDistinctIntancesNotEmpty(); var collection = GetSafeDefaultInstance(); var handler = new CollectionHandler <TCollection, TItem>(collection, Context); var initialContent = new ReadOnlyCollection <TItem>(new List <TItem>(collection)); foreach (var item in DistinctInstances) { if (!initialContent.Contains(item)) { handler.AddSingleItemOk(item); } if (AcceptEqualItems) { handler.AddDuplicateItemOk(item); } else { handler.AddDuplicateItemFails(item); } } })); }
/// <summary> /// Returns true if this type is a collection type /// </summary> /// <param name="context">the serialization context</param> /// <returns>true if a collection</returns> public virtual bool IsCollection() { if (!collectionLookedUp) { collectionHandler = FindCollectionHandler(); collectionLookedUp = true; } return(collectionHandler != null); }
public override void Process(IMetaData metaData, ICustomAttributeProvider attributeProvider, ISerializerSettings config) { TypeData typeData = metaData as TypeData; if (typeData == null) { return; } JsonExCollectionAttribute attr = ReflectionUtils.GetAttribute <JsonExCollectionAttribute>(attributeProvider, true); if (attr == null) { return; } if (!attr.IsValid()) { throw new Exception("Invalid JsonExCollectionAttribute specified for " + attributeProvider + ", either CollectionHandlerType or ItemType or both must be specified"); } Type collHandlerType = attr.GetCollectionHandlerType(); Type itemType = attr.GetItemType(); // Try exact type match first CollectionHandler handler = null; if (collHandlerType == null) { handler = typeData.FindCollectionHandler(); handler = new CollectionHandlerWrapper(handler, typeData.ForType, itemType); } bool registerHandler = false; if (handler == null) { handler = ConstructOrFindHandler(config, collHandlerType, ref registerHandler); } typeData.CollectionHandler = handler; // install the handler if (registerHandler) { config.RegisterCollectionHandler(handler); } }
public static void Main(string[] args) { IApplicationContext springContainer = ContextRegistry.GetContext(); IStandardStreamingEventBus streamingEventBus = springContainer.GetObject( typeof(IStandardStreamingEventBus).FullName) as IStandardStreamingEventBus; IStreamingCollectionHandler<ModernMajorGeneralMessage> handler = new CollectionHandler(); streamingEventBus.SubscribeToCollection<ModernMajorGeneralMessage>(handler); Console.WriteLine("If all events have been received, hit the Enter Key to exit the program."); Console.Read(); Environment.Exit(0); }
/// <summary> /// Returns true if this type is a collection type /// </summary> /// <param name="context">the serialization context</param> /// <returns>true if a collection</returns> public virtual bool IsCollection() { if (!collectionLookedUp) { if (this.ForType.IsDefined(typeof(JsonExCollectionAttribute), true)) { collectionHandler = GetCollectionHandlerFromAttribute(); } else { collectionHandler = FindCollectionHandler(); } collectionLookedUp = true; } return(collectionHandler != null); }
/// <summary> /// Initializes a new instance of the <see cref="Eto.Forms.FilterCollection{T}"/> class with the specified <paramref name="collection"/>. /// </summary> /// <param name="collection">Collection of items as the source of this collection.</param> public FilterCollection(IEnumerable <T> collection) { var changed = collection as INotifyCollectionChanged; if (changed != null) { changedHandler = new CollectionHandler { List = this }; changedHandler.Register(collection); } else { items = new List <T>(collection); } }
private void AddCollectionHandler(string tagName, string[] values) { string type = values[0]; if (string.IsNullOrEmpty(type)) { throw new ArgumentException("Must specify 'type' for CollectionHandlers add"); } // load the specified types Type handlerType = Type.GetType(type, true); CollectionHandler collHandler = (CollectionHandler)Activator.CreateInstance(handlerType); context.CollectionHandlers.Insert(_collectionInsertPoint++, collHandler); }
void Initialize(swc.DataGridCell cell, swc.ComboBox control, object dataItem) { var collection = new CollectionHandler { Handler = Handler }; collection.Register(Handler.Widget.DataStoreBinding.GetValue(dataItem)); control.ItemsSource = collection.Items; if (!IsControlInitialized(control)) { control.DataContextChanged += (sender, e) => SetValue(control.GetParent <swc.DataGridCell>(), (swc.ComboBox)sender, e.NewValue); SetControlInitialized(control, true); } SetValue(cell, control, dataItem); }
/// <summary> /// Deletes message. Gets id to remove from input field. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void DeleteMessage(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Are you sure you want to delete?", "Deleting", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes && idToDelete.Text.Length > 0) { FirebaseHandler firebaseHandler = new FirebaseHandler(); CollectionHandler collection = new CollectionHandler(); string locale = ""; int index = 0; foreach (dataModel item in this.dataCollection) { if (item.id.Equals(idToDelete.Text)) { locale = item.locale; index = this.dataCollection.IndexOf(item); } } if (locale.Equals("fi") || locale.Equals("en")) { string[] response = await firebaseHandler.DeleteFromDb(idToDelete.Text, collection.GetNewsCollection(locale)); if (response[0].Equals("200")) { this.dataCollection.RemoveAt(index); _ = MessageBox.Show("Deleted succesfully", "Deleted", MessageBoxButton.OK, MessageBoxImage.Information); } else { _ = MessageBox.Show(response[1], "Error happened", MessageBoxButton.OK, MessageBoxImage.Error); } } else { _ = MessageBox.Show("Error cannot get locale from news delete. Are you sure id is valid?", "Error happened", MessageBoxButton.OK, MessageBoxImage.Error); } } else if (idToDelete.Text.Length == 0) { _ = MessageBox.Show("Id to delete cannot be empty!", "Id is empty", MessageBoxButton.OK, MessageBoxImage.Information); } else { _ = MessageBox.Show("Nothing deleted!", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); } }
// remove button private async void RemoveMessage(object sender, RoutedEventArgs e) { MessageBoxResult wannaRemove = MessageBox.Show("Are you sure you want to remove?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (wannaRemove == MessageBoxResult.Yes) { // collection does get removed if empty, prevent that if (this.data.Count > 1) { FirebaseHandler firebaseHandler = new FirebaseHandler(); CollectionHandler collectionH = new CollectionHandler(); string[] response = await firebaseHandler.DeleteFromDb(this.currentMessage, collectionH.GetMessageCollection()); if (response[0].Equals("200")) { int index = this.FindIndex(this.currentMessage); try { this.data.RemoveAt(index); this.InsertToDom(this.data[0]); _ = MessageBox.Show("Document deleted!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ed) { _ = MessageBox.Show(ed.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } //error from firebase else { _ = MessageBox.Show(response[1], "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } // cannot remove only document else { _ = MessageBox.Show("Nothing removed! Collection length must be at least one.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } // cancelled remove else { _ = MessageBox.Show("Nothing removed!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// Reads the JsonExCollection attribute for the class and loads the collection handler from that. It first /// checks the list of collectionhandlers to see if its already been loaded. /// </summary> /// <returns>CollectionHandler specified by the JsonExCollection attribute</returns> protected virtual CollectionHandler GetCollectionHandlerFromAttribute() { JsonExCollectionAttribute attr = ((JsonExCollectionAttribute[])this.ForType.GetCustomAttributes(typeof(JsonExCollectionAttribute), true))[0]; if (!attr.IsValid()) { throw new Exception("Invalid JsonExCollectionAttribute specified for " + this.ForType + ", either CollectionHandlerType or ItemType or both must be specified"); } Type collHandlerType = attr.GetCollectionHandlerType(); Type itemType = attr.GetItemType(); // Try exact type match first CollectionHandler handler = null; if (collHandlerType == null) { handler = FindCollectionHandler(); handler = new CollectionHandlerWrapper(handler, this.ForType, itemType); } if (handler == null) { handler = context.CollectionHandlers.Find(delegate(CollectionHandler h) { return(h.GetType() == collHandlerType); }); if (handler != null) { return(handler); } // try inherited type next handler = context.CollectionHandlers.Find(delegate(CollectionHandler h) { return(collHandlerType.IsInstanceOfType(h)); }); if (handler != null) { return(handler); } // create the handler handler = (CollectionHandler)Activator.CreateInstance(collHandlerType); } // install the handler context.RegisterCollectionHandler(handler); return(handler); }
/// <summary> /// Loads news from firestore. /// Controls mouse cursor to show loading. Raises exception if firebase fails. /// </summary> /// <exception cref="Exception">Errors in firebase</exception> private async void GetData() { Mouse.OverrideCursor = Cursors.Wait; try { FirebaseHandler fbh = new FirebaseHandler(); CollectionHandler collectionHandler = new CollectionHandler(); List <Dictionary <string, object> > list1 = await fbh.GetCollection(collectionHandler.GetNewsCollection("fi")); List <Dictionary <string, object> > list2 = await fbh.GetCollection(collectionHandler.GetNewsCollection("en")); this.news.AddRange(list1); this.news.AddRange(list2); Mouse.OverrideCursor = null; this.FillDataCollection(); } catch (Exception e) { _ = MessageBox.Show(e.Message, "There was an error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void Should_receive_all_segments_published_as_a_chunked_sequence() { ManualResetEvent signal = new ManualResetEvent(false); CollectionHandler handler = new CollectionHandler(signal); _streamingBus.SubscribeToCollection(handler); IList <TestStreamEvent> eventSequence = new List <TestStreamEvent>(); eventSequence.Add(new TestStreamEvent(1)); eventSequence.Add(new TestStreamEvent(2)); eventSequence.Add(new TestStreamEvent(3)); _streamingBus.PublishChunkedSequence(eventSequence); signal.WaitOne(TimeSpan.FromSeconds(10)); Assert.That(handler.ReceivedEvents, Is.Not.Null, "The collection of events was not receieved before the timeout expired."); Assert.That(handler.ReceivedEvents.Length, Is.EqualTo(3)); Assert.That(handler.ReceivedEvents.Select(e => e.Event), Is.Ordered.By("Sequence")); }
/// <summary> /// Constructs a builder used to build the deserialized collection /// </summary> /// <param name="collection">an existing collection object or null for a new collection</param> /// <param name="list">the list expression</param> /// <param name="itemType">the type of the items</param> /// <returns>collection builder</returns> protected virtual ICollectionBuilder ConstructBuilder(object collection, ArrayExpression list, out Type itemType) { Type listType = collection != null?collection.GetType() : list.ResultType; ITypeData typeHandler = Settings.Types[listType]; CollectionHandler collHandler = typeHandler.CollectionHandler; itemType = collHandler.GetItemType(listType); if (itemType == null) { throw new Exception("Null item type returned from " + collHandler.GetType() + " for Collection type: " + listType); } if (collection != null) { return(collHandler.ConstructBuilder(collection)); } else { return(collHandler.ConstructBuilder(listType, list.Items.Count)); } }
protected virtual CollectionHandler ConstructOrFindHandler(ISerializerSettings config, Type collHandlerType, ref bool handlerConstructed) { handlerConstructed = false; CollectionHandler handler = config.CollectionHandlers.Find(delegate(CollectionHandler h) { return(h.GetType() == collHandlerType); }); if (handler != null) { return(handler); } // try inherited type next handler = config.CollectionHandlers.Find(delegate(CollectionHandler h) { return(collHandlerType.IsInstanceOfType(h)); }); if (handler != null) { return(handler); } // create the handler handler = (CollectionHandler)Activator.CreateInstance(collHandlerType); handlerConstructed = true; return(handler); }
/// <summary> /// Serializes the data into a json array expression. /// </summary> /// <param name="data">the data to serialize</param> /// <param name="currentPath">the current path to the data</param> /// <param name="serializer">serializer instance to use to serialize list items</param> /// <returns>a json array expression representation</returns> public override Expression GetExpression(object data, JsonPath currentPath, IExpressionBuilder serializer) { ITypeData handler = Settings.Types[data.GetType()]; CollectionHandler collectionHandler = handler.CollectionHandler; Type elemType = collectionHandler.GetItemType(handler.ForType); int index = 0; ArrayExpression expression = new ArrayExpression(); foreach (object value in collectionHandler.GetEnumerable(data)) { Expression itemExpr = serializer.Serialize(value, currentPath.Append(index)); if (value != null && !ReflectionUtils.AreEquivalentTypes(value.GetType(), elemType)) { itemExpr = new CastExpression(value.GetType(), itemExpr); } expression.Add(itemExpr); index++; } return(expression); }
public ListBoxHandler() { collection = new CollectionHandler { Handler = this }; Control = new EtoListBoxTableView { Handler = this }; var col = new NSTableColumn(); col.ResizingMask = NSTableColumnResizing.Autoresizing; col.Editable = false; cell = new MacImageListItemCell(); cell.Wraps = false; col.DataCell = cell; Control.AddColumn(col); Control.DataSource = new DataSource { Handler = this }; Control.HeaderView = null; Control.DoubleClick += HandleDoubleClick; Control.Delegate = new Delegate { Handler = this }; scroll = new EtoScrollView { Handler = this }; scroll.AutoresizesSubviews = true; scroll.DocumentView = Control; scroll.HasVerticalScroller = true; scroll.HasHorizontalScroller = true; scroll.AutohidesScrollers = true; scroll.BorderType = NSBorderType.BezelBorder; }
public DevicesViewModel() { Devices = new ObservableCollection <DeviceViewModel>(); lock (Context.Current.Locks["Devices"]) { foreach (var device in Context.Current.Devices) { if (device != null) { var devVM = new DeviceViewModel() { Title = device.Title, Status = Convert.ToInt32(device.Status) }; Devices.Add(devVM); } } CollectionHandler <DeviceViewModel> handler = new CollectionHandler <DeviceViewModel>(Devices, SelectedDevice); Context.Current.Devices.CollectionChanged += handler.Devices_CollectionChanged; } }
public ReadingsViewModel() { Readings = new ObservableCollection <ReadingViewModel>(); lock (Context.Current.Locks["Readings"]) { foreach (var reading in Context.Current.Readings) { if (reading != null) { var readVM = new ReadingViewModel() { Title = reading.Title, Value = reading.Value, Unit = reading.Unit }; Readings.Add(readVM); } } CollectionHandler <ReadingViewModel> handler = new CollectionHandler <ReadingViewModel>(Readings, null); Context.Current.Readings.CollectionChanged += handler.Readings_CollectionChanged; } }
/// <summary> /// Registers a collection handler which provides support for a certain type /// or multiple types of collections. /// </summary> /// <param name="handler">the collection handler</param> public void RegisterCollectionHandler(CollectionHandler handler) { _collectionHandlers.Insert(0, handler); }
public OutputController(ILogger <OutputController> logger, IOptions <AppSettings> settings, CollectionHandler preingestHandler) { _logger = logger; _settings = settings.Value; _preingestHandler = preingestHandler; }
public NewsPage() { InitializeComponent(); this.collectionHandler = new CollectionHandler(); dateBox.Text = DateToday(); }
void Start() { ch = GameObject.FindGameObjectWithTag("CollectionHandler").GetComponent <CollectionHandler>(); }