private CachedField GetFieldsAndFragmentNames(
            ValidationContext context,
            Dictionary <SelectionSet, CachedField> cachedFieldsAndFragmentNames,
            IGraphType parentType,
            SelectionSet selectionSet)
        {
            cachedFieldsAndFragmentNames.TryGetValue(selectionSet, out CachedField cached);

            if (cached == null)
            {
                var nodeAndDef    = new Dictionary <string, List <FieldDefPair> >();
                var fragmentNames = new Dictionary <string, bool>();

                CollectFieldsAndFragmentNames(
                    context,
                    parentType,
                    selectionSet,
                    nodeAndDef,
                    fragmentNames);

                cached = new CachedField {
                    NodeAndDef = nodeAndDef, Names = fragmentNames.Keys.ToList()
                };
                cachedFieldsAndFragmentNames.Add(selectionSet, cached);
            }
            return(cached);
        }
Exemple #2
0
    private CachedField GetFieldsAndFragmentNames(
        Dictionary <SelectionSet, CachedField> cachedFieldsAndFragmentNames,
        TypeDefinition parentType,
        SelectionSet selectionSet)
    {
        cachedFieldsAndFragmentNames.TryGetValue(selectionSet,
                                                 out var cached);

        if (cached == null)
        {
            var nodeAndDef    = new Dictionary <string, List <FieldDefPair> >();
            var fragmentNames = new Dictionary <string, bool>();

            CollectFieldsAndFragmentNames(
                parentType,
                selectionSet,
                nodeAndDef,
                fragmentNames);

            cached = new CachedField {
                NodeAndDef = nodeAndDef, Names = fragmentNames.Keys.ToList()
            };
            cachedFieldsAndFragmentNames.Add(selectionSet, cached);
        }

        return(cached);
    }
        public static IEnumerable <GameTurn> GetTurnsBySide(this CachedField gameField, PlayerSide side)
        {
            var simpleMoves   = new List <GameTurn>();
            var requiredJumps = new List <GameTurn>();

            void Processor(int cellIdx)
            {
                var cellTurns = GameTurnUtils.FindTurnsForCell(gameField, cellIdx);

                foreach (var turn in cellTurns)
                {
                    if (turn.IsSimple)
                    {
                        simpleMoves.Add(turn);
                    }
                    else
                    {
                        requiredJumps.Add(turn);
                    }
                }
            }

            gameField.ProcessCellsBySide(side, Processor);

            return(requiredJumps.Any() ? GetCompositeJumps(gameField.Origin, requiredJumps) : simpleMoves);
        }
 public static void ProcessCellsBySide(this CachedField gameField, PlayerSide side, Action <int> processor)
 {
     foreach (var cellIdx in gameField.PiecesBySide(side))
     {
         processor(cellIdx);
     }
 }
Exemple #5
0
        public static double CompareWithMetrics(CachedField oldField, CachedField newField, PlayerSide side)
        {
            double result = 0.0;

            foreach (var metric in _metrics)
            {
                result += metric.Compare(oldField, newField, side) * metric.MetricCost;
            }

            return(result);
        }
        public FormViewModel Create(CachedForm cachedForm)
        {
            IEnumerable <CachedField> cachedFields = new CachedField[] { };

            if (!string.IsNullOrEmpty(cachedForm.CachedFields))
            {
                cachedFields = JsonConvert.DeserializeObject <IEnumerable <CachedField> >(cachedForm.CachedFields);
            }

            return(new FormViewModel()
            {
                Id = cachedForm.FormId,
                Name = cachedForm.Name,
                Fields = cachedFields.Select(
                    cf => new FieldViewModelFactory(this.RequestHandler).Create(cf)
                    )
            });
        }
        public static IEnumerable <GameTurn> FindWorstTurn(CachedField oldField, IEnumerable <GameTurn> newTurns)
        {
            var index       = -1;
            var minPriority = double.PositiveInfinity;

            foreach (var(turn, idx) in newTurns.Select((t, i) => (t, i)))
            {
                GameFieldUtils.TryCreateField(oldField.Origin, turn, out GameField newField);
                var turnMetric = MetricsProcessor.CompareWithMetrics(oldField, new CachedField(newField), turn.Side);

                if (turnMetric < minPriority)
                {
                    minPriority = turnMetric;
                    index       = idx;
                }
            }

            return(newTurns.Any() ? new[] { newTurns.ElementAt(index) } : newTurns);
        }
        public FieldViewModel Build(CachedField cachedField)
        {
            IEnumerable <CachedFieldOption> cachedFieldOptions = new CachedFieldOption[] { };

            if (!string.IsNullOrEmpty(cachedField.CachedFieldOptions))
            {
                cachedFieldOptions = JsonConvert.DeserializeObject <IEnumerable <CachedFieldOption> >(cachedField.CachedFieldOptions);
            }

            return(new FieldViewModel()
            {
                Id = cachedField.FieldId,
                FieldType = new FieldTypeViewModel()
                {
                    Code = cachedField.FieldTypeCode
                },
                Name = cachedField.Name,
                FieldOptions = cachedFieldOptions.Select(
                    fo => new FieldOptionViewModelBuilder(this.handler).Build(fo)
                    )
            });
        }
Exemple #9
0
        static void Main(string[] args)
        {
            x = new CachedField <string>(() => { Thread.Sleep(5000); return(DateTime.Now.ToString()); }, new TimeSpan(0, 0, 30));
            x.OnInvalidated += X_OnInvalidated;
            new Thread(() => { while (true)
                               {
                                   Thread.Sleep(10000); x.Invalidate();
                               }
                       }).Start();
            new Thread(() => { while (true)
                               {
                                   Thread.Sleep(20000); x.Invalidate();
                               }
                       }).Start();

            while (true)
            {
                Console.WriteLine(x.Value);

                Thread.Sleep(2 * 1000);
            }
        }
Exemple #10
0
        private CachedField CacheField(Culture culture, Field field)
        {
            List <CachedFieldOption> cachedFieldOptions = new List <CachedFieldOption>();

            foreach (FieldOption fieldOption in this.handler.Storage.GetRepository <IFieldOptionRepository>().FilteredByFieldId(field.Id))
            {
                cachedFieldOptions.Add(this.CacheFieldOption(culture, fieldOption));
            }

            CachedField cachedField = new CachedField();

            cachedField.FieldId       = field.Id;
            cachedField.FieldTypeCode = this.handler.Storage.GetRepository <IFieldTypeRepository>().WithKey(field.FieldTypeId).Code;
            cachedField.Name          = this.GetLocalizationValue(culture.Id, field.NameId);
            cachedField.Position      = field.Position;

            if (cachedFieldOptions.Count != 0)
            {
                cachedField.CachedFieldOptions = this.SerializeObject(cachedFieldOptions);
            }

            return(cachedField);
        }
        private List <Conflict> FindConflictsWithinSelectionSet(
            ValidationContext context,
            Dictionary <SelectionSet, CachedField> cachedFieldsAndFragmentNames,
            PairSet comparedFragmentPairs,
            IGraphType parentType,
            SelectionSet selectionSet)
        {
            var conflicts = new List <Conflict>();

            CachedField cachedField = GetFieldsAndFragmentNames(
                context,
                cachedFieldsAndFragmentNames,
                parentType,
                selectionSet);

            var fieldMap      = cachedField.NodeAndDef;
            var fragmentNames = cachedField.Names;

            CollectConflictsWithin(
                context,
                conflicts,
                cachedFieldsAndFragmentNames,
                comparedFragmentPairs,
                fieldMap);

            if (fragmentNames.Count != 0)
            {
                // (B) Then collect conflicts between these fields and those represented by
                // each spread fragment name found.
                var comparedFragments = new ObjMap <bool>();
                for (int i = 0; i < fragmentNames.Count; i++)
                {
                    CollectConflictsBetweenFieldsAndFragment(
                        context,
                        conflicts,
                        cachedFieldsAndFragmentNames,
                        comparedFragments,
                        comparedFragmentPairs,
                        false,
                        fieldMap,
                        fragmentNames[i]);

                    // (C) Then compare this fragment with all other fragments found in this
                    // selection set to collect conflicts between fragments spread together.
                    // This compares each item in the list of fragment names to every other
                    // item in that same list (except for itself).
                    for (int j = i + 1; j < fragmentNames.Count; j++)
                    {
                        CollectConflictsBetweenFragments(
                            context,
                            conflicts,
                            cachedFieldsAndFragmentNames,
                            comparedFragmentPairs,
                            false,
                            fragmentNames[i],
                            fragmentNames[j]);
                    }
                }
            }
            return(conflicts);
        }
Exemple #12
0
 public FairyGUITextComponentManipulator()
 {
     _html     = ClrTypes.TextField.CachedField("html") ?? ClrTypes.TextField.CachedFieldByIndex(3, typeof(bool), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
     _text     = ClrTypes.TextField.CachedProperty("text");
     _htmlText = ClrTypes.TextField.CachedProperty("htmlText");
 }
Exemple #13
0
        public int Compare(CachedField oldField, CachedField newField, PlayerSide side)
        {
            var oppositeSide = side.ToOpposite();

            return(oldField.PiecesCount(oppositeSide) - newField.PiecesCount(oppositeSide));
        }
Exemple #14
0
 public int Compare(CachedField oldField, CachedField newField, PlayerSide side) =>
 oldField.PiecesCount(side) - newField.PiecesCount(side);