Esempio n. 1
0
 void OnEnable()
 {
     if (!AllTags.Contains(this))
     {
         AllTags.Add(this);
     }
 }
Esempio n. 2
0
        private void AddNewTag()
        {
            if (TagSearchDataContext.FullSearchText.Length > 20)
            {
                MessageBox.Show("Tag name cannot be longer than 20 characters (including space).", "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error, MessageBoxResult.OK);
                return;
            }

            // Check if this tag has been deleted before, then prompt the user to see if we should restore or replace it.
            var newTag = DeletedTags.SingleOrDefault(t => t.Name == TagSearchDataContext.FullSearchText);

            if (newTag == null)
            {
                newTag = Context.Tags.SingleOrDefault(t => t.DateDeleted != null && t.Name == TagSearchDataContext.FullSearchText);
            }

            if (newTag != null)
            {
                var result =
                    MessageBox.Show($"The tag [{newTag.Name}] was previously deleted. You can either restore this tag and all Omni associations, " +
                                    "or replace the deleted tag with a brand new one.\n\nWhen this tag is undeleted, do you want to restore " +
                                    "Omni associations?", "Confirm Restore", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes);
                if (result == MessageBoxResult.Cancel)
                {
                    return;
                }
                else if (result == MessageBoxResult.No)
                {
                    newTag.Omnis.Clear();
                    Context.Tags.Remove(newTag);
                    newTag = null;
                }
                DeletedTags.Remove(newTag);
            }

            if (newTag == null)
            {
                newTag = new Tag
                {
                    Name = TagSearchDataContext.FullSearchText,
                };
                AddedTags.Add(newTag);
            }

            newTag.DateDeleted      = null;
            newTag.LastModifiedDate = DateTime.Now;
            newTag.IsVerified       = true;
            newTag.ManuallyVerified = true;

            AllTags.Add(newTag);
            TagSearchDataContext.FullSearchText = String.Empty;
            SelectedTag = newTag;
            ChangesMade = true;
        }
Esempio n. 3
0
    /// <summary>
    /// Add new tag.
    /// </summary>
    public async void AddTagAsync()
    {
        TagEditViewModel viewModel = await DialogService.ShowCustomLocalizedMessageAsync <TagEditView, TagEditViewModel>("NewTag");

        if (viewModel.DialogResultOk)
        {
            viewModel.Tag.ID = await tagService.CreateAsync(viewModel.Tag);

            AllTags.Add(viewModel.Tag);
        }
    }
Esempio n. 4
0
 public SettlementTemplatePresenter([NotNull] ApplicationPresenter applicationPresenter, [NotNull] SettlementTemplateView view,
                                    [NotNull] SettlementTemplate template) : base(view, "ThisTemplate.HeaderString", template, applicationPresenter)
 {
     _hhdIntensity = new EnergyIntensityConverter.EnergyIntensityForDisplay(EnergyIntensityType.EnergyIntensive, "Energy Intensive");
     _template     = template;
     RefreshGeneratedSettlements();
     RefreshGeneratedHouses();
     foreach (var tag in Sim.HouseholdTags.It)
     {
         var te = new TagEntry(tag, false);
         AllTags.Add(te);
     }
     RefreshTraits();
 }
Esempio n. 5
0
 private void AddTag()
 {
     if (String.IsNullOrWhiteSpace(NewTag))
     {
         return;
     }
     if (!AllTags.Any(t => t.Name == NewTag))
     {
         AllTags.Add(new Tag()
         {
             Name = NewTag
         });
     }
     Tags.Add(AllTags.First(t => t.Name == NewTag));
     NewTag = String.Empty;
 }
Esempio n. 6
0
        private void RemoveFromCurrent()
        {
            //Need to reassign as Remove will set SelectedCurrent to null

            var tmp = SelectedCurrent;

            if (tmp == null)
            {
                return;
            }

            bool removed = CurrentList.Remove(tmp);

            if (removed && tmp.ID > 0)
            {
                AllTags.Add(tmp);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Returns a full list of the user's tags along with the number of times they were used.
        /// </summary>
        /// <returns>List of tags and their counts</returns>
        public Task <AllTags> Get()
        {
            var url = TagsURL.AppendPathSegment("get");

            return(MakeRequestAsync <AllTags>(url, (content) =>
            {
                var allTagCounts = JsonConvert.DeserializeObject <IDictionary <string, int> >(content);

                var allTags = new AllTags();
                foreach (KeyValuePair <string, int> kv in allTagCounts)
                {
                    allTags.Add(new TagCount
                    {
                        Tag = kv.Key,
                        Count = kv.Value
                    });
                }

                return allTags;
            }));
        }
Esempio n. 8
0
        public EditInstrumentViewModel(Instrument model, IDataClient client, IClosableView view, IDialogCoordinator dialogCoordinator) : base(model, new InstrumentValidator())
        {
            _view             = view;
            DialogCoordinator = dialogCoordinator;
            if (model.Sessions == null)
            {
                model.Sessions = new List <InstrumentSession>();
            }
            if (model.Tags == null)
            {
                model.Tags = new List <Tag>();
            }

            foreach (var session in model.Sessions)
            {
                Sessions.Add(new SessionViewModel(session));
            }

            ContractMonths = new ObservableCollection <KeyValuePair <int, string> >();
            //fill the continuous futures contrat month combobox
            for (int i = 1; i < 10; i++)
            {
                ContractMonths.Add(new KeyValuePair <int, string>(i, MyUtils.Ordinal(i) + " Contract"));
            }

            Load = ReactiveCommand.CreateFromTask(async _ =>
            {
                var tags              = client.GetTags();
                var sessionTemplates  = client.GetSessionTemplates();
                var exchanges         = client.GetExchanges();
                var underlyingSymbols = client.GetUnderlyingSymbols();
                var datasources       = client.GetDatasources();

                await Task.WhenAll(tags, sessionTemplates, exchanges, underlyingSymbols, datasources).ConfigureAwait(true);

                var responses = new ApiResponse[] { tags.Result, sessionTemplates.Result, exchanges.Result, underlyingSymbols.Result, datasources.Result };
                if (await responses.DisplayErrors(this, DialogCoordinator).ConfigureAwait(true))
                {
                    return;
                }

                foreach (var tag in tags.Result.Result.Select(x => new CheckBoxTag(x, model.Tags.Contains(x))))
                {
                    AllTags.Add(tag);
                    tag.PropertyChanged += Tag_PropertyChanged;
                }

                Exchanges.AddRange(exchanges.Result.Result);

                foreach (var template in sessionTemplates.Result.Result)
                {
                    SessionTemplates.Add(template);
                }
                foreach (var us in underlyingSymbols.Result.Result)
                {
                    UnderlyingSymbols.Add(us);
                }
                foreach (var ds in datasources.Result.Result)
                {
                    Datasources.Add(ds);
                }
            });

            //Sessions
            AddNewSession = ReactiveCommand.Create(() => AddSession());
            RemoveSession = ReactiveCommand.Create <SessionViewModel>(ExecRemoveSession);

            //Save
            var saveCanExecute = this
                                 .WhenAnyValue(x => x.HasErrors)
                                 .Select(x => !x);

            Save = ReactiveCommand.CreateFromTask(async _ =>
            {
                if (model.ID == null || model.ID <= 0)
                {
                    //adding a new instrument
                    return(await client.AddInstrument(model).ConfigureAwait(true));
                }
                else
                {
                    //updating an existing one
                    return(await client.UpdateInstrument(model).ConfigureAwait(true));
                }
            }
                                                  , saveCanExecute);
            Save.Subscribe(async result =>
            {
                var errors = await result.DisplayErrors(this, DialogCoordinator).ConfigureAwait(true);
                if (!errors)
                {
                    AddedInstrument = result.Result;
                    _view.Close();
                }
            });

            this.Validate();
        }
Esempio n. 9
0
 private void OnTagAdded(TagAddedMessage msg)
 {
     AllTags.Add(new TodoTagViewModel(msg.Tag));
 }