Example #1
0
        public static T Clone <T>(this IFormatter formatter, object graph)
        {
            object?item = formatter.Clone(graph);

            if (item is IDictionary dictionary)
            {
                return(dictionary.Convert <T>());
            }
            return((T)item);
        }
Example #2
0
        /// <summary>
        /// Make sure we don't return direct references to mutable objects within the model
        /// </summary>
        protected virtual void EnsureNoMutableReferences(ref object result, IOperationWithResult operation)
        {
            if (result != null)
            {
                bool operationIsResponsible = operation != null && operation.ResultIsSafe;

                if (!operationIsResponsible && !result.IsImmutable())
                {
                    result = _resultFormatter.Clone(result);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Apply the command to the food taster. If it succeeds, apply to the real model.
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public override object ExecuteCommand(Command command)
        {
            try
            {
                command.PrepareStub(_foodTaster);
                command.ExecuteStub(_foodTaster); //outofmemory,commandaborted, unhandled user
            }
            catch (CommandAbortedException)
            {
                throw;
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _foodTaster = _formatter.Clone(_model); //reset
                throw new CommandAbortedException("Royal taster died of food poisoning, see inner exception for details", ex);
            }

            return(base.ExecuteCommand(command));
        }
Example #4
0
 public RoyalFoodTaster(EngineConfiguration config, Model model)
     : base(config, model)
 {
     _formatter = config.CreateFormatter(FormatterUsage.Snapshot);
     _foodTaster = _formatter.Clone(Model);
 }
Example #5
0
 public RoyalFoodTaster(EngineConfiguration config, Model model)
     : base(config, model)
 {
     _formatter  = config.CreateFormatter(FormatterUsage.Snapshot);
     _foodTaster = _formatter.Clone(_model);
 }