public AutoMockedContainer(ServiceLocator locator) { _locator = locator; onMissingFactory = delegate(Type pluginType, ProfileManager profileManager) { if (!pluginType.IsAbstract && pluginType.IsClass) { return null; } var factory = new InstanceFactory(new PluginFamily(pluginType)); try { object service = _locator.Service(pluginType); var instance = new ObjectInstance(service); profileManager.SetDefault(pluginType, instance); } catch (Exception) { // ignore errors } return factory; }; }
/// <summary> /// Configure this type as the supplied value /// </summary> /// <returns></returns> public ObjectInstance Add(object @object) { var instance = new ObjectInstance(@object); Add(instance); return instance; }
public void Build_happy_path() { var target = new ATarget(); var instance = new ObjectInstance(target); instance.Build<ATarget>().ShouldBeTheSameAs(target); }
public AutoMockedContainer(ServiceLocator locator) { _locator = locator; onMissingFactory = delegate(Type pluginType, ProfileManager profileManager) { //Modified to inject concrete classes that have virtual methods if (!pluginType.IsAbstract && pluginType.IsClass && !pluginType.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Where(p => p.IsVirtual).Any()) { return null; } var factory = new InstanceFactory(new PluginFamily(pluginType)); try { object service = _locator.Service(pluginType); var instance = new ObjectInstance(service); profileManager.SetDefault(pluginType, instance); } catch (Exception) { // ignore errors } return factory; }; }
public static Boolean CheckRuleIsValid(Rule ruleToEval, ObjectInstance oi, out RuleViolation violatedRule) { try { if (CheckCondition(ruleToEval.Condition, oi)) { if (ruleToEval.Assertion(oi) != true) { violatedRule = new RuleViolation(ruleToEval, oi); return false; } else { violatedRule = null; return true; } } violatedRule = null; return true; } catch(Exception ex) { violatedRule = new RuleViolationFromException(ruleToEval, oi, ex); return false; } }
public void get_for_uncached_instance_returns_passed_instance() { var aWidget = new AWidget(); var instance = new ObjectInstance(aWidget); var cachedWidget = cache.Get(typeof (IWidget), instance, new StubBuildSession()); cachedWidget.ShouldBe(aWidget); }
public void get_for_uncached_instance_builds_instance() { var instance = new ObjectInstance(new AWidget()); var mockBuildSession = MockRepository.GenerateMock<IBuildSession>(); cache.Get(typeof (IWidget), instance, mockBuildSession); mockBuildSession.AssertWasCalled(session => session.BuildNewInOriginalContext(typeof (IWidget), instance)); }
public void get_for_cached_instance_returns_cached_instance() { var aWidget = new AWidget(); var instance = new ObjectInstance(aWidget); cache.Get(typeof(IWidget), instance, new StubBuildSession()); var cachedWidget = cache.Get(typeof(IWidget), instance, new StubBuildSession()); Assert.AreEqual(aWidget, cachedWidget); }
public void returns_missing_instance_if_it_exists_and_the_requested_instance_is_not_found() { var factory = new InstanceFactory(typeof (IWidget)); var missing = new ObjectInstance(new AWidget()); factory.MissingInstance = missing; factory.FindInstance("anything").ShouldBeTheSameAs(missing); factory.FindInstance(Guid.NewGuid().ToString()).ShouldBeTheSameAs(missing); }
public void FindMaster_Instance_happy_path() { var family = new PluginFamily(typeof (ISomething)); ObjectInstance redInstance = new ObjectInstance(new SomethingOne()).WithName("Red"); family.AddInstance(redInstance); family.AddInstance(new ObjectInstance(new SomethingOne()).WithName("Blue")); var instance = new ReferencedInstance("Red"); Assert.AreSame(redInstance, ((IDiagnosticInstance) instance).FindInstanceForProfile(family, null, null)); }
public void get_for_cached_instance_does_not_build_instance() { var instance = new ObjectInstance(new AWidget()); var mockBuildSession = Substitute.For<IBuildSession>(); cache.Get(typeof(IWidget), instance, new StubBuildSession()); cache.Get(typeof(IWidget), instance, mockBuildSession); mockBuildSession.DidNotReceive().BuildNewInOriginalContext(typeof(IWidget), instance); }
public void returns_missing_instance_if_it_exists_and_the_requested_instance_is_not_found() { var graph = new PluginGraph(); var family = graph.Families[typeof (IWidget)]; var missing = new ObjectInstance(new AWidget()); family.MissingInstance = missing; graph.FindInstance(typeof (IWidget), "anything").ShouldBeTheSameAs(missing); graph.FindInstance(typeof (IWidget), Guid.NewGuid().ToString()).ShouldBeTheSameAs(missing); }
public void Add_instance_that_does_not_exist_in_destination() { var source = new PluginFamily(typeof (IWidget)); var sourceInstance = new ObjectInstance(new AWidget()); source.AddInstance(sourceInstance); var destination = new PluginFamily(typeof (IWidget)); destination.ImportFrom(source); Assert.AreSame(sourceInstance, destination.GetInstance(sourceInstance.Name)); }
public void eject_a_non_disposable_object() { var widget = new AWidget(); var instance = new ObjectInstance(widget); cache.Set(typeof (IWidget), instance, widget); cache.Eject(typeof (IWidget), instance); cache.Has(typeof (IWidget), instance).ShouldBeFalse(); }
public void Can_be_part_of_PluginFamily() { var target = new ATarget(); var instance = new ObjectInstance(target); IDiagnosticInstance diagnosticInstance = instance; var family1 = new PluginFamily(typeof (ATarget)); Assert.IsTrue(diagnosticInstance.CanBePartOfPluginFamily(family1)); var family2 = new PluginFamily(GetType()); Assert.IsFalse(diagnosticInstance.CanBePartOfPluginFamily(family2)); }
public void eject_a_disposable_object() { var disposable = Substitute.For<IDisposable>(); var instance = new ObjectInstance(disposable); cache.Set(typeof(IWidget), instance, disposable); cache.Eject(typeof(IWidget), instance); cache.Has(typeof(IWidget), instance).ShouldBeFalse(); disposable.Received().Dispose(); }
public void eject_a_disposable_object() { var disposable = MockRepository.GenerateMock<IDisposable>(); var instance = new ObjectInstance(disposable); cache.Set(typeof (IWidget), instance, disposable); cache.Eject(typeof (IWidget), instance); cache.Has(typeof (IWidget), instance).ShouldBeFalse(); disposable.AssertWasCalled(x => x.Dispose()); }
public void Do_not_override_named_instance() { var source = new PluginFamily(typeof (IWidget)); ObjectInstance sourceInstance = new ObjectInstance(new AWidget()).WithName("New"); source.AddInstance(sourceInstance); var destination = new PluginFamily(typeof (IWidget)); ObjectInstance destinationInstance = new ObjectInstance(new AWidget()).WithName("New"); destination.AddInstance(destinationInstance); destination.ImportFrom(source); Assert.AreSame(destinationInstance, destination.GetInstance(sourceInstance.Name)); }
public void Import_a_default_for_a_profile_in_destination_will_override_existing_default_in_that_profile() { var source = new ProfileManager(); var sourceInstance = new ConfiguredInstance(typeof (AWidget)); source.SetDefault(PROFILE, typeof (IWidget), sourceInstance); // Fill in value before the ImportFrom var destination = new ProfileManager(); var destinationInstance = new ObjectInstance(new AWidget()); destination.SetDefault(PROFILE, typeof (IWidget), destinationInstance); destination.ImportFrom(source); Assert.AreSame(sourceInstance, destination.GetDefault(typeof (IWidget), PROFILE)); }
public void CreatePool(GameObject prefab, int poolSize) { int poolKey = prefab.GetInstanceID (); if (!poolDictionary.ContainsKey (poolKey)) { poolDictionary.Add (poolKey, new Queue<ObjectInstance> ()); GameObject poolHolder = new GameObject (prefab.name + " pool"); poolHolder.transform.parent = transform; for (int i = 0; i < poolSize; i++) { ObjectInstance newObject = new ObjectInstance(Instantiate (prefab) as GameObject); poolDictionary [poolKey].Enqueue (newObject); newObject.SetParent (poolHolder.transform); } } }
public void can_use_lifecyle_resolver_for_dependency() { var build = new ConcreteBuild<LifecycleTarget>(); var gateway = new StubbedGateway(); var instance = new ObjectInstance(gateway); var session = new FakeBuildSession(); session.LifecycledObjects[typeof (IGateway)][instance] = gateway; var arg = new LifecycleDependencySource(typeof (IGateway), instance); build.ConstructorArgs(arg); var target = build.Build<LifecycleTarget>(session); target.Gateway.ShouldBeTheSameAs(gateway); }
PluginFamily IFamilyPolicy.Build(Type pluginType) { if (pluginType.IsConcrete()) { return null; } var family = new PluginFamily(pluginType); var service = _locator.Service(pluginType); var instance = new ObjectInstance(service); family.SetDefault(instance); return family; }
public void get_for_cached_instance_created_on_different_thread_returns_cached_instance() { var aWidget = new AWidget(); var instance = new ObjectInstance(aWidget); cache.Get(typeof (IWidget), instance, new StubBuildSession()); object cachedWidget = null; var thread = new Thread(() => { cachedWidget = cache.Get(typeof (IWidget), instance, new StubBuildSession()); }); thread.Start(); // Allow 10ms for the thread to start and for Get call to complete thread.Join(10); cachedWidget.ShouldNotBeNull(); cachedWidget.ShouldBe(aWidget); }
public void has() { var widget = new AWidget(); var instance = new ObjectInstance(widget); cache.Has(typeof (IWidget), instance).ShouldBeFalse(); cache.Set(typeof (Rule), instance, widget); cache.Has(typeof (IWidget), instance).ShouldBeFalse(); cache.Set(typeof (IWidget), new ObjectInstance(new AWidget()), widget); cache.Has(typeof (IWidget), instance).ShouldBeFalse(); cache.Set(typeof (IWidget), instance, widget); cache.Has(typeof (IWidget), instance).ShouldBeTrue(); }
public void can_serialize() { var widget = new ColorWidget("blue"); var instance = new ObjectInstance(widget); cache.Set(typeof(Rule), instance, widget); var formatter = new BinaryFormatter(); var stream = new MemoryStream(); formatter.Serialize(stream, cache); stream.Position = 0; var deserializedCache = (LifecycleObjectCache)formatter.Deserialize(stream); Assert.AreNotSame(cache, deserializedCache); var cachedWidget = deserializedCache.Get(typeof(Rule), instance, null) as ColorWidget; cachedWidget.ShouldNotBeNull(); cachedWidget.Color.ShouldEqual("blue"); }
public void get_for_cached_instance_created_on_different_thread_returns_cached_instance() { var aWidget = new AWidget(); var instance = new ObjectInstance(aWidget); cache.Get(typeof(IWidget), instance, new StubBuildSession()); object cachedWidget = null; var thread = new Thread(() => { cachedWidget = cache.Get(typeof(IWidget), instance, new StubBuildSession()); }); thread.Start(); // Allow 10ms for the thread to start and for Get call to complete thread.Join(10); Assert.NotNull(cachedWidget, "Get did not return cachedWidget within allowed time. Is your thread being blocked?"); Assert.AreEqual(aWidget, cachedWidget); }
public static RuleViolation GetFirstRuleViolation(IEnumerable<Rule> rules, ObjectInstance oi) { foreach (var rule in rules) { RuleViolation ruleViolation; //property rules should be evalated up until an invalid rule is found or a conditional rule is found // (we'd have to make sure everything else is valid and then go back and do conditional rules // (does a rule need some sort of flag indicating that it can be evaluated immediately or only after all immediate rules?) //update: it's not just conditions as rules that check other property values would also be affected //for now just catch the exceptions and or maybe return a special rule violation if (!CheckRuleIsValid(rule, oi, out ruleViolation)) { return ruleViolation; //break;//found an invalid rule, no point in continuing } } return null; }
public DryLogicProxy(Object objectToProxy) { this.proxiedObject = objectToProxy; dynamic dynamicObject = objectToProxy; PropertyInfo prop = objectToProxy.GetType().GetProperty("OI", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); this.objectInstance = ObjectInstance.GetObjectInstance(objectToProxy, true); //this.domainObject = dynamicObject.DomainContainer; //if the parent object implements INotifyPropertyChanged... if (this.proxiedObject is INotifyPropertyChanged) { //then wire it up ((INotifyPropertyChanged)proxiedObject).PropertyChanged += new PropertyChangedEventHandler(Object_PropertyChanged); } else //parent does not implement INotify... { //wire up the domain object instead this.objectInstance.PropertyChanged += new PropertyChangedEventHandler(Object_PropertyChanged); } }
private static Boolean CheckCondition(Func<ObjectInstance, Boolean> condition, ObjectInstance oi) { if(condition == null) return true; else { try { return condition(oi); } //if the condition is dependent on another field which is also invalid, it will fail. catch(Exception ex) { if(Debugger.IsAttached) { Debug.WriteLine("Rule '{0}' not applied - condition invalid with exception:"); Debug.WriteLine(ex); } throw; } } }
public ObjectInstanceEditor(ObjectInstance item) { InitializeComponent(); cxBox.Tag = cxInt; cyBox.Tag = cyInt; rxBox.Tag = rxInt; ryBox.Tag = ryInt; nameEnable.Tag = nameBox; questEnable.Tag = new Control[] { questAdd, questRemove, questList }; tagsEnable.Tag = tagsBox; this.item = item; xInput.Value = item.X; yInput.Value = item.Y; zInput.Value = item.Z; rBox.Checked = item.r; pathLabel.Text = HaCreatorStateManager.CreateItemDescription(item, "\r\n"); if (item.Name != null) { nameEnable.Checked = true; nameBox.Text = item.Name; } rBox.Checked = item.r; flowBox.Checked = item.flow; SetOptionalInt(rxInt, rxBox, item.rx); SetOptionalInt(ryInt, ryBox, item.ry); SetOptionalInt(cxInt, cxBox, item.cx); SetOptionalInt(cyInt, cyBox, item.cy); if (item.tags == null) tagsEnable.Checked = false; else { tagsEnable.Checked = true; tagsBox.Text = item.tags; } if (item.QuestInfo != null) { questEnable.Checked = true; foreach (ObjectInstanceQuest info in item.QuestInfo) questList.Items.Add(info); } }
public SPProcessIdentityInstance(ObjectInstance prototype) : base(prototype) { this.PopulateFields(); this.PopulateFunctions(); }
public ObjectInstanceOperations(ObjectInstance instance) { _instance = instance; }
public CreateServiceOut(ObjectInstance prototype) : base(prototype) { this.PopulateFunctions(); }
public static void Execute(CharacterInstance ch, ObjectInstance obj) { }
public WebPartZoneBaseInstance(ObjectInstance prototype) : base(prototype) { this.PopulateFields(); this.PopulateFunctions(); }
protected Hashlink(Script script, ObjectInstance proto) : base(script.Engine, proto) { this.PopulateFunctions(); }
// CODE-GEN METHODS //_________________________________________________________________________________________ /// <summary> /// Creates a new instance of a user-defined function. /// </summary> /// <param name="prototype"> The next object in the prototype chain. </param> /// <param name="name"> The name of the function. </param> /// <param name="argumentNames"> The names of the arguments. </param> /// <param name="parentScope"> The scope at the point the function is declared. </param> /// <param name="bodyText"> The source code for the function body. </param> /// <param name="generatedMethod"> A delegate which represents the body of the function plus any dependencies. </param> /// <param name="strictMode"> <c>true</c> if the function body is strict mode; <c>false</c> otherwise. </param> /// <param name="container"> A reference to the containing class prototype or object literal (or <c>null</c>). </param> /// <remarks> This is used by functions declared in JavaScript code (including getters and setters). </remarks> public static UserDefinedFunction CreateFunction(ObjectInstance prototype, string name, IList <string> argumentNames, RuntimeScope parentScope, string bodyText, GeneratedMethod generatedMethod, bool strictMode, ObjectInstance container) { return(new UserDefinedFunction(prototype, name, argumentNames, parentScope, bodyText, generatedMethod, strictMode, container)); }
public void Set(Vector3Int absolutePosition, ObjectInstance lookObject, int lookObjectIndex, ObjectInstance useObject, int useObjectIndex, Creatures.Creature creature) { _absolute = absolutePosition; _lookObject = lookObject; _lookObjectStackPos = lookObjectIndex; _useObject = useObject; _useObjectStackPos = useObjectIndex; _creature = creature; }
/// <summary> /// Sets the value of a class property to a value. /// </summary> /// <param name="obj"> The object to set the property on. </param> /// <param name="key"> The property key (can be a string or a symbol). </param> /// <param name="value"> The value to set. </param> public static void SetClassValue(ObjectInstance obj, object key, object value) { obj.DefineProperty(key, new PropertyDescriptor(value, Library.PropertyAttributes.NonEnumerable), throwOnError: false); }
private JsValue Str(string key, ObjectInstance holder) { var value = holder.Get(key); if (value.IsObject()) { var toJson = value.AsObject().Get("toJSON"); if (toJson.IsObject()) { var callableToJson = toJson.AsObject() as ICallable; if (callableToJson != null) { value = callableToJson.Call(value, Arguments.From(key)); } } } if (_replacerFunction != Undefined.Instance) { var replacerFunctionCallable = (ICallable)_replacerFunction.AsObject(); value = replacerFunctionCallable.Call(holder, Arguments.From(key, value)); } if (value.IsObject()) { var valueObj = value.AsObject(); switch (valueObj.Class) { case "Number": value = TypeConverter.ToNumber(value); break; case "String": value = TypeConverter.ToString(value); break; case "Boolean": value = TypeConverter.ToPrimitive(value); break; case "Array": value = SerializeArray(value.As <ArrayInstance>()); return(value); case "Object": value = SerializeObject(value.AsObject()); return(value); } } if (value == Null.Instance) { return("null"); } if (value.IsBoolean() && value.AsBoolean()) { return("true"); } if (value.IsBoolean() && !value.AsBoolean()) { return("false"); } if (value.IsString()) { return(Quote(value.AsString())); } if (value.IsNumber()) { if (GlobalObject.IsFinite(Undefined.Instance, Arguments.From(value)).AsBoolean()) { return(TypeConverter.ToString(value)); } return("null"); } var isCallable = value.IsObject() && value.AsObject() is ICallable; if (value.IsObject() && isCallable == false) { if (value.AsObject().Class == "Array") { return(SerializeArray(value.As <ArrayInstance>())); } return(SerializeObject(value.AsObject())); } return(JsValue.Undefined); }
public static BlittableJsonReaderObject Translate(JsonOperationContext context, Engine scriptEngine, ObjectInstance objectInstance, IResultModifier modifier = null, BlittableJsonDocumentBuilder.UsageMode usageMode = BlittableJsonDocumentBuilder.UsageMode.None, bool isNested = false) { if (objectInstance == null) { return(null); } if (objectInstance is BlittableObjectInstance boi && boi.Changed == false && isNested == false) { return(boi.Blittable.Clone(context)); } using (var writer = new ManualBlittableJsonDocumentBuilder <UnmanagedWriteBuffer>(context)) { writer.Reset(usageMode); writer.StartWriteObjectDocument(); var blittableBridge = new JsBlittableBridge(writer, usageMode, scriptEngine); blittableBridge.WriteInstance(objectInstance, modifier, isRoot: true, filterProperties: false); writer.FinalizeDocument(); return(writer.CreateReader()); } }
public ObjectInstance AppendObject(int x, int y, int z, ObjectInstance thing) { return(field[ToIndexInternal(x, y, z)].PutObject(thing, MapSizeW)); }
public TermStoreCollectionInstance(ObjectInstance prototype) : base(prototype) { PopulateFields(); PopulateFunctions(); }
public ObjectInstance InsertObject(int x, int y, int z, int stackPosition, ObjectInstance thing) { return(field[ToIndexInternal(x, y, z)].PutObject(thing, stackPosition)); }
public Common(ObjectInstance prototype) : base(prototype) { PopulateFunctions(); }
// INITIALIZATION //_________________________________________________________________________________________ /// <summary> /// Creates a new derived error function. /// </summary> /// <param name="prototype"> The next object in the prototype chain. </param> /// <param name="typeName"> The name of the error object, e.g. "Error", "RangeError", etc. </param> internal ErrorConstructor(ObjectInstance prototype, string typeName) : base(prototype, typeName, GetInstancePrototype(prototype.Engine, typeName)) { }
/// <summary> /// Loads this plugin /// </summary> public override void Load() { // Load the plugin LoadSource(); if (JavaScriptEngine.GetValue(Name).TryCast <ObjectInstance>() == null) { throw new Exception("Plugin is missing main object"); } Class = JavaScriptEngine.GetValue(Name).AsObject(); if (!Class.HasProperty("Name")) { Class.FastAddProperty("Name", Name, true, false, true); } else { Class.Put("Name", Name, true); } // Read plugin attributes if (!Class.HasProperty("Title") || string.IsNullOrEmpty(Class.Get("Title").AsString())) { throw new Exception("Plugin is missing title"); } if (!Class.HasProperty("Author") || string.IsNullOrEmpty(Class.Get("Author").AsString())) { throw new Exception("Plugin is missing author"); } if (!Class.HasProperty("Version") || Class.Get("Version").ToObject() == null) { throw new Exception("Plugin is missing version"); } Title = Class.Get("Title").AsString(); Author = Class.Get("Author").AsString(); Version = (VersionNumber)Class.Get("Version").ToObject(); if (Class.HasProperty("Description")) { Description = Class.Get("Description").AsString(); } if (Class.HasProperty("ResourceId")) { ResourceId = (int)Class.Get("ResourceId").AsNumber(); } HasConfig = Class.HasProperty("HasConfig") && Class.Get("HasConfig").AsBoolean(); // Set attributes Class.FastAddProperty("Plugin", JsValue.FromObject(JavaScriptEngine, this), true, false, true); Globals = new Dictionary <string, ICallable>(); foreach (var property in Class.GetOwnProperties()) { var callable = property.Value.Value?.TryCast <ICallable>(); if (callable != null) { Globals.Add(property.Key, callable); } } foreach (var property in Class.Prototype.GetOwnProperties()) { var callable = property.Value.Value?.TryCast <ICallable>(); if (callable != null) { Globals.Add(property.Key, callable); } } if (!HasConfig) { HasConfig = Globals.ContainsKey("LoadDefaultConfig"); } // Bind any base methods (we do it here because we don't want them to be hooked) BindBaseMethods(); }
public TermRangeFilterInstance(ObjectInstance prototype) : base(prototype) { this.PopulateFields(); this.PopulateFunctions(); }
protected SPFieldLookupValueInstance(ObjectInstance prototype, SPFieldLookupValue fieldLookupValue) : base(prototype) { m_fieldLookupValue = fieldLookupValue; }
public static void do_apply(CharacterInstance ch, string argument) { var firstArg = argument.FirstWord(); if (CheckFunctions.CheckIfEmptyString(ch, firstArg, "Apply what?")) { return; } var secondArg = argument.SecondWord(); if (CheckFunctions.CheckIfNotNullObject(ch, ch.CurrentFighting, "You're too busy fighting...")) { return; } if (handler.FindObject_CheckMentalState(ch)) { return; } var salve = ch.GetCarriedObject(firstArg); if (CheckFunctions.CheckIfNullObject(ch, salve, "You do not have that.")) { return; } CharacterInstance victim; ObjectInstance obj = null; if (string.IsNullOrEmpty(secondArg)) { victim = ch; } else { victim = ch.GetCharacterInRoom(secondArg); obj = ch.GetObjectOnMeOrInRoom(secondArg); if (CheckFunctions.CheckIfTrue(ch, victim == null && obj == null, "Apply it to what or whom?")) { return; } } if (CheckFunctions.CheckIfNotNullObject(ch, obj, "You can't do that... yet.")) { return; } if (CheckFunctions.CheckIfNotNullObject(ch, victim.CurrentFighting, "Wouldn't work very well while they're fighting...")) { return; } if (salve.ItemType != ItemTypes.Salve) { ApplyNonSalve(salve, ch, victim); return; } salve.Split(); salve.Values.Charges -= 1; if (!MudProgHandler.ExecuteObjectProg(MudProgTypes.Use, ch, salve, null, null)) { UseSalve(salve, ch, victim); } Macros.WAIT_STATE(ch, salve.Values.Delay); var retcode = ch.ObjectCastSpell((int)salve.Values.Skill1ID, (int)salve.Values.SpellLevel, victim); if (retcode == ReturnTypes.None) { retcode = ch.ObjectCastSpell((int)salve.Values.Skill2ID, (int)salve.Values.SpellLevel, victim); } if (retcode == ReturnTypes.CharacterDied || retcode == ReturnTypes.BothDied) { throw new CharacterDiedException("Salve {0}, Actor {1}, Victim {2}", salve.ID, ch.ID, victim.ID); } if (!handler.obj_extracted(salve) && salve.Values.Charges <= 0) { salve.Extract(); } }
private void ProcessMaps(ObjectInstance definitions, JintPreventResolvingTasksReferenceResolver resolver, List <string> mapList, List <MapMetadata> mapReferencedCollections, out Dictionary <string, List <JavaScriptMapOperation> > collectionFunctions) { var mapsArray = definitions.GetProperty(MapsProperty).Value; if (mapsArray.IsNull() || mapsArray.IsUndefined() || mapsArray.IsArray() == false) { ThrowIndexCreationException($"doesn't contain any map function or '{GlobalDefinitions}.{Maps}' was modified in the script"); } var maps = mapsArray.AsArray(); collectionFunctions = new Dictionary <string, List <JavaScriptMapOperation> >(); for (int i = 0; i < maps.Length; i++) { var mapObj = maps.Get(i.ToString()); if (mapObj.IsNull() || mapObj.IsUndefined() || mapObj.IsObject() == false) { ThrowIndexCreationException($"map function #{i} is not a valid object"); } var map = mapObj.AsObject(); if (map.HasProperty(CollectionProperty) == false) { ThrowIndexCreationException($"map function #{i} is missing a collection name"); } var mapCollectionStr = map.Get(CollectionProperty); if (mapCollectionStr.IsString() == false) { ThrowIndexCreationException($"map function #{i} collection name isn't a string"); } var mapCollection = mapCollectionStr.AsString(); if (collectionFunctions.TryGetValue(mapCollection, out var list) == false) { list = new List <JavaScriptMapOperation>(); collectionFunctions.Add(mapCollection, list); } if (map.HasProperty(MethodProperty) == false) { ThrowIndexCreationException($"map function #{i} is missing its {MethodProperty} property"); } var funcInstance = map.Get(MethodProperty).As <FunctionInstance>(); if (funcInstance == null) { ThrowIndexCreationException($"map function #{i} {MethodProperty} property isn't a 'FunctionInstance'"); } var operation = new JavaScriptMapOperation(_engine, resolver) { MapFunc = funcInstance, IndexName = _definitions.Name, MapString = mapList[i] }; if (map.HasOwnProperty(MoreArgsProperty)) { var moreArgsObj = map.Get(MoreArgsProperty); if (moreArgsObj.IsArray()) { var array = moreArgsObj.AsArray(); if (array.Length > 0) { operation.MoreArguments = array; } } } operation.Analyze(_engine); if (ReferencedCollections.TryGetValue(mapCollection, out var collectionNames) == false) { collectionNames = new HashSet <CollectionName>(); ReferencedCollections.Add(mapCollection, collectionNames); } collectionNames.UnionWith(mapReferencedCollections[i].ReferencedCollections); if (mapReferencedCollections[i].HasCompareExchangeReferences) { CollectionsWithCompareExchangeReferences.Add(mapCollection); } list.Add(operation); } }
public SessionJSInstance(ObjectInstance prototype) : base(prototype) { //this.PopulateFunctions(); //this.PopulateFields(); }
public UriInstance(ObjectInstance prototype) : base(prototype) { PopulateFields(); PopulateFunctions(); }
public UriInstance(ObjectInstance prototype, Uri uri) : this(prototype) { m_uri = uri; }
public void CreateContainerView(int id, ObjectInstance icon, string name, bool subContainer, bool dragAndDrop, bool pagination, int nOfSlots, int nOfObjects, int indexOfFirstObject) { var containerView = new ContainerView(id, icon, name, subContainer, dragAndDrop, pagination, nOfSlots, nOfObjects, indexOfFirstObject); m_ContainerViews[id] = containerView; }
public TfsTeamProjectCollectionInstance(ObjectInstance prototype) : base(prototype) { this.PopulateFields(); this.PopulateFunctions(); }
public JSScribbleImage(ObjectInstance prototype) : base(prototype.Engine, ((ClrFunction)prototype.Engine.Global["ScribbleImage"]).InstancePrototype) { this.PopulateFunctions(); }
public ObjectInstance PutObject(int x, int y, int z, ObjectInstance thing) { return(field[ToIndexInternal(x, y, z)].PutObject(thing, -1)); }
// CODE GEN METHODS //_________________________________________________________________________________________ /// <summary> /// Sets the value of a object literal property to a value. /// </summary> /// <param name="obj"> The object to set the property on. </param> /// <param name="key"> The property key (can be a string or a symbol). </param> /// <param name="value"> The value to set. </param> public static void SetObjectLiteralValue(ObjectInstance obj, object key, object value) { obj.DefineProperty(key, new PropertyDescriptor(value, Library.PropertyAttributes.FullAccess), throwOnError: false); }
// INITIALIZATION //_________________________________________________________________________________________ /// <summary> /// Creates a new String object. /// </summary> /// <param name="prototype"> The next object in the prototype chain. </param> internal StringConstructor(ObjectInstance prototype) : base(prototype, "String", new StringInstance(prototype.Engine.Object.InstancePrototype, string.Empty)) { }