Example #1
0
        public void Can_Use_ModelNode_SetPropertyBagValue()
        {
            var modelNode = new ModelNode();

            var name  = Rnd.String();
            var value = Rnd.String();

            modelNode.SetPropertyBagValue(name, value);

            Assert.AreEqual(value, modelNode.GetPropertyBagValue(name));
            Assert.AreEqual(value, modelNode.PropertyBag.FirstOrDefault(p => p.Name == name).Value);
        }
Example #2
0
        protected override void OnAfterDeployModel(object modelHost, ModelNode modelNode)
        {
            base.OnAfterDeployModel(modelHost, modelNode);

            // save model hash to a persistan storages
            var storages = ResolvePersistenceStorages(modelHost, modelNode);

            if (Configuration != null && storages.Count() > 0)
            {
                TraceService.Information(0, "Model hash save: found [{0}] storage impl in Configuration.PersistenceStorages. Automatic model hash management is used");

                var modelIdProperty = modelNode.GetPropertyBagValue(DefaultModelNodePropertyBagValue.Sys.IncrementalProvision.PersistenceStorageModelId);

                if (modelIdProperty == null)
                {
                    throw new SPMeta2Exception(
                              "IncrementalProvisionModelId is not set. Either clean PersistenceStorages and handle model hash persistence manually or set .PersistenceStorageModelId");
                }

                var modelId  = modelIdProperty;
                var objectId = string.Format("{0}.{1}", DefaultPersistenceModelIdPrefix, modelId);

                var serializer = ServiceContainer.Instance.GetService <DefaultXMLSerializationService>();
                serializer.RegisterKnownTypes(new[]
                {
                    typeof(ModelHash),
                    typeof(ModelNodeHash)
                });

                var data = Encoding.UTF8.GetBytes(serializer.Serialize(CurrentModelHash));

                foreach (var storage in storages)
                {
                    TraceService.Information(0, string.Format("Saving model hash with object id:[{0}] using storage impl [{1}]. Size:[{2}] bytes",
                                                              objectId, storage.GetType(), data.LongLength));

                    storage.SaveObject(objectId, data);
                }
            }
            else
            {
                TraceService.Information(0, "Model hash save: can't find any persistence storage impl in Configuration... Assuming manual model hash management is used");
            }
        }
Example #3
0
        protected override void OnBeforeDeployModel(object modelHost, ModelNode modelNode)
        {
            base.OnBeforeDeployModel(modelHost, modelNode);

            // clean up current model hash
            CurrentModelHash = new ModelHash();
            ClearCaches();

            TraceService.InformationFormat(0, "Starting incremental provision with EnableCaching = {0}", EnableCaching);

            var storages = ResolvePersistenceStorages(modelHost, modelNode);

            // restore previous one
            if (Configuration != null && storages.Count() > 0)
            {
                TraceService.Information(0, "Model hash restore: found [{0}] storage impl in Configuration.PersistenceStorages. Automatic model hash management is used");

                var modelIdProperty = modelNode.GetPropertyBagValue(DefaultModelNodePropertyBagValue.Sys.IncrementalProvision.PersistenceStorageModelId);

                if (modelIdProperty == null)
                {
                    throw new SPMeta2Exception("IncrementalProvisionModelId is not set. Either clean PersistenceStorages and handle model hash persistence manually or set .PersistenceStorageModelId");
                }

                var modelId  = modelIdProperty;
                var objectId = string.Format("{0}.{1}", DefaultPersistenceModelIdPrefix, modelId);

                var serializer = ServiceContainer.Instance.GetService <DefaultXMLSerializationService>();
                serializer.RegisterKnownTypes(new[]
                {
                    typeof(ModelHash),
                    typeof(ModelNodeHash)
                });

                foreach (var storage in storages)
                {
                    TraceService.Information(0, string.Format("Restoring model hash with object id:[{0}] using storage impl [{1}]",
                                                              objectId, storage.GetType()));

                    var data = storage.LoadObject(objectId);

                    if (data != null)
                    {
                        var dataString = Encoding.UTF8.GetString(data);
                        var dataObject = serializer.Deserialize(typeof(ModelHash), dataString) as ModelHash;

                        if (dataObject != null)
                        {
                            PreviousModelHash = dataObject;

                            TraceService.Information(0, string.Format("Restored model hash with object id:[{0}] using storage impl [{1}]",
                                                                      objectId, storage.GetType()));
                            break;
                        }
                    }
                    else
                    {
                        TraceService.Information(0, string.Format("Restored model hash with object id:[{0}] using storage impl [{1}]",
                                                                  objectId, storage.GetType()));
                    }
                }

                TraceService.Information(0, string.Format("Coudn't restore model hash with object id:[{0}]. Either first provision is user or storage is wrong.", objectId));
            }
            else
            {
                TraceService.Information(0, "Model hash restore: can't find any persistence storage impl in Configuration.PersistenceStorages. Assuming manual model hash management is used");
            }
        }