/// <summary> /// このオブジェクトの複製(ディープ コピー)を作成します。 /// </summary> /// <remarks>複製したオブジェクトのIDは必ず -1 になります。適宜再設定してください。</remarks> public ShipGroupData Clone() { var clone = (ShipGroupData)MemberwiseClone(); clone.GroupID = -1; clone.ViewColumns = ViewColumns.Select(p => p.Value.Clone()).ToDictionary(p => p.Name); clone.SortOrder = new List <KeyValuePair <string, ListSortDirection> >(SortOrder); clone.Expressions = Expressions.Clone(); clone.InclusionFilter = new List <int>(InclusionFilter); clone.ExclusionFilter = new List <int>(ExclusionFilter); clone.Members = new List <int>(Members); return(clone); }
public override IList <DatabaseColumn> ViewColumns(string viewName) { var columns = new ViewColumns(Owner, viewName) .Execute(DbConnection, DbTransaction); if (string.IsNullOrEmpty(viewName) || !columns.Any()) { var mCols = new MaterializedViewColumns(Owner, viewName) .Execute(DbConnection, DbTransaction); foreach (var mcol in mCols) { columns.Add(mcol); } } return(columns); }
void CellGUI(Rect cellRect, TreeViewItem <BehaviorTreeNode> item, ViewColumns column, ref RowGUIArgs args) { CenterRectUsingSingleLineHeight(ref cellRect); BehaviorTreeNode node = item.data; switch (column) { case ViewColumns.kIcon: { GUI.DrawTexture(cellRect, (Texture2D)EditorGUIUtility.Load(node.GetIconPath()), ScaleMode.ScaleToFit); } break; case ViewColumns.kName: { Rect toggleRect = cellRect; toggleRect.x += GetContentIndent(item); toggleRect.width = TOGGLE_WIDTH; if (toggleRect.xMax < cellRect.xMax) { item.data.DEBUG_on = EditorGUI.Toggle(toggleRect, item.data.DEBUG_on); } args.rowRect = cellRect; args.label = item.data.Name; base.RowGUI(args); } break; case ViewColumns.kType: { cellRect.x += GetContentIndent(item); DefaultGUI.Label(cellRect, node.GetType().ToString().Split('.')[1], args.selected, args.focused); } break; } }
static void ParseView(StreamReader reader, string view) { string line, name, column, mtype; string word; string tmp; string sql; Dictionary <string, string> table_aliases = new Dictionary <string, string> (); StringBuilder builder = new StringBuilder(); List <ViewColumns> columns = new List <ViewColumns> (); List <string> all_columns = new List <string> (); while (null != (line = reader.ReadLine())) { view += " " + line; if (line.Contains(";")) { break; } } if ((word = ReadWord(ref view)) != "CREATE") { Console.WriteLine("Invalid view, expected 'CREATE', got '{0}'", word); return; } if ((word = ReadWord(ref view)) != "VIEW") { Console.WriteLine("Invalid view, expected 'VIEW', got '{0}'", word); return; } name = ReadWord(ref view); Console.WriteLine("Parsing view {0}: {1}", name, view); if ((word = ReadWord(ref view)) != "AS") { Console.WriteLine("Invalid view, expected 'AS', got '{0}'", word); return; } sql = view; if ((word = ReadWord(ref view)) != "SELECT") { Console.WriteLine("Invalid view, expected 'SELECT', got '{0}'", word); return; } do { ViewColumns c = new ViewColumns(); column = ReadWord(ref view); if (string.IsNullOrEmpty(column) || column == "FROM") { break; } c.Column = column; tmp = ReadWord(ref view); if (!string.IsNullOrEmpty(tmp) && tmp.ToLowerInvariant() == "as") { column = ReadWord(ref view); tmp = ReadWord(ref view); c.Name = column; } else { c.Name = column.IndexOf('.') >= 0 ? column.Substring(column.IndexOf('.') + 1) : column; } // Console.WriteLine ("Found column: {0}, name: {1}", c.Column, c.Name); columns.Add(c); if (tmp != ",") { column = tmp; } } while (tmp == ","); if (column == "FROM") { ReadWord(ref view); // skip one workd column = ReadWord(ref view); while (column == "INNER" || column == "LEFT" || column == "RIGHT") { column = ReadWord(ref view); if (column != "JOIN") { break; } string table; string alias = null; table = ReadWord(ref view); column = ReadWord(ref view); // ON or AS if (column == "AS") { alias = ReadWord(ref view); column = ReadWord(ref view); // ON } column = ReadWord(ref view); // left part column = ReadWord(ref view); // = if (column != "=") { break; } column = ReadWord(ref view); // right part column = ReadWord(ref view); // if (alias != null) { Console.WriteLine("Added table alias {0}={1}", alias, table); table_aliases.Add(alias, table); } } } string filename = Path.Combine(OUTPUT_DIR, string.Format("DB{0}.generated.cs", name)); using (StreamWriter writer = new StreamWriter(filename)) { WriteHeader(writer, Path.GetFileName(filename)); writer.WriteLine(@" using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.IO; using System.Reflection; #pragma warning disable 649 namespace MonkeyWrench.DataClasses {{ public partial class DB{0} : DBView {{" , name); for (int c = 0; c < columns.Count; c++) { string type; bool is_null = false; ViewColumns col = columns [c]; // Console.WriteLine ("Name: {0}, Column: {1},", col.Name, col.Column); if (col.Name == "id") { continue; } type = col.Column; if (!col_type_mapping.ContainsKey(type)) { string tbl; if (col.Column.IndexOf('.') < 0) { Console.WriteLine("Couldn't find type for column: '{0}' (type: {1})", column, type); continue; } tbl = col.Column.Substring(0, col.Column.IndexOf('.')); if (table_aliases.ContainsKey(tbl)) { string tbl_alias = table_aliases [tbl]; type = tbl_alias + "." + col.Column.Substring(col.Column.IndexOf('.') + 1); if (!col_type_mapping.ContainsKey(type)) { Console.WriteLine("Couldn't find type for column: '{0}' (type: {1} aliased table: {2}={3})", column, type, tbl, tbl_alias); continue; } } // Console.WriteLine ("Found column in aliased table."); } mtype = col_type_mapping [type]; if (col_type_isnull_mapping.ContainsKey(type)) { is_null = col_type_isnull_mapping [type]; Console.WriteLine("{0} isnull: {1}", type, is_null); } all_columns.Add(col.Name); if (is_null && !mtype.EndsWith("?")) { mtype += "?"; } Console.WriteLine("Found mtype {0} for column {1} type {2}", mtype, column, type); writer.WriteLine("\t\tprivate {0} _{1};", mtype, col.Name); builder.AppendFormat("\t\tpublic {0} @{1} {{ get {{ return _{1}; }} set {{ _{1} = value; }} }}\n", mtype, col.Name); } writer.WriteLine(""); writer.WriteLine(builder.ToString()); writer.WriteLine(""); writer.WriteLine("\t\tpublic const string SQL = \n@\"{0}\";", sql.Replace("\"", "\\\"").Replace("\t\t", "\t ").Replace("\t", "\n\t").Replace("\t ", "\t\t")); writer.WriteLine(""); writer.WriteLine(@" private static string [] _fields_ = new string [] {{ ""{0}"" }}; public override string [] Fields {{ get {{ return _fields_; }} }} ", string.Join("\", \"", all_columns.ToArray())); writer.WriteLine(@" public DB{0} () {{ }} public DB{0} (IDataReader reader) : base (reader) {{ }} ", name); writer.WriteLine(@" } } "); } Console.WriteLine("View '{1}' written to {0}", filename, name); }
static void ParseView (StreamReader reader, string view) { string line, name, column, mtype; string word; string tmp; string sql; Dictionary<string, string> table_aliases = new Dictionary<string, string> (); StringBuilder builder = new StringBuilder (); List<ViewColumns> columns = new List<ViewColumns> (); List<string> all_columns = new List<string> (); while (null != (line = reader.ReadLine ())) { view += " " + line; if (line.Contains (";")) break; } if ((word = ReadWord (ref view)) != "CREATE") { Console.WriteLine ("Invalid view, expected 'CREATE', got '{0}'", word); return; } if ((word = ReadWord (ref view)) != "VIEW") { Console.WriteLine ("Invalid view, expected 'VIEW', got '{0}'", word); return; } name = ReadWord (ref view); Console.WriteLine ("Parsing view {0}: {1}", name, view); if ((word = ReadWord (ref view)) != "AS") { Console.WriteLine ("Invalid view, expected 'AS', got '{0}'", word); return; } sql = view; if ((word = ReadWord (ref view)) != "SELECT") { Console.WriteLine ("Invalid view, expected 'SELECT', got '{0}'", word); return; } do { string type; ViewColumns c = new ViewColumns (); column = ReadWord (ref view); type = column; if (string.IsNullOrEmpty (column) || column == "FROM") break; c.Column = column; tmp = ReadWord (ref view); if (!string.IsNullOrEmpty (tmp) && tmp.ToLowerInvariant () == "as") { column = ReadWord (ref view); tmp = ReadWord (ref view); c.Name = column; } else { c.Name = column.IndexOf ('.') >= 0 ? column.Substring (column.IndexOf ('.') + 1) : column; } // Console.WriteLine ("Found column: {0}, name: {1}", c.Column, c.Name); columns.Add (c); if (tmp != ",") column = tmp; } while (tmp == ","); if (column == "FROM") { ReadWord (ref view); // skip one workd column = ReadWord (ref view); while (column == "INNER" || column == "LEFT" || column == "RIGHT") { column = ReadWord (ref view); if (column != "JOIN") break; string table; string alias = null; table = ReadWord (ref view); column = ReadWord (ref view); // ON or AS if (column == "AS") { alias = ReadWord (ref view); column = ReadWord (ref view); // ON } column = ReadWord (ref view); // left part column = ReadWord (ref view); // = if (column != "=") break; column = ReadWord (ref view); // right part column = ReadWord (ref view); // if (alias != null) { Console.WriteLine ("Added table alias {0}={1}", alias, table); table_aliases.Add (alias, table); } } } string filename = Path.Combine (OUTPUT_DIR, string.Format ("DB{0}.generated.cs", name)); using (StreamWriter writer = new StreamWriter (filename)) { WriteHeader (writer, Path.GetFileName (filename)); writer.WriteLine (@" using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.IO; using System.Reflection; #pragma warning disable 649 namespace MonkeyWrench.DataClasses {{ public partial class DB{0} : DBView {{", name); for (int c = 0; c < columns.Count; c++) { string type; bool is_null = false; ViewColumns col = columns [c]; // Console.WriteLine ("Name: {0}, Column: {1},", col.Name, col.Column); if (col.Name == "id") continue; type = col.Column; if (!col_type_mapping.ContainsKey (type)) { string tbl; if (col.Column.IndexOf ('.') < 0) { Console.WriteLine ("Couldn't find type for column: '{0}' (type: {1})", column, type); continue; } tbl = col.Column.Substring (0, col.Column.IndexOf ('.')); if (table_aliases.ContainsKey (tbl)) { string tbl_alias = table_aliases [tbl]; type = tbl_alias + "." + col.Column.Substring (col.Column.IndexOf ('.') + 1); if (!col_type_mapping.ContainsKey (type)) { Console.WriteLine ("Couldn't find type for column: '{0}' (type: {1} aliased table: {2}={3})", column, type, tbl, tbl_alias); continue; } } // Console.WriteLine ("Found column in aliased table."); } mtype = col_type_mapping [type]; if (col_type_isnull_mapping.ContainsKey (type)) { is_null = col_type_isnull_mapping [type]; Console.WriteLine ("{0} isnull: {1}", type, is_null); } all_columns.Add (col.Name); if (is_null && !mtype.EndsWith ("?")) mtype += "?"; Console.WriteLine ("Found mtype {0} for column {1} type {2}", mtype, column, type); writer.WriteLine ("\t\tprivate {0} _{1};", mtype, col.Name); builder.AppendFormat ("\t\tpublic {0} @{1} {{ get {{ return _{1}; }} set {{ _{1} = value; }} }}\n", mtype, col.Name); } writer.WriteLine (""); writer.WriteLine (builder.ToString ()); writer.WriteLine (""); writer.WriteLine ("\t\tpublic const string SQL = \n@\"{0}\";", sql.Replace ("\"", "\\\"").Replace ("\t\t", "\t ").Replace ("\t", "\n\t").Replace ("\t ", "\t\t")); writer.WriteLine (""); writer.WriteLine (@" private static string [] _fields_ = new string [] {{ ""{0}"" }}; public override string [] Fields {{ get {{ return _fields_; }} }} ", string.Join ("\", \"", all_columns.ToArray ())); writer.WriteLine (@" public DB{0} () {{ }} public DB{0} (IDataReader reader) : base (reader) {{ }} ", name); writer.WriteLine (@" } } "); } Console.WriteLine ("View '{1}' written to {0}", filename, name); }