Example #1
0
        public string Project([FromBody] DynamicSword obj)
        {
            dynamic project    = obj;
            var     objs       = Universal.Objects.ToList(new { ProjectID = project.ProjectID }).OrderBy(o => o["ClassName"]).ToList();
            string  cmd        = "select TABLE_NAME TableName from INFORMATION_SCHEMA.TABLES where TABLE_TYPE ='BASE TABLE' and Table_Schema ='dbo' and Table_Name <> 'sysdiagrams' and table_Name not like 'sys%' and table_name not like 'MS%' order by TABLE_SCHEMA, TABLE_NAME";
            var     connString = (string)obj["DefaultConnectionString"];
            var     tables     = cmd.GetCommand(connString).ToList();

            StringBuilder sb = new StringBuilder();

            CodeConstructor.Projects.SetUsings(sb, objs);
            sb.AppendLine("namespace " + project.Namespace);
            sb.AppendLine("{");
            objs.ForEach(o =>
            {
                CodeConstructor.Objects.Set(sb, o);
                sb.AppendLine();
            });
            CodeConstructor.Tables.Set(sb, tables);
            sb.AppendWithTabs("public static class Dbo", 1);
            sb.AppendWithTabs("{", 1);
            CodeConstructor.ProjectProcedures.Set(sb, obj);
            sb.AppendWithTabs("}", 1);
            sb.AppendLine();
            CodeConstructor.ConnectionStrings.Set(sb, obj);
            sb.AppendLine();
            CodeConstructor.Enums.Set(sb, obj);
            sb.AppendLine("}");
            return(sb.ToString());
        }
Example #2
0
        internal override DynamicSword Before(ActionType action, DynamicSword obj)
        {
            switch (action)
            {
            case ActionType.Select:
                break;

            case ActionType.Insert:
                break;

            case ActionType.Update:
                break;

            case ActionType.Delete:
                Universal.Fields.Delete(obj);
                break;

            case ActionType.Partial:
                break;

            default:
                break;
            }
            return(obj);
        }
Example #3
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            IDynamic obj = null;

            if (type == typeof(DynamicSword))
            {
                obj = new DynamicSword();
            }
            else
            {
                var temp = Activator.CreateInstance(type, null);
                if (temp is IDynamic)
                {
                    obj = (IDynamic)temp;
                }
            }

            if (obj != null)
            {
                foreach (KeyValuePair <string, object> item in dictionary)
                {
                    try
                    {
                        obj[item.Key] = item.Value;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            return(obj);
        }
Example #4
0
        /// <summary>
        /// Requires a value for the parameters "Table" property
        /// </summary>
        /// <param name="parameters"></param>
        public static void Update(this DynamicSword parameters)
        {
            var found = Sword.Data.Tables.FirstOrDefault(t => t.Name == parameters.Table);

            if (found != null)
            {
                found.Update(parameters);
            }
        }
Example #5
0
 public string Select([FromBody] DynamicSword obj)
 {
     if (obj["Type"] != null)
     {
         try
         {
             var type = (string)obj["Type"];
             var path = "~/Views/" + type + ".html";
             path = System.Web.HttpContext.Current.Server.MapPath(path);
             var raw = System.IO.File.ReadAllText(path);
             return(raw);
         }
         catch (Exception ex)
         {
         }
     }
     return(null);
 }
Example #6
0
        internal override List <DynamicSword> AfterSelect(List <DynamicSword> objs)
        {
            //need to check for new fields
            var obj      = Universal.Objects.FirstOrDefault(new { ObjectID = this.Parameter.ObjectID });
            var conn     = Universal.Connections.FirstOrDefault(new { ConnectionID = obj["ConnectionID"] });
            var existing = (new DynamicTable(obj["TableName"].ToString(), conn["ConnectionString"].ToString())).FieldDefinitions();

            foreach (dynamic item in existing)
            {
                var found = objs.FirstOrDefault(o => o["TableName"].ToString() == item.TableName.ToString());
                if (found == null)
                {
                    dynamic newField = new DynamicSword();
                    newField.TableName        = item.TableName;
                    newField.PropertyName     = item.TableName;
                    newField.SqlDbType        = item.SqlDbType;
                    newField.ObjectID         = this.Parameter.ObjectID;
                    newField.Include          = true;
                    newField.JsonSerializable = true;
                    newField.XmlSerializable  = true;
                    newField.UDT               = "";
                    newField.GetMethod         = "";
                    newField.SetMethod         = "";
                    newField.IsReadOnly        = false;
                    newField.Aliases           = "";
                    newField.UseChangeEvent    = false;
                    newField.DefaultValue      = "";
                    newField.IsEnum            = false;
                    newField.IncludeInSetValue = true;
                    Universal.Fields.Insert(newField);
                    objs.Add((DynamicSword)newField);
                }
            }

            return(objs.OrderBy(o => o["PropertyName"]).ToList());
        }
Example #7
0
 public string Items([FromBody] DynamicSword obj)
 {
     return(CodeConstructor.Objects.TypeScript(obj));
 }
Example #8
0
 public string Enum([FromBody] DynamicSword obj)
 {
     return(CodeConstructor.Enums.TypeScript(obj));
 }
Example #9
0
 internal override object DatabaseObject(DynamicSword obj, ActionType actionType)
 {
     return(Universal.Projects);
 }
Example #10
0
 internal override object DatabaseObject(DynamicSword obj, ActionType actionType)
 {
     return(Universal.ConnectionsStrings);
 }