示例#1
0
        public void Edit()
        {
            var generator      = new JSchemaGenerator();
            var schema         = new JSchema();
            var propertiesInfo = new JsonPropertiesInfo();

            foreach (var item in this.Properties)
            {
                var itemSchema = generator.Generate(item.PropertyType);
                schema.Properties.Add(item.PropertyName, itemSchema);
                propertiesInfo.Add(item.PropertyName, item.Value);
            }

            var result = GetResult();

            if (result == null)
            {
                return;
            }

            foreach (var item in result)
            {
                if (this.Properties.ContainsKey(item.Key) == true)
                {
                    var value1 = item.Value;
                    var value2 = this.Properties[item.Key].Value;

                    if (object.Equals(value1, value2) == false)
                    {
                        this.Properties[item.Key].Value = value1;
                        this.Out.WriteLine($"{item.Key} : {value2} => {value1}");
                    }
                }
            }

            JsonPropertiesInfo GetResult()
            {
                using (var editor = new JsonEditorHost(propertiesInfo, schema))
                {
                    if (editor.Execute() == false)
                    {
                        return(null);
                    }

                    return(editor.Read <JsonPropertiesInfo>());
                }
            }
        }
示例#2
0
        protected override async Task OnExecuteAsync(CancellationToken cancellationToken)
        {
            var tableInfo = this.Content.Dispatcher.Invoke(() => this.Content.Table.TableInfo);
            var keys      = tableInfo.Columns.Where(item => item.IsKey).ToArray();
            var schema    = this.CreateSchema(tableInfo.Columns);

            var fieldList = new List <object>();

            for (var i = 0; i < this.Keys.Length; i++)
            {
                var key     = keys[i];
                var keyText = this.Keys[i];
                var type    = CremaDataTypeUtility.IsBaseType(key.DataType) ? CremaDataTypeUtility.GetType(key.DataType) : typeof(string);
                var value   = CremaConvert.ChangeType(keyText, type);
                fieldList.Add(value);
            }

            var fields         = new JsonPropertiesInfo();
            var authentication = this.CommandContext.GetAuthentication(this);
            var tableRow       = await this.Content.FindAsync(authentication, fieldList.ToArray());

            this.Content.Dispatcher.Invoke(() =>
            {
                foreach (var item in tableInfo.Columns)
                {
                    var field = tableRow[item.Name];
                    if (field != null || item.AllowNull == false)
                    {
                        fields.Add(item.Name, field);
                    }
                }
            });

            var result = fields.Execute(schema);

            if (result == null)
            {
                return;
            }

            foreach (var item in fields)
            {
                if (result.ContainsKey(item.Key) == false)
                {
                    await tableRow.SetFieldAsync(authentication, item.Key, DBNull.Value);
                }
            }

            foreach (var item in result)
            {
                if (tableInfo.Columns.Any(i => i.Name == item.Key) == false)
                {
                    continue;
                }
                var value1 = tableRow[item.Key];
                var value2 = item.Value;
                if (object.Equals(value1, value2) == true)
                {
                    continue;
                }

                await tableRow.SetFieldAsync(authentication, item.Key, item.Value);
            }
        }
示例#3
0
        protected override void OnExecute()
        {
            var tableInfo = this.Content.Dispatcher.Invoke(() => this.Content.Table.TableInfo);
            var schema    = new JSchema();

            foreach (var item in tableInfo.Columns)
            {
                var itemSchema = this.CreateSchema(item.DataType);
                itemSchema.Description = item.Comment;
                schema.Properties.Add(item.Name, itemSchema);
            }

            var required = tableInfo.Columns.Where(item => item.AllowNull == false).Select(item => item.Name);

            foreach (var item in required)
            {
                schema.Required.Add(item);
            }

            var fields         = new JsonPropertiesInfo();
            var authentication = this.CommandContext.GetAuthentication(this);
            var tableRow       = this.Content.Dispatcher.Invoke(() => this.Content.AddNew(authentication, null));

            this.Content.Dispatcher.Invoke(() =>
            {
                foreach (var item in tableInfo.Columns)
                {
                    var field = tableRow[item.Name];
                    if (field != null || item.AllowNull == false)
                    {
                        fields.Add(item.Name, field);
                    }
                }
            });

            var result = GetResult();

            if (result == null)
            {
                return;
            }

            this.Content.Dispatcher.Invoke(() =>
            {
                foreach (var item in result)
                {
                    if (tableInfo.Columns.Any(i => i.Name == item.Key) == false)
                    {
                        continue;
                    }
                    if (item.Value == null)
                    {
                        continue;
                    }
                    tableRow.SetField(authentication, item.Key, item.Value);
                }

                this.Content.EndNew(authentication, tableRow);
            });

            JsonPropertiesInfo GetResult()
            {
                using (var editor = new JsonEditorHost(fields, schema))
                {
                    if (editor.Execute() == false)
                    {
                        return(null);
                    }

                    return(editor.Read <JsonPropertiesInfo>());
                }
            }
        }