Exemple #1
0
        public string[] GetValue(CodeGroupType groupType, string language, string code)
        {
            if (!CodeGroups.Any())
            {
                return(null);
            }
            if (string.IsNullOrEmpty(language))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }

            var codeGroup = CodeGroups.FirstOrDefault(cg => cg.Type == groupType &&
                                                      cg.Translations.Any(t => t.Language.Equals(language, StringComparison.OrdinalIgnoreCase)));

            if (codeGroup == null)
            {
                return(null);
            }

            var translations = codeGroup.Translations.Where(t => t.Language.Equals(language, StringComparison.OrdinalIgnoreCase));

            return(translations.Select(t => t.Value).ToArray());
        }
Exemple #2
0
        public string GetValue(CodeGroupType groupType, string culture, string language, string code)
        {
            if (!CodeGroups.Any())
            {
                return(null);
            }
            if (string.IsNullOrEmpty(culture))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(language))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }

            var codeGroup = CodeGroups.FirstOrDefault(cg => cg.Type == groupType &&
                                                      cg.Translations.Any(t => t.Culture.Equals(culture, StringComparison.OrdinalIgnoreCase) &&
                                                                          t.Language.Equals(language, StringComparison.OrdinalIgnoreCase)));

            if (codeGroup == null)
            {
                return(null);
            }

            var translation = codeGroup.Translations.FirstOrDefault(t => t.Culture.Equals(culture, StringComparison.OrdinalIgnoreCase) &&
                                                                    t.Language.Equals(language, StringComparison.OrdinalIgnoreCase));

            return(translation != null ? translation.Value : null);
        }
Exemple #3
0
        public ObservableCollection <CodeGroup> GetCodeGroups(CodeGroupType type)
        {
            var codeGroups = new ObservableCollection <CodeGroup>();

            if (!CodeGroups.Any())
            {
                return(codeGroups);
            }

            return(CodeGroups.Where(cg => cg.Type == type)
                   .ToObservableCollection());
        }
Exemple #4
0
        public static int GetEdgeMatchScore(LabeledEdge sourceEdge, LabeledEdge imageEdge, SharedSourceOrDest sharingSourceOrDest, NodePairings pairings, IndexImportance indexImportance, bool usePastPairings = true)
        {
            int           edgeMatchScore = 0;
            LabeledVertex sourceEdgeVertex;
            LabeledVertex imageEdgeVertex;

            if (sharingSourceOrDest == SharedSourceOrDest.Source)
            {
                sourceEdgeVertex = sourceEdge.DestinationVertex;
                imageEdgeVertex  = imageEdge.DestinationVertex;
            }
            else
            {
                sourceEdgeVertex = sourceEdge.SourceVertex;
                imageEdgeVertex  = imageEdge.SourceVertex;
            }

            if (imageEdge.Index == sourceEdge.Index || indexImportance == IndexImportance.NotImportant)
            {
                edgeMatchScore += EdgeScorePoints.IndexMatch;
            }
            if (usePastPairings)
            {
                lock (pairings)
                {
                    if (pairings.Pairings[imageEdgeVertex].Any(x => x.ImageGraphVertex == sourceEdgeVertex))
                    {
                        edgeMatchScore += EdgeScorePoints.TargetVertexArePaired;
                    }
                }
            }
            if (sourceEdgeVertex.Opcode == imageEdgeVertex.Opcode)
            {
                edgeMatchScore += EdgeScorePoints.TargetVertexCodeExactMatch;
            }
            else if (CodeGroups.AreSameGroup(sourceEdgeVertex.Opcode, imageEdgeVertex.Opcode))
            {
                edgeMatchScore += EdgeScorePoints.TargetVertexCodeFamilyMatch;
            }
            if (sourceEdge.EdgeType != EdgeType.ProgramFlowAffecting)
            {
                edgeMatchScore *= ImportantEdgeTypeMultiplier;
            }
            if (sourceEdge.SourceVertex.IsInReturnBackTree && sourceEdge.DestinationVertex.IsInReturnBackTree)
            {
                //edgeMatchScore *= ImportantEdgeTypeMultiplier;
            }
            return(edgeMatchScore);
        }
Exemple #5
0
        public void Initialize(AppInfo appInfo)
        {
            if (appInfo == null)
            {
                return;
            }

            appInfo.PossibleCountries.ToList()
            .ForEach(pc => Countries.Add(pc));

            appInfo.PossibleLanguages.ToList()
            .ForEach(pl => Languages.Add(pl));

            appInfo.PossibleCodeGroups.ToList()
            .ForEach(cg => CodeGroups.Add(cg));
        }
Exemple #6
0
        public string GetValue(CodeGroupType groupType, string code)
        {
            if (!CodeGroups.Any())
            {
                return(null);
            }
            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }

            var codeGroup = CodeGroups.FirstOrDefault(cg => cg.Type == groupType &&
                                                      cg.Code.Equals(code, StringComparison.OrdinalIgnoreCase));

            return(codeGroup != null ? codeGroup.Value : null);
        }
Exemple #7
0
        public string GetCode(CodeGroupType groupType, string value)
        {
            if (!CodeGroups.Any())
            {
                return(null);
            }
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            var codeGroup = CodeGroups.FirstOrDefault(cg => cg.Type == groupType &&
                                                      cg.Translations.Any(t => t.Value != null &&
                                                                          t.Value.Contains(value)));

            return(codeGroup != null ? codeGroup.Code : null);
        }