public static void GenerateProvider(IBase baseObject, string providerFolderPath, string title, string providerName, string configPathString, NamingConvention namingConvention, IGeneratorConfiguration generatorConfiguration, List <ServiceMethod> serviceMethods)
        {
            var host              = new TemplateEngineHost();
            var container         = (RestEntityContainer)baseObject;
            var rootObject        = (object)container.JsonRootObject;
            var expressionHandler = generatorConfiguration.GetExpressionHandler(Guid.Parse(AbstraXProviderGuids.RestService));
            Dictionary <string, object> sessionVariables;
            FileInfo fileInfo;
            string   fileLocation;
            string   filePath;
            string   output;

            try
            {
                // WebAPI Rest provider class

                sessionVariables = new Dictionary <string, object>();

                sessionVariables.Add("Title", title);
                sessionVariables.Add("ProviderName", providerName);
                sessionVariables.Add("ConfigPathString", configPathString);
                sessionVariables.Add("ServiceMethods", serviceMethods);
                sessionVariables.Add("NamingConvention", namingConvention);
                sessionVariables.Add("RootNamespace", generatorConfiguration.AppName);

                if (baseObject is IEntityWithPrefix)
                {
                    fileLocation = PathCombine(providerFolderPath, baseObject.CastTo <IEntityWithPrefix>().PathPrefix);
                }
                else
                {
                    fileLocation = providerFolderPath;
                }

                filePath = PathCombine(fileLocation, providerName + ".cs");
                fileInfo = new FileInfo(filePath);

                output = host.Generate <WebAPIRestServiceProviderClassTemplate>(sessionVariables, false);

                generatorConfiguration.CreateFile(fileInfo, output, FileKind.Services, () => generatorConfiguration.GenerateInfo(sessionVariables, "WebAPIRestProvider Class"));
            }
            catch (Exception e)
            {
                generatorConfiguration.AppGeneratorEngine.WriteError(e.ToString());
            }
        }
        public bool Process(IBase baseObject, Facet facet, IGeneratorConfiguration generatorConfiguration)
        {
            var name              = baseObject.Name;
            var container         = (RestEntityContainer)baseObject;
            var variables         = container.Variables;
            var parentPath        = (string)variables["parentPath"];
            var parentObject      = baseObject.EntityDictionary.Single(p => p.Value.GetCondensedID() == parentPath).Value;
            var rootObject        = (object)container.JsonRootObject;
            var expressionHandler = generatorConfiguration.GetExpressionHandler(Guid.Parse(AbstraXProviderGuids.RestService));
            var title             = (string)container.Variables["title"];
            var serviceName       = title + "ServiceProvider";
            List <ServiceMethod> serviceMethods;

            this.container = container;

            serviceMethods = new List <ServiceMethod>();
            generatorConfiguration.KeyValuePairs["RestServiceMethods"] = serviceMethods;

            foreach (var entitySet in container.EntitySets.Cast <RestEntitySet>())
            {
                var additionalProperties = (object)entitySet.SelectOriginal("$.additionalProperties");

                if (additionalProperties != null)
                {
                    var operations   = additionalProperties.JsonSelect("$.operations");
                    var entity       = (RestEntityType)entitySet.Entities.Single();
                    var entityObject = (object)entity.JsonObject;
                    var entityId     = entityObject.JsonSelect("$.properties..uniqueId");

                    // kn todo future - flush out entitySet.Operations

                    foreach (var operationPair in operations.GetDynamicMemberNameValueDictionary())
                    {
                        var operationName = operationPair.Key.ToTitleCase();
                        var serviceMethod = new ServiceMethod(entitySet, operationName, serviceName, "string id", generatorConfiguration);
                        var operation     = operationPair.Value;
                        var urlExpression = additionalProperties.GetDynamicMemberValue <string>("url");
                        var resultPath    = operation.GetDynamicMemberValue <string>("resultPath");
                        Dictionary <string, string> methodVariables;
                        Dictionary <string, string> returnProperties;
                        string parms;
                        string test;

                        if (operation.HasDynamicMember("queryString"))
                        {
                            var queryString = operation.GetDynamicMemberValue <string>("queryString");

                            parms           = expressionHandler.Handle <string>(container, ExpressionResultLocation.Provider, ExpressionType.QueryString, ExpressionReturnType.QueryString, queryString);
                            methodVariables = expressionHandler.Handle <Dictionary <string, string> >(container, ExpressionResultLocation.Provider, ExpressionType.Url, ExpressionReturnType.MethodVariables, urlExpression, parms);
                        }
                        else
                        {
                            methodVariables = expressionHandler.Handle <Dictionary <string, string> >(container, ExpressionResultLocation.Provider, ExpressionType.Url, ExpressionReturnType.MethodVariables, urlExpression);
                        }

                        returnProperties = expressionHandler.Handle <Dictionary <string, string> >(container, ExpressionResultLocation.Provider, ExpressionType.Url, ExpressionReturnType.ReturnProperties, urlExpression);

                        serviceMethod.MethodVariables  = methodVariables;
                        serviceMethod.ReturnProperties = returnProperties;
                        serviceMethod.ResultPath       = resultPath.RemoveSurrounding("{", "}");

                        serviceMethod.UniqueIdFactory = expressionHandler.Handle <Func <string[], string> >(entity, ExpressionResultLocation.Provider, ExpressionType.UniqueId, ExpressionReturnType.UniqueIdFactory, entityId);

                        //test = serviceMethod.UniqueIdFactory(new string[] { "a", "b" });

                        if (generatorConfiguration.CurrentPass == GeneratorPass.Files)
                        {
                            serviceMethods.Add(serviceMethod);
                        }
                    }
                }
            }

            return(true);
        }