示例#1
0
        public void DataPortal_Create(Criteria.LineInfosCriteria lineInfosCriteria)
        {
            if (lineInfosCriteria.LineInfos.Count == 0)
            {
                throw new ArgumentException("lineInfosCriteria");
            }
            using (var dalManager = DalFactory.GetDalManager())
            {
                var languageText = lineInfosCriteria.LanguageText;
                var language     = DataPortal.FetchChild <LanguageEdit>(languageText);
                //var languageDal = dalManager.GetProvider<ILanguageDal>();
                //var languageResult = languageDal.Fetch(languageText);
                //LanguageEdit language = null;
                //if (!languageResult.IsSuccess)
                //{
                //  var exception = languageResult.GetExceptionFromInfo();
                //  if (exception == null)
                //    throw new LanguageTextNotFoundException(languageText);
                //  else if (exception.Message.Contains(LanguageTextNotFoundException.GetDefaultErrorMessage(languageText)))
                //  {
                //    //IF THE LANGUAGE TEXT DOES NOT EXIST, CREATE IT
                //    //CAN'T CHECK FOR DATA EXCEPTION TYPE BECAUSE IT WILL BE A GENERAL CSLA DATAPORTAL EXCEPTION
                //    language = LanguageEdit.NewLanguageEdit();
                //    language.Text = languageText;
                //    //language = language.Save();
                //  }
                //  else
                //    throw new CreateFailedException(DataAccess.DalResources.ErrorMsgLanguageTextProblemWhileCreatingLineInfos);
                //}

                //var languageDto = languageResult.Obj;
                //language = LanguageEdit.NewLanguageEdit(languageDto);
                //language.LoadFromDtoBypassPropertyChecks(languageDto);

                //WE NOW HAVE OUR LANGUAGEEDIT THAT WILL BE USED FOR ALL PHRASE TEXTS.
                var LineDal = dalManager.GetProvider <ILineDal>();

                //LineList newLineList = LineList.NewLineList();
                foreach (var lineInfo in lineInfosCriteria.LineInfos)
                {
                    //FOREACH LINEINFO, CREATE A PHRASE, THEN CREATE A LINE CONTAINING THAT PHRASE WITH GIVEN LINE NUMBER
                    var lineNumber = lineInfo.Key;
                    var lineText   = lineInfo.Value;
                    if (string.IsNullOrEmpty(lineText) || lineNumber < 0)
                    {
                        continue;
                    }

                    PhraseEdit phraseEdit = DataPortal.CreateChild <PhraseEdit>();
                    phraseEdit.Language = language;
                    phraseEdit.Text     = lineText;

                    LineEdit lineEdit = DataPortal.CreateChild <LineEdit>();
                    lineEdit.Phrase     = phraseEdit;
                    lineEdit.LineNumber = lineNumber;

                    Add(lineEdit);
                }
            }
        }
        private void Phrases_AddedNew(object sender, Csla.Core.AddedNewEventArgs <PhraseEdit> e)
        {
            var phrase    = e.NewObject;
            var phraseDto = _PhraseAdding.CreateDto();

            _PhraseAdding = null;
            phrase.LoadFromDtoBypassPropertyChecks(phraseDto);
        }
 public void AddPhrase(PhraseEdit phrase)
 {
     //PhraseIds.Add(phrase.Id);
     if (_PhraseAdding != null)
     {
         throw new Exception();
     }
     _PhraseAdding     = phrase;
     Phrases.AddedNew += Phrases_AddedNew;
     Phrases.AddNew();
     Phrases.AddedNew -= Phrases_AddedNew;
     BusinessRules.CheckRules();
 }
示例#4
0
        public void DataPortal_Create()
        {
            RetrieverId = Guid.NewGuid();

            Phrase = PhraseEdit.NewPhraseEdit();

            Phrase.LanguageId = LanguageEdit.GetDefaultLanguageId();
            Phrase.Language   = DataPortal.FetchChild <LanguageEdit>(Phrase.LanguageId);
            //LanguageEdit.GetLanguageEdit(Phrase.LanguageId);

            //var phraseB = Translation.Phrases.AddNew();
            //phraseB.LanguageId = LanguageEdit.GetDefaultLanguageId();
            //phraseB.Language = LanguageEdit.GetLanguageEdit(phraseB.LanguageId);
        }
示例#5
0
        public void DataPortal_Create(PhraseEdit criteria)
        {
            //INITIALIZE
            RetrieverId           = Guid.NewGuid();
            RetrievedPhrases      = null;
            RetrievedSinglePhrase = null;

            //GET ALL PHRASES (FOR THIS USER ONLY)
            PhraseList allPhrases = PhraseList.GetAll();

            var retrievedPhrase = FindPhraseInPhraseList(criteria.Text, criteria.Language.Text, allPhrases);

            //if we directly add this retrievedPhrase, then it will be a child
            //we need to get the non-child version of this
            //RetrievedPhrases.Add(criteriaPhrase.Id, retrievedPhrase);
            if (retrievedPhrase != null && retrievedPhrase.IsChild)
            {
                var nonChildVersion = PhraseEdit.GetPhraseEdit(retrievedPhrase.Id);
                RetrievedSinglePhrase = nonChildVersion;
            }
        }
示例#6
0
        public void DataPortal_Create(Criteria.FindPhraseInPhraseListCriteria criteria)
        {
            //INITIALIZE
            RetrieverId           = Guid.NewGuid();
            RetrievedPhrases      = null;
            RetrievedSinglePhrase = null;

            var retrievedPhrase = FindPhraseInPhraseList(criteria.PhraseText,
                                                         criteria.LanguageText,
                                                         criteria.Phrases);

            //if we directly add this retrievedPhrase, then it will be a child
            //we need to get the non-child version of this
            //RetrievedPhrases.Add(criteriaPhrase.Id, retrievedPhrase);
            if (criteria.GetPhraseFromDB && retrievedPhrase != null && retrievedPhrase.IsChild)
            {
                var nonChildVersion = PhraseEdit.GetPhraseEdit(retrievedPhrase.Id);
                RetrievedSinglePhrase = nonChildVersion;
            }
            else
            {
                RetrievedSinglePhrase = retrievedPhrase;
            }
        }
示例#7
0
        /// <summary>
        /// Retrieves a single PhraseEdit from the DB that match the PhraseEdit given in
        /// the criteria.  It stores this retrieved phrases in a dictionary, with the
        /// given phrase.Id in the criteria as the keys and the retrieved phrases as the
        /// values.
        ///
        /// For any phrase in criteria given that is not found in DB, the retrieved phrase
        /// will be null.
        ///
        /// THIS IS NOT OPTIMIZED, AND IT DOES MOST OF THE WORK ON THE SERVER SIDE.  I MIGHT
        /// SHOULD TURN THIS INTO A COMMAND OBJECT
        /// AND HAVE THIS DONE ON THE CLIENT SIDE, ESPECIALLY SINCE CURRENTLY IT IS JUST
        /// USING PHRASELIST.GETALL() AND THEN
        /// WORKING OFF OF THAT ANYWAY.
        /// </summary>
        /// <param name="criteria">single phrase that you want to retrieve</param>
        public static async Task <PhrasesByTextAndLanguageRetriever> CreateNewAsync(PhraseEdit criteria)
        {
            var result = await DataPortal.CreateAsync <PhrasesByTextAndLanguageRetriever>(criteria);

            return(result);
        }
示例#8
0
        public void DataPortal_Create(Criteria.ListOfPhrasesCriteria criteria)
        {
            //WE ARE GOING TO GET ALL THE PHRASES
            //WE WILL THEN ITERATE THROUGH OUR CRITERIA PHRASES, POPULATING OUR
            //RETRIEVED PHRASES

            //INITIALIZE
            RetrieverId = Guid.NewGuid();
            if (RetrievedPhrases == null)
            {
                RetrievedPhrases = new MobileDictionary <Guid, PhraseEdit>();
            }

            ////GET ALL PHRASES (FOR THIS USER ONLY)
            //PhraseList allPhrases = PhraseList.GetAll();

            //KEY = TEXT, VALUE = PHRASELIST CONTAINING ALL PHRASES THAT CONTAIN THE KEY TEXT
            var phraseLists = new Dictionary <string, PhraseList>();

            for (int i = 0; i < criteria.Phrases.Count; i++)
            {
                var criteriaPhrase = criteria.Phrases[i];

                //IF WE'VE ALREADY DONE THIS PHRASE, THEN GO ON TO THE NEXT ONE, SO WE DON'T DUPLICATE WORK
                if (RetrievedPhrases.ContainsKey(criteriaPhrase.Id))
                {
                    continue;
                }

                //INITIALIZE RETRIEVED PHRASE
                PhraseEdit retrievedPhrase = null;

                //GET ALL PHRASES THAT CONTAIN THIS PHRASE, IN ANY LANGUAGE
                var allPhrasesContainingPhrase = PhraseList.GetAllContainingText(criteriaPhrase.Text);

                //IF WE FOUND A PHRASE/MULTIPLE PHRASES, THEN WE WANT THE ONE THAT MATCHES OUR
                //CRITERIA PHRASE IN TEXT AND LANGUAGE
                if (allPhrasesContainingPhrase.Count > 0)
                {
                    retrievedPhrase = (from phrase in allPhrasesContainingPhrase
                                       where phrase.Text == criteriaPhrase.Text &&
                                       phrase.Language.Text == criteriaPhrase.Language.Text
                                       select phrase).FirstOrDefault();
                }

                if (retrievedPhrase != null && retrievedPhrase.IsChild)
                {
                    //WE ONLY WANT NON-CHILD VERSIONS OF PHRASE
                    var nonChildVersion = PhraseEdit.GetPhraseEdit(retrievedPhrase.Id);
                    RetrievedPhrases.Add(criteriaPhrase.Id, nonChildVersion);
                }
                else if (retrievedPhrase != null && !retrievedPhrase.IsChild)
                {
                    //PHRASE IS ALREADY NOT A CHILD, SO ADD IT
                    RetrievedPhrases.Add(criteriaPhrase.Id, retrievedPhrase);
                }
                else
                {
                    //NO RETRIEVED PHRASE, SO ADD NULL FOR THIS CRITERIAPHRASE.ID
                    RetrievedPhrases.Add(criteriaPhrase.Id, null);
                }
            }
        }
示例#9
0
 /// <summary>
 /// Retrieves a single PhraseEdit from the DB that match the PhraseEdit given in the criteria.
 /// It stores this retrieved phrases in a dictionary, with the given phrase.Id in the criteria
 /// as the keys and the retrieved phrases as the values.
 ///
 /// For any phrase in criteria given that is not found in DB, the retrieved phrase will be null.
 ///
 /// THIS IS NOT OPTIMIZED, AND IT DOES MOST OF THE WORK ON THE SERVER SIDE.  I MIGHT SHOULD TURN THIS INTO A COMMAND OBJECT
 /// AND HAVE THIS DONE ON THE CLIENT SIDE, ESPECIALLY SINCE CURRENTLY IT IS JUST USING PHRASELIST.GETALL() AND THEN
 /// WORKING OFF OF THAT ANYWAY.
 /// </summary>
 /// <param name="criteria">single phrase that you want to retrieve</param>
 /// <param name="callback">callback executed once retrieval is complete</param>
 public static PhrasesByTextAndLanguageRetriever CreateNew(PhraseEdit criteria)
 {
     return(DataPortal.Create <PhrasesByTextAndLanguageRetriever>(criteria));
 }
        /// <summary>
        /// Gets all of the translations that contain the given phrase, using that phrase's id.  This in
        /// contrast to searching through all translations' texts and matching up the phrase.text or regex, etc.
        /// THIS DOES NOT THROW AN EXCEPTION IF THE PHRASE IS NOT FOUND.
        /// </summary>
        public static TranslationList GetAllTranslationsContainingPhraseById(PhraseEdit phrase)
        {
            var criteria = new Criteria.PhraseCriteria(phrase);

            return(DataPortal.Fetch <TranslationList>(criteria));
        }
        /// <summary>
        /// Gets all of the translations that contain the given phrase, using that phrase's id.  This in
        /// contrast to searching through all translations' texts and matching up the phrase.text or regex, etc.
        /// THIS DOES NOT THROW AN EXCEPTION IF THE PHRASE IS NOT FOUND.
        /// </summary>
        public static async Task <TranslationList> GetAllTranslationsContainingPhraseByIdAsync(PhraseEdit phrase)
        {
            var criteria = new Criteria.PhraseCriteria(phrase);
            var result   = await DataPortal.FetchAsync <TranslationList>(criteria);

            return(result);
        }