コード例 #1
0
        public async Task <HttpResponseMessage> PostJsonSchema([FromBody] AppGenConfig appGenConfig)
        {
            Guid   taskId = Guid.NewGuid();
            string errors = null;

            ValidateAppConfig(taskId, appGenConfig);
            try
            {
                string taskFolder = GetDataPath(taskId.ToString());
                Directory.CreateDirectory(taskFolder);

                string taskRequestFile = GetDataPath(taskId.ToString(), taskId.ToString() + ".request");
                File.WriteAllText(taskRequestFile, JsonConvert.SerializeObject(appGenConfig, Formatting.Indented));

                var engine = new Wham.WhamEngine(taskFolder);
                engine.Context["appGen"] = appGenConfig;
                errors = engine.Liquidize(appGenConfig.AppOptions.Theme + "Theme.dlq");

                errors = errors?.Replace(taskFolder, string.Empty)?.Trim();

                if (string.IsNullOrEmpty(errors)) // pre-create the zip if there were no errors
                {
                    CreateZipFile(taskId);
                }
            }
            catch (Exception x)
            {
                errors = x.ToString();
            }

            if (!string.IsNullOrEmpty(errors))
            {
                string taskErrorFile = GetDataPath(taskId.ToString(), taskId.ToString() + ".error.log");
                File.WriteAllText(taskErrorFile, errors);
            }

            var response = Request.CreateResponse(
                string.IsNullOrEmpty(errors) ? HttpStatusCode.OK : HttpStatusCode.InternalServerError,
                new
            {
                taskId,
                errors,
            });

            return(response);
        }
コード例 #2
0
        private void ValidateAppConfig(Guid taskId, AppGenConfig appGenConfig)
        {
            if (appGenConfig == null)
            {
                ThrowValidationError(taskId, "Validation error: App config required");
            }
            if (string.IsNullOrWhiteSpace(appGenConfig.AppOptions.AppName))
            {
                ThrowValidationError(taskId, "Validation error: App name required");
            }
            if (appGenConfig.AppOptions.AppName.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
            {
                ThrowValidationError(taskId, "Validation error: App name must be a valid file name");
            }

            appGenConfig.DataModel = appGenConfig.DataModel
                                     .OrderByDescending(table => table.IsVisible
                    ? table.Fields.Sum(f => (f.IsAuth ? 999 : 0)
                                       + (f.Type == Constants.DataTypes.TRef ? 2 : 0)
                                       + (f.IsCollection ? 1 : 0))
                    : -999)
                                     .ToArray();
        }