/// <summary> /// <para>Creates a CMSSolutions.Collections.Generic.PairCollection<TFirst,TSecond> from a System.Collections.Generic.IEnumerable<T></para> /// <para>according to specified first and second selector functions.</para> /// </summary> /// <typeparam name="TSource">The type of the elements of source.</typeparam> /// <typeparam name="TFirst">The type of the First returned by firstSelector.</typeparam> /// <typeparam name="TSecond">The type of the Second returned by secondSelector.</typeparam> /// <param name="source">An System.Collections.Generic.IEnumerable<T> to create a CMSSolutions.Collections.Generic.PairCollection<TFirst,TSecond> from</param> /// <param name="firstSelector">A transform function to produce a result element First from each element.</param> /// <param name="secondSelector">A transform function to produce a result element Second from each element.</param> /// <returns> /// <para>A CMSSolutions.Collections.Generic.PairCollection<TFirst,TSecond> that contains values</para> /// <para> of type TFirst and TSecond selected from the input sequence.</para> /// </returns> public static PairList <TFirst, TSecond> ToPairList <TSource, TFirst, TSecond>( this IEnumerable <TSource> source, Func <TSource, TFirst> firstSelector, Func <TSource, TSecond> secondSelector) { if (source == null) { throw new ArgumentNullException("source"); } if (firstSelector == null) { throw new ArgumentNullException("firstSelector"); } if (secondSelector == null) { throw new ArgumentNullException("secondSelector"); } var dictionary = new PairList <TFirst, TSecond>(); foreach (TSource item in source) { dictionary.Add(firstSelector(item), secondSelector(item)); } return(dictionary); }
private PairList <CFGBlockLogicalConstruct, List <int> > GetOrderedCFGSuccessorToLabelsMap(SwitchData switchData) { //Ugly but effective. Sorry PairList <CFGBlockLogicalConstruct, List <int> > result = new PairList <CFGBlockLogicalConstruct, List <int> >(); Dictionary <InstructionBlock, KeyValuePair <int, List <int> > > blockSuccessorToResultPositionMap = new Dictionary <InstructionBlock, KeyValuePair <int, List <int> > >(); for (int i = 0; i < switchData.OrderedCasesArray.Length; i++) { InstructionBlock instructionBlock = switchData.OrderedCasesArray[i]; if (instructionBlock != switchData.DefaultCase) { KeyValuePair <int, List <int> > positionToLabelListPair; if (!blockSuccessorToResultPositionMap.TryGetValue(instructionBlock, out positionToLabelListPair)) { positionToLabelListPair = new KeyValuePair <int, List <int> >(result.Count, new List <int>()); result.Add(GetCFGLogicalConstructFromBlock(instructionBlock), positionToLabelListPair.Value); blockSuccessorToResultPositionMap.Add(instructionBlock, positionToLabelListPair); } positionToLabelListPair.Value.Add(i); } } return(result); }
public void setStat(byte blockId, int stat, float value) { int block = -1; if (!updatedStats.ContainsKey(blockId)) { updatedStats.Add(blockId, new List <int>()); } if (!updatedStats[blockId].Contains(stat)) { updatedStats[blockId].Add(stat); } while (blockId > 0) { blockId = (byte)(blockId >> 1); ++block; } if (!(value > 0 || value < 0 || value == 0)) //NaN? { System.Diagnostics.Debugger.Break(); } if (!stats[block].ContainsKey(stat)) { stats[block].Add(stat, value); } else { stats[block][stat] = value; } }
public static PairList <string, int> SectionPositionsFromSortedList(IList <IGroupingItem> sortedList) { if (sortedList == null) { return(new PairList <string, int>()); } PairList <string, int> positions = new PairList <string, int>(); string lastGroupingLetter = null; int lastIndex = 0; for (int i = 0; i < sortedList.Count; i++) { string groupingName = sortedList[i].GroupingName; if (groupingName == null || groupingName.Length == 0) { continue; } char firstLetter = Char.ToUpper(groupingName[0]); if (lastGroupingLetter == null || firstLetter != lastGroupingLetter[0]) { lastGroupingLetter = firstLetter.ToString(); lastIndex = i; positions.Add(lastGroupingLetter, lastIndex); } } return(positions); }
public static PairList<string, int> SectionPositionsFromSortedList(IList<IGroupingItem> sortedList) { if (sortedList == null) return new PairList<string, int>(); PairList<string, int> positions = new PairList<string, int>(); string lastGroupingLetter = null; int lastIndex = 0; for (int i = 0; i < sortedList.Count; i++) { string groupingName = sortedList[i].GroupingName; if (groupingName == null || groupingName.Length == 0) continue; char firstLetter = Char.ToUpper(groupingName[0]); if (lastGroupingLetter == null || firstLetter != lastGroupingLetter[0]) { lastGroupingLetter = firstLetter.ToString(); lastIndex = i; positions.Add(lastGroupingLetter, lastIndex); } } return positions; }
public PairList GetAllTableStyleInfoPairs() { var pairs = new PairList(); using (var rdr = ExecuteReader(SqlSelectAllTableStyle)) { while (rdr.Read()) { var styleInfo = GetTableStyleInfoByReader(rdr); var inputType = styleInfo.InputType; if (InputTypeUtils.IsWithStyleItems(inputType)) { styleInfo.StyleItems = DataProvider.TableStyleItemDao.GetStyleItemInfoList(styleInfo.Id); } var key = TableStyleManager.GetCacheKey(styleInfo.RelatedIdentity, styleInfo.TableName, styleInfo.AttributeName); if (!pairs.ContainsKey(key)) { var pair = new Pair(key, styleInfo); pairs.Add(pair); } } rdr.Close(); } return(pairs); }
private void ResetPairList(IEnumerable <NameValuePair> list) { PairList.Clear(); foreach (var x in list) { PairList.Add(x); } }
protected override async Task <int> Delete <TEntity>(TEntity entity, string table, bool @async) { PublicHelper.CheckNull(entity); TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(typeof(TEntity)); PublicHelper.EnsureHasPrimaryKey(typeDescriptor); PairList <PrimitivePropertyDescriptor, object> keyValues = new PairList <PrimitivePropertyDescriptor, object>(typeDescriptor.PrimaryKeys.Count); foreach (PrimitivePropertyDescriptor keyPropertyDescriptor in typeDescriptor.PrimaryKeys) { object keyValue = keyPropertyDescriptor.GetValue(entity); PrimaryKeyHelper.KeyValueNotNull(keyPropertyDescriptor, keyValue); keyValues.Add(keyPropertyDescriptor, keyValue); } PrimitivePropertyDescriptor rowVersionDescriptor = null; if (typeDescriptor.HasRowVersion()) { rowVersionDescriptor = typeDescriptor.RowVersion; var rowVersionValue = typeDescriptor.RowVersion.GetValue(entity); this.EnsureRowVersionValueIsNotNull(rowVersionValue); keyValues.Add(typeDescriptor.RowVersion, rowVersionValue); } DbTable dbTable = PublicHelper.CreateDbTable(typeDescriptor, table); DbExpression conditionExp = PublicHelper.MakeCondition(keyValues, dbTable); DbDeleteExpression e = new DbDeleteExpression(dbTable, conditionExp); int rowsAffected = await this.ExecuteNonQuery(e, @async); if (rowVersionDescriptor != null) { PublicHelper.CauseErrorIfOptimisticUpdateFailed(rowsAffected); } return(rowsAffected); }
private void CreateSwitchConstruct(CFGBlockLogicalConstruct switchBlock, ILogicalConstruct parentConstruct, SwitchData switchData, DominatorTree dominatorTree) { List <KeyValuePair <CFGBlockLogicalConstruct, List <int> > > cfgSuccessorToLabelsMap = GetOrderedCFGSuccessorToLabelsMap(switchData); Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> > validCaseEntryToDominatedNodesMap = GetValidCases(dominatorTree, switchBlock); List <CaseLogicalConstruct> orderedCaseConstructs = new List <CaseLogicalConstruct>(); PairList <List <int>, CFGBlockLogicalConstruct> labelsToCFGSuccessorsList = new PairList <List <int>, CFGBlockLogicalConstruct>(); foreach (KeyValuePair <CFGBlockLogicalConstruct, List <int> > cfgSuccessorToLabelsPair in cfgSuccessorToLabelsMap) { ILogicalConstruct successor; HashSet <ISingleEntrySubGraph> dominatedNodes; if (LogicalFlowUtilities.TryGetParentConstructWithGivenParent(cfgSuccessorToLabelsPair.Key, parentConstruct, out successor) && validCaseEntryToDominatedNodesMap.TryGetValue(successor, out dominatedNodes)) { CaseLogicalConstruct newCaseConstruct = new CaseLogicalConstruct(successor); newCaseConstruct.CaseNumbers.AddRange(cfgSuccessorToLabelsPair.Value); newCaseConstruct.Body.UnionWith(dominatedNodes.Cast <ILogicalConstruct>()); newCaseConstruct.AttachCaseConstructToGraph(); orderedCaseConstructs.Add(newCaseConstruct); } else { labelsToCFGSuccessorsList.Add(cfgSuccessorToLabelsPair.Value, cfgSuccessorToLabelsPair.Key); } } CaseLogicalConstruct defaultCase = null; CFGBlockLogicalConstruct defaultCFGSuccessor = GetCFGLogicalConstructFromBlock(switchData.DefaultCase); ILogicalConstruct defaultSuccessor; HashSet <ISingleEntrySubGraph> defaultCaseNodes; if (LogicalFlowUtilities.TryGetParentConstructWithGivenParent(defaultCFGSuccessor, parentConstruct, out defaultSuccessor) && validCaseEntryToDominatedNodesMap.TryGetValue(defaultSuccessor, out defaultCaseNodes)) { defaultCase = new CaseLogicalConstruct(defaultSuccessor); if (HasSuccessors(defaultCaseNodes)) { defaultCase.Body.UnionWith(defaultCaseNodes.Cast <ILogicalConstruct>()); } defaultCase.AttachCaseConstructToGraph(); } SwitchLogicalConstruct theSwitch = SwitchLogicalConstruct.GroupInSwitchConstruct(switchBlock, orderedCaseConstructs, labelsToCFGSuccessorsList, defaultCase, defaultCFGSuccessor); UpdateDominatorTree(dominatorTree, theSwitch); }
public PairList <byte, List <int> > getAllStats() { var toReturn = new PairList <byte, List <int> >(); for (byte i = 0; i < 5; ++i) { foreach (var kv in stats[i]) { if (!toReturn.ContainsKey((byte)(1 << i))) { toReturn.Add((byte)(1 << i), new List <int>()); } toReturn[(byte)(1 << i)].Add(kv.Item1); } } return(toReturn); }
private void CreateSwitchConstruct(CFGBlockLogicalConstruct switchBlock, ILogicalConstruct parentConstruct, SwitchData switchData, DominatorTree dominatorTree) { stackVariable2 = this.GetOrderedCFGSuccessorToLabelsMap(switchData); V_0 = this.GetValidCases(dominatorTree, switchBlock); V_1 = new List <CaseLogicalConstruct>(); V_2 = new PairList <List <int>, CFGBlockLogicalConstruct>(); V_8 = stackVariable2.GetEnumerator(); try { while (V_8.MoveNext()) { V_9 = V_8.get_Current(); if (!LogicalFlowUtilities.TryGetParentConstructWithGivenParent(V_9.get_Key(), parentConstruct, out V_10) || !V_0.TryGetValue(V_10, out V_11)) { V_2.Add(V_9.get_Value(), V_9.get_Key()); } else { V_12 = new CaseLogicalConstruct(V_10); V_12.get_CaseNumbers().AddRange(V_9.get_Value()); V_12.get_Body().UnionWith(V_11.Cast <ILogicalConstruct>()); V_12.AttachCaseConstructToGraph(); V_1.Add(V_12); } } } finally { ((IDisposable)V_8).Dispose(); } V_3 = null; V_4 = this.GetCFGLogicalConstructFromBlock(switchData.get_DefaultCase()); if (LogicalFlowUtilities.TryGetParentConstructWithGivenParent(V_4, parentConstruct, out V_5) && V_0.TryGetValue(V_5, out V_6)) { V_3 = new CaseLogicalConstruct(V_5); if (this.HasSuccessors(V_6)) { V_3.get_Body().UnionWith(V_6.Cast <ILogicalConstruct>()); } V_3.AttachCaseConstructToGraph(); } V_7 = SwitchLogicalConstruct.GroupInSwitchConstruct(switchBlock, V_1, V_2, V_3, V_4); this.UpdateDominatorTree(dominatorTree, V_7); return; }
public PairList <byte, List <int> > getUpdatedStats() { var ret = new PairList <byte, List <int> >(); lock (updatedStats) { foreach (var blocks in updatedStats) { var retStats = new List <int>(); foreach (var stat in blocks.Item2) { retStats.Add(stat); } ret.Add(blocks.Item1, retStats); } } return(ret); }
public PairList GetAllTableStyleInfoPairs() { var pairs = new PairList(); using (var rdr = ExecuteReader(SqlSelectAllTableStyle)) { while (rdr.Read()) { var styleInfo = GetTableStyleInfoByReader(rdr); var key = TableStyleManager.GetCacheKey(styleInfo.RelatedIdentity, styleInfo.TableName, styleInfo.AttributeName); if (!pairs.ContainsKey(key)) { var pair = new Pair(key, styleInfo); pairs.Add(pair); } } rdr.Close(); } return(pairs); }
private PairList <CFGBlockLogicalConstruct, List <int> > GetOrderedCFGSuccessorToLabelsMap(SwitchData switchData) { V_0 = new PairList <CFGBlockLogicalConstruct, List <int> >(); V_1 = new Dictionary <InstructionBlock, KeyValuePair <int, List <int> > >(); V_2 = 0; while (V_2 < (int)switchData.get_OrderedCasesArray().Length) { V_3 = switchData.get_OrderedCasesArray()[V_2]; if (InstructionBlock.op_Inequality(V_3, switchData.get_DefaultCase())) { if (!V_1.TryGetValue(V_3, out V_4)) { V_4 = new KeyValuePair <int, List <int> >(V_0.get_Count(), new List <int>()); V_0.Add(this.GetCFGLogicalConstructFromBlock(V_3), V_4.get_Value()); V_1.Add(V_3, V_4); } V_4.get_Value().Add(V_2); } V_2 = V_2 + 1; } return(V_0); }
private void AddNumsBtn_Click(object sender, EventArgs e) { try { long[] nums = new long[2]; // nums[0] = a, nums[1] = b nums[0] = long.Parse(EntryATbox.Text); // ERROR HANDLING HERE nums[1] = long.Parse(EntryBTbox.Text); PairList.Add(nums); // add array to PairList property // clear text boxes EntryATbox.Clear(); EntryBTbox.Clear(); AddedNums += String.Format("a = {0}, b = {1}\n", nums[0], nums[1]); AddedNumsTbox.Text = AddedNums; } catch (FormatException fe) { MessageBox.Show("Wrong or missing input. Please enter a and b in a correct format."); } catch (OverflowException oe) { MessageBox.Show("Entered number(s) is too big."); } }
static SqlDbTypeConverter() { netTypes.Add(SqlDbType.BigInt, typeof(Int64)); netTypes.Add(SqlDbType.Binary, typeof(Byte[])); netTypes.Add(SqlDbType.Bit, typeof(Boolean)); netTypes.Add(SqlDbType.Char, typeof(String)); netTypes.Add(SqlDbType.Date, typeof(DateTime)); netTypes.Add(SqlDbType.DateTime, typeof(DateTime)); netTypes.Add(SqlDbType.DateTime2, typeof(DateTime)); netTypes.Add(SqlDbType.DateTimeOffset, typeof(DateTimeOffset)); netTypes.Add(SqlDbType.Decimal, typeof(Decimal)); netTypes.Add(SqlDbType.Float, typeof(Double)); netTypes.Add(SqlDbType.Int, typeof(Int32)); netTypes.Add(SqlDbType.Money, typeof(Decimal)); netTypes.Add(SqlDbType.NChar, typeof(String)); netTypes.Add(SqlDbType.NText, typeof(String)); netTypes.Add(SqlDbType.NVarChar, typeof(String)); netTypes.Add(SqlDbType.Real, typeof(Single)); netTypes.Add(SqlDbType.SmallDateTime, typeof(DateTime)); netTypes.Add(SqlDbType.SmallInt, typeof(Int16)); netTypes.Add(SqlDbType.SmallMoney, typeof(Decimal)); netTypes.Add(SqlDbType.Structured, typeof(Object)); netTypes.Add(SqlDbType.Text, typeof(String)); netTypes.Add(SqlDbType.Time, typeof(TimeSpan)); netTypes.Add(SqlDbType.Timestamp, typeof(Byte[])); netTypes.Add(SqlDbType.TinyInt, typeof(Byte)); netTypes.Add(SqlDbType.Udt, typeof(Object)); netTypes.Add(SqlDbType.UniqueIdentifier, typeof(Guid)); netTypes.Add(SqlDbType.VarBinary, typeof(Byte[])); netTypes.Add(SqlDbType.VarChar, typeof(String)); netTypes.Add(SqlDbType.Variant, typeof(Object)); netTypes.Add(SqlDbType.Xml, typeof(SqlXml)); dbTypes.Add(SqlDbType.BigInt, DbType.Int64); dbTypes.Add(SqlDbType.Binary, DbType.Binary); dbTypes.Add(SqlDbType.Bit, DbType.Boolean); dbTypes.Add(SqlDbType.Char, DbType.StringFixedLength); dbTypes.Add(SqlDbType.Date, DbType.Date); dbTypes.Add(SqlDbType.DateTime, DbType.DateTime); dbTypes.Add(SqlDbType.DateTime2, DbType.DateTime2); dbTypes.Add(SqlDbType.DateTimeOffset, DbType.DateTimeOffset); dbTypes.Add(SqlDbType.Decimal, DbType.Decimal); dbTypes.Add(SqlDbType.Float, DbType.Double); dbTypes.Add(SqlDbType.Int, DbType.Int32); dbTypes.Add(SqlDbType.Money, DbType.Currency); dbTypes.Add(SqlDbType.NChar, DbType.String); dbTypes.Add(SqlDbType.NText, DbType.String); dbTypes.Add(SqlDbType.NVarChar, DbType.String); dbTypes.Add(SqlDbType.Real, DbType.Single); dbTypes.Add(SqlDbType.SmallDateTime, DbType.DateTime); dbTypes.Add(SqlDbType.SmallInt, DbType.Int16); dbTypes.Add(SqlDbType.SmallMoney, DbType.Currency); dbTypes.Add(SqlDbType.Structured, DbType.Object); dbTypes.Add(SqlDbType.Text, DbType.String); dbTypes.Add(SqlDbType.Time, DbType.Time); dbTypes.Add(SqlDbType.Timestamp, DbType.Binary); dbTypes.Add(SqlDbType.TinyInt, DbType.Byte); dbTypes.Add(SqlDbType.Udt, DbType.Object); dbTypes.Add(SqlDbType.UniqueIdentifier, DbType.Guid); dbTypes.Add(SqlDbType.VarBinary, DbType.Binary); dbTypes.Add(SqlDbType.VarChar, DbType.String); dbTypes.Add(SqlDbType.Variant, DbType.Object); dbTypes.Add(SqlDbType.Xml, DbType.Xml); oleDbTypes.Add(SqlDbType.BigInt, OleDbType.BigInt); oleDbTypes.Add(SqlDbType.Binary, OleDbType.Binary); oleDbTypes.Add(SqlDbType.Bit, OleDbType.Boolean); oleDbTypes.Add(SqlDbType.Char, OleDbType.Char); oleDbTypes.Add(SqlDbType.Date, OleDbType.DBTimeStamp); oleDbTypes.Add(SqlDbType.DateTime, OleDbType.DBTimeStamp); oleDbTypes.Add(SqlDbType.DateTime2, OleDbType.DBTimeStamp); oleDbTypes.Add(SqlDbType.DateTimeOffset, OleDbType.VarChar); oleDbTypes.Add(SqlDbType.Decimal, OleDbType.Decimal); oleDbTypes.Add(SqlDbType.Float, OleDbType.Double); oleDbTypes.Add(SqlDbType.Int, OleDbType.Integer); oleDbTypes.Add(SqlDbType.Money, OleDbType.Currency); oleDbTypes.Add(SqlDbType.NChar, OleDbType.Char); oleDbTypes.Add(SqlDbType.NText, OleDbType.VarChar); oleDbTypes.Add(SqlDbType.NVarChar, OleDbType.VarChar); oleDbTypes.Add(SqlDbType.Real, OleDbType.Single); oleDbTypes.Add(SqlDbType.SmallDateTime, OleDbType.DBTimeStamp); oleDbTypes.Add(SqlDbType.SmallInt, OleDbType.SmallInt); oleDbTypes.Add(SqlDbType.SmallMoney, OleDbType.Currency); oleDbTypes.Add(SqlDbType.Structured, OleDbType.Variant); oleDbTypes.Add(SqlDbType.Text, OleDbType.VarChar); oleDbTypes.Add(SqlDbType.Time, OleDbType.DBTime); oleDbTypes.Add(SqlDbType.Timestamp, OleDbType.Binary); oleDbTypes.Add(SqlDbType.TinyInt, OleDbType.TinyInt); oleDbTypes.Add(SqlDbType.Udt, OleDbType.VarChar); oleDbTypes.Add(SqlDbType.UniqueIdentifier, OleDbType.Guid); oleDbTypes.Add(SqlDbType.VarBinary, OleDbType.VarBinary); oleDbTypes.Add(SqlDbType.VarChar, OleDbType.VarChar); oleDbTypes.Add(SqlDbType.Variant, OleDbType.Variant); oleDbTypes.Add(SqlDbType.Xml, OleDbType.VarChar); }
private void InitializeCities() { nationCity = new PairList <string, string>(); // Argentina nationCity.Add("Argentina", "Boca"); nationCity.Add("Argentina", "Buenos Aires"); // England nationCity.Add("England", "London"); nationCity.Add("England", "Birmingham"); nationCity.Add("England", "Liverpool"); nationCity.Add("England", "Manchester"); // Brazil nationCity.Add("Brazil", "Rio de Janeiro"); nationCity.Add("Brazil", "Sao Paulo"); // Canada nationCity.Add("Canada", "Toronto"); nationCity.Add("Canada", "Montreal"); nationCity.Add("Canada", "Vancouver"); nationCity.Add("Canada", "Calgary"); nationCity.Add("Canada", "Winnipeg"); nationCity.Add("Canada", "Ottawa"); nationCity.Add("Canada", "Halifax"); nationCity.Add("Canada", "Quebec"); nationCity.Add("Canada", "Thunder Bay"); nationCity.Add("Canada", "Regina"); nationCity.Add("Canada", "Scarborough"); nationCity.Add("Canada", "Mississauga"); nationCity.Add("Canada", "Edmonton"); nationCity.Add("Canada", "Hamilton"); nationCity.Add("Canada", "Burlington"); nationCity.Add("Canada", "London"); nationCity.Add("Canada", "Niagara Falls"); nationCity.Add("Canada", "Windsor"); // Iceland nationCity.Add("Iceland", "Reykjavik"); nationCity.Add("Iceland", "Kopavogur"); // Denmark nationCity.Add("Denmark", "Copenhagen"); // USA nationCity.Add("USA", "New York"); nationCity.Add("USA", "Boston"); nationCity.Add("USA", "Los Angeles"); }
private void InitializeCities() { nationCity = new PairList<string, string>(); // Argentina nationCity.Add("Argentina", "Boca"); nationCity.Add("Argentina", "Buenos Aires"); // England nationCity.Add("England", "London"); nationCity.Add("England", "Birmingham"); nationCity.Add("England", "Liverpool"); nationCity.Add("England", "Manchester"); // Brazil nationCity.Add("Brazil", "Rio de Janeiro"); nationCity.Add("Brazil", "Sao Paulo"); // Canada nationCity.Add("Canada", "Toronto"); nationCity.Add("Canada", "Montreal"); nationCity.Add("Canada", "Vancouver"); nationCity.Add("Canada", "Calgary"); nationCity.Add("Canada", "Winnipeg"); nationCity.Add("Canada", "Ottawa"); nationCity.Add("Canada", "Halifax"); nationCity.Add("Canada", "Quebec"); nationCity.Add("Canada", "Thunder Bay"); nationCity.Add("Canada", "Regina"); nationCity.Add("Canada", "Scarborough"); nationCity.Add("Canada", "Mississauga"); nationCity.Add("Canada", "Edmonton"); nationCity.Add("Canada", "Hamilton"); nationCity.Add("Canada", "Burlington"); nationCity.Add("Canada", "London"); nationCity.Add("Canada", "Niagara Falls"); nationCity.Add("Canada", "Windsor"); // Iceland nationCity.Add("Iceland", "Reykjavik"); nationCity.Add("Iceland", "Kopavogur"); // Denmark nationCity.Add("Denmark", "Copenhagen"); // USA nationCity.Add("USA", "New York"); nationCity.Add("USA", "Boston"); nationCity.Add("USA", "Los Angeles"); }
private void CheckChildCollisions(PairList<ICollidable> CollisionList) { if (Children != null) for (int i = 0; i < Children.Length; i++) Children[i].CheckChildCollisions(CollisionList); else { Collisions.Clear(); if (Objects.Count >= 2) for (int i = 0; i < Objects.Count - 1; i++) for (int j = i + 1; j < Objects.Count; j++) if (Objects[i].Shape.Intersects(Objects[j].Shape)) { CollisionList.Add(Objects[i], Objects[j]); Collisions.Add(Objects[i], Objects[j]); } } }
private void CheckCollisions(PairList<ICollidable> collisions) { if (!IsDivided() && Objects.Count > 1 && PrimaryCount > 0) { for (var i = 0; i < Objects.Count - 1; i++) { for (var j = i + 1; j < Objects.Count; j++) { if (!Objects[i].Primary && !Objects[j].Primary) continue; if (!Objects[i].Enabled || !Objects[j].Enabled) continue; if (!Objects[i].Shape.Intersects(Objects[j].Shape)) continue; collisions.Add(Objects[i], Objects[j]); } } } else { if (Children != null) for (int i = 0; i < Children.Length; i++) { Children[i].CheckCollisions(collisions); } } }
static SystemTypeConverter() { #region fieldTypes //fieldTypes.Add(FieldType.AutoNumber, typeof(Int32)); fieldTypes.Add(FieldType.Binary, typeof(Byte[])); fieldTypes.Add(FieldType.Byte, typeof(byte)); fieldTypes.Add(FieldType.Boolean, typeof(Boolean)); fieldTypes.Add(FieldType.Char, typeof(Char)); fieldTypes.Add(FieldType.Choice, typeof(String)); fieldTypes.Add(FieldType.Calculated, typeof(String)); fieldTypes.Add(FieldType.Currency, typeof(Decimal)); fieldTypes.Add(FieldType.Date, typeof(DateTime)); fieldTypes.Add(FieldType.DateTime, typeof(DateTime)); fieldTypes.Add(FieldType.DateTimeOffset, typeof(DateTimeOffset)); fieldTypes.Add(FieldType.Decimal, typeof(Decimal)); fieldTypes.Add(FieldType.Double, typeof(Double)); fieldTypes.Add(FieldType.Geometry, typeof(String)); fieldTypes.Add(FieldType.Guid, typeof(Guid)); fieldTypes.Add(FieldType.Int16, typeof(Int16)); fieldTypes.Add(FieldType.Int32, typeof(Int32)); fieldTypes.Add(FieldType.Int64, typeof(Int64)); fieldTypes.Add(FieldType.Lookup, typeof(String)); fieldTypes.Add(FieldType.MultiChoice, typeof(String)); fieldTypes.Add(FieldType.MultiLookup, typeof(String)); fieldTypes.Add(FieldType.MultiUser, typeof(String)); fieldTypes.Add(FieldType.Object, typeof(Object)); fieldTypes.Add(FieldType.RichText, typeof(String)); fieldTypes.Add(FieldType.SByte, typeof(SByte)); fieldTypes.Add(FieldType.Single, typeof(Single)); fieldTypes.Add(FieldType.String, typeof(String)); fieldTypes.Add(FieldType.Time, typeof(TimeSpan)); fieldTypes.Add(FieldType.Timestamp, typeof(Byte[])); fieldTypes.Add(FieldType.UInt16, typeof(UInt16)); fieldTypes.Add(FieldType.UInt32, typeof(UInt32)); fieldTypes.Add(FieldType.UInt64, typeof(UInt64)); fieldTypes.Add(FieldType.Url, typeof(Uri)); fieldTypes.Add(FieldType.User, typeof(String)); fieldTypes.Add(FieldType.Xml, typeof(SqlXml)); #endregion fieldTypes #region netTypes netTypes.Add(typeof(Boolean), FieldType.Boolean); netTypes.Add(typeof(Byte), FieldType.Byte); netTypes.Add(typeof(Char), FieldType.Char); netTypes.Add(typeof(Int16), FieldType.Int16); netTypes.Add(typeof(Int32), FieldType.Int32); netTypes.Add(typeof(Int64), FieldType.Int64); netTypes.Add(typeof(Decimal), FieldType.Decimal); netTypes.Add(typeof(Double), FieldType.Double); netTypes.Add(typeof(DateTime), FieldType.DateTime); netTypes.Add(typeof(DateTimeOffset), FieldType.DateTimeOffset); netTypes.Add(typeof(Guid), FieldType.Guid); netTypes.Add(typeof(Single), FieldType.Single); netTypes.Add(typeof(String), FieldType.String); netTypes.Add(typeof(SByte), FieldType.SByte); netTypes.Add(typeof(TimeSpan), FieldType.Time); netTypes.Add(typeof(UInt16), FieldType.UInt16); netTypes.Add(typeof(UInt32), FieldType.UInt32); netTypes.Add(typeof(UInt64), FieldType.UInt64); netTypes.Add(typeof(Uri), FieldType.Url); #endregion netTypes }
public void Render( ITree tree, IRemote usedRemote, IBranchesKnowledge branchesKnowledge, ITreeRenderingOptions options) { IRemoteWebUrlProvider remoteUrlProvider = _remoteWebUrlProviderFactory.CreateUrlProvider(usedRemote.Url, options.ForceTreatAsGitHub); WriteHeader(); IBranch[] branchesWithNodes = tree.Branches.Where(b => tree.EnumerateNodes(b).Any()).ToArray(); IBranch[] currentBranchesSorted = OrderByFirstCommitDate(branchesWithNodes, tree).ToArray(); IPairList <INode, INode> unwrittenMerges = new PairList <INode, INode>(); IPairList <INode, INode> writtenMerges = new PairList <INode, INode>(); // Main branches. foreach (IBranch b in currentBranchesSorted) { _gvWriter.EmptyLine(); _gvWriter.Comment($"Branch {b.Label}."); using (_gvWriter.StartSubGraph()) { _gvWriter.SetNodeAttributes(AttrSet.Empty.Group(b.Label)); Color drawColor = branchesKnowledge.GetSuggestedDrawingColorFor(b); bool isLesser = branchesKnowledge.IsAWorkItemBranch(b); IAttrSet nodeStyle = _style.GetBranchNodeStyle(drawColor, isLesser); IAttrSet edgeStyle = _style.GetBranchEdgeStyle(drawColor, isLesser); _gvWriter.SetNodeAttributes(nodeStyle); _gvWriter.SetEdgeAttributes(edgeStyle); INode[] nodes = tree.EnumerateNodes(b).ToArray(); for (int i = 0; i < nodes.Length; i++) { INode currentNode = nodes[i]; WriteNode(currentNode, remoteUrlProvider); if (i == 0) { // Starting node. INode parent = currentNode.Parents.FirstOrDefault(); bool hasParent = parent != null; if (!hasParent) { _gvWriter.Comment("Starting line."); string id = string.Format($"{currentNode.Commit.Treeish}_start"); // Write starting empty node. using (_gvWriter.StartSubGraph()) { _gvWriter.RawAttributes(AttrSet.Empty.Rank(RankType.Source)); _gvWriter.Node(id, AttrSet.Empty.Width(0).Height(0).PenWidth(0)); } _gvWriter.Edge(id, currentNode.Commit, _style.EdgeBranchStartVirtual); _gvWriter.EmptyLine(); } else { // It is some other branch, and we draw that edge. WriteEdge(parent, currentNode, remoteUrlProvider); writtenMerges.Add(parent, currentNode); } } bool isLast = i == nodes.Length - 1; INode nextNode = isLast ? null : nodes[i + 1]; if (!isLast) { // Edge to the next node. WriteEdge(currentNode, nextNode, remoteUrlProvider); } else { WriteBranchPointer(b, tree, isLesser, remoteUrlProvider); } INode[] otherChildren = currentNode.Children.Except(nextNode).ToArray(); foreach (INode child in otherChildren) { unwrittenMerges.Add(currentNode, child); } } } } IBranch[] branchesWithoutNodes = tree.Branches.Except(branchesWithNodes).ToArray(); foreach (IBranch b in branchesWithoutNodes) { bool isLesser = branchesKnowledge.IsAWorkItemBranch(b); WriteBranchPointer(b, tree, isLesser, remoteUrlProvider); } // Tags. ITag[] tags = tree.Tags.ToArray(); foreach (ITag t in tags) { _gvWriter.EmptyLine(); INode n = tree.GetNode(t.Tip); string id = MakeNodeIdForPointerLabel(n, t); using (_gvWriter.StartSubGraph()) { _gvWriter.Comment($"Tag {t.Label}."); _gvWriter.RawAttributes(AttrSet.Empty.Rank(RankType.Same)); string url = remoteUrlProvider?.GetTagLink(t); _gvWriter.Node(id, _style.LabelTag.Label(t.Label).Url(url)); _gvWriter.Edge(n.Commit, id, _style.EdgeTagLabel); } } INode[] allLeftOvers = tree.Nodes.Where(n => tree.GetContainingBranch(n) == null).ToArray(); if (allLeftOvers.Length > 0) { using (_gvWriter.StartSubGraph()) { _gvWriter.EmptyLine(); _gvWriter.Comment("Leftover nodes."); _gvWriter.SetNodeAttributes(_style.NodeOrphaned); foreach (INode currentNode in allLeftOvers) { WriteNode(currentNode, remoteUrlProvider); // Remember children. foreach (INode child in currentNode.Children) { unwrittenMerges.Add(currentNode, child); } } } } PairList <INode, INode> edgesToWrite = unwrittenMerges.Except(writtenMerges).ToPairList(); if (edgesToWrite.Count > 0) { using (_gvWriter.StartSubGraph()) { _gvWriter.EmptyLine(); _gvWriter.Comment("Other edges."); _gvWriter.SetEdgeAttributes(_style.EdgeOther); foreach (Tuple <INode, INode> edge in edgesToWrite) { _gvWriter.Edge(edge.Item1.Commit, edge.Item2.Commit); } } } WriteFooter(); }
public PairList<byte, List<int>> getAllStats() { var toReturn = new PairList<byte, List<int>>(); for (byte i = 0; i < 5; ++i) { foreach (var kv in stats[i]) { if (!toReturn.ContainsKey((byte)(1 << i))) toReturn.Add((byte)(1 << i), new List<int>()); toReturn[(byte)(1 << i)].Add(kv.Item1); } } return toReturn; }
static DbTypeConverter() { netTypes.Add(DbType.AnsiString, typeof(String)); netTypes.Add(DbType.AnsiStringFixedLength, typeof(Char)); netTypes.Add(DbType.Binary, typeof(Byte[])); netTypes.Add(DbType.Boolean, typeof(Boolean)); netTypes.Add(DbType.Byte, typeof(Byte)); netTypes.Add(DbType.Currency, typeof(Decimal)); netTypes.Add(DbType.Date, typeof(DateTime)); netTypes.Add(DbType.DateTime, typeof(DateTime)); netTypes.Add(DbType.DateTime2, typeof(DateTime)); netTypes.Add(DbType.DateTimeOffset, typeof(DateTimeOffset)); netTypes.Add(DbType.Decimal, typeof(Decimal)); netTypes.Add(DbType.Double, typeof(Double)); netTypes.Add(DbType.Guid, typeof(Guid)); netTypes.Add(DbType.Int16, typeof(Int16)); netTypes.Add(DbType.Int32, typeof(Int32)); netTypes.Add(DbType.Int64, typeof(Int64)); netTypes.Add(DbType.Object, typeof(Object)); netTypes.Add(DbType.SByte, typeof(SByte)); netTypes.Add(DbType.Single, typeof(Single)); netTypes.Add(DbType.String, typeof(String)); netTypes.Add(DbType.StringFixedLength, typeof(Char)); netTypes.Add(DbType.Time, typeof(TimeSpan)); netTypes.Add(DbType.UInt16, typeof(UInt16)); netTypes.Add(DbType.UInt32, typeof(UInt32)); netTypes.Add(DbType.UInt64, typeof(UInt64)); netTypes.Add(DbType.VarNumeric, typeof(Int32)); netTypes.Add(DbType.Xml, typeof(SqlXml)); sqlDbTypes.Add(DbType.AnsiString, SqlDbType.VarChar); sqlDbTypes.Add(DbType.AnsiStringFixedLength, SqlDbType.Char); sqlDbTypes.Add(DbType.Binary, SqlDbType.Binary); sqlDbTypes.Add(DbType.Boolean, SqlDbType.Bit); sqlDbTypes.Add(DbType.Byte, SqlDbType.TinyInt); sqlDbTypes.Add(DbType.Currency, SqlDbType.Money); sqlDbTypes.Add(DbType.Date, SqlDbType.Date); sqlDbTypes.Add(DbType.DateTime, SqlDbType.DateTime); sqlDbTypes.Add(DbType.DateTime2, SqlDbType.DateTime2); sqlDbTypes.Add(DbType.DateTimeOffset, SqlDbType.DateTimeOffset); sqlDbTypes.Add(DbType.Decimal, SqlDbType.Decimal); sqlDbTypes.Add(DbType.Double, SqlDbType.Float); sqlDbTypes.Add(DbType.Guid, SqlDbType.UniqueIdentifier); sqlDbTypes.Add(DbType.Int16, SqlDbType.SmallInt); sqlDbTypes.Add(DbType.Int32, SqlDbType.Int); sqlDbTypes.Add(DbType.Int64, SqlDbType.BigInt); sqlDbTypes.Add(DbType.Object, SqlDbType.Variant); sqlDbTypes.Add(DbType.SByte, SqlDbType.TinyInt); sqlDbTypes.Add(DbType.Single, SqlDbType.Real); sqlDbTypes.Add(DbType.String, SqlDbType.NVarChar); sqlDbTypes.Add(DbType.StringFixedLength, SqlDbType.NChar); sqlDbTypes.Add(DbType.Time, SqlDbType.Time); sqlDbTypes.Add(DbType.UInt16, SqlDbType.SmallInt); sqlDbTypes.Add(DbType.UInt32, SqlDbType.Int); sqlDbTypes.Add(DbType.UInt64, SqlDbType.BigInt); sqlDbTypes.Add(DbType.VarNumeric, SqlDbType.Int); sqlDbTypes.Add(DbType.Xml, SqlDbType.Xml); oleDbTypes.Add(DbType.AnsiString, OleDbType.VarChar); oleDbTypes.Add(DbType.AnsiStringFixedLength, OleDbType.Char); oleDbTypes.Add(DbType.Binary, OleDbType.Binary); oleDbTypes.Add(DbType.Boolean, OleDbType.Boolean); oleDbTypes.Add(DbType.Byte, OleDbType.UnsignedTinyInt); oleDbTypes.Add(DbType.Currency, OleDbType.Currency); oleDbTypes.Add(DbType.Date, OleDbType.Date); oleDbTypes.Add(DbType.DateTime, OleDbType.DBTimeStamp); oleDbTypes.Add(DbType.DateTime2, OleDbType.DBTimeStamp); oleDbTypes.Add(DbType.DateTimeOffset, OleDbType.VarChar); oleDbTypes.Add(DbType.Decimal, OleDbType.Decimal); oleDbTypes.Add(DbType.Double, OleDbType.Double); oleDbTypes.Add(DbType.Guid, OleDbType.Guid); oleDbTypes.Add(DbType.Int16, OleDbType.SmallInt); oleDbTypes.Add(DbType.Int32, OleDbType.Integer); oleDbTypes.Add(DbType.Int64, OleDbType.BigInt); oleDbTypes.Add(DbType.Object, OleDbType.Variant); oleDbTypes.Add(DbType.SByte, OleDbType.TinyInt); oleDbTypes.Add(DbType.Single, OleDbType.Single); oleDbTypes.Add(DbType.String, OleDbType.VarChar); oleDbTypes.Add(DbType.StringFixedLength, OleDbType.Char); oleDbTypes.Add(DbType.Time, OleDbType.DBTime); oleDbTypes.Add(DbType.UInt16, OleDbType.UnsignedSmallInt); oleDbTypes.Add(DbType.UInt32, OleDbType.UnsignedInt); oleDbTypes.Add(DbType.UInt64, OleDbType.UnsignedBigInt); oleDbTypes.Add(DbType.VarNumeric, OleDbType.VarNumeric); oleDbTypes.Add(DbType.Xml, OleDbType.VarChar); }
static SystemTypeConverter() { dbTypes.Add(typeof(Boolean), DbType.Boolean); dbTypes.Add(typeof(Byte), DbType.Byte); dbTypes.Add(typeof(Char), DbType.StringFixedLength); dbTypes.Add(typeof(Int16), DbType.Int16); dbTypes.Add(typeof(Int32), DbType.Int32); dbTypes.Add(typeof(Int64), DbType.Int64); dbTypes.Add(typeof(Decimal), DbType.Decimal); dbTypes.Add(typeof(Double), DbType.Double); dbTypes.Add(typeof(DateTime), DbType.DateTime); dbTypes.Add(typeof(DateTimeOffset), DbType.DateTimeOffset); dbTypes.Add(typeof(Guid), DbType.Guid); dbTypes.Add(typeof(Single), DbType.Single); dbTypes.Add(typeof(String), DbType.String); dbTypes.Add(typeof(SByte), DbType.SByte); dbTypes.Add(typeof(TimeSpan), DbType.Time); dbTypes.Add(typeof(UInt16), DbType.UInt16); dbTypes.Add(typeof(UInt32), DbType.UInt32); dbTypes.Add(typeof(UInt64), DbType.UInt64); dbTypes.Add(typeof(Uri), DbType.String); sqlDbTypes.Add(typeof(Boolean), SqlDbType.Bit); sqlDbTypes.Add(typeof(Byte), SqlDbType.TinyInt); sqlDbTypes.Add(typeof(Char), SqlDbType.NChar); sqlDbTypes.Add(typeof(Int16), SqlDbType.SmallInt); sqlDbTypes.Add(typeof(Int32), SqlDbType.Int); sqlDbTypes.Add(typeof(Int64), SqlDbType.BigInt); sqlDbTypes.Add(typeof(Decimal), SqlDbType.Decimal); sqlDbTypes.Add(typeof(Double), SqlDbType.Float); sqlDbTypes.Add(typeof(DateTime), SqlDbType.DateTime); sqlDbTypes.Add(typeof(DateTimeOffset), SqlDbType.DateTimeOffset); sqlDbTypes.Add(typeof(Guid), SqlDbType.UniqueIdentifier); sqlDbTypes.Add(typeof(Single), SqlDbType.Real); sqlDbTypes.Add(typeof(String), SqlDbType.NVarChar); sqlDbTypes.Add(typeof(SByte), SqlDbType.TinyInt); sqlDbTypes.Add(typeof(TimeSpan), SqlDbType.Time); sqlDbTypes.Add(typeof(UInt16), SqlDbType.SmallInt); sqlDbTypes.Add(typeof(UInt32), SqlDbType.Int); sqlDbTypes.Add(typeof(UInt64), SqlDbType.BigInt); sqlDbTypes.Add(typeof(Uri), SqlDbType.NVarChar); oleDbTypes.Add(typeof(Boolean), OleDbType.Boolean); oleDbTypes.Add(typeof(Byte), OleDbType.UnsignedTinyInt); oleDbTypes.Add(typeof(Char), OleDbType.Char);//check oleDbTypes.Add(typeof(Int16), OleDbType.SmallInt); oleDbTypes.Add(typeof(Int32), OleDbType.Integer); oleDbTypes.Add(typeof(Int64), OleDbType.BigInt); oleDbTypes.Add(typeof(Decimal), OleDbType.Decimal); oleDbTypes.Add(typeof(Double), OleDbType.Double); oleDbTypes.Add(typeof(DateTime), OleDbType.DBTimeStamp); oleDbTypes.Add(typeof(DateTimeOffset), OleDbType.VarChar); oleDbTypes.Add(typeof(Guid), OleDbType.Guid); oleDbTypes.Add(typeof(Single), OleDbType.Single); oleDbTypes.Add(typeof(String), OleDbType.VarChar); oleDbTypes.Add(typeof(SByte), OleDbType.TinyInt); oleDbTypes.Add(typeof(TimeSpan), OleDbType.DBTime); oleDbTypes.Add(typeof(UInt16), OleDbType.UnsignedSmallInt); oleDbTypes.Add(typeof(UInt32), OleDbType.UnsignedInt); oleDbTypes.Add(typeof(UInt64), OleDbType.UnsignedBigInt); oleDbTypes.Add(typeof(Uri), OleDbType.VarChar); }
/// <summary> /// Loads the map with the given path /// </summary> /// <param name="path">map path</param> /// <returns>true if successful and map is playable, false otherwise</returns> public override bool LoadMap(string path) { currentWaveId = -1; random = new Random(); this.path = path; // Clear all data from previous maps try { string[] tempFiles = Directory.GetFiles(directory + "temp"); foreach (string s in tempFiles) File.Delete(s); } catch (Exception) { } // Set the map name mapName = path.Substring(path.LastIndexOf("\\") + 1).Replace(".thld", ""); try { // Load sprites string[] categoryNames = { "Tile", "Tower", "Enemy" }; using (FileStream stream = new FileStream(path, FileMode.Open)) { for (int collection = 0; collection < 3; ++collection) { // Read the collection size byte[] collectionSizeBytes = new byte[2]; stream.Read(collectionSizeBytes, 0, 2); short collectionSize = BitConverter.ToInt16(collectionSizeBytes, 0); // Load each image in the collection for (short i = 0; i < collectionSize; ++i) { // Read the image name short nameLength = (short)stream.ReadByte(); string name = ""; for (int nameIndex = 0; nameIndex < nameLength; ++nameIndex) { byte[] character = new byte[2]; stream.Read(character, 0, 2); name += BitConverter.ToChar(character, 0); } // Read the image size byte[] imageSizeBytes = new byte[4]; stream.Read(imageSizeBytes, 0, 4); int imageSize = BitConverter.ToInt32(imageSizeBytes, 0); // Read the image byte[] imageBytes = new byte[imageSize]; stream.Read(imageBytes, 0, imageSize); // Save the image using (FileStream copyStream = new FileStream(directory + "temp\\" + categoryNames[collection] + name + ".png", FileMode.Create)) { copyStream.Write(imageBytes, 0, imageSize); } } } } // Initialize lists builtTowers = new List<TowerInstance>(); tiles = new PairList<string, bool?>(); towers = new List<Tower>(); enemies = new List<Enemy>(); statuses = new List<Status>(); // Load level data using (StreamReader read = new StreamReader(path)) { // Skip over image data string line; do { line = read.ReadLine(); } while (!line.Equals("[END OF SPRITE IMAGE DATA]")); // Read level JSON data JSONParser parser = new JSONParser(read.ReadToEnd()); foreach (PairList<string, object> collection in parser.Objects) foreach (PairListNode<string, object> data in collection) { if (data.Key.Equals("MapProperties")) { foreach (PairListNode<string, object> property in data.Value as PairList<string, object>) if (property.Key.Equals("Money")) money = int.Parse(property.Value.ToString()); else if (property.Key.Equals("Health")) health = int.Parse(property.Value.ToString()); else if (property.Key.Equals("Width")) width = int.Parse(property.Value.ToString()); else if (property.Key.Equals("Height")) height = int.Parse(property.Value.ToString()); else if (property.Key.Equals("Details")) { SimpleList<object> details = property.Value as SimpleList<object>; creator = details[0].ToString(); date = details[1].ToString(); description = details[2].ToString(); } } else if (data.Key.Equals("MapTiles")) { int index = 0; map = new string[width, height]; foreach (string tile in data.Value as SimpleList<object>) { string[] details = tile.Split(splitter); for (int i = 0; i < int.Parse(details[1]); ++i) map[index % width, index++ / width] = details[0]; } } else if (data.Key.Equals("Tiles")) foreach (string tile in data.Value as SimpleList<object>) { string[] details = tile.Split(splitter); tiles.Add(details[0], details[1] == "null" ? null : (bool?)bool.Parse(details[1])); } else if (data.Key.Equals("Towers")) foreach (object tower in data.Value as SimpleList<object>) towers.Add(new Tower(tower as PairList<string, object>)); else if (data.Key.Equals("Enemies")) foreach (object enemy in data.Value as SimpleList<object>) enemies.Add(new Enemy(enemy as PairList<string, object>)); else if (data.Key.Equals("Statuses")) foreach (object status in data.Value as SimpleList<object>) statuses.Add(new Status(status as PairList<string, object>)); } } } // Problems with the map catch (Exception) { return BadMap("The map data is corrupt"); } if (enemies.Count == 0) return BadMap("The map has no enemies"); if (towers.Count == 0) return BadMap("The map has no towers"); foreach (PairListNode<string, bool?> tile in tiles) if (!File.Exists(directory + "Temp\\Tile" + tile.Key + ".png")) return BadMap("Tile sprites are missing from the map data"); foreach (Enemy e in enemies) if (!File.Exists(directory + "Temp\\Enemy" + e.Name + ".png")) return BadMap("Enemy sprites are missing from the map data"); foreach (Tower t in towers) if (!File.Exists(directory + "Temp\\Tower" + t.name + ".png")) return BadMap("Tower sprites are missing from the map data"); foreach (Tower t in towers) { if (t.status.Equals("None")) continue; Boolean statusLoaded = false; foreach (Status s in statuses) if (s.name.Equals(t.status)) statusLoaded = true; if (!statusLoaded) return BadMap("Statuses are missing from the map data"); } GetWave(0); return true; }
static OleDbTypeConverter() { netTypes.Add(OleDbType.BigInt, typeof(Int64)); netTypes.Add(OleDbType.Binary, typeof(Byte[])); netTypes.Add(OleDbType.Boolean, typeof(Boolean)); netTypes.Add(OleDbType.BSTR, typeof(String)); netTypes.Add(OleDbType.Char, typeof(String)); netTypes.Add(OleDbType.Currency, typeof(Decimal)); netTypes.Add(OleDbType.Date, typeof(DateTime)); netTypes.Add(OleDbType.DBDate, typeof(DateTime)); netTypes.Add(OleDbType.DBTime, typeof(TimeSpan)); netTypes.Add(OleDbType.DBTimeStamp, typeof(DateTime)); netTypes.Add(OleDbType.Decimal, typeof(Decimal)); netTypes.Add(OleDbType.Double, typeof(Double)); netTypes.Add(OleDbType.Empty, null); netTypes.Add(OleDbType.Error, typeof(Exception)); netTypes.Add(OleDbType.Filetime, typeof(DateTime)); netTypes.Add(OleDbType.Guid, typeof(Guid)); netTypes.Add(OleDbType.IDispatch, typeof(Object)); netTypes.Add(OleDbType.Integer, typeof(Int32)); netTypes.Add(OleDbType.IUnknown, typeof(Object)); netTypes.Add(OleDbType.LongVarBinary, typeof(Byte[])); netTypes.Add(OleDbType.LongVarChar, typeof(String)); netTypes.Add(OleDbType.LongVarWChar, typeof(String)); netTypes.Add(OleDbType.Numeric, typeof(Decimal)); netTypes.Add(OleDbType.PropVariant, typeof(Object)); netTypes.Add(OleDbType.Single, typeof(Single)); netTypes.Add(OleDbType.SmallInt, typeof(Int16)); netTypes.Add(OleDbType.TinyInt, typeof(SByte)); netTypes.Add(OleDbType.UnsignedBigInt, typeof(UInt64)); netTypes.Add(OleDbType.UnsignedInt, typeof(UInt32)); netTypes.Add(OleDbType.UnsignedSmallInt, typeof(UInt16)); netTypes.Add(OleDbType.UnsignedTinyInt, typeof(Byte)); netTypes.Add(OleDbType.VarBinary, typeof(Byte[])); netTypes.Add(OleDbType.VarChar, typeof(String)); netTypes.Add(OleDbType.Variant, typeof(Object)); netTypes.Add(OleDbType.VarNumeric, typeof(Decimal)); netTypes.Add(OleDbType.VarWChar, typeof(String)); netTypes.Add(OleDbType.WChar, typeof(String)); sqlDbTypes.Add(OleDbType.BigInt, SqlDbType.BigInt); sqlDbTypes.Add(OleDbType.Binary, SqlDbType.Binary); sqlDbTypes.Add(OleDbType.Boolean, SqlDbType.Bit); sqlDbTypes.Add(OleDbType.BSTR, SqlDbType.NVarChar); sqlDbTypes.Add(OleDbType.Char, SqlDbType.VarChar); sqlDbTypes.Add(OleDbType.Currency, SqlDbType.Money); sqlDbTypes.Add(OleDbType.Date, SqlDbType.Date); sqlDbTypes.Add(OleDbType.DBDate, SqlDbType.Date); sqlDbTypes.Add(OleDbType.DBTime, SqlDbType.Time); sqlDbTypes.Add(OleDbType.DBTimeStamp, SqlDbType.DateTime); sqlDbTypes.Add(OleDbType.Decimal, SqlDbType.Decimal); sqlDbTypes.Add(OleDbType.Double, SqlDbType.Float); sqlDbTypes.Add(OleDbType.Empty, SqlDbType.Variant); //correct? sqlDbTypes.Add(OleDbType.Error, SqlDbType.Variant); //correct? sqlDbTypes.Add(OleDbType.Filetime, SqlDbType.VarChar); sqlDbTypes.Add(OleDbType.Guid, SqlDbType.UniqueIdentifier); sqlDbTypes.Add(OleDbType.IDispatch, SqlDbType.Variant); sqlDbTypes.Add(OleDbType.Integer, SqlDbType.Int); sqlDbTypes.Add(OleDbType.IUnknown, SqlDbType.Variant); sqlDbTypes.Add(OleDbType.LongVarBinary, SqlDbType.VarBinary); sqlDbTypes.Add(OleDbType.LongVarChar, SqlDbType.VarChar); sqlDbTypes.Add(OleDbType.LongVarWChar, SqlDbType.NVarChar); sqlDbTypes.Add(OleDbType.Numeric, SqlDbType.Decimal); sqlDbTypes.Add(OleDbType.PropVariant, SqlDbType.Variant); sqlDbTypes.Add(OleDbType.Single, SqlDbType.Float); sqlDbTypes.Add(OleDbType.SmallInt, SqlDbType.SmallInt); sqlDbTypes.Add(OleDbType.TinyInt, SqlDbType.TinyInt); //cannot map exactly sqlDbTypes.Add(OleDbType.UnsignedBigInt, SqlDbType.BigInt); //cannot map exactly sqlDbTypes.Add(OleDbType.UnsignedInt, SqlDbType.Int); //cannot map exactly sqlDbTypes.Add(OleDbType.UnsignedSmallInt, SqlDbType.SmallInt); //cannot map exactly sqlDbTypes.Add(OleDbType.UnsignedTinyInt, SqlDbType.TinyInt); sqlDbTypes.Add(OleDbType.VarBinary, SqlDbType.VarBinary); sqlDbTypes.Add(OleDbType.VarChar, SqlDbType.VarChar); sqlDbTypes.Add(OleDbType.Variant, SqlDbType.Variant); sqlDbTypes.Add(OleDbType.VarNumeric, SqlDbType.Decimal); sqlDbTypes.Add(OleDbType.VarWChar, SqlDbType.NVarChar); sqlDbTypes.Add(OleDbType.WChar, SqlDbType.NVarChar); dbTypes.Add(OleDbType.BigInt, DbType.Int64); dbTypes.Add(OleDbType.Binary, DbType.Binary); dbTypes.Add(OleDbType.Boolean, DbType.Boolean); dbTypes.Add(OleDbType.BSTR, DbType.String); dbTypes.Add(OleDbType.Char, DbType.String); dbTypes.Add(OleDbType.Currency, DbType.Currency); dbTypes.Add(OleDbType.Date, DbType.Date); dbTypes.Add(OleDbType.DBDate, DbType.Date); dbTypes.Add(OleDbType.DBTime, DbType.Time); dbTypes.Add(OleDbType.DBTimeStamp, DbType.DateTime); dbTypes.Add(OleDbType.Decimal, DbType.Decimal); dbTypes.Add(OleDbType.Double, DbType.Double); dbTypes.Add(OleDbType.Empty, DbType.Object); //correct? dbTypes.Add(OleDbType.Error, DbType.Object); //correct? dbTypes.Add(OleDbType.Filetime, DbType.UInt64); dbTypes.Add(OleDbType.Guid, DbType.Guid); dbTypes.Add(OleDbType.IDispatch, DbType.Object); dbTypes.Add(OleDbType.Integer, DbType.Int32); dbTypes.Add(OleDbType.IUnknown, DbType.Object); dbTypes.Add(OleDbType.LongVarBinary, DbType.Binary); dbTypes.Add(OleDbType.LongVarChar, DbType.String); dbTypes.Add(OleDbType.LongVarWChar, DbType.String); dbTypes.Add(OleDbType.Numeric, DbType.Decimal); dbTypes.Add(OleDbType.PropVariant, DbType.Object); dbTypes.Add(OleDbType.Single, DbType.Single); dbTypes.Add(OleDbType.SmallInt, DbType.Int16); dbTypes.Add(OleDbType.TinyInt, DbType.SByte); dbTypes.Add(OleDbType.UnsignedBigInt, DbType.UInt64); dbTypes.Add(OleDbType.UnsignedInt, DbType.UInt32); dbTypes.Add(OleDbType.UnsignedSmallInt, DbType.UInt16); dbTypes.Add(OleDbType.UnsignedTinyInt, DbType.Byte); dbTypes.Add(OleDbType.VarBinary, DbType.Binary); dbTypes.Add(OleDbType.VarChar, DbType.String); dbTypes.Add(OleDbType.Variant, DbType.Object); dbTypes.Add(OleDbType.VarNumeric, DbType.VarNumeric); dbTypes.Add(OleDbType.VarWChar, DbType.String); dbTypes.Add(OleDbType.WChar, DbType.String); }
protected override async Task <int> Update <TEntity>(TEntity entity, string table, bool @async) { PublicHelper.CheckNull(entity); TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(typeof(TEntity)); PublicHelper.EnsureHasPrimaryKey(typeDescriptor); PairList <PrimitivePropertyDescriptor, object> keyValues = new PairList <PrimitivePropertyDescriptor, object>(typeDescriptor.PrimaryKeys.Count); IEntityState entityState = this.TryGetTrackedEntityState(entity); Dictionary <PrimitivePropertyDescriptor, DbExpression> updateColumns = new Dictionary <PrimitivePropertyDescriptor, DbExpression>(); foreach (PrimitivePropertyDescriptor propertyDescriptor in typeDescriptor.PrimitivePropertyDescriptors) { if (propertyDescriptor.IsPrimaryKey) { var keyValue = propertyDescriptor.GetValue(entity); PrimaryKeyHelper.KeyValueNotNull(propertyDescriptor, keyValue); keyValues.Add(propertyDescriptor, keyValue); continue; } if (propertyDescriptor.CannotUpdate()) { continue; } object val = propertyDescriptor.GetValue(entity); PublicHelper.NotNullCheck(propertyDescriptor, val); if (entityState != null && !entityState.HasChanged(propertyDescriptor, val)) { continue; } DbExpression valExp = DbExpression.Parameter(val, propertyDescriptor.PropertyType, propertyDescriptor.Column.DbType); updateColumns.Add(propertyDescriptor, valExp); } PrimitivePropertyDescriptor rowVersionDescriptor = null; object rowVersionValue = null; object rowVersionNewValue = null; if (typeDescriptor.HasRowVersion()) { rowVersionDescriptor = typeDescriptor.RowVersion; if (rowVersionDescriptor.IsTimestamp()) { rowVersionValue = rowVersionDescriptor.GetValue(entity); this.EnsureRowVersionValueIsNotNull(rowVersionValue); keyValues.Add(rowVersionDescriptor, rowVersionValue); } else { rowVersionValue = rowVersionDescriptor.GetValue(entity); rowVersionNewValue = PublicHelper.IncreaseRowVersionNumber(rowVersionValue); updateColumns.Add(rowVersionDescriptor, DbExpression.Parameter(rowVersionNewValue, rowVersionDescriptor.PropertyType, rowVersionDescriptor.Column.DbType)); keyValues.Add(rowVersionDescriptor, rowVersionValue); } } if (updateColumns.Count == 0) { return(0); } DbTable dbTable = PublicHelper.CreateDbTable(typeDescriptor, table); DbExpression conditionExp = PublicHelper.MakeCondition(keyValues, dbTable); DbUpdateExpression e = new DbUpdateExpression(dbTable, conditionExp); foreach (var item in updateColumns) { e.UpdateColumns.Add(item.Key.Column, item.Value); } int rowsAffected = 0; if (rowVersionDescriptor == null) { rowsAffected = await this.ExecuteNonQuery(e, @async); if (entityState != null) { entityState.Refresh(); } return(rowsAffected); } if (rowVersionDescriptor.IsTimestamp()) { List <Action <TEntity, IDataReader> > mappers = new List <Action <TEntity, IDataReader> >(); mappers.Add(GetMapper <TEntity>(rowVersionDescriptor, e.Returns.Count)); e.Returns.Add(rowVersionDescriptor.Column); IDataReader dataReader = await this.ExecuteReader(e, @async); using (dataReader) { while (dataReader.Read()) { rowsAffected++; foreach (var mapper in mappers) { mapper(entity, dataReader); } } } PublicHelper.CauseErrorIfOptimisticUpdateFailed(rowsAffected); } else { rowsAffected = await this.ExecuteNonQuery(e, @async); PublicHelper.CauseErrorIfOptimisticUpdateFailed(rowsAffected); rowVersionDescriptor.SetValue(entity, rowVersionNewValue); } if (entityState != null) { entityState.Refresh(); } return(rowsAffected); }
/// <summary> /// Loads the object from the data /// </summary> /// <param name="currentObject">object being loaded</param> /// <param name="data">JSON data</param> private PairList<string, object> LoadObject() { PairList<string, object> loadedObject = new PairList<string, object>(); string current = ""; while (data.Length > 0) { char c = data[0]; data = data.Substring(1); // End of object if (c == '}') return loadedObject; // End of key else if (c == ':') { string key = current; object value = null; current = ""; bool repeat = true; while (repeat && data.Length > 0) { c = data[0]; data = data.Substring(1); // End of value if (c == ',') { value = current; repeat = false; } // End of value and object else if (c == '}') { value = current; loadedObject.Add(key, value); return loadedObject; } // Value is array else if (c == '[') { value = LoadArray(); repeat = false; } // Value is object else if (c == '{') { value = LoadObject(); while (data[0] != ',') { if (data[0] == '}') { data = data.Substring(1); loadedObject.Add(key, value); return loadedObject; } data = data.Substring(1); } data = data.Substring(1); repeat = false; } else current += c; } // Add the pair when found loadedObject.Add(key, value); current = ""; } else if (c == ',') continue; else current += c; } return loadedObject; }
private void CreateSwitchConstruct(CFGBlockLogicalConstruct switchBlock, ILogicalConstruct parentConstruct, SwitchData switchData, DominatorTree dominatorTree) { List<KeyValuePair<CFGBlockLogicalConstruct, List<int>>> cfgSuccessorToLabelsMap = GetOrderedCFGSuccessorToLabelsMap(switchData); Dictionary<ILogicalConstruct, HashSet<ISingleEntrySubGraph>> validCaseEntryToDominatedNodesMap = GetValidCases(dominatorTree, switchBlock); List<CaseLogicalConstruct> orderedCaseConstructs = new List<CaseLogicalConstruct>(); PairList<List<int>, CFGBlockLogicalConstruct> labelsToCFGSuccessorsList = new PairList<List<int>, CFGBlockLogicalConstruct>(); foreach (KeyValuePair<CFGBlockLogicalConstruct, List<int>> cfgSuccessorToLabelsPair in cfgSuccessorToLabelsMap) { ILogicalConstruct successor; HashSet<ISingleEntrySubGraph> dominatedNodes; if (LogicalFlowUtilities.TryGetParentConstructWithGivenParent(cfgSuccessorToLabelsPair.Key, parentConstruct, out successor) && validCaseEntryToDominatedNodesMap.TryGetValue(successor, out dominatedNodes)) { CaseLogicalConstruct newCaseConstruct = new CaseLogicalConstruct(successor); newCaseConstruct.CaseNumbers.AddRange(cfgSuccessorToLabelsPair.Value); newCaseConstruct.Body.UnionWith(dominatedNodes.Cast<ILogicalConstruct>()); newCaseConstruct.AttachCaseConstructToGraph(); orderedCaseConstructs.Add(newCaseConstruct); } else { labelsToCFGSuccessorsList.Add(cfgSuccessorToLabelsPair.Value, cfgSuccessorToLabelsPair.Key); } } CaseLogicalConstruct defaultCase = null; CFGBlockLogicalConstruct defaultCFGSuccessor = GetCFGLogicalConstructFromBlock(switchData.DefaultCase); ILogicalConstruct defaultSuccessor; HashSet<ISingleEntrySubGraph> defaultCaseNodes; if (LogicalFlowUtilities.TryGetParentConstructWithGivenParent(defaultCFGSuccessor, parentConstruct, out defaultSuccessor) && validCaseEntryToDominatedNodesMap.TryGetValue(defaultSuccessor, out defaultCaseNodes)) { defaultCase = new CaseLogicalConstruct(defaultSuccessor); if (HasSuccessors(defaultCaseNodes)) { defaultCase.Body.UnionWith(defaultCaseNodes.Cast<ILogicalConstruct>()); } defaultCase.AttachCaseConstructToGraph(); } SwitchLogicalConstruct theSwitch = SwitchLogicalConstruct.GroupInSwitchConstruct(switchBlock, orderedCaseConstructs, labelsToCFGSuccessorsList, defaultCase, defaultCFGSuccessor); UpdateDominatorTree(dominatorTree, theSwitch); }
private PairList<CFGBlockLogicalConstruct, List<int>> GetOrderedCFGSuccessorToLabelsMap(SwitchData switchData) { //Ugly but effective. Sorry PairList<CFGBlockLogicalConstruct, List<int>> result = new PairList<CFGBlockLogicalConstruct, List<int>>(); Dictionary<InstructionBlock, KeyValuePair<int, List<int>>> blockSuccessorToResultPositionMap = new Dictionary<InstructionBlock, KeyValuePair<int, List<int>>>(); for (int i = 0; i < switchData.OrderedCasesArray.Length; i++) { InstructionBlock instructionBlock = switchData.OrderedCasesArray[i]; if (instructionBlock != switchData.DefaultCase) { KeyValuePair<int, List<int>> positionToLabelListPair; if (!blockSuccessorToResultPositionMap.TryGetValue(instructionBlock, out positionToLabelListPair)) { positionToLabelListPair = new KeyValuePair<int, List<int>>(result.Count, new List<int>()); result.Add(GetCFGLogicalConstructFromBlock(instructionBlock), positionToLabelListPair.Value); blockSuccessorToResultPositionMap.Add(instructionBlock, positionToLabelListPair); } positionToLabelListPair.Value.Add(i); } } return result; }
static DbTypeConverter() { #region fieldTypes //fieldTypes.Add(FieldType.AutoNumber, DbType.Int64); fieldTypes.Add(FieldType.Binary, DbType.Binary); fieldTypes.Add(FieldType.Byte, DbType.Byte); //Cannot map exactly fieldTypes.Add(FieldType.Boolean, DbType.Boolean); fieldTypes.Add(FieldType.Char, DbType.StringFixedLength); fieldTypes.Add(FieldType.Choice, DbType.String); fieldTypes.Add(FieldType.Calculated, DbType.String); fieldTypes.Add(FieldType.Currency, DbType.Currency); fieldTypes.Add(FieldType.Date, DbType.Date); fieldTypes.Add(FieldType.DateTime, DbType.DateTime); fieldTypes.Add(FieldType.DateTimeOffset, DbType.DateTimeOffset); fieldTypes.Add(FieldType.Decimal, DbType.Decimal); fieldTypes.Add(FieldType.Double, DbType.Double); fieldTypes.Add(FieldType.Geometry, DbType.String); fieldTypes.Add(FieldType.Guid, DbType.Guid); fieldTypes.Add(FieldType.Int16, DbType.Int16); fieldTypes.Add(FieldType.Int32, DbType.Int32); fieldTypes.Add(FieldType.Int64, DbType.Int64); fieldTypes.Add(FieldType.Lookup, DbType.String); fieldTypes.Add(FieldType.MultiChoice, DbType.String); fieldTypes.Add(FieldType.MultiLookup, DbType.String); fieldTypes.Add(FieldType.MultiUser, DbType.String); fieldTypes.Add(FieldType.Object, DbType.Object); fieldTypes.Add(FieldType.RichText, DbType.String); fieldTypes.Add(FieldType.SByte, DbType.SByte); fieldTypes.Add(FieldType.Single, DbType.Single); fieldTypes.Add(FieldType.String, DbType.String); fieldTypes.Add(FieldType.Time, DbType.Time); fieldTypes.Add(FieldType.Timestamp, DbType.Binary); //not sure if best mapping fieldTypes.Add(FieldType.UInt16, DbType.UInt16); //Cannot map exactly fieldTypes.Add(FieldType.UInt32, DbType.UInt32); //Cannot map exactly fieldTypes.Add(FieldType.UInt64, DbType.UInt64); //Cannot map exactly fieldTypes.Add(FieldType.Url, DbType.String); fieldTypes.Add(FieldType.User, DbType.String); fieldTypes.Add(FieldType.Xml, DbType.Xml); #endregion fieldTypes #region dbTypes dbTypes.Add(DbType.AnsiString, FieldType.String); dbTypes.Add(DbType.AnsiStringFixedLength, FieldType.Char); dbTypes.Add(DbType.Binary, FieldType.Binary); dbTypes.Add(DbType.Boolean, FieldType.Boolean); dbTypes.Add(DbType.Byte, FieldType.Byte); dbTypes.Add(DbType.Currency, FieldType.Currency); dbTypes.Add(DbType.Date, FieldType.DateTime); dbTypes.Add(DbType.DateTime, FieldType.DateTime); dbTypes.Add(DbType.DateTime2, FieldType.DateTime); dbTypes.Add(DbType.DateTimeOffset, FieldType.DateTimeOffset); dbTypes.Add(DbType.Decimal, FieldType.Decimal); dbTypes.Add(DbType.Double, FieldType.Double); dbTypes.Add(DbType.Guid, FieldType.Guid); dbTypes.Add(DbType.Int16, FieldType.Int16); dbTypes.Add(DbType.Int32, FieldType.Int32); dbTypes.Add(DbType.Int64, FieldType.Int64); dbTypes.Add(DbType.Object, FieldType.Object); dbTypes.Add(DbType.SByte, FieldType.SByte); dbTypes.Add(DbType.Single, FieldType.Single); dbTypes.Add(DbType.String, FieldType.String); dbTypes.Add(DbType.StringFixedLength, FieldType.Char); dbTypes.Add(DbType.Time, FieldType.Time); dbTypes.Add(DbType.UInt16, FieldType.UInt16); dbTypes.Add(DbType.UInt32, FieldType.UInt32); dbTypes.Add(DbType.UInt64, FieldType.UInt64); dbTypes.Add(DbType.VarNumeric, FieldType.Decimal); //not sure if best mapping dbTypes.Add(DbType.Xml, FieldType.Xml); #endregion dbTypes }
static SqlDbTypeConverter() { #region fieldTypes //fieldTypes.Add(FieldType.AutoNumber, SqlDbType.Int); fieldTypes.Add(FieldType.Binary, SqlDbType.Binary); fieldTypes.Add(FieldType.Byte, SqlDbType.TinyInt); //Cannot map exactly fieldTypes.Add(FieldType.Boolean, SqlDbType.Bit); fieldTypes.Add(FieldType.Char, SqlDbType.Char); fieldTypes.Add(FieldType.Choice, SqlDbType.NVarChar); fieldTypes.Add(FieldType.Calculated, SqlDbType.NVarChar); fieldTypes.Add(FieldType.Currency, SqlDbType.Money); fieldTypes.Add(FieldType.Date, SqlDbType.Date); fieldTypes.Add(FieldType.DateTime, SqlDbType.DateTime); fieldTypes.Add(FieldType.DateTimeOffset, SqlDbType.DateTimeOffset); fieldTypes.Add(FieldType.Decimal, SqlDbType.Decimal); fieldTypes.Add(FieldType.Double, SqlDbType.Float); fieldTypes.Add(FieldType.Geometry, SqlDbType.VarChar); fieldTypes.Add(FieldType.Guid, SqlDbType.UniqueIdentifier); fieldTypes.Add(FieldType.Int16, SqlDbType.SmallInt); fieldTypes.Add(FieldType.Int32, SqlDbType.Int); fieldTypes.Add(FieldType.Int64, SqlDbType.BigInt); fieldTypes.Add(FieldType.Lookup, SqlDbType.NVarChar); fieldTypes.Add(FieldType.MultiChoice, SqlDbType.NVarChar); fieldTypes.Add(FieldType.MultiLookup, SqlDbType.NVarChar); fieldTypes.Add(FieldType.MultiUser, SqlDbType.NVarChar); fieldTypes.Add(FieldType.Object, SqlDbType.Variant); //Binary? fieldTypes.Add(FieldType.RichText, SqlDbType.NVarChar); fieldTypes.Add(FieldType.SByte, SqlDbType.TinyInt); fieldTypes.Add(FieldType.Single, SqlDbType.Float); fieldTypes.Add(FieldType.String, SqlDbType.NVarChar); fieldTypes.Add(FieldType.Time, SqlDbType.Time); fieldTypes.Add(FieldType.Timestamp, SqlDbType.Timestamp); fieldTypes.Add(FieldType.UInt16, SqlDbType.SmallInt); //Cannot map exactly fieldTypes.Add(FieldType.UInt32, SqlDbType.Int); //Cannot map exactly fieldTypes.Add(FieldType.UInt64, SqlDbType.BigInt); //Cannot map exactly fieldTypes.Add(FieldType.Url, SqlDbType.NVarChar); fieldTypes.Add(FieldType.User, SqlDbType.NVarChar); fieldTypes.Add(FieldType.Xml, SqlDbType.Xml); #endregion fieldTypes #region sqlDbTypes sqlDbTypes.Add(SqlDbType.BigInt, FieldType.Int64); sqlDbTypes.Add(SqlDbType.Binary, FieldType.Binary); sqlDbTypes.Add(SqlDbType.Bit, FieldType.Boolean); sqlDbTypes.Add(SqlDbType.Char, FieldType.String); sqlDbTypes.Add(SqlDbType.Date, FieldType.Date); sqlDbTypes.Add(SqlDbType.DateTime, FieldType.DateTime); sqlDbTypes.Add(SqlDbType.DateTime2, FieldType.DateTime); sqlDbTypes.Add(SqlDbType.DateTimeOffset, FieldType.DateTimeOffset); sqlDbTypes.Add(SqlDbType.Decimal, FieldType.Decimal); sqlDbTypes.Add(SqlDbType.Float, FieldType.Double); sqlDbTypes.Add(SqlDbType.Int, FieldType.Int32); sqlDbTypes.Add(SqlDbType.Money, FieldType.Currency); sqlDbTypes.Add(SqlDbType.NChar, FieldType.String); sqlDbTypes.Add(SqlDbType.NText, FieldType.String); sqlDbTypes.Add(SqlDbType.NVarChar, FieldType.String); sqlDbTypes.Add(SqlDbType.Real, FieldType.Decimal); sqlDbTypes.Add(SqlDbType.SmallDateTime, FieldType.DateTime); sqlDbTypes.Add(SqlDbType.SmallInt, FieldType.Int16); sqlDbTypes.Add(SqlDbType.SmallMoney, FieldType.Currency); sqlDbTypes.Add(SqlDbType.Structured, FieldType.Binary); sqlDbTypes.Add(SqlDbType.Text, FieldType.String); sqlDbTypes.Add(SqlDbType.Time, FieldType.Time); sqlDbTypes.Add(SqlDbType.Timestamp, FieldType.Timestamp); sqlDbTypes.Add(SqlDbType.TinyInt, FieldType.Int16); sqlDbTypes.Add(SqlDbType.Udt, FieldType.Binary); sqlDbTypes.Add(SqlDbType.UniqueIdentifier, FieldType.Guid); sqlDbTypes.Add(SqlDbType.VarBinary, FieldType.Binary); sqlDbTypes.Add(SqlDbType.VarChar, FieldType.String); sqlDbTypes.Add(SqlDbType.Variant, FieldType.Object); sqlDbTypes.Add(SqlDbType.Xml, FieldType.Xml); sqlDbTypes.Add(SqlDbType.Image, FieldType.Binary); #endregion sqlDbTypes }
public PairList<byte, List<int>> getUpdatedStats() { var ret = new PairList<byte, List<int>>(); lock (updatedStats) { foreach (var blocks in updatedStats) { var retStats = new List<int>(); foreach (var stat in blocks.Item2) retStats.Add(stat); ret.Add(blocks.Item1, retStats); } } return ret; }
protected virtual async Task <int> Update <TEntity>(TEntity entity, string table, bool @async) { PublicHelper.CheckNull(entity); TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(typeof(TEntity)); PublicHelper.EnsureHasPrimaryKey(typeDescriptor); PairList <PrimitivePropertyDescriptor, object> keyValues = new PairList <PrimitivePropertyDescriptor, object>(typeDescriptor.PrimaryKeys.Count); IEntityState entityState = this.TryGetTrackedEntityState(entity); Dictionary <PrimitivePropertyDescriptor, DbExpression> updateColumns = new Dictionary <PrimitivePropertyDescriptor, DbExpression>(); foreach (PrimitivePropertyDescriptor propertyDescriptor in typeDescriptor.PrimitivePropertyDescriptors) { if (propertyDescriptor.IsPrimaryKey) { var keyValue = propertyDescriptor.GetValue(entity); PrimaryKeyHelper.KeyValueNotNull(propertyDescriptor, keyValue); keyValues.Add(propertyDescriptor, keyValue); continue; } if (propertyDescriptor.IsAutoIncrement || propertyDescriptor.HasSequence() || propertyDescriptor.IsRowVersion) { continue; } object val = propertyDescriptor.GetValue(entity); PublicHelper.NotNullCheck(propertyDescriptor, val); if (entityState != null && !entityState.HasChanged(propertyDescriptor, val)) { continue; } DbExpression valExp = DbExpression.Parameter(val, propertyDescriptor.PropertyType, propertyDescriptor.Column.DbType); updateColumns.Add(propertyDescriptor, valExp); } object rowVersionNewValue = null; if (typeDescriptor.HasRowVersion()) { var rowVersionDescriptor = typeDescriptor.RowVersion; var rowVersionOldValue = rowVersionDescriptor.GetValue(entity); rowVersionNewValue = PublicHelper.IncreaseRowVersionNumber(rowVersionOldValue); updateColumns.Add(rowVersionDescriptor, DbExpression.Parameter(rowVersionNewValue, rowVersionDescriptor.PropertyType, rowVersionDescriptor.Column.DbType)); keyValues.Add(rowVersionDescriptor, rowVersionOldValue); } if (updateColumns.Count == 0) { return(0); } DbTable dbTable = PublicHelper.CreateDbTable(typeDescriptor, table); DbExpression conditionExp = PublicHelper.MakeCondition(keyValues, dbTable); DbUpdateExpression e = new DbUpdateExpression(dbTable, conditionExp); foreach (var item in updateColumns) { e.UpdateColumns.Add(item.Key.Column, item.Value); } int rowsAffected = await this.ExecuteNonQuery(e, @async); if (typeDescriptor.HasRowVersion()) { PublicHelper.CauseErrorIfOptimisticUpdateFailed(rowsAffected); typeDescriptor.RowVersion.SetValue(entity, rowVersionNewValue); } if (entityState != null) { entityState.Refresh(); } return(rowsAffected); }
/// <summary> /// Loads tile data /// </summary> public static void Load() { tileTypes = new PairList<string,bool?>(); try { using (StreamReader read = new StreamReader(directory + "\\Data")) { JSONParser parser = new JSONParser(read.ReadToEnd()); foreach (PairList<string, object> collection in parser.Objects) foreach (PairListNode<string, object> element in collection) if (element.Key.Equals("Tiles")) foreach (string tile in element.Value as SimpleList<object>) { string[] details = tile.Split(splitter); tileTypes.Add(details[0], details[1] == "null" ? null : (bool?) bool.Parse(details[1])); } } } catch (Exception) { } }