5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
28 using System.Collections.Generic;
\r
31 using System.Xml.Serialization;
\r
32 using DbLinq.Vendor;
\r
35 namespace DbMetal.Schema
\r
37 public class TableAlias
\r
39 public class Renamings : INameAliases
\r
41 [XmlElement("Renaming")]
\r
42 public readonly List<Renaming> Arr = new List<Renaming>();
\r
44 protected string GetAlias(string name)
\r
46 return (from r in Arr where r.old == name select r.@new).SingleOrDefault();
\r
49 public string GetTableTypeAlias(string table, string schema)
\r
51 return GetAlias(table);
\r
54 public string GetTableMemberAlias(string table, string schema)
\r
59 public string GetColumnMemberAlias(string column, string table, string schema)
\r
61 return GetAlias(column);
\r
64 public string GetColumnForcedType(string column, string table, string schema)
\r
66 return GetAlias(column);
\r
70 public class Renaming
\r
78 public static Renamings Load(string fileName)
\r
80 using (var stream = File.OpenRead(fileName))
\r
82 var renamingsXmlSerializer = new XmlSerializer(typeof(Renamings));
\r
83 var renamings = (Renamings)renamingsXmlSerializer.Deserialize(stream);
\r
88 public static IDictionary<string, string> Load(string fileName, Parameters parameters)
\r
90 if (!System.IO.File.Exists(fileName))
\r
91 throw new ArgumentException("Renames file missing:" + parameters.Aliases);
\r
93 Console.WriteLine("Loading renames file: " + fileName);
\r
95 Renamings renamings = Load(parameters.Aliases);
\r
97 Dictionary<string, string> aliases = new Dictionary<string, string>();
\r
98 foreach (Renaming renaming in renamings.Arr)
\r
100 aliases[renaming.old] = renaming.@new;
\r
105 public static IDictionary<string, string> Load(Parameters parameters)
\r
107 if (parameters.Aliases == null)
\r
108 return new Dictionary<string, string>();
\r
109 return Load(parameters.Aliases, parameters);
\r