Ejemplo n.º 1
0
        private IEnumerable <TranslationEntity> FilterNotYetSavedTranslations(ExpressionEntity ex)
        {
            var res = new List <TranslationEntity>();

            for (var i = 0; i < ex.Translations.Count;)
            {
                var t = ex.Translations[i];

                if (t.Id == 0)
                {
                    if (!t.Deleted)
                    {
                        res.Add(t);
                    }

                    ex.Translations.Remove(t);
                }
                else
                {
                    i++;
                }
            }

            return(res);
        }
Ejemplo n.º 2
0
        private void MergeTranslations(ExpressionEntity source, ExpressionEntity dest, MergerConfiguration conf)
        {
            foreach (var sourceTran in source.Translations)
            {
                var destTran = dest.Translations.Where(t => t.Language == sourceTran.Language).FirstOrDefault();

                if (destTran == null)
                {
                    if (!conf.ImportStatisticsForNew)
                    {
                        ClearStatistics(sourceTran);
                    }

                    dest.Translations.Add(sourceTran);
                }
                else
                {
                    if (conf.ImportStatisticsForNew)
                    {
                        CopyStatistics(sourceTran, destTran);
                    }
                    else
                    {
                        ClearStatistics(destTran);
                    }

                    destTran.Translation  = sourceTran.Translation;
                    destTran.Translation2 = sourceTran.Translation2;
                }
            }
        }
Ejemplo n.º 3
0
        private void FormArray()
        {
            foreach (var item in Entities)
            {
                if (item is Operand <bool> )
                {
                    OutArray.Add(item);
                }
                else if (item is Operation <bool> )
                {
                    var oper = item as Operation <bool>;
                    if (Operations.Count == 0)
                    {
                        Operations.Push(oper);
                    }
                    else
                    {
                        ExpressionEntity head = Operations.Peek();
                        if (head is Operation <bool> )
                        {
                            var headOper = head as Operation <bool>;
                            if (oper.Priority <= headOper.Priority)
                            {
                                OutArray.Add(Operations.Pop());
                                Operations.Push(oper);
                            }
                            else
                            {
                                Operations.Push(oper);
                            }
                        }
                        else
                        {
                            Operations.Push(oper);
                        }
                    }
                }
                else if (item is Bracket)
                {
                    if (item.Name == "(")
                    {
                        Operations.Push(item);
                    }
                    else
                    {
                        var head = Operations.Pop();
                        while (head.Name != "(")
                        {
                            OutArray.Add(head);
                            head = Operations.Pop();
                        }
                    }
                }
            }

            while (Operations.Count != 0)
            {
                OutArray.Add(Operations.Pop());
            }
        }
Ejemplo n.º 4
0
 public void Remove(ExpressionEntity ex)
 {
     Log.StartTiming();
     using (var context = GetContext())
     {
         context.Remove(ex);
     }
     Log.StopTiming();
 }
Ejemplo n.º 5
0
        public bool IsExpressionUnique(ExpressionEntity expressionToCheck)
        {
            bool res;

            Log.StartTiming();
            using (var context = GetContext())
            {
                res = context.IsExpressionUnique(expressionToCheck);
            }
            Log.StopTiming();

            return(res);
        }
Ejemplo n.º 6
0
        public ExpressionEntity CreateExpression(bool allDefaultLanguages)
        {
            var ex = new ExpressionEntity();

            if (allDefaultLanguages)
            {
                foreach (var li in _languagesProvider.Languages)
                {
                    ex.Translations.Add(new TranslationEntity {
                        Language = li.Id
                    });
                }
            }

            ex.CreationDate = _dateTimeProvider.Current;
            ex.MakeDirty();

            return(ex);
        }
Ejemplo n.º 7
0
        private void ExecuteAddExpression()
        {
            var vm = new LanguageChooserVM(null)
            {
                Name = Resources.Lbl.ManageLanguages
            };

            ServiceProvider.Inject(vm);

            if (WindowService
                .ShowDialog(vm, canResize: true, allowSettings: false, saveSizeAndPosition: true,
                            extraSettingsKey: "ManageLanguages", showOkCancelButtons: true) == true)
            {
                ExpressionEntity ex = EntityCreator.CreateExpression(vm.SelectedLanguages);
                Expressions.Add(ServiceProvider.Inject(new ExpressionVM(this, ex)));

                DataAccess.Save(ex);

                RefreshStatistics();
            }
        }
Ejemplo n.º 8
0
        public ExpressionEntity CopyExpression(ExpressionEntity ex)
        {
            ex.NotNull("ex");

            var ms = new MemoryStream();

            _serializer.Serialize(ms, ex);
            ms.Position = 0;

            var copy = (ExpressionEntity)_serializer.Deserialize(ms);

            copy.Id           = 0;
            copy.UpdateDate   = null;
            copy.CreationDate = _dateTimeProvider.Current;
            copy.Translations.ForEach(t =>
            {
                t.BadAnswers        = 0;
                t.GoodAnswers       = 0;
                t.WasLastAnswerGood = true;

                t.SpellingBadAnswers        = 0;
                t.SpellingGoodAnswers       = 0;
                t.SpellingWasLastAnswerGood = true;

                t.ReverseBadAnswers        = 0;
                t.ReverseGoodAnswers       = 0;
                t.ReverseWasLastAnswerGood = true;

                t.ReverseSpellingBadAnswers        = 0;
                t.ReverseSpellingGoodAnswers       = 0;
                t.ReverseSpellingWasLastAnswerGood = true;

                t.RecentlyUsed = null;
                t.Defined      = _dateTimeProvider.Current;
            });
            copy.MakeDirty();

            return(copy);
        }
Ejemplo n.º 9
0
        private void Parse()
        {
            while (IsBound())
            {
                SkipSpaces();
                for (int i = 0; i < lexems.Length; i++)
                {
                    //string expr = Expression.Substring(offset);
                    Regex r = new Regex(lexems[i]);
                    //var match = r.Match(expr);
                    var match = r.Match(Expression, offset);
                    if (!match.Success || match.Index != offset)
                    {
                        continue;
                    }

                    offset += match.Length;

                    ExpressionEntity e = EntityFabric.GetEntity(match.Value);
                    Entities.Add(e);
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        public void Mark(bool answer, ExpressionEntity entity, TestConfiguration config)
        {
            entity[config.Language].RecentlyUsed = _dateTimeProvider.Current;

            if (config.CheckTheSpelling)
            {
                if (config.Reverse)
                {
                    entity[config.Language].ReverseSpellingWasLastAnswerGood = answer;
                }
                else
                {
                    entity[config.Language].SpellingWasLastAnswerGood = answer;
                }
            }
            else
            {
                if (config.Reverse)
                {
                    entity[config.Language].ReverseWasLastAnswerGood = answer;
                }
                else
                {
                    entity[config.Language].WasLastAnswerGood = answer;
                }
            }

            if (answer)
            {
                if (config.CheckTheSpelling)
                {
                    if (config.Reverse)
                    {
                        entity[config.Language].ReverseSpellingGoodAnswers++;
                    }
                    else
                    {
                        entity[config.Language].SpellingGoodAnswers++;
                    }
                }
                else
                {
                    if (config.Reverse)
                    {
                        entity[config.Language].ReverseGoodAnswers++;
                    }
                    else
                    {
                        entity[config.Language].GoodAnswers++;
                    }
                }
            }
            else
            {
                if (config.CheckTheSpelling)
                {
                    if (config.Reverse)
                    {
                        entity[config.Language].ReverseSpellingBadAnswers++;
                    }
                    else
                    {
                        entity[config.Language].SpellingBadAnswers++;
                    }
                }
                else
                {
                    if (config.Reverse)
                    {
                        entity[config.Language].ReverseBadAnswers++;
                    }
                    else
                    {
                        entity[config.Language].BadAnswers++;
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public void Mark(bool answer, ExpressionEntity entity, TestConfiguration config)
 {
 }
Ejemplo n.º 12
0
        internal static DocumentEntity ConvertToDocumentEntity(IContentItem fileInfo, IPolicyResponseObject uro)
        {
            if (fileInfo == null)
                return null;

            DocumentEntity documentEntity = new DocumentEntity();
            List<PolicySetEventEntity> policyEvents = new List<PolicySetEventEntity>();

            // Can't actually do much populating if this is null
            documentEntity.ContentType = fileInfo.Type;
            documentEntity.Name = fileInfo.Name;

            InitialiseFileEntityMetadata(documentEntity, fileInfo);

            if (fileInfo.PolicySetCollection != null)
            {
                foreach (IPolicySetResponse policySetInfo in fileInfo.PolicySetCollection)
                {
                    PolicySetEventEntity PolicySet = new PolicySetEventEntity();
                    PolicySet.EventDate = policySetInfo.Date;
                    PolicySet.PolicySetName = policySetInfo.Name;
                    List<PolicyEntity> PolicyEntities = new List<PolicyEntity>();

                    if (policySetInfo.PolicyReportCollection != null)
                    {
                        foreach (IPolicyResponse policyInfo in policySetInfo.PolicyReportCollection)
                        {
                            if (!ProEntityConverter.ShouldAudit(policyInfo))
                                continue;

                            PolicyEntity PolicyEntity = new PolicyEntity();

                            PolicyEntity.PolicyName = policyInfo.Name;
                            PolicyEntity.Triggered = policyInfo.Triggered;

                            List<ExpressionEntity> expressionList = new List<ExpressionEntity>();
                            if (policyInfo.ExpressionCollection != null)
                            {
                                foreach (IExpressionResponse expressionInfo in policyInfo.ExpressionCollection)
                                {
                                    if (!expressionInfo.Triggered)
                                        continue;

                                    ExpressionEntity expression = new ExpressionEntity();
                                    expression.ExpressionName = expressionInfo.Name;
                                    expression.ExpressionRating = expressionInfo.Rating;
                                    expression.ExpressionType = "CONDITION";
                                    expression.ExpressionTriggered = expressionInfo.Triggered;

                                    // IMPORTANT!! these not put to the audit trail as is storing personal info. bad.
                                    List<ExpressionPropertyEntity> expressionProperty = new List<ExpressionPropertyEntity>();
                                    expression.ExpressionProperties = expressionProperty.ToArray();

                                    expressionList.Add(expression);
                                }
                            }

                            if (policyInfo.Routing != null)
                            {
                                ExpressionEntity routing = new ExpressionEntity();
                                routing.ExpressionName = policyInfo.Routing.Name;
                                routing.ExpressionRating = policyInfo.Routing.Rating;
                                routing.ExpressionType = "ROUTING";
                                routing.ExpressionTriggered = true;

                                // IMPORTANT!! these not put to the audit trail as is storing personal info. bad.
                                List<ExpressionPropertyEntity> expressionProperty = new List<ExpressionPropertyEntity>();
                                routing.ExpressionProperties = expressionProperty.ToArray();

                                expressionList.Add(routing);
                            }
                            PolicyEntity.Expressions = expressionList.ToArray();

                            List<PolicyPropertyEntity> policyPropList = new List<PolicyPropertyEntity>();
                            if (policyInfo.Properties != null)
                            {
                                foreach (KeyValuePair<string, string> de in policyInfo.Properties)
                                {
                                    PolicyPropertyEntity prop = new PolicyPropertyEntity();
                                    prop.Name = de.Key;
                                    prop.PropertyValue = de.Value;
                                    policyPropList.Add(prop);
                                }
                            }
                            PolicyEntity.PolicyProperties = policyPropList.ToArray();

                            List<ActionEntity> acList = new List<ActionEntity>();
                            if (policyInfo.ActionCollection != null)
                            {
                                foreach (IPolicyResponseAction actionInfo in policyInfo.ActionCollection)
                                {
                                    ActionEntity ae = ConvertActionEntity(actionInfo);

                                    if (ae != null)
                                        acList.Add(ae);
                                }
                            }
                            PolicyEntity.Actions = acList.ToArray();
                            PolicyEntities.Add(PolicyEntity);
                        }
                    }
                    PolicySet.Policies = PolicyEntities.ToArray();
                    policyEvents.Add(PolicySet);
                }
            }
            documentEntity.DocumentEvents = policyEvents.ToArray();
            return documentEntity;
        }
Ejemplo n.º 13
0
 public void Remove(ExpressionEntity ex)
 {
     Expressions.Attach(ex);
     Expressions.Remove(ex);
     SaveChanges();
 }
Ejemplo n.º 14
0
 public void Save(ExpressionEntity ex)
 {
     Save(new[] { ex });
 }
Ejemplo n.º 15
0
        public bool IsExpressionUnique(ExpressionEntity expressionToCheck)
        {
            expressionToCheck.NotNull("expressionToCheck");

            return(Expressions.Any(e => e.Expression == expressionToCheck.Expression));
        }