public Implementations FindImplementations(PropertyRoute route) { if (route.PropertyRouteType == PropertyRouteType.LiteEntity) { route = route.Parent; } Type type = route.RootType; if (!Tables.ContainsKey(type)) { return(Schema.Current.Settings.GetImplementations(route)); } Field field = TryFindField(Table(type), route.Members); //if (field == null) // return Implementations.ByAll; FieldReference refField = field as FieldReference; if (refField != null) { return(Implementations.By(refField.FieldType.CleanType())); } FieldImplementedBy ibField = field as FieldImplementedBy; if (ibField != null) { return(Implementations.By(ibField.ImplementationColumns.Keys.ToArray())); } FieldImplementedByAll ibaField = field as FieldImplementedByAll; if (ibaField != null) { return(Implementations.ByAll); } Implementations?implementations = CalculateExpressionImplementations(route); if (implementations != null) { return(implementations.Value); } var ss = Schema.Current.Settings; if (route.Follow(r => r.Parent) .TakeWhile(t => t.PropertyRouteType != PropertyRouteType.Root) .Any(r => ss.FieldAttribute <IgnoreAttribute>(r) != null)) { var ib = ss.FieldAttribute <ImplementedByAttribute>(route); var iba = ss.FieldAttribute <ImplementedByAllAttribute>(route); return(Implementations.TryFromAttributes(route.Type.CleanType(), route, ib, iba) ?? Implementations.By()); } throw new InvalidOperationException("Impossible to determine implementations for {0}".FormatWith(route, typeof(IEntity).Name)); }
private bool TryGetTable(IContext context, SqlConnection connection, string modelName, out Discovery.SqlTable table) { bool b = false; table = null; string s = String.Empty; if (!IsCacheLoaded(connection)) { LoadCache(connection); } if (Tables.ContainsKey(connection.ConnectionString)) { List <XF.Common.Discovery.SqlTable> list = Tables[connection.ConnectionString]; if (list != null && list.Count > 0) { var found = list.Find(x => x.TableName.Equals(modelName, StringComparison.OrdinalIgnoreCase)); if (found != null) { table = found; b = true; } } } return(b); }
public bool Buy(int table, params string[] p) { if (1 <= table && table <= 30) { if (!Tables.ContainsKey(table)) { Tables.Add(table, new List <Product>()); } foreach (var item in p) { var product = Menu[item.ToLower().Trim()]; Tables[table].Add(product); sellsCount++; sellsMoney += product.Price; if (!sellsByCategory.ContainsKey(product.Category)) { sellsByCategory.Add(product.Category, new Pair <int, decimal>()); } sellsByCategory[product.Category].First++; sellsByCategory[product.Category].Second += product.Price; } return(true); } else { return(false); } }
public List <T> Get <T>(Dictionary <string, object> criteria, bool loadChildren) { if (Tables.ContainsKey(typeof(T))) { TableData tableData = Tables[typeof(T)]; string sql = SQLBuilder.BuildSelect(tableData.TableName, criteria); if (loadChildren && tableData.LinkedTables != null && tableData.LinkedTables.Count > 0) { foreach (TableData.TableAssociation tableAssociation in tableData.LinkedTables) { sql += string.Format("{0}{0}{1}", Environment.NewLine, SQLBuilder.BuildLinkedTableSelect(tableAssociation.ParentTable.TableName, tableAssociation.LinkedColumnOnParent, tableAssociation.ChildTable.TableName, tableAssociation.LinkedColumnOnChild, criteria)); } } return(ExecuteSelect <T>(sql)); } else { return(null); } }
public void AppendFrom(ITable table) { if (Tables.Count == 0) { SelectTable = table; } string key = table.Datasource + table.Owner + table.Name; if (Tables.Count > 1 && !JoinInWhereClause) { Tables.Clear(); Tables.Add(key, SelectTable); } if (Tables.Count > 0 && !JoinInWhereClause) { return; } if (!Tables.ContainsKey(key)) { Tables.Add(key, table); } }
private T MapRowToObject <T>(DataRow row) { T resultObj = default(T); if (Tables.ContainsKey(typeof(T)) && row != null) { resultObj = ComponentContainer.Resolve <T>(); TableData table = Tables[typeof(T)]; table.ColumnMappings.ToList().ForEach(columAndPropMapping => { if (row.Table.Columns.Contains(columAndPropMapping.Key)) { object objValue = row[columAndPropMapping.Key]; if (columAndPropMapping.Value.PropertyType == objValue.GetType()) { columAndPropMapping.Value.SetValue(resultObj, objValue, null); } } }); } return(resultObj); }
public MemoryRepository() { tableName = typeof(T).Name; if (!Tables.ContainsKey(tableName)) { Tables.Add(tableName, new List <T>()); } }
/// <summary> /// Execute a request on the database schema (Create, Update or Delete a record for an existing table) /// on depends on the restriction view for the area and the profile /// </summary> /// <param name="database"></param> /// <param name="tick"></param> /// <param name="customerId"></param> /// <param name="userId"></param> /// <param name="area"></param> /// <param name="profile"></param> /// <param name="table"></param> /// <param name="action"></param> /// <param name="id"></param> /// <param name="record"></param> /// <returns></returns> public void OnAfterExecuteRequest(DatabaseContext database, int tick, int customerId, int userId, string area, UserProfile.EUserProfile profile, string table, string action, int id, DSRecord record) { if (!Tables.ContainsKey(table)) { throw new ExceptionDefinitionRecord("ERR_REQUEST_UNKNOWN"); } Tables[table].OnAfterExecuteRequest(database, tick, customerId, userId, area, profile, action, id, record); }
/// <summary> /// Look for the record Id of the request /// </summary> /// <param name="database"></param> /// <param name="userId"></param> /// <param name="table"></param> /// <param name="action"></param> /// <param name="record"></param> /// <param name="identity"></param> /// <returns></returns> public int GetRecordId(DatabaseContext database, int userId, string table, string action, JObject record, JObject identity) { if (!Tables.ContainsKey(table)) { return(-1); } return(Tables[table].GetRecordId(database, userId, action, record, identity)); }
private HashSet <string> GetTables(string key) { if (!Tables.ContainsKey(key)) { var tables = new HashSet <string>(); Tables.Add(key, tables); } return(Tables[key]); }
private AzureTableReference GetOrCreate <T>() { if (!Tables.ContainsKey(typeof(T))) { var table = Client.GetTableReference(typeof(T).Name.ToLower()); table.CreateIfNotExistsAsync().Wait(); Tables.Add(typeof(T), new AzureTableReference(table)); } return(Tables[typeof(T)]); }
private List <T> MapDataToObjects <T>(DataSet results) { Dictionary <object, T> resultList = null; if (Tables.ContainsKey(typeof(T)) && results != null && results.Tables != null && results.Tables.Count > 0) { TableData primaryTable = Tables[typeof(T)]; resultList = new Dictionary <object, T>(); DataTable primaryResults = results.Tables[0]; foreach (DataRow dataRow in primaryResults.Rows) { object key = dataRow[primaryTable.KeyColumn]; T result = MapRowToObject <T>(dataRow); resultList.Add(key, result); } if (results.Tables.Count > 1 && primaryTable.LinkedTables.Count > 0) { for (int i = 1; i < results.Tables.Count; i++) { DataTable currentTable = results.Tables[i]; TableData.TableAssociation tableAssociation = primaryTable.LinkedTables[i - 1]; if (Tables.ContainsKey(tableAssociation.ChildTable.ObjectType)) { Type childType = tableAssociation.ChildTable.ObjectType; foreach (DataRow childRow in currentTable.Rows) { object parentKey = childRow[tableAssociation.LinkedColumnOnChild]; if (resultList.ContainsKey(parentKey)) { T parent = resultList[parentKey]; object child = MapRowToObject(childType, childRow); if (tableAssociation.ParentProperty != null) { SetValueOnLinkedProperty(parent, tableAssociation.ParentProperty, childType, child); } if (tableAssociation.ChildProperty != null) { SetValueOnLinkedProperty(child, tableAssociation.ChildProperty, typeof(T), parent); } } } } } } } return(resultList.Values.ToList()); }
/// <summary> /// Retrieve for each row in the database for the given table, /// Each columns within only the expected columns due to the restriction in area and profile /// </summary> /// <param name="database"></param> /// <param name="table"></param> /// <param name="customerId"></param> /// <param name="userId"></param> /// <param name="profile"></param> /// <param name="area"></param> /// <param name="recordId"></param> /// <param name="existingRecords">Define it to replace the loading into the database</param> /// <returns></returns> public IEnumerable <object[]> ReadTable(DatabaseContext database, string table, int customerId, int userId, UserProfile.EUserProfile profile, string area, int?recordId, List <DSRecord> existingRecords) { if (!Tables.ContainsKey(table)) { return(Enumerable.Empty <object[]>()); } // Retrieve the list of columns to return return(Tables[table].ReadTable(database, customerId, userId, profile, area, recordId, existingRecords)); }
private CloudTable GetTable() { lock (Tables) { if (!Tables.ContainsKey(TableName)) { Tables.Add(TableName, Client.GetTableReference(TableName)); Create(); } } return(Tables[TableName]); }
/// <summary> /// Convert the schema into JSON /// </summary> /// <param name="area">if null, all tables, else tables and columns having the restriction to the area</param> /// <param name="profile">if None, all tables, else tables and columns having the restriction to the profile</param> /// <param name="cache">if null, no order, else list of tables in the expected order</param> /// <returns></returns> public JObject ToJSON(string area, UserProfile.EUserProfile profile, DSCache cache) { JObject result = new JObject(); if (cache == null) { foreach (KeyValuePair <string, DSTable> table in Tables) { JObject tableDescription = table.Value.ToJSON(area, profile); if (tableDescription != null) { result[table.Key] = tableDescription; } } } else { foreach (string table in cache.Tables) { if (!Tables.ContainsKey(table)) { continue; } JObject tableDescription = Tables[table].ToJSON(area, profile); if (tableDescription != null) { result[table] = tableDescription; } } foreach (KeyValuePair <string, DSTable> table in Tables) { if (cache.Tables.IndexOf(table.Key) >= 0) { continue; } JObject tableDescription = table.Value.ToJSON(area, profile); if (tableDescription != null) { result[table.Key] = tableDescription; } } } return(result); }
public void BindTableResult(IAnalysisResult tableResult, IParser parser) { if (string.IsNullOrWhiteSpace(tableResult.Name)) { parser.ReportSyntaxError(tableResult.LocationIndex, tableResult.LocationIndex + 1, "Database table found with no name.", Severity.Error); } else { if (!Tables.ContainsKey(tableResult.Name)) { Tables.Add(tableResult.Name, tableResult); } } }
private SmartTable FindSmartTable(string path) { if (Tables.ContainsKey(path)) { return(Tables[path]); } else { SmartTable newTable = new SmartTable(); newTable.Files = new List <TablePair>(); Tables.Add(path, newTable); return(newTable); } }
/// <summary> /// 加载区域下的某个类型的列表 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="table"></param> public void Load(DBTable table) { lock (tablesLock) { Type t = table.ObjectType; if (!Tables.ContainsKey(t)) { Tables.Add(t, table); } else { Tables[t] = table; } } }
public string GetKey <T>(T obj) { if (Tables.ContainsKey(typeof(T))) { return(Tables[typeof(T)].GetKey <T>(obj)); } else if (obj != null) { return(obj.ToString()); } else { return(null); } }
public PackageClass GetClasses(string name) { if (Messages.ContainsKey(name)) { return(Messages[name]); } else if (Tables.ContainsKey(name)) { return(Tables[name]); } else if (Classes.ContainsKey(name)) { return(Classes[name]); } throw new Exception($"找不到自定义类 : {name}"); }
/// <summary> /// Execute a request on the database schema (Create, Update or Delete a record for an existing table) /// on depends on the restriction view for the area and the profile /// </summary> /// <param name="database"></param> /// <param name="transaction"></param> /// <param name="lot"></param> /// <returns></returns> public List <Tuple <DSRecord, InformationRecord> > ExecuteRequest(DatabaseContext database, DSTransaction transaction, List <DSRequest> lot) { if (lot.Count == 0) { return(new List <Tuple <DSRecord, InformationRecord> >()); } DSRequest reference = lot[0]; if (!Tables.ContainsKey(reference.Table)) { throw new ExceptionDefinitionRecord("ERR_REQUEST_UNKNOWN"); } return(Tables[reference.Table].ExecuteRequest(database, transaction, reference.Action, lot)); }
internal bool Remove(int tableHash, string type) { if (Tables != null && (type == null || type == "U") && Tables.ContainsKey(tableHash)) { return(Tables.Remove(tableHash)); } if (Views != null && (type == null || type == "V") && Views.ContainsKey(tableHash)) { return(Views.Remove(tableHash)); } if (Procs != null && (type == null || type == "P") && Procs.ContainsKey(tableHash)) { return(Procs.Remove(tableHash)); } return(false); }
internal TableInfo GetTableInfo(int tableHash, string type) { if (Tables != null && (type == null || type == "U") && Tables.ContainsKey(tableHash)) { return(Tables[tableHash]); } if (Views != null && (type == null || type == "V") && Views.ContainsKey(tableHash)) { return(Views[tableHash]); } if (Procs != null && (type == null || type == "P") && Procs.ContainsKey(tableHash)) { return(Procs[tableHash]); } return(null); }
public ITable[] ConvertToRecord(string path, Type type) { List <ITable> records = new List <ITable>(); if (Tables.ContainsKey(path) == false) { throw new Exception("Table is missing: " + path); } SmartTable table = Tables[path]; foreach (var file in table.Files) { records.Add((ITable)JsonConvert.DeserializeObject(file.Value, type)); } return(records.ToArray()); }
internal string GetTableName(Type entityType) { if (!Tables.ContainsKey(entityType)) { lock (_tablesLock) { if (!Tables.ContainsKey(entityType)) { string tableName = GetMapStrategy(entityType).MapTable(entityType); Tables.Add(entityType, tableName); return(tableName); } } } return(Tables[entityType]); }
public List <T> GetAll <T>(bool loadChildren) { List <T> objects = null; if (Tables.ContainsKey(typeof(T))) { if (Tables[typeof(T)].CacheData && CachedData.ContainsKey(typeof(T))) { objects = CachedData[typeof(T)] as List <T>; } else { objects = ExecuteSelect <T>(SQLBuilder.BuildSelect(Tables[typeof(T)].TableName)); } } return(objects); }
public IMobileServiceSyncTable <TEntity> GetTable <TEntity>() where TEntity : class, IEntity { try { var tableName = typeof(TEntity).Name; if (!Tables.ContainsKey(tableName)) { Tables.Add(tableName, Client.GetSyncTable <TEntity>() as object); } return(Tables[tableName] as IMobileServiceSyncTable <TEntity>); } catch (Exception err) { Log.Log.Instance.AddLog(err); } return(null); }
public override void Write(System.IO.Stream stream, ushort[] glyfIndexes, FontMap map) { string[] tags = { "CFF ", "head", "hhea", "hmtx", "maxp", "name", "post" }; int count = tags.Length; writeHeader(stream, 1330926671); byte[][] bytes = new byte[count][]; long offset = 12 + 16 * count; int curTable = 0; for (int i = 0; i < tags.Length; ++i) { if (Tables.ContainsKey(tags[i])) { OffsetTable table = Tables[tags[i]]; byte[] buffer; if (table.Table is CMapTable) { buffer = (table.Table as CMapTable).GetData(map); } else { buffer = table.Table.GetData(glyfIndexes); } bytes[curTable] = buffer; table.Length = buffer.Length; table.Checksum = calculateCheckSum(buffer); table.Offset = offset; table.Write(stream); offset += buffer.Length; ++curTable; } } for (int i = 0; i < bytes.Length; ++i) { byte[] buf = bytes[i]; stream.Write(buf, 0, buf.Length); } }
public Dictionary <Guid, KeyValuePair <PropertyInfo, object> > AddInsertScript(StringBuilder persistScript) { Dictionary <Guid, KeyValuePair <PropertyInfo, object> > inserts = new Dictionary <Guid, KeyValuePair <PropertyInfo, object> >(); foreach (object addObj in Changes[ChangeType.Add]) { if (addObj != null) { Type addType = addObj.GetType(); if (Tables.ContainsKey(addType)) { TableData tableData = Tables[addType]; Dictionary <string, object> columnValues = tableData.ColumnMappings.Where(kvp => string.Compare(kvp.Key, tableData.KeyColumn, true) != 0) .ToDictionary(cm => cm.Key, cm => cm.Value.GetValue(addObj, null)); if (inserts.Count == 0) { persistScript.Append(SQLBuilder.OutputTableScript); } Guid insertKey = Guid.NewGuid(); persistScript.AppendLine(SQLBuilder.BuildInsert(tableData.TableName, insertKey.ToString(), tableData.KeyColumn, columnValues)); inserts.Add(insertKey, new KeyValuePair <PropertyInfo, object>(tableData.KeyProperty, addObj)); // invalidate cache data if (CachedData.ContainsKey(addType)) { CachedData.Remove(addType); } } } } if (inserts.Count > 0) { persistScript.AppendLine(SQLBuilder.OutputSelectScript); } return(inserts); }
public void EnsureVisible(IEnumerable <Table> tables, bool hideOthers) { var incr = 10; foreach (var t in tables) { if (!Tables.ContainsKey(t)) { Add(t, incr); incr += 12; } } if (hideOthers) { foreach (var t in Tables.Keys.Except(tables).ToList()) { Hide(Tables[t]); } } }