コード例 #1
0
        /// <summary>
        /// Creates a new Context.
        /// </summary>
        /// <param name="configuration">The configuration section.</param>
        public ContextBuilder(ContextSection configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            Configuration = configuration;
        }
コード例 #2
0
        /// <summary>
        /// Returns a GlobalConfiguration object from a valid json string.
        /// </summary>
        /// <param name="json">A valid json configuration string.</param>
        /// <returns>A GlobalConfiguration object.</returns>
        public static GlobalConfiguration FromJson(string json)
        {
            GlobalConfiguration configuration = new GlobalConfiguration();
            JObject             jsonObject    = JObject.Parse(json);

            if (jsonObject["contexts"] == null)
            {
                throw new DataflipToolException("The 'contexts' array element in dataflip.json is required.");
            }

            foreach (JObject contextObject in jsonObject["contexts"].AsJEnumerable())
            {
                ContextSection contextConfiguration = ContextSection.FromJson(contextObject);
                configuration.Contexts.Add(contextConfiguration);
            }

            return(configuration);
        }
コード例 #3
0
 /// <summary>
 /// Constructs a SprocSection from the current context configuration.
 /// </summary>
 /// <param name="configuration">The current Context section.</param>
 public SprocSection(ContextSection configuration)
 {
     Configuration = configuration;
 }
コード例 #4
0
 public Context(ContextSection section)
 {
     Section = section;
 }
コード例 #5
0
        /// <summary>
        /// Creates a context section from a valid JObject containing a context section.
        /// </summary>
        /// <param name="jsonObject">A valid context JObject object.</param>
        /// <returns>Returns an object containing the data set in the dataflip.json file for a context.</returns>
        public static ContextSection FromJson(JObject jsonObject)
        {
            ContextSection result = new ContextSection();

            try
            {
                string connectionString    = jsonObject["connectionString"]?.Value <string>();
                string nspace              = jsonObject["namespace"]?.Value <string>();
                string name                = jsonObject["name"]?.Value <string>();
                string output              = jsonObject["output"]?.Value <string>();
                string typeScriptTypings   = jsonObject["typeScript"]?["output"]?.Value <string>();
                bool?  useCamelCasing      = jsonObject["typeScript"]?["useCamelCasing"]?.Value <bool>();
                string angularHtmlBindings = jsonObject["angular"]?["htmlBindings"]?.Value <string>();

                if (connectionString == null)
                {
                    throw new DataflipToolException("The '/contexts[]/connectionString' element in dataflip.json is required.");
                }
                if (nspace == null)
                {
                    throw new DataflipToolException("The '/contexts[]/namespace' element in dataflip.json is required.");
                }
                if (name == null)
                {
                    throw new DataflipToolException("The '/contexts[]/name' element in dataflip.json is required.");
                }
                if (output == null)
                {
                    throw new DataflipToolException("The '/contexts[]/output' element in dataflip.json is required.");
                }
                if (useCamelCasing == null)
                {
                    useCamelCasing = true;
                }

                result.ConnectionString         = connectionString;
                result.Namespace                = nspace;
                result.Name                     = name;
                result.Output                   = output;
                result.TypeScriptTypings        = typeScriptTypings;
                result.TypeScriptUseCamelCasing = useCamelCasing.Value;
                result.AngularHtmlBindings      = angularHtmlBindings;
            }
            catch (Exception ex)
            {
                throw new DataflipToolException("There was a problem parsing the configuration for at least one context, error details: " + ex.Message);
            }


            if (jsonObject["sprocs"] == null)
            {
                throw new DataflipToolException("The context does not contain a 'sprocs' element. The 'sprocs' element is required.");
            }

            foreach (var sproc in jsonObject["sprocs"].AsJEnumerable())
            {
                SprocSection sprocSection = new SprocSection(result)
                {
                    Name     = sproc["name"].Value <string>(),
                    Return   = sproc["return"]?.Value <string>(),
                    Method   = sproc["method"]?.Value <string>(),
                    Comments = sproc["comments"]?.Value <string>()
                };

                if (sprocSection.Name == null)
                {
                    throw new DataflipToolException("'contexts[]/sprocs[n]/name' section in dataflip.json is required.");
                }

                if (sprocSection.Method == null)
                {
                    sprocSection.Method = sprocSection.Name;
                }

                result.Sprocs.Add(sprocSection);

                if (sproc["testParams"] != null)
                {
                    foreach (var testParam in sproc["testParams"].AsJEnumerable())
                    {
                        var property = ((Newtonsoft.Json.Linq.JProperty)testParam.First);
                        if (property == null || property.Name == null || property.Value == null)
                        {
                            throw new DataflipToolException("There was a problem parsing the entry in 'testParams'.");
                        }

                        string paramName  = property.Name;
                        string paramValue = property.Value.ToString();

                        sprocSection.TestParams.Add(new TestParamSection()
                        {
                            Name  = paramName,
                            Value = paramValue
                        }
                                                    );
                    }
                }
            }

            return(result);
        }
コード例 #6
0
 /// <summary>
 /// Constructs a new SprocParameterResolver object.
 /// </summary>
 /// <param name="configuration">Represents the current context configuration.</param>
 public SprocParameterResolver(ContextSection configuration)
 {
     Configuration = configuration;
 }