Exemplo n.º 1
0
#pragma warning restore 649

        public virtual Object Deserialize(Type type, Qi4CSConfigurationResource resource)
        {
            var xmlResource = (XMLConfigurationResource)resource;

            Stream fs; XDocument doc;

            if (this._streamCallback.TryGetStreamFor(xmlResource.DocumentResource, SerializationAction.DESERIALIZING, out fs))
            {
                using ( fs )
                {
                    doc = XDocument.Load(fs);
                }
            }
            else
            {
                throw new NotSupportedException("Can not get stream for " + xmlResource.DocumentResource + ".");
            }

            XElement element;
            var      xpath = xmlResource.XPath;

            if (String.IsNullOrEmpty(xpath))
            {
                element = doc.Root;
            }
            else
            {
                // Get the actual element to deserialize from
                element = doc.XPathSelectElement(xpath);
                CheckForXPathElement(xpath, element);
            }
            Boolean dummy;

            return(this.Deserialize(type, element, null, out dummy));
        }
Exemplo n.º 2
0
 public ConfigurationCompositeDefaultInfo SetDefaultLocationInfo(Qi4CSConfigurationResource locationInfo)
 {
     foreach (var id in this._types)
     {
         this._info.CompositeInfos.GetOrAdd_NotThreadSafe(id, () => new ConfigurationCompositeInfo()).Resource = locationInfo;
     }
     return(this);
 }
        internal ConfigurationEventArgs(ConfigurationInstance <Object> instance, Qi4CSConfigurationResource resource)
        {
            ArgumentValidator.ValidateNotNull("Configuration instance", instance);
            ArgumentValidator.ValidateNotNull("Resource", resource);

            this._instance = instance;
            this._resource = resource;
        }
#pragma warning restore 649

        #region ConfigurationInstance Members

        public virtual void Reload(Qi4CSConfigurationResource newResource)
        {
            newResource = newResource ?? this.Resource;
            var invokeEvent = this._state.Configuration.Item1.IsValueCreated;

            this.SetConfigurationComposite(newResource);
            this._reloadRequestedEvent.InvokeAction(this._meAsInstance, new ConfigurationEventArgs(this._meAsInstance, newResource));
        }
        private void SaveState(Qi4CSConfigurationResource resource)
        {
            var configInfo = this._state.Configuration;

            this._state.Serializer.Serialize(
                configInfo.Item1.Value,
                resource);
            this._afterSaveEvent.InvokeAction(this._meAsInstance, new ConfigurationEventArgs(this._meAsInstance, resource));
        }
 private void SetConfigurationComposite(Qi4CSConfigurationResource resource)
 {
     this._state.Configuration = Tuple.Create(new Lazy <TConfiguration>(() =>
     {
         return((TConfiguration)this._state.Serializer.Deserialize(
                    typeof(TConfiguration),
                    resource));
         // Don't invoke afterLoad event here as it might cause another request to get configuration -> an exception will be thrown
     },
                                                                        System.Threading.LazyThreadSafetyMode.ExecutionAndPublication), resource);
 }
Exemplo n.º 7
0
        public virtual void Serialize(Object contents, Qi4CSConfigurationResource resource)
        {
            var xmlResource = (XMLConfigurationResource)resource;

            Stream fs;

            XDocument existingFullDoc = null;
            var       xpath           = xmlResource.XPath;

            if (!String.IsNullOrEmpty(xpath))
            {
                if (this._streamCallback.TryGetStreamFor(xmlResource.DocumentResource, SerializationAction.DESERIALIZING, out fs))
                {
                    using ( fs )
                    {
                        existingFullDoc = XDocument.Load(fs);
                    }
                }
                else
                {
                    throw new NotSupportedException("Can not get stream for " + xmlResource.DocumentResource + ".");
                }
            }

            if (this._streamCallback.TryGetStreamFor(xmlResource.DocumentResource, SerializationAction.SERIALIZING, out fs))
            {
                using ( fs )
                {
                    var existingElement = existingFullDoc == null ? null : existingFullDoc.XPathSelectElement(xpath);
                    if (existingFullDoc != null)
                    {
                        CheckForXPathElement(xpath, existingElement);
                    }

                    var type    = this._application.GetCompositeInstance(contents).ModelInfo.Model.PublicTypes.First();
                    var element = this.Serialize(contents, type, existingElement == null ? type.Name : existingElement.Name.LocalName, null);
                    if (existingElement == null)
                    {
                        element.Save(fs);
                    }
                    else
                    {
                        existingElement.ReplaceWith(element);
                        existingFullDoc.Save(fs);
                    }
                }
            }
            else
            {
                throw new NotSupportedException("Can not get stream for " + xmlResource.DocumentResource + ".");
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Creates a new instance of <see cref="ConfigurationCompositeInfo"/> with given information about resource and serializer type.
 /// </summary>
 /// <param name="resource">The context-dependent information of resource to load configuration from.</param>
 /// <param name="serializer">The type responsible of serializing and deserializing configuration contents. Must implement <see cref="ConfigurationSerializer"/>.</param>
 public ConfigurationCompositeInfo(Qi4CSConfigurationResource resource, Type serializer)
 {
     this.Resource   = resource;
     this.Serializer = serializer;
 }
Exemplo n.º 9
0
    /// <summary>
    /// Helper method to invoke <see cref="ConfigurationManager.Create"/> method for configuration located in specific location and serialized by specific serializer.
    /// </summary>
    /// <typeparam name="TConfiguration">The type of configuration contents.</typeparam>
    /// <param name="manager">The <see cref="ConfigurationManager"/>.</param>
    /// <param name="configurationLocation">The location of configuration. May be <c>null</c> for default location.</param>
    /// <param name="configurationSerializer">The serializer for configuration. Must implement <see cref="ConfigurationSerializer"/>. May be <c>null</c> for default serializer.</param>
    /// <returns>An instance of <see cref="ConfigurationInstance{T}"/>.</returns>
    /// <remarks>See <see cref="ConfigurationManager.Create"/> method for more detailed description about exceptions and return values.</remarks>
    public static ConfigurationInstance <TConfiguration> Create <TConfiguration>(this ConfigurationManager manager, Qi4CSConfigurationResource configurationLocation, Type configurationSerializer)
        where TConfiguration : class
    {
        var info = new ConfigurationCompositeInfo(configurationLocation, configurationSerializer);

        return(manager.Create <TConfiguration>(info));
    }
Exemplo n.º 10
0
 /// <summary>
 /// Helper method to invoke <see cref="ConfigurationManager.Create"/> method for configuration located in specific location but serialized by default serializer.
 /// </summary>
 /// <typeparam name="TConfiguration">The type of configuration contents.</typeparam>
 /// <param name="manager">The <see cref="ConfigurationManager"/>.</param>
 /// <param name="configurationLocation">The location of configuration. May be <c>null</c> for default location.</param>
 /// <returns>An instance of <see cref="ConfigurationInstance{T}"/>.</returns>
 /// <remarks>See <see cref="ConfigurationManager.Create"/> method for more detailed description about exceptions and return values.</remarks>
 public static ConfigurationInstance <TConfiguration> Create <TConfiguration>(this ConfigurationManager manager, Qi4CSConfigurationResource configurationLocation)
     where TConfiguration : class
 {
     return(manager.Create <TConfiguration>(configurationLocation, null));
 }
 public virtual void Save(Qi4CSConfigurationResource newResource)
 {
     newResource = newResource ?? this.Resource;
     this.SaveState(newResource);
 }