Exemple #1
0
        /// <summary>
        /// This method is called when the user presses the Go button.
        /// </summary>
        public async Task DeleteSelected()
        {
            if (!CanDeleteSelected)
            {
                return;
            }

            Business.DeleteMultiLineTextsReadOnly deleter = null;

            var description = "SelectSongsViewModel.DeleteSelected";

            IncrementApplicationBusyEventMessage.Publish(description);
            try
            {
                var ids = new MobileList <Guid>();
                foreach (var songViewModel in Items)
                {
                    if (songViewModel.IsChecked)
                    {
                        Guid id      = default(Guid);
                        var  results = from entry in _MultiLineTextIdsAndTitles
                                       where entry.Value == songViewModel.SongTitle
                                       select entry;
                        id = results.First().Key;
                        ids.Add(id);
                    }
                }

                var thinkId = new Guid(@"70CDC58A-40CD-46C6-A496-BCF23D77E8C2");
                try
                {
                    deleter = await Business.DeleteMultiLineTextsReadOnly.CreateNewAsync(ids);
                }
                finally
                {
                    History.Events.ThinkedAboutTargetEvent.Publish(thinkId);
                }
            }
            finally
            {
                DecrementApplicationBusyEventMessage.Publish(description);
            }

            History.Events.ThinkingAboutTargetEvent.Publish(System.Guid.Empty);
            if (!deleter.WasSuccessful)
            {
                MessageBox.Show(StudyResources.ErrorMsgSomeSongsWereNotDeletedSimple);
                Services.PublishMessageEvent(string.Format(StudyResources.ErrorMsgSomeSongsWereNotDeletedDetailed, deleter.UnsuccessfulIds),
                                             Common.MessagePriority.High,
                                             Common.MessageType.Error);
            }
            else
            {
                MessageBox.Show(StudyResources.MsgSongsSuccessfullyDeleted);
            }
        }//left off here: front end done. need to create stored procedure and import it into the edmx. then fill it in in the dal.
        public async Task Login()
        {
            if (!CanLogin)
            {
                return;
            }

            LoggingIn = true;
#if DEBUG
            //var allEdits = await Business.PhraseList.GetAllAsync();
#endif

            IncrementApplicationBusyEventMessage.Publish("LoginViewModel.Login");
            try
            {
                var result = await UserPrincipal.LoginAsync(Username, Password);

                AuthenticationChangedEventMessage.Publish();
            }
            finally
            {
                DecrementApplicationBusyEventMessage.Publish("LoginViewModel.Login");
            }

            if (Csla.ApplicationContext.User.Identity.IsAuthenticated)
            {
                //LOGIN SUCCESSFUL
                LoggingIn = false;
            }
            else
            {
                //LOGIN UNSUCCESSFUL
                //PENALIZE FOR NOT LOGGING IN PROPERLY.
                //QUICK AND DIRTY PENALTY.
                //HACK: LOGIN FAILED PENALTY EASILY CIRCUMVENTED.  THIS REALLY NEEDS TO BE DONE ON THE SERVER SIDE.
                System.Windows.MessageBox.Show(AppResources.LoginFailedMessage);
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (sender, eventArg) =>
                {
                    System.Threading.Thread.Sleep(int.Parse(AppResources.LoginFailedPenaltyInMilliseconds));
                    LoggingIn = false;
                };
                worker.RunWorkerAsync();
            }
        }
        /// <summary>
        /// Logs in when the user presses enter. Should refactor. But need
        /// to change the view as well.
        /// </summary>
        public async void ExecuteAction(ActionExecutionContext context)
        {
            var eventArgs = (KeyEventArgs)context.EventArgs;

            if (eventArgs.Key != Key.Enter)
            {
                return;
            }

            IncrementApplicationBusyEventMessage.Publish("LoginViewModel.ExecuteAction");
            try
            {
                await Login();
            }
            finally
            {
                DecrementApplicationBusyEventMessage.Publish("LoginViewModel.ExecuteAction");
            }
        }
Exemple #4
0
        public override async Task SaveAsync()
        {
            IsSaving = true;
            IncrementApplicationBusyEventMessage.Publish("AddSongMultiLineTextEditViewModel.SaveAsync");
            //DisableNavigationRequestedEventMessage.Publish();
            var thinkId = Guid.NewGuid();

            History.Events.ThinkingAboutTargetEvent.Publish(thinkId);
            try
            {
                //TODO: PUT ALL SAVE SONG STUFF INTO ONE SAVER COMMAND OBJECT.  THIS OBJECT SHOULD TAKE THE ENTERED SONG INFO, PARSE THE SONG, AND SAVE ALL SUBPHRASES AS WE DO HERE.  THIS SHOULD *NOT* GO INTO THE SONGEDIT MODEL SAVE, AS THE SONG MODEL SHOULD NOT PARSE EVERY TIME IT IS SAVED.

                ///when we save the song lyrics, we want to...
                ///  1) Parse each text line into a subphrase, parse each subphrase into a word-subphrase
                ///     if subphrase is unique and not already in the database, save that subphrase
                ///  2) Create LineEdits from text lines and add these to the song model.
                ///  3) Save the song model itself.
                ///e.g.
                ///  this is line one
                ///  this is line two
                ///  this is line three
                ///  subphrases: "this is line one" "this is line two" "this is line three"
                ///  word-subphrases: "this" "is" "line" "one" "two" "three"

                #region PARSE THE SONGTEXT INTO LINES AND ADD TO MODEL.LINES
                {
                    var songText     = SongText;
                    var languageText = SongLanguage.Text;
                    var lines        = songText.ParseIntoLines(); //removes empty entries
                    var words        = songText.ParseIntoWords();
                    var wordCount    = words.Count;
                    var escapeHelper = 0;
                    while (words.Contains(""))
                    {
                        History.Events.ThinkedAboutTargetEvent.Publish();

                        //ESCAPE HELPER TO ESCAPE IN CASE OF INFINITE LOOP WITH WHILE STATEMENT.
                        //I WANT THE WHILE LOOP TO USE THE QUICKNESS OF CONTAINS(),
                        //AS OPPOSED TO FOREACH-ING OR FOR-ING.  BUT I HATE POSSIBILITY OF
                        //ENDLESS LOOP, EVEN THOUGH I DON'T SEE HOW IT COULD HAPPEN.
                        words.Remove("");
                        escapeHelper++;
                        if (escapeHelper > wordCount)
                        {
                            break;
                        }
                    }

                    //I'M CHANGING THIS TO UTILIZE MY LINELIST.NEWLINELIST(INFOS) ALREADY IN
                    //PLACE.
                    //SO AT THIS TIME, WE ONLY NEED TO SAVE THE WORDS THEMSELVES.  THE LINES
                    //WILL BE SAVED IN FUTURE STEP IN THIS BLOCK.
                    var allWords = new List <string>(words);

                    #region REMOVE ALL WORDS THAT ALREADY EXIST IN DB, SO THAT WE ARE LEFT WITH ONLY NEW WORDS

                    //WE DON'T WANT TO ADD DUPLICATE WORDS TO THE DB, SO CHECK TO SEE IF ANY
                    //OF THESE WORDS ALREADY EXIST IN DB.
                    var removeCmd = await RemoveAlreadyExistingPhraseTextsCommand.ExecuteAsync(languageText, allWords);

                    var allWordsNotAlreadyInDatabase = removeCmd.PrunedPhraseTexts;

                    #region CREATE PHRASE FOR EACH NEW WORD

                    var criteria = new Business.Criteria.PhraseTextsCriteria(languageText,
                                                                             allWordsNotAlreadyInDatabase);
                    History.Events.ThinkedAboutTargetEvent.Publish();
                    var phraseListContainingAllWordsNotAlreadyInDatabase =
                        await PhraseList.NewPhraseListAsync(criteria);

                    History.Events.ThinkedAboutTargetEvent.Publish();

                    #region SAVE ALL WORDS THAT ARE NEW (NOT ALREADY IN DATABASE)

                    //phraseListContainingAllWordsNotAlreadyInDatabase =
                    //  await phraseListContainingAllWordsNotAlreadyInDatabase.SaveAsync();
                    //SO NOW, ALL OF OUR SONG'S WORDS THAT WERE NOT ALREADY IN THE DATABASE
                    //ARE INDEED NOW STORED IN THE DATABASE.

                    #region CREATE LINEEDIT OBJECTS FOR EACH TEXT LINE AND ADD TO MODEL

                    var lineInfoDictionary = new Dictionary <int, string>();
                    for (int i = 0; i < lines.Count; i++)
                    {
                        History.Events.ThinkedAboutTargetEvent.Publish();
                        lineInfoDictionary.Add(i, lines[i]);
                    }

                    //WE NOW HAVE INFO DICTIONARY WHICH HAS LINE NUMBER AND CORRESPONDING LINE TEXT
                    //CREATE A NEW LINELIST WITH THIS CRITERIA WILL CREATE PHRASES WITH EACH LINE TEXT,
                    //AND LINEEDITS OBJECT FOR EACH LINE NUMBER + PHRASE.
                    var criteria2 = new Business.Criteria.LineInfosCriteria(languageText, lineInfoDictionary);
                    Model.Lines = await LineList.NewLineListAsync(criteria2);

                    //WE NOW HAVE A LIST OF LINEEDITS, EACH WITH A PHRASE WITH A SINGLE LINE OF TEXT AND LINE NUMBER.
                    //SET OUR MODEL.LINES TO THIS LINELIST
                    History.Events.ThinkedAboutTargetEvent.Publish();

                    #region SET SONG TITLE (IF NECESSARY)
                    //IF THE SONGTITLE IS EMPTY, THEN USE THE FIRST LINE OF THE SONG AS THE SONG TITLE
                    if (string.IsNullOrEmpty(Model.Title))
                    {
                        Model.Title = ViewViewModelResources.AutoTitlePrefix + Model.Lines.GetLine(0).Phrase.Text;
                    }
                    #endregion
                    History.Events.ThinkedAboutTargetEvent.Publish();

                    #region ADD METADATA TYPEISSONG

                    Model.AddMetadata(BusinessResources.MetadataKeyType,
                                      BusinessResources.MetadataValueTypeSong);

                    #endregion

                    #region SAVE THE ACTUAL SONG MODEL

                    //NOW WE CAN USE THE BASE SAVE
                    History.Events.ThinkedAboutTargetEvent.Publish();
                    await base.SaveAsync();

                    SongHasBeenSaved = true;
                    IsSaving         = false;
                    History.Events.ThinkedAboutTargetEvent.Publish();

                    #endregion

                    #endregion

                    #endregion

                    #endregion

                    #endregion
                }
                #endregion
            }
            finally
            {
                History.Events.ThinkedAboutTargetEvent.Publish(thinkId);
                //EnableNavigationRequestedEventMessage.Publish();
                DecrementApplicationBusyEventMessage.Publish("AddSongMultiLineTextEditViewModel.SaveAsync");
            }
        }