Ejemplo n.º 1
0
        public void CreateNameSpace(ObjectNameSpaceConfig config)
        {
            var nameSpace = config.Name;

            // check reserved namespace
            if (ObjectNaming.DefaultNameSpace.Equals(nameSpace, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("The specified name space is reserved.");
            }
            else
            {
                // validate characters and form of the namespace
                if (ObjectNameValidator.IsValidNameSpace(nameSpace))
                {
                    var nsKey = SerializerHelper.Serialize(nameSpace);

                    // only allow namespaces to be created once.
                    // we need to iterate the name spaces in order to do a case insensitive comparison
                    foreach (var storedNameSpace in EnumerateNameSpaces())
                    {
                        if (storedNameSpace.Equals(nameSpace, StringComparison.InvariantCultureIgnoreCase))
                        {
                            throw new ArgumentException("Namespace already exists.");
                        }
                    }
                    // namespace is not already used so go ahead and store it
                    _nsStore.Set(nsKey, SerializerHelper.Serialize<ObjectNameSpaceConfig>(config));
                    lock (_nsCache)
                    {
                        _nsCache[nameSpace] = config;
                    }
                    if (null != ObjectNameSpaceAdded)
                    {
                        ObjectNameSpaceAdded(nameSpace);
                    }
                }
                else
                {
                    throw new ArgumentException("The name space is invalid. Please ensure it contains only alphanumeric characters and periods or underscores.");
                }
            }
        }
Ejemplo n.º 2
0
 public void WriteNameSpace(ObjectNameSpaceConfig nameSpace)
 {
     _out.WriteLine(NameSpacePrefix + BinaryHelper.ByteToHexString(SerializerHelper.Serialize<ObjectNameSpaceConfig>(nameSpace)));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates an existing name space record. Does not create a new record and will throw an exception if the name space does not exist.
        /// Use ObjectMetadataStore Exists method to check if a name space exists already.
        /// </summary>
        /// <param name="config">The name space configuration.</param>
        public void UpdateNameSpace(ObjectNameSpaceConfig config)
        {
            var nameSpace = config.Name;

            // check reserved namespace
            if (ObjectNaming.DefaultNameSpace.Equals(nameSpace, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("The specified name space is reserved.");
            }
            else
            {
                // validate characters and form of the namespace
                if (ObjectNameValidator.IsValidNameSpace(nameSpace))
                {
                    var nsKey = SerializerHelper.Serialize(nameSpace);

                    // verify that the namespace already exists
                    if (NameSpaceExists(nameSpace))
                    {
                        // overwrite the existing namespace
                        _nsStore.Set(nsKey, SerializerHelper.Serialize<ObjectNameSpaceConfig>(config));
                        lock (_nsCache)
                        {
                            _nsCache[nameSpace] = config;
                        }
                    }
                    else
                    {
                        throw new ArgumentException("The specified name space does not exist: " + nameSpace);
                    }
                }
                else
                {
                    throw new ArgumentException("The name space is invalid. Please ensure it contains only alphanumeric characters and periods or underscores.");
                }
            }
        }