Пример #1
0
        public static CoupledExecutableModelCreator <SafetySharpRuntimeModel> CreateExecutedModelCreator(ModelBase model, params Formula[] formulasToCheckInBaseModel)
        {
            Requires.NotNull(model, nameof(model));
            Requires.NotNull(formulasToCheckInBaseModel, nameof(formulasToCheckInBaseModel));

            Func <int, SafetySharpRuntimeModel> creatorFunc;

            // serializer.Serialize has potentially a side effect: Model binding. The model gets bound when it isn't
            // bound already. The lock ensures that this binding is only made by one thread because model.EnsureIsBound
            // is not reentrant.
            lock (model)
            {
                var serializer = new RuntimeModelSerializer();
                model.EnsureIsBound();                 // Bind the model explicitly. Otherwise serialize.Serializer makes it implicitly.
                serializer.Serialize(model, formulasToCheckInBaseModel);

                creatorFunc = serializer.Load;
            }
            var faults = model.Faults;

            return(new CoupledExecutableModelCreator <SafetySharpRuntimeModel>(creatorFunc, model, formulasToCheckInBaseModel, faults));
        }