From 990aa856f2197a97a9e306e8f30cfb8792f4036c Mon Sep 17 00:00:00 2001 From: Khaja Nizamuddin Date: Wed, 10 May 2017 20:53:01 +0530 Subject: [PATCH 1/2] Fixed duplicate content addition --- .../Controls/ChatContentCollectionControl.cs | 79 +++++++------------ .../Controls/ChatNodeCollectionEditor.cs | 22 +++--- 2 files changed, 37 insertions(+), 64 deletions(-) diff --git a/ANAConversationStudio/Controls/ChatContentCollectionControl.cs b/ANAConversationStudio/Controls/ChatContentCollectionControl.cs index d31c77a..db3e257 100644 --- a/ANAConversationStudio/Controls/ChatContentCollectionControl.cs +++ b/ANAConversationStudio/Controls/ChatContentCollectionControl.cs @@ -25,13 +25,11 @@ public ChatNode ParentChatNode else control.Visibility = Visibility.Visible; })); - public object ChatContentOwner { get { return (object)GetValue(ChatContentOwnerProperty); } set { SetValue(ChatContentOwnerProperty, value); } } - public static readonly DependencyProperty ChatContentOwnerProperty = DependencyProperty.Register(nameof(ChatContentOwner), typeof(object), typeof(ChatContentCollectionControl), new PropertyMetadata((s, e) => { var control = s as ChatContentCollectionControl; @@ -61,59 +59,40 @@ public object ChatContentOwner else control.Visibility = Visibility.Collapsed; })); - public ChatContentCollectionControl() { ItemAdding += ItemAddingEventHandler; - //ItemAdded += ItemAddedEventHandler; - //ItemDeleted += ItemDeletedEventHandler; - Items.CollectionChanged += Items_CollectionChanged; + ItemAdded += ItemAddedEventHandler; + ItemDeleted += ItemDeletedEventHandler; } - - private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + public void ContentItemAddExternal(BaseContent item) { - switch (e.Action) - { - case System.Collections.Specialized.NotifyCollectionChangedAction.Add: - if (e.NewItems?.Count > 0) - { - var contentItem = e.NewItems.Cast().First(); - MongoHelper.Current.Contents.Add(contentItem as BaseContent); - } - break; - case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: - if (e.OldItems?.Count > 0) - { - var c = e.OldItems.Cast().First() as BaseContent; - var content = MongoHelper.Current.Contents.FirstOrDefault(x => x._id == c._id); - if (content != null) - MongoHelper.Current.Contents.Remove(content); - } - break; - default: - break; - } + if (item == null) return; + PreProccessAddingItem(item); + Items.Add(item); + ContentItemAdded(item); + } + public void ContentItemDeleted(BaseContent item) + { + if (item == null) return; + var content = MongoHelper.Current.Contents.FirstOrDefault(x => x._id == item._id); + if (content != null) + MongoHelper.Current.Contents.Remove(content); } - //private void ItemDeletedEventHandler(object sender, ItemEventArgs e) - //{ - // var c = e.Item as BaseContent; - // var content = MongoHelper.Current.Contents.FirstOrDefault(x => x._id == c._id); - // if (content != null) - // MongoHelper.Current.Contents.Remove(content); - //} - - //private void ItemAddedEventHandler(object sender, ItemEventArgs e) - //{ - // MongoHelper.Current.Contents.Add(e.Item as BaseContent); - //} - + private void ItemDeletedEventHandler(object sender, ItemEventArgs e) + { + ContentItemDeleted(e.Item as BaseContent); + } + private void ItemAddedEventHandler(object sender, ItemEventArgs e) + { + ContentItemAdded(e.Item as BaseContent); + } private void ItemAddingEventHandler(object sender, ItemAddingEventArgs e) { PreProccessAddingItem(e.Item); } - - public void PreProccessAddingItem(object item) + private void PreProccessAddingItem(object item) { if (item is BaseIdEntity) (item as BaseIdEntity)._id = ObjectId.GenerateNewId().ToString(); @@ -132,17 +111,15 @@ public void PreProccessAddingItem(object item) if ((item is SectionContent || item is ButtonContent) && ChatContentOwner != null) { if (ChatContentOwner is Section && item is SectionContent) - { (item as SectionContent).SectionId = (ChatContentOwner as Section)._id; - //if (item is TextSectionContent tsItem) - // tsItem.SectionText = (ChatContentOwner as Section).Alias; - } else if (ChatContentOwner is Button && item is ButtonContent) - { (item as ButtonContent).ButtonId = (ChatContentOwner as Button)._id; - //(item as ButtonContent).ButtonText = (ChatContentOwner as Button).Alias; - } } } + private void ContentItemAdded(BaseContent item) + { + if (item == null) return; + MongoHelper.Current.Contents.Add(item as BaseContent); + } } } diff --git a/ANAConversationStudio/Controls/ChatNodeCollectionEditor.cs b/ANAConversationStudio/Controls/ChatNodeCollectionEditor.cs index d4a427c..1a8f8db 100644 --- a/ANAConversationStudio/Controls/ChatNodeCollectionEditor.cs +++ b/ANAConversationStudio/Controls/ChatNodeCollectionEditor.cs @@ -46,7 +46,7 @@ protected override void ResolveValueBinding(PropertyItem propertyItem) _collectionControl.Loaded += _collectionControl_Loaded; _collectionControl.ItemAdding += ItemAdding; - _collectionControl.ItemAdded += ItemAdded; + _collectionControl.ItemAdded += ItemAddedAsync; _collectionControl.ItemDeleted += ItemCollectionChanged; _collectionControl.ItemMovedDown += ItemCollectionChanged; _collectionControl.ItemMovedUp += ItemCollectionChanged; @@ -62,22 +62,18 @@ protected override void ResolveValueBinding(PropertyItem propertyItem) base.ResolveValueBinding(_propertyItem); } - private void ItemAdded(object sender, ItemEventArgs e) + private async void ItemAddedAsync(object sender, ItemEventArgs e) { InvalidateSource(); - Task.Delay(1000).ContinueWith(async (s) => + await Application.Current.Dispatcher.InvokeAsync(() => { - await App.Current.Dispatcher.InvokeAsync(() => + var editor = MainWindow.Current.ChatContentCollectionEditor; + if (editor != null && editor.NewItemTypes?.Count > 0 && editor.Items.Count == 0) { - var editor = MainWindow.Current.ChatContentCollectionEditor; - if (editor != null && editor.NewItemTypes?.Count > 0 && editor.Items.Count == 0) - { - var newItem = Activator.CreateInstance(editor.NewItemTypes.First()); - editor.PreProccessAddingItem(newItem); - editor.Items.Add(newItem); - editor.SelectedItem = newItem; - } - }); + var newItem = Activator.CreateInstance(editor.NewItemTypes.First()); + editor.ContentItemAddExternal(newItem as BaseContent); + editor.SelectedItem = newItem; + } }); } From 11e0d94e05308fc35c8aaff5b23395bee9fa750a Mon Sep 17 00:00:00 2001 From: vozille Date: Sat, 23 Sep 2017 22:55:00 +0530 Subject: [PATCH 2/2] update readme --- README.MD | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/README.MD b/README.MD index 7d045a2..3044f8b 100644 --- a/README.MD +++ b/README.MD @@ -36,13 +36,24 @@ Web & Messenger SDK **Setup Platform:** -1. Download the pre-built binary from [releases](https://github.com/Kitsune-tools/ProjectANA/releases/latest) or Clone the repo. -2. In ANA Conversation Platform project, open appsettings-Sample.json and edit DatabaseConnectionSettings section to match your MongoDB details. +1. Download the pre-built binary from [releases](https://github.com/Kitsune-tools/ProjectANA/releases/latest) or Clone the repo.
You can also build from the docker image hosted on dockerhub. Click [here](https://hub.docker.com/r/projectana/platform/) to go to the dockerhub link. + +2. You need to set up your mongodb instance first. You can either do that on your local machine or a server such as [MLab](https://mlab.com) .
Click [here](https://docs.mongodb.com/manual/tutorial/getting-started/) to know more about mongoDB such as installation and setting up a database.
+ + +3. In ANA Conversation Platform project, open `appsettings-Sample.json` and edit `DatabaseConnectionSettings` section to match your MongoDB details you had configured earlier. + 3. Change Collection names to new/empty collections. -4. Save and Rename appsettings-Sample.json to appsettings.json -5. Build and publish the project to the server as usual. It's a .NET Core project, which can be hosted on Windows, Linux and Mac. -6. Note down the base URL of your hosted project. -7. Optionally, Set the APIKey and APISecret in appsettings.json under BasicAuth section for security. +5. Save and Rename appsettings-Sample.json to appsettings.json. + +6. To build the project, you need to have dotnet core version 2 installed in your system. Click [here](https://www.microsoft.com/net/download/core) to get the latest version. Note : Dotnet core is cross platform and will work on windows, linux and mac. + +7. If you cloned the repository, follow the usual steps to restore, build and run a dotnet core project. + +8. If you downloaded the pre built binaries, go inside the platform folder and find the `ANAConversationPlatform.dll` file.
Run `dotnet ANAConversationPlatform.dll` to execute. + +9. Note down the base URL of your hosted project. +10. Optionally, Set the APIKey and APISecret in appsettings.json under BasicAuth section for security. **Setup Studio:**