private static string GetStepParametersForCommandLine(Step step) { string[] commonSettings = new CommonStep().SettingNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string[] stepSettings = step.SettingNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); Dictionary <string, string> settings = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (string settingName in commonSettings) { settings.Upsert(settingName, SettingEntityModel.GetSingle(settingName, true).SettingValue); } foreach (string settingName in stepSettings) { settings.Upsert(settingName, SettingEntityModel.GetSingle(settingName, true).SettingValue); } StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> setting in settings) { string parameter = " /" + setting.Key + ":\"{0}\""; // Important! /folder:"C:\folder\" will cause problem by escape the last double quote ". string settingValue = setting.Value.TrimEnd('\\'); parameter = parameter.FormatWith(settingValue); sb.Append(parameter); } return(sb.ToString()); }
public RenderData(GraphicsDevice Device, ContentManager Content, String Effect, String Skin) { this.Device = Device; this.Effect = Content.Load <Effect>(Effect); CalculateScreenSize(); // Load skin from disc. The skin is a set of tilesheets. var skin = Newtonsoft.Json.JsonConvert.DeserializeObject <JsonTileSheetSet>( System.IO.File.ReadAllText(Skin)); // Pack skin into a single texture - Build atlas information from texture sizes. var atlas = TextureAtlas.Compiler.Compile(skin.Sheets.Select(s => { var realTexture = Content.Load <Texture2D>(s.Texture); return(new TextureAtlas.Entry { Sheet = s, Rect = new Rectangle(0, 0, realTexture.Width, realTexture.Height) }); }).ToList()); // Create the atlas texture Texture = new Texture2D(Device, atlas.Dimensions.Width, atlas.Dimensions.Height); TileSheets = new Dictionary <String, ITileSheet>(); foreach (var texture in atlas.Textures) { // Copy source texture into the atlas var realTexture = Content.Load <Texture2D>(texture.Sheet.Texture); var textureData = new Color[realTexture.Width * realTexture.Height]; realTexture.GetData(textureData); if (texture.Sheet.Type == JsonTileSheetType.VariableWidthFont) { for (int i = 0; i < textureData.Length; ++i) { if (textureData[i].R == 0 && textureData[i].G == 0 && textureData[i].B == 0) { textureData[i] = new Color(0, 0, 0, 0); } } TileSheets.Upsert(texture.Sheet.Name, new VariableWidthFont(realTexture, Texture.Width, Texture.Height, texture.Rect)); } else { // Create a tilesheet pointing into the atlas texture. TileSheets.Upsert(texture.Sheet.Name, new TileSheet(Texture.Width, Texture.Height, texture.Rect, texture.Sheet.TileWidth, texture.Sheet.TileHeight, texture.Sheet.RepeatWhenUsedAsBorder)); } // Paste texture data into atlas. Texture.SetData(0, texture.Rect, textureData, 0, realTexture.Width * realTexture.Height); } }
internal void Register <T>(Func <T, string> toStringFunction) where T : class { _Dictionary.Upsert(typeof(T), obj => { var typed = (T)obj; return(typed != null ? toStringFunction(typed) : DefaultValue); }); }
/// <summary> /// Create a standard message. If a standard message with this name already exists, replace it. /// If an override message with this name already exists, do not replace it. /// </summary> /// <param name="Name"></param> /// <param name="Contents"></param> public static void StandardMessage(String Name, String Contents) { if (MessageDefinitions.ContainsKey(Name) && MessageDefinitions[Name].Priority == MessageDefinitionPriority.Override) { return; } MessageDefinitions.Upsert(Name, new MessageDefinition { Message = Contents, Priority = MessageDefinitionPriority.Standard }); }
public static MudObject CreateObject(String path) { if (GetObject(path) != null) { return(null); } NamedObjects.Upsert(path, new MudObject { Path = path }); return(NamedObjects[path]); }
private static void Initialize() { if (typeCodes != null) { return; } typeCodes = new Dictionary <Type, ScriptTypes>(); typeCodes.Upsert(typeof(Int32), ScriptTypes.Int32); typeCodes.Upsert(typeof(UInt32), ScriptTypes.UInt32); typeCodes.Upsert(typeof(String), ScriptTypes.String); typeCodes.Upsert(typeof(Single), ScriptTypes.Single); typeCodes.Upsert(typeof(Common.ObjectList), ScriptTypes.List); }
public override object ReadValue(Type ValueType, Newtonsoft.Json.JsonReader Reader, MudObject Owner) { var r = new Dictionary<RelativeLocations, List<MudObject>>(); Reader.Read(); while (Reader.TokenType != Newtonsoft.Json.JsonToken.EndObject) { var relloc = StringToRelativeLocation(Reader.Value.ToString()); var l = new List<MudObject>(); Reader.Read(); Reader.Read(); while (Reader.TokenType != Newtonsoft.Json.JsonToken.EndArray) { var mudObject = MudObject.GetObject(Reader.Value.ToString()); if (mudObject != null) l.Add(mudObject); mudObject.Location = Owner; Reader.Read(); } Reader.Read(); r.Upsert(relloc, l); } Reader.Read(); return r; }
override public object GetProperty(string name) { var field = this.GetType().GetField(name); if (field != null) { return(field.GetValue(this)); } if (thunkedFunctions.ContainsKey(name)) { return(thunkedFunctions[name]); } var func = this.GetType().GetMethod(name); var saveThis = this; if (func != null) { var impl = Function.MakeSystemFunction(name, Arguments.Args(Arguments.Optional(Arguments.Repeat("arg"))), "Auto-bound function", (context, arguments) => { return(func.Invoke(saveThis, (arguments[0] as ScriptList).ToArray())); }); thunkedFunctions.Upsert(name, impl); return(impl); } return(null); }
public override object ReadValue(Type ValueType, Newtonsoft.Json.JsonReader Reader, MudObject Owner) { var r = new Dictionary <RelativeLocations, List <MudObject> >(); Reader.Read(); while (Reader.TokenType != Newtonsoft.Json.JsonToken.EndObject) { var relloc = StringToRelativeLocation(Reader.Value.ToString()); var l = new List <MudObject>(); Reader.Read(); Reader.Read(); while (Reader.TokenType != Newtonsoft.Json.JsonToken.EndArray) { var mudObject = MudObject.GetObject(Reader.Value.ToString()); if (mudObject != null) { l.Add(mudObject); } mudObject.Location = Owner; Reader.Read(); } Reader.Read(); r.Upsert(relloc, l); } Reader.Read(); return(r); }
public int Part1() { var rules = new Dictionary <string, HashSet <string> >(); foreach (var rule in _input) { var nameMatch = Regex.Match(rule, @"^(?<name>\w+ \w+) bags contain (?<rest>.*)$"); var name = nameMatch.Groups["name"].Value; var rest = nameMatch.Groups["rest"].Value; foreach (Match match in Regex.Matches(rest, @"(?:\d+) (?<name>\w+ \w+) bags?[,\.]")) { rules.Upsert(match.Groups["name"].Value, hs => hs.Add(name), () => new() { name }); } } var hasgold = new HashSet <string>(); Check("shiny gold"); void Check(string name) { if (rules.TryGetValue(name, out var bags)) { foreach (var bag in bags) { hasgold.Add(bag); Check(bag); } } } return(hasgold.Count); }
public async Task RunAsync(TimeSpan waitPeriodAfterEachUpdate, CancellationToken ct) { var buildManagement = new BuildManagement(devOpsAccessSetting); var releaseManagement = new ReleaseManagement(devOpsAccessSetting); var bugManagement = new BugManagement(devOpsAccessSetting); while (!ct.IsCancellationRequested) { await ImportVstsBugDataAsync(bugManagement, bugQueries); foreach (string branch in this.branches) { buildLastUpdatePerBranchPerDefinition.Upsert( branch, await ImportVstsBuildsDataAsync(buildManagement, branch, BuildExtension.BuildDefinitions)); } foreach (string branch in this.branches) { await ImportVstsReleasesDataAsync(releaseManagement, branch, ReleaseDefinitionId.E2ETest); } Console.WriteLine($"Import Vsts data finished at {DateTime.UtcNow}; wait {waitPeriodAfterEachUpdate} for next update."); await Task.Delay((int)waitPeriodAfterEachUpdate.TotalMilliseconds); } }
public Environment AddEnvironment(String name, Engine engine, Context context) { environments.Upsert(name, new Environment { engine = engine, context = context, name = name }); return(environments[name]); }
public void SetProperty(String Name, Object Value) { if (Properties == null) { Properties = new Dictionary <string, object>(); } Properties.Upsert(Name, Value); }
public void GetOrInsertNewTestDoesntExist() { var dict = new Dictionary <string, Person>(); dict.Upsert("michael"); dict.ContainsKey("michael").ShouldBeTrue(); Assert.IsNull(dict["michael"].Name); dict["michael"].Age.ShouldEqual(0); }
public static Dictionary <String, Object> MakeDictionary(params Object[] Pairs) { var r = new Dictionary <String, Object>(); for (int i = 0; (i + 1) < Pairs.Length; ++i) { r.Upsert(Pairs[i].ToString().ToUpper(), Pairs[i + 1]); } return(r); }
public void SetProperty(String Name, Object Value) { if (PropertyManifest.CheckPropertyType(Name, Value)) { Properties.Upsert(Name, Value); } else { throw new InvalidOperationException("Setting property with object of wrong type."); } }
public void GetOrInsertNewTestExists() { var dict = new Dictionary <string, Person> { { "michael", new Person { Name = "Michael", Age = 43 } } }; dict.Upsert("michael"); dict["michael"].Name.ShouldEqual("Michael"); dict["michael"].Age.ShouldEqual(43); // fail. it's 44 now }
public void Should_Insert_Given_A_Non_Existing_Key() { var dictionary = new Dictionary <int, string>() { [0] = "0", }; dictionary.Upsert(1, "1"); bool result = dictionary.ContainsKey(1); Assert.True(result); }
public void Should_Update_Given_An_Existing_Key() { var dictionary = new Dictionary <int, string>() { [0] = "0", }; dictionary.Upsert(0, "Zero"); string result = dictionary[0]; Assert.Equal("Zero", result); }
private static void AddLine(Dictionary <Point, int> grid, Point a, Point b) { var xlen = Math.Abs(b.X - a.X); var ylen = Math.Abs(b.Y - a.Y); var xsign = Math.Sign(b.X - a.X); var ysign = Math.Sign(b.Y - a.Y); for (int i = 0; i <= Math.Max(xlen, ylen); i++) { var point = new Point(a.X + xsign * i, a.Y + ysign * i); grid.Upsert(point, v => v + 1, 1); } }
public static void RegisterProperty(String Name, System.Type Type, Object DefaultValue, TypeSerializer Serializer) { if (RegisteredProperties.ContainsKey(Name)) { var existingProperty = RegisteredProperties[Name]; if (existingProperty.Type != Type) { throw new InvalidOperationException("Property " + Name + " was re-registered with a different type."); } } RegisteredProperties.Upsert(Name, new PropertyInfo { Type = Type, DefaultValue = DefaultValue, Converter = Serializer }); }
public virtual ITemplate Load(JinjaEnvironment environment, string name, IDictionary <string, object?> variableTemplate) { environment = environment ?? throw new ArgumentNullException(nameof(environment)); name = name ?? throw new ArgumentNullException(nameof(name)); variableTemplate = variableTemplate ?? throw new ArgumentNullException(nameof(variableTemplate)); var templateInfo = GetSource(environment, name); if (_TemplateCache.ContainsKey(name) == false || templateInfo.UpToDate == false) { var template = environment.GetTemplate(name, templateInfo, variableTemplate); _TemplateCache.Upsert(name, template); } return(_TemplateCache[name]); }
private string UpsertArgument(string command, string argument, string value) { command = this.MaskRemoteCommand(command); command = this.MaskCommand(command); //string[] commandParts = command.Split(new string[]{" /"}, StringSplitOptions.RemoveEmptyEntries); string[] commandParts = ParseCommandArguments(command); Dictionary <string, string> arguments = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); for (int i = 1; i < commandParts.Length; i++) { string argumentName = ""; string argumentValue = ""; int delimiterIndex = commandParts[i].IndexOf(':'); if (delimiterIndex >= 0) { argumentName = commandParts[i].Substring(0, delimiterIndex).TrimStart('/'); if (delimiterIndex < commandParts[i].Length) { argumentValue = commandParts[i].Substring(delimiterIndex + 1).Trim('"'); } } else { argumentName = commandParts[i].TrimStart('/'); } try { arguments.Add(argumentName, argumentValue); } catch (Exception ex) { throw new Exception("Exception caught when Add (key = {0}, value = {1})!".FormatWith(argumentName, argumentValue), ex); } } arguments.Upsert(argument, value); List <string> argList = new List <string>(); foreach (KeyValuePair <string, string> arg in arguments) { argList.Add("/{0}:\"{1}\"".FormatWith(arg.Key, arg.Value)); } return(this.UnmaskCommand( this.UnmaskRemoteCommand(string.Join(" ", commandParts[0], string.Join(" ", argList.ToArray()))))); }
/// <summary> /// Use seralization to load settings /// </summary> internal static void LoadSettings() { try { LoadDefaultSettings(); Settings.Upsert(Serializer.DeSerialize <Dictionary <string, BotSetting> >("Settings.dat")); Plugins.Upsert(Serializer.DeSerialize <Dictionary <string, SerializablePlugin> >("Plugins.dat")); Items = Serializer.DeSerialize <Collection <SerializableItem> >("Items.dat"); } catch (Exception ex) { Logging.Log(ex); LoadDefaults(); } }
void IModule.AddComponents(List <Component> components) { foreach (var component in components) { if (!(component is ISyncable) || simulation.IsLocalEntity(component.EntityID)) { continue; } if (!syncables.ContainsKey(component.EntityID)) { syncables.Upsert(component.EntityID, new List <ISyncable>()); } syncables[component.EntityID].Add(component as ISyncable); } }
public override object ReadValue(Type ValueType, Newtonsoft.Json.JsonReader Reader, MudObject Owner) { var r = new Dictionary <String, Object>(); Reader.Read(); while (Reader.TokenType != Newtonsoft.Json.JsonToken.EndObject) { var name = Reader.Value.ToString(); Reader.Read(); var value = PersistAttribute._ReadValue(null, Reader, Owner); r.Upsert(name, value); } Reader.Read(); return(r); }
public override object ReadValue(Type ValueType, Newtonsoft.Json.JsonReader Reader, MudObject Owner) { var r = new Dictionary<String, Object>(); Reader.Read(); while (Reader.TokenType != Newtonsoft.Json.JsonToken.EndObject) { var name = Reader.Value.ToString(); Reader.Read(); var value = PersistAttribute._ReadValue(null, Reader, Owner); r.Upsert(name, value); } Reader.Read(); return r; }
public void UpdateGeoCoordinate(Device device, GeoCoordinate geoCoor) { string userName = ""; if (ServiceSecurityContext.Current != null) { userName = ServiceSecurityContext.Current.PrimaryIdentity.Name; } else { // TODO: Throw fault exception } IdentifiedDevice idd = new IdentifiedDevice(userName, device); geoDictionary.Upsert(idd, geoCoor); }
public SpriteAtlas(GraphicsDevice Device, ContentManager Content) { this.Device = Device; var coreSheets = FileUtils.LoadJsonListFromMultipleSources <TileSheetDefinition>(ContentPaths.GUI.Skin, null, (s) => s.Name); SheetGenerators = FindGenerators(); CoreAtlasEntries = coreSheets.Select(s => { Texture2D realTexture = null; switch (s.Type) { case TileSheetType.TileSheet: case TileSheetType.VariableWidthFont: case TileSheetType.JsonFont: realTexture = AssetManager.GetContentTexture(s.Texture); break; case TileSheetType.Generated: realTexture = SheetGenerators[s.Texture](Device, Content, s); break; } var r = new TextureAtlas.SpriteAtlasEntry { SourceDefinition = s, AtlasBounds = new Rectangle(0, 0, realTexture.Width, realTexture.Height), SourceTexture = realTexture }; r.TileSheet = MakeTileSheet(r, realTexture.Bounds); return(r); }).ToList(); NamedTileSheets = new Dictionary <string, ITileSheet>(); foreach (var coreSheet in CoreAtlasEntries) { NamedTileSheets.Upsert(coreSheet.SourceDefinition.Name, coreSheet.TileSheet); } Prerender(); }
/// <summary> /// Map the collection to a dictionary safely. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TK">The type of the K.</typeparam> /// <typeparam name="TV">The type of the V.</typeparam> /// <param name="source">The source.</param> /// <param name="getKey">The get key.</param> /// <param name="getVal">The get val.</param> /// <returns></returns> public static IDictionary <TK, TV> ToDictionarySafely <T, TK, TV>(this IEnumerable <T> source, Func <T, TK> getKey, Func <T, TV> getVal) { if (source == null) { throw new ArgumentNullException("source"); } if (getKey == null) { throw new ArgumentNullException("getKey"); } if (getVal == null) { throw new ArgumentNullException("getVal"); } var result = new Dictionary <TK, TV>(); source.ForEach(item => result.Upsert(getKey(item), getVal(item))); return(result); }
public RMUD.MudObject ResetObject(string Path) { Path = Path.Replace('\\', '/'); if (NamedObjects.ContainsKey(Path)) { var existing = NamedObjects[Path]; existing.State = ObjectState.Destroyed; var newObject = Activator.CreateInstance(existing.GetType()) as MudObject; NamedObjects.Upsert(Path, newObject); MudObject.InitializeObject(newObject); //Preserve the location of actors, and actors only. if (existing is Container) { foreach (var item in (existing as Container).EnumerateObjectsAndRelloc()) { if (item.Item1 is Actor) { (newObject as Container).Add(item.Item1, item.Item2); item.Item1.Location = newObject; } } } if (existing is MudObject && (existing as MudObject).Location != null) { var loc = ((existing as MudObject).Location as Container).RelativeLocationOf(existing); MudObject.Move(newObject as MudObject, (existing as MudObject).Location, loc); MudObject.Move(existing as MudObject, null, RelativeLocations.None); } existing.Destroy(false); return(newObject); } else { return(null); } }
override public void SetProperty(string name, object value) { var field = this.GetType().GetField(name); if (field != null) { if (field.FieldType == typeof(bool)) { field.SetValue(this, (value != null)); } else { field.SetValue(this, value); } } else { properties.Upsert(name, value); } }
public void __ApplySSA() { /* Step 1: Should become ==> SET R0, [0x0002+J] SET R0, [0x0002+J] SET R0, [0x0001+R0] SET R1, [0x0001+R0] SET R1, [0x0002+J] SET R2, [0x0002+J] SET R1, [0x0003+R1] SET R3, [0x0003+R2] ADD R0, R1 SET R4, R1; ADD R4, R3 <- Sets are a special case. Other ops need to SET R2, [0x0002+J] SET R5, [0x0002+J] expand to two instructions. SET [0x0001+R2], R0 SET [0x0001+R5], R4 */ var operandMapping = new Dictionary<ushort, ushort>(); var operandValues = new Dictionary<ushort, Operand>(); var ssa_instructions = new StatementNode(); ushort new_vr = 0; foreach (var child in children) { var ins = child as Instruction; if (ins == null) ssa_instructions.children.Add(child); else { Operand second_operand = null; if (ins.secondOperand != null) { second_operand = ins.secondOperand.Clone(); if (second_operand.register == OperandRegister.VIRTUAL) { if (!operandMapping.ContainsKey(second_operand.virtual_register)) throw new InternalError("Virtual register used as source before being encountered as destination"); second_operand.virtual_register = operandMapping[second_operand.virtual_register]; } } var operands_modified = ins.instruction.GetOperandsModified(); var first_operand = ins.firstOperand.Clone(); var ori_first_operand = first_operand.Clone(); if (first_operand.register == OperandRegister.VIRTUAL) { if (operandMapping.ContainsKey(first_operand.virtual_register)) { first_operand.virtual_register = operandMapping[first_operand.virtual_register]; ori_first_operand.virtual_register = first_operand.virtual_register; } if (operands_modified == OperandsModified.A && (first_operand.semantics & OperandSemantics.Dereference) != OperandSemantics.Dereference) { var new_register = new_vr++; operandMapping.Upsert(ins.firstOperand.virtual_register, new_register); first_operand.virtual_register = new_register; } } if (ins.instruction == Instructions.SET) { ssa_instructions.AddInstruction(Instructions.SET, first_operand, second_operand); if ((first_operand.semantics & OperandSemantics.Dereference) != OperandSemantics.Dereference) operandValues.Upsert(first_operand.virtual_register, second_operand); } else if (operands_modified == OperandsModified.A) { if (first_operand.register == OperandRegister.VIRTUAL) { ssa_instructions.AddInstruction(Instructions.SET, CompilableNode.Virtual(first_operand.virtual_register), ori_first_operand); ssa_instructions.AddInstruction(ins.instruction, CompilableNode.Virtual(first_operand.virtual_register), second_operand); } else ssa_instructions.AddInstruction(ins.instruction, first_operand, second_operand); } else { ssa_instructions.AddInstruction(ins.instruction, first_operand, second_operand); } } } /* Step 2: Should become ==> SET R0, [0x0002+J] SET R0, [0x0002+J] SET R1, [0x0001+R0] SET R1, [0x0001+R0] SET R2, [0x0002+J] SET R3, [0x0003+R2] SET R3, [0x0003+R0] SET R4, R1; ADD R4, R3 SET R4, R1; ADD R4, R3 SET R5, [0x0002+J] SET [0x0001+R5], R4 SET [0x0001+R0], R4 Duplicate values to R0 were lifted. */ this.children = new List<IRNode>(ssa_instructions.children); ssa_instructions.children.Clear(); for (var i = 0; i < children.Count; ++i) { var child = children[i]; var ins = child as Instruction; if (ins == null) ssa_instructions.children.Add(child); else if (ins.instruction != Instructions.SET) ssa_instructions.children.Add(child); else if (ins.firstOperand.semantics != OperandSemantics.None) { if (Operand.OperandsEqual(ins.firstOperand, ins.secondOperand)) continue; ssa_instructions.children.Add(child); } else if (ins.firstOperand.register != OperandRegister.VIRTUAL) ssa_instructions.children.Add(child); else { // Earlier replacements could have left us with the equivilent of 'SET A, A' if (Operand.OperandsEqual(ins.firstOperand, ins.secondOperand)) continue; var valueName = ins.firstOperand; var value = ins.secondOperand; var usage_count = 0; var simplyReplace = ins.instruction == Instructions.SET && ins.firstOperand.semantics == OperandSemantics.None && ins.firstOperand.register == OperandRegister.VIRTUAL && ins.secondOperand.semantics == OperandSemantics.None && ins.secondOperand.register == OperandRegister.VIRTUAL; bool substitutionsMade = false; bool insertedLater = false; for (var c = i + 1; c < children.Count; ++c) { var candidateForReplacement = children[c]; var c_ins = candidateForReplacement as Instruction; if (c_ins == null) continue; //if (c_ins.secondOperand == null) continue; if (simplyReplace) { if (c_ins.secondOperand != null && c_ins.secondOperand.register == OperandRegister.VIRTUAL && c_ins.secondOperand.virtual_register == ins.firstOperand.virtual_register) c_ins.secondOperand.virtual_register = ins.secondOperand.virtual_register; if (c_ins.firstOperand.register == OperandRegister.VIRTUAL && c_ins.firstOperand.virtual_register == ins.firstOperand.virtual_register) c_ins.firstOperand.virtual_register = ins.secondOperand.virtual_register; continue; } // If second operand is a duplicate of value, replace with our register. if (c_ins.secondOperand != null && Operand.OperandsEqual(c_ins.secondOperand, value)) { usage_count += 1; c_ins.secondOperand = valueName; } // If second operand is a bare reference to our register, replace with our value.. else if (c_ins.secondOperand != null && c_ins.secondOperand.semantics == OperandSemantics.None && c_ins.secondOperand.register == OperandRegister.VIRTUAL && c_ins.secondOperand.virtual_register == valueName.virtual_register) { if (usage_count == 0) { c_ins.secondOperand = value; substitutionsMade = true; } } // Repeat, but for the first operand. if (c_ins.firstOperand.semantics == OperandSemantics.None && c_ins.firstOperand.register == OperandRegister.VIRTUAL && c_ins.firstOperand.virtual_register == valueName.virtual_register // But don't f**k with J && !(value.semantics == OperandSemantics.None && value.register == OperandRegister.J)) { if (usage_count == 0) { c_ins.firstOperand = value; substitutionsMade = true; } } // Now check to see if our register is actually ever mentioned again. if (c_ins.secondOperand != null && c_ins.secondOperand.register == OperandRegister.VIRTUAL && c_ins.secondOperand.virtual_register == valueName.virtual_register) { if (usage_count == 0 && substitutionsMade) { insertedLater = true; children.Insert(c, new Instruction { instruction = Instructions.SET, firstOperand = valueName, secondOperand = value }); } usage_count += 1; } if (c_ins.firstOperand.register == OperandRegister.VIRTUAL && c_ins.firstOperand.virtual_register == valueName.virtual_register) { if (usage_count == 0 && substitutionsMade) { insertedLater = true; children.Insert(c, new Instruction { instruction = Instructions.SET, firstOperand = valueName, secondOperand = value }); } usage_count += 1; } } if (usage_count > 0 && !insertedLater) ssa_instructions.children.Add(ins); } } this.children = new List<IRNode>(ssa_instructions.children); }
private static void MapLocation(int[,] MapGrid, Dictionary<int, String> RoomLegend, int X, int Y, RMUD.Room Location, int Symbol) { if (X < 1 || X >= MapWidth - 1 || Y < 1 || Y >= MapHeight - 1) return; if (MapGrid[X, Y] != ' ') return; if (Symbol == ' ') Symbol = FindSymbol(Location); RoomLegend.Upsert(Symbol, Location.Short); PlaceSymbol(MapGrid, X, Y, Symbol); PlaceSymbol(MapGrid, X - 2, Y - 1, '+'); PlaceSymbol(MapGrid, X - 1, Y - 1, '-'); PlaceSymbol(MapGrid, X - 0, Y - 1, '-'); PlaceSymbol(MapGrid, X + 1, Y - 1, '-'); PlaceSymbol(MapGrid, X + 2, Y - 1, '+'); PlaceSymbol(MapGrid, X + 2, Y, '|'); PlaceSymbol(MapGrid, X - 2, Y, '|'); PlaceSymbol(MapGrid, X - 2, Y + 1, '+'); PlaceSymbol(MapGrid, X - 1, Y + 1, '-'); PlaceSymbol(MapGrid, X - 0, Y + 1, '-'); PlaceSymbol(MapGrid, X + 1, Y + 1, '-'); PlaceSymbol(MapGrid, X + 2, Y + 1, '+'); foreach (var link in Location.EnumerateObjects().Where(t => t.HasProperty("link direction"))) { var destinationName = link.GetProperty<string>("link destination"); var destination = MudObject.GetObject(destinationName) as RMUD.Room; var direction = link.GetPropertyOrDefault<RMUD.Direction>("link direction", RMUD.Direction.NORTH); if (direction == Direction.UP) { PlaceSymbol(MapGrid, X + 1, Y - 2, ':'); PlaceSymbol(MapGrid, X + 1, Y - 3, FindSymbol(destination)); } else if (direction == Direction.DOWN) { PlaceSymbol(MapGrid, X - 1, Y + 2, ':'); PlaceSymbol(MapGrid, X - 1, Y + 3, FindSymbol(destination)); } else { var directionVector = RMUD.Link.GetAsVector(direction); PlaceEdge(MapGrid, X + directionVector.X * 3, Y + directionVector.Y * 2, direction); //if (destination.RoomType == Location.RoomType) MapLocation(MapGrid, RoomLegend, X + (directionVector.X * 7), Y + (directionVector.Y * 5), destination, ' '); } } }
public void GetOrInsertNewTestDoesntExist() { var dict = new Dictionary<string, Person>(); dict.Upsert("michael"); dict.ContainsKey("michael").ShouldBeTrue(); Assert.IsNull(dict["michael"].Name); dict["michael"].Age.ShouldEqual(0); }
public void GetOrInsertNewTestExists() { var dict = new Dictionary<string, Person> { { "michael", new Person { Name = "Michael", Age = 43 } } }; dict.Upsert("michael"); dict["michael"].Name.ShouldEqual("Michael"); dict["michael"].Age.ShouldEqual(43); // fail. it's 44 now }
private static void Initialize() { if (typeCodes != null) return; typeCodes = new Dictionary<Type,ScriptTypes>(); typeCodes.Upsert(typeof(Int32), ScriptTypes.Int32); typeCodes.Upsert(typeof(UInt32), ScriptTypes.UInt32); typeCodes.Upsert(typeof(String), ScriptTypes.String); typeCodes.Upsert(typeof(Single), ScriptTypes.Single); typeCodes.Upsert(typeof(MISP.ScriptList), ScriptTypes.List); }