Ejemplo n.º 1
0
        /// <summary>
        /// Registers the specified type.
        /// </summary>
        /// <param name="toRegister">To register.</param>
        /// <returns></returns>
        public DataType Register(DataType toRegister)
        {
            if (toRegister.Id == int.MaxValue)
            {
                throw new InvalidOperationException("Cannot Update StaticType");
            }

            if (toRegister.Id == 0)
            {
                if (this.RegisteredTypes.Where(t => t.NormalizedName == toRegister.NormalizedName).FirstOrDefault() != null)
                {
                    throw new InvalidOperationException("Duplicate Structure Name");
                }

                toRegister.EnsureHasNeccessaryProperties();
                _db.Insert(toRegister);
            }
            else
            {
                toRegister.EnsureHasNeccessaryProperties();
                _db.Update(toRegister);
            }

            _CachedDataType = null;

            var finalType = this.RegisteredTypes.Where(t => t.NormalizedName == toRegister.NormalizedName).FirstOrDefault();

            return(finalType);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers the specified type.
        /// </summary>
        /// <param name="toRegister">To register.</param>
        /// <returns></returns>
        public DataType Register(DataType toRegister)
        {
            if (toRegister.Id == int.MaxValue)
            {
                throw new InvalidOperationException("Cannot Update StaticType");
            }

            lock (this)
            {
                // for anonymous type which we used for query - does not store it into database
                // but cache it into memory
                if (toRegister.NormalizedName.StartsWith("anonymoustype"))
                {
                    if (this.Types.ContainsKey(toRegister.NormalizedName) == false)
                    {
                        if (this.Types.TryAdd(toRegister.NormalizedName, toRegister) == false)
                        {
                            throw new InvalidOperationException("Cannot Cache Type:" + toRegister.NormalizedName);
                        }
                        return(toRegister);
                    }

                    return(this.Types[toRegister.NormalizedName]);
                }

                if (toRegister.Id == 0)
                {
                    if (this.RegisteredTypes.Where(t => t.NormalizedName == toRegister.NormalizedName).FirstOrDefault() != null)
                    {
                        throw new InvalidOperationException("Duplicate Structure Name");
                    }

                    toRegister.EnsureHasNeccessaryProperties();
                    _db.Insert(toRegister);
                }
                else
                {
                    toRegister.EnsureHasNeccessaryProperties();
                    _db.Update(toRegister);
                }

                _CachedDataType = null;

                var finalType = this.RegisteredTypes.Where(t => t.NormalizedName == toRegister.NormalizedName).FirstOrDefault();
                return(finalType);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Scaffolds the specified input JObject
        /// </summary>
        /// <param name="inputJson">The input json.</param>
        /// <returns></returns>
        public DataType Scaffold(JObject sourceObject)
        {
            var clientDataType = new DataType();

            clientDataType.OriginalName = "Scaffoled";

            clientDataType.Properties = (from KeyValuePair <string, JToken> property in sourceObject
                                         select new DataProperty(property.Key, property.Value.Type)).ToList();

            clientDataType.EnsureHasNeccessaryProperties();

            return(clientDataType);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Scaffolds the specified input json into DataType
        /// </summary>
        /// <param name="inputJson">The input json.</param>
        /// <returns></returns>
        public DataType Scaffold(string inputJson)
        {
            var sourceObject = JsonConvert.DeserializeObject(inputJson) as JObject;

            var clientDataType = new DataType();

            clientDataType.OriginalName = "Scaffoled";

            clientDataType.Properties = (from KeyValuePair <string, JToken> property in sourceObject
                                         select new DataProperty(property.Key, property.Value.Type)).ToList();

            clientDataType.EnsureHasNeccessaryProperties();

            return(clientDataType);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Scaffolds the specified input JObject
        /// </summary>
        /// <param name="inputJson">The input json.</param>
        /// <returns></returns>
        public DataType Scaffold(JObject sourceObject)
        {
            var clientDataType = new DataType();
            clientDataType.OriginalName = "Scaffoled";

            clientDataType.Properties = (from KeyValuePair<string, JToken> property in sourceObject
                                         select new DataProperty(property.Key, property.Value.Type)).ToList();

            clientDataType.EnsureHasNeccessaryProperties();

            return clientDataType;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Scaffolds the specified input json into DataType
        /// </summary>
        /// <param name="inputJson">The input json.</param>
        /// <returns></returns>
        public DataType Scaffold(string inputJson)
        {
            var sourceObject = JsonConvert.DeserializeObject(inputJson) as JObject;

            var clientDataType = new DataType();
            clientDataType.OriginalName = "Scaffoled";

            clientDataType.Properties = (from KeyValuePair<string, JToken> property in sourceObject
                                         select new DataProperty(property.Key, property.Value.Type)).ToList();

            clientDataType.EnsureHasNeccessaryProperties();

            return clientDataType;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Registers the specified type.
        /// </summary>
        /// <param name="toRegister">To register.</param>
        /// <returns></returns>
        public DataType Register(DataType toRegister)
        {
            if (toRegister.Id == int.MaxValue)
            {
                throw new InvalidOperationException("Cannot Update StaticType");
            }

            if (toRegister.Id == 0)
            {
                if (this.RegisteredTypes.Where(t => t.NormalizedName == toRegister.NormalizedName).FirstOrDefault() != null)
                {
                    throw new InvalidOperationException("Duplicate Structure Name");
                }

                toRegister.EnsureHasNeccessaryProperties();
                _db.Insert(toRegister);
            }
            else
            {
                toRegister.EnsureHasNeccessaryProperties();
                _db.Update(toRegister);
            }

            _CachedDataType = null;

            var finalType = this.RegisteredTypes.Where(t => t.NormalizedName == toRegister.NormalizedName).FirstOrDefault();
            return finalType;
        }