public IEntityShape AddShape(IEntity entity, PointF position) { if (!(IsInitialized?.Get() ?? false)) { return(null); } if (entity == null) { throw new ArgumentNullException(nameof(entity)); } IEntityShape result = null; if (GetEntityShape(entity.Id) == null) { if (_entities == null) { _entities = new List <IEntityShape>(); } result = new EntityShape(Model?.Get(), entity) { Position = position }; _entities.Add(result); Dirty.IsDirty = true; _entityShapeAdded?.Invoke(EntityShapesContainer?.Get(), result); } return(result); }
public IThreatEventScenario AddScenario(IThreatActor threatActor, ISeverity severity, string name = null) { if (!(IsInitialized?.Get() ?? false)) { return(null); } if (threatActor == null) { throw new ArgumentNullException(nameof(threatActor)); } if (severity == null) { throw new ArgumentNullException(nameof(severity)); } IThreatEventScenario result = new ThreatEventScenario(MySelf?.Get(), threatActor, name) { Severity = severity }; if (_scenarios == null) { _scenarios = new List <IThreatEventScenario>(); } _scenarios.Add(result); Dirty.IsDirty = true; _threatEventScenarioAdded?.Invoke(ScenariosContainer?.Get(), result); return(result); }
/// <summary> /// /// </summary> private static void CatmullClarkSmoothFixed <V, E, F>(HeMeshBase <V, E, F> mesh, Property <V, Vec3d> position) where V : HeVertex <V, E, F> where E : Halfedge <V, E, F> where F : HeFace <V, E, F> { var verts = mesh.Vertices; int ev0 = verts.Count - mesh.Edges.Count; // index of first edge vertex int fv0 = ev0 - mesh.Faces.Count; // index of first face vertex // set old vertices for (int i = 0; i < fv0; i++) { var v = verts[i]; if (v.IsRemoved || v.IsBoundary) { continue; // skip boundary verts } var fsum = new Vec3d(); var esum = new Vec3d(); int n = 0; foreach (var he in v.OutgoingHalfedges) { fsum += position.Get(verts[he.Face.Index + fv0]); esum += position.Get(verts[(he.Index >> 1) + ev0]); n++; } var t = 1.0 / n; position.Set(v, (position.Get(v) * (n - 3) + fsum * t + 2 * esum * t) * t); } }
public IThreatEvent AddThreatEvent(IThreatType threatType) { if (!(IsInitialized?.Get() ?? false)) { return(null); } IThreatEvent result = null; var threatEventsContainer = ThreatEventsContainer?.Get(); if ((_threatEvents?.All(x => x.ThreatTypeId != threatType.Id) ?? true) && threatEventsContainer is IIdentity identity) { result = new ThreatEvent(Model?.Get(), threatType, identity); if (_threatEvents == null) { _threatEvents = new List <IThreatEvent>(); } _threatEvents.Add(result); Dirty.IsDirty = true; _threatEventAdded?.Invoke(threatEventsContainer, result); } return(result); }
public ILink AddLink(IDataFlow dataFlow) { if (!(IsInitialized?.Get() ?? false)) { return(null); } if (dataFlow == null) { throw new ArgumentNullException(nameof(dataFlow)); } ILink result = null; if (GetLink(dataFlow.Id) == null) { if (_links == null) { _links = new List <ILink>(); } result = new Link(dataFlow); _links.Add(result); Dirty.IsDirty = true; _linkAdded?.Invoke(LinksContainer?.Get(), result); } return(result); }
public IThreatEventMitigation AddMitigation(IMitigation mitigation, IStrength strength, MitigationStatus status = MitigationStatus.Proposed, string directives = null) { if (!(IsInitialized?.Get() ?? false)) { return(null); } if (mitigation == null) { throw new ArgumentNullException(nameof(mitigation)); } IThreatEventMitigation result = null; if (GetMitigation(mitigation.Id) == null) { result = new ThreatEventMitigation(MySelf?.Get(), mitigation, strength); result.Status = status; result.Directives = directives; if (_mitigations == null) { _mitigations = new List <IThreatEventMitigation>(); } _mitigations.Add(result); Dirty.IsDirty = true; _threatEventMitigationAdded?.Invoke(MitigationsContainer?.Get(), result); } return(result); }
/// <summary> /// /// </summary> /// <typeparam name="V"></typeparam> /// <typeparam name="E"></typeparam> /// <typeparam name="F"></typeparam> /// <param name="mesh"></param> /// <param name="position"></param> private static void QuadSplitGeometry <V, E, F>(HeMesh <V, E, F> mesh, Property <V, Vec3d> position) where V : HeMesh <V, E, F> .Vertex where E : HeMesh <V, E, F> .Halfedge where F : HeMesh <V, E, F> .Face { // create face vertices foreach (var f in mesh.Faces) { var v = mesh.AddVertex(); if (!f.IsUnused) { position.Set(v, f.Vertices.Mean(position.Get)); } } // create edge vertices foreach (var he in mesh.Edges) { var v = mesh.AddVertex(); if (!he.IsUnused) { var p = (position.Get(he.Start) + position.Get(he.End)) * 0.5; position.Set(v, p); } } }
public IGroupShape AddShape(IGroup group, PointF position, SizeF size) { if (!(IsInitialized?.Get() ?? false)) { return(null); } if (group == null) { throw new ArgumentNullException(nameof(group)); } IGroupShape result = null; if (GetGroupShape(group.Id) == null) { if (_groups == null) { _groups = new List <IGroupShape>(); } result = new GroupShape(Model?.Get(), group) { Position = position, Size = size }; _groups.Add(result); Dirty.IsDirty = true; _groupShapeAdded?.Invoke(GroupShapesContainer?.Get(), result); } return(result); }
public bool Lock(string key) { if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); bool result = false; if (string.IsNullOrWhiteSpace(_lockingKey) || string.CompareOrdinal(key, _lockingKey) == 0) { _lockingKey = key; result = true; try { CascadeLock?.Invoke(); } catch { // TODO: verify if hiding exceptions is the right thing to do, here. } finally { var identity = Identity?.Get(); if (identity != null) _objectLocked?.Invoke(identity); } } return result; }
public IThreatEventScenario GetScenario(Guid id) { if (!(IsInitialized?.Get() ?? false)) { return(null); } return(_scenarios?.FirstOrDefault(x => x.Id == id)); }
/// <summary> /// Method invoked when (instead of) the target field or property is retrieved. /// </summary> /// <param _name="args">Context information.</param> public override void OnGetValue(LocationInterceptionArgs args) { object value = _viewState.Get()[_name]; if (value != null) { args.Value = value; } }
public IThreatEventMitigation GetMitigation(Guid mitigationId) { if (!(IsInitialized?.Get() ?? false)) { return(null); } return(_mitigations?.FirstOrDefault(x => x.MitigationId == mitigationId)); }
public void OnPropertyChanged(IProperty property) { if (property == null) { throw new ArgumentNullException(nameof(property)); } _propertyValueChanged?.Invoke(PropertiesContainer?.Get(), property); }
public ILink GetLink(Guid dataFlowId) { if (!(IsInitialized?.Get() ?? false)) { return(null); } return(_links?.FirstOrDefault(x => x.AssociatedId == dataFlowId)); }
public IEntity GetEntity(Guid id) { if (!(IsInitialized?.Get() ?? false)) { return(null); } return(Model?.Get().Entities?.FirstOrDefault(x => x.Id == id && x.ParentId == _id?.Get())); }
/// <summary> /// Method invoked when (instead of) the target field or property is retrieved. /// </summary> /// <param name="args">Context information.</param> public override void OnGetValue(LocationInterceptionArgs args) { var value = ViewState.Get()[name]; if (value != null) { args.Value = value; } }
// Sets up fundamental class connections for the Chr public void Start() { if (bStarted == false) { bStarted = true; nMaxSkillsLeft = 1; InitSkillSlots(); stateSelect = STATESELECT.IDLE; pnMaxHealth = new Property <int>(100); nCurHealth = pnMaxHealth.Get(); pnArmour = new Property <int>(0); pnPower = new Property <int>(0); pnDefense = new Property <int>(0); SetStateReadiness(new StateFatigued(this)); view = GetComponent <ViewChr>(); view.Start(); } }
public virtual bool Update(T obj, bool update, params string[] properties) { Type t = GetType(); if (properties != null && properties.Length > 0) { foreach (string s in properties) { PropertyInfo type = t.GetProperty(s); if (type.SetMethod != null) { Property.Set(this, type.Name, Property.Get(obj, type.Name)); } } } else { foreach (PropertyInfo prop in t.GetProperties()) { if (prop.SetMethod != null) { Property.Set(this, prop.Name, Property.Get(obj, prop.Name)); } //prop.SetValue(this, prop.GetValue(obj)); } } if (update) { return(Update()); } return(true); }
public new bool Equals(object x, object y) { object value1 = Property.Get(x); object value2 = Property.Get(y); return(Comparer.Equals(value1, value2)); }
public static byte[] Serialize(object obj) { using (MemoryStream str = new MemoryStream()) using (BinaryWriter wri = new BinaryWriter(str)) { Type t = obj.GetType(); if (t.IsPrimitive) { SerializePrimitive(wri, obj); } else if (t.IsList()) { SerializeList(wri, obj); } else if (t.IsArray) { SerializeArray(wri, obj); } else { foreach (PropertyInfo p in t.GetProperties().OrderBy(x => x.Name)) { SerializeProperty(wri, p.PropertyType, Property.Get(obj, p.Name)); } } return(str.ToArray()); } }
/// <summary> /// Constructor /// </summary> private Reflection(System.Type type) { this.Type = type; this.Interfaces = new ReadOnlyCollection <System.Type>(type.GetInterfaces()); this.PropertyInfos = new ReadOnlyCollection <PropertyInfo>(type.GetProperties()); var propDic = new Dictionary <string, Property>(); foreach (var property in this.PropertyInfos) { var xbProp = Property.Get(property); propDic.Add(property.Name, xbProp); } this.Properties = new ReadOnlyDictionary <string, Property>(propDic); this.Constructors = new ReadOnlyCollection <ConstructorInfo>(type.GetConstructors()); this.MethodInfos = new ReadOnlyCollection <MethodInfo>(type.GetMethods()); var methodDic = new Dictionary <MethodInfo, ReadOnlyCollection <ParameterInfo> >(); foreach (var method in this.MethodInfos) { methodDic.Add(method, new ReadOnlyCollection <ParameterInfo>(method.GetParameters())); } this.MethodParameters = new ReadOnlyDictionary <MethodInfo, ReadOnlyCollection <ParameterInfo> >(methodDic); this.EventInfos = new ReadOnlyCollection <EventInfo>(type.GetEvents()); this.FieldInfos = new ReadOnlyCollection <FieldInfo>(type.GetFields()); }
public void CannotWriteToReadonlyProperties() { var sut = Property.Get <PropertyTests, string>(GetType().GetProperty("ReadonlyProperty")); var iSut = (IProperty)sut; Assert.That(() => sut.Set(this, "wooo!!"), Throws.Exception); Assert.That(() => iSut.Set(this, "wooo!!"), Throws.Exception); }
public void CannotReadFromWriteonlyProperties() { var sut = Property.Get <PropertyTests, string>(GetType().GetProperty("WriteonlyProperty")); var iSut = (IProperty)sut; Assert.That(() => sut.Get(this), Throws.Exception); Assert.That(() => iSut.Get(this), Throws.Exception); }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (ReferenceObject.Expression != null) { targetCommand.AddParameter("ReferenceObject", ReferenceObject.Get(context)); } if (DifferenceObject.Expression != null) { targetCommand.AddParameter("DifferenceObject", DifferenceObject.Get(context)); } if (SyncWindow.Expression != null) { targetCommand.AddParameter("SyncWindow", SyncWindow.Get(context)); } if (Property.Expression != null) { targetCommand.AddParameter("Property", Property.Get(context)); } if (ExcludeDifferent.Expression != null) { targetCommand.AddParameter("ExcludeDifferent", ExcludeDifferent.Get(context)); } if (IncludeEqual.Expression != null) { targetCommand.AddParameter("IncludeEqual", IncludeEqual.Get(context)); } if (PassThru.Expression != null) { targetCommand.AddParameter("PassThru", PassThru.Get(context)); } if (Culture.Expression != null) { targetCommand.AddParameter("Culture", Culture.Get(context)); } if (CaseSensitive.Expression != null) { targetCommand.AddParameter("CaseSensitive", CaseSensitive.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
/// <summary> /// /// </summary> /// <typeparam name="V"></typeparam> /// <typeparam name="E"></typeparam> /// <typeparam name="F"></typeparam> /// <param name="mesh"></param> /// <param name="position"></param> /// <param name="boundaryType"></param> private static void CatmullClarkGeometry <V, E, F>(HeMeshBase <V, E, F> mesh, Property <V, Vec3d> position, SmoothBoundaryType boundaryType) where V : HeVertex <V, E, F> where E : Halfedge <V, E, F> where F : HeFace <V, E, F> { var verts = mesh.Vertices; int fv0 = verts.Count; // index of first face vertex // create face vertices foreach (var f in mesh.Faces) { var v = mesh.AddVertex(); if (!f.IsRemoved) { position.Set(v, f.Vertices.Mean(position.Get)); } } // create edge vertices foreach (var he0 in mesh.Edges) { var v = mesh.AddVertex(); if (he0.IsRemoved) { continue; } if (he0.IsBoundary) { position.Set(v, he0.Lerp(position.Get, 0.5)); continue; } var he1 = he0.Twin; var p0 = position.Get(he0.Start); var p1 = position.Get(he1.Start); var p2 = position.Get(verts[he0.Face.Index + fv0]); var p3 = position.Get(verts[he1.Face.Index + fv0]); position.Set(v, (p0 + p1 + p2 + p3) * 0.25); } // smooth old vertices CatmullClarkSmooth(mesh, position, boundaryType); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: public float getValue(@Nullable final android.view.View view) //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: public float GetValue(View view) { if (view != null) { return((float)mViewProperty.Get(view)); } return(0); }
public void ChangeHealth(int nChange) { if (nCurHealth + nChange > pnMaxHealth.Get()) { nCurHealth = pnMaxHealth.Get(); } else if (nCurHealth + nChange <= 0) { nCurHealth = 0; KillCharacter(); } else { nCurHealth += nChange; } subLifeChange.NotifyObs(this, nChange); }
public IGroup GetGroup(Guid id) { if (!(IsInitialized?.Get() ?? false)) { return(null); } return(Model?.Get().Groups? .FirstOrDefault(x => x.Id == id && ((x as IGroupElement)?.ParentId ?? Guid.Empty) == _id?.Get())); }
//Internals internal static void FixIndex(IUnifiedIMObject obj, Type t, string property, object oldValue) { if (Indexes.ContainsKey(t)) { ObjectIndexer <IUnifiedIMObject> pIndexes = Indexes[t]; object cVal = Property.Get(obj, property) ?? null; pIndexes.RemoveIndex(property, oldValue, obj); pIndexes.AddIndex(property, cVal, obj); } }
public void GetShouldReturnValueForExistingPath() { var foo = new Foo { Boo = new Boo { Name = "me" } }; Assert.AreEqual("me", Property.Get(foo, "Boo.Name")); }
public StudioUI(Studio studio, Sequence sequence, Gui gui, Layer gridLayer, Layer uiLayer) { _gui = gui; // create layers var studioLayer = Add(new Layer()); var annotationLayer = studioLayer.Add(new Layer()); // fullscreen switch Add(new KeyBinding(Keys.F1, () => Render.Viewport.IsFullScreen = !Render.Viewport.IsFullScreen)); // tool bars setup var panel = uiLayer.Add(new StackPanel(5) { Padding = new Margin() }); var horizontalBar = panel.Add(new StackPanel(5) { Padding = new Margin(), Orientation = Orientation.Horizontal }); //var verticalBar = panel.Add(new StackPanel(5)); //uiLayer.Add(new BackgroundView(verticalBar)); // time controls var timePanel = horizontalBar.Add(new StackPanel(5) { Orientation = Orientation.Horizontal }); uiLayer.Add(new BackgroundView(timePanel)); // camera var cameraMode = Add(new ToolUI()); cameraMode.Add(new EditorCameraController()); // editor mode / game mode switch var toolMode = new ToggleComponent(v => { UI.ToolMode.Set(v); Hgl.Time.IsPaused = v; gui.Scene.IsFocusable = v; uiLayer.IsEnabled = v; }); var pauseButton = timePanel.Add(new ToggleButton(toolMode) { Size = _buttonSize }); uiLayer.Add(new ToggleButonView(pauseButton, DataPack.Textures.Studio.Pause, DataPack.Textures.Studio.Play)); //Add(new PropertyRecorder<bool>("toolMode", toolMode)); Add(new KeyBinding(Keys.Tab, toolMode.Toggle)); Add(new KeyBinding(Keys.Q, Hgl.Time.TogglePause)); // next frame var nextFrameButton = timePanel.Add(new Button(() => NextFrame(pauseButton)) { Size = _buttonSize }); uiLayer.Add(new PressButtonView(nextFrameButton, DataPack.Textures.Studio.NextFrame)); Add(new KeyBinding(Keys.E, nextFrameButton)); // slow motion var slowMo = Add(new SlowMotion(pauseButton)); var slowMoButton = timePanel.Add(new Button(slowMo.Start, slowMo.Stop) { Size = _buttonSize }); uiLayer.Add(new PressButtonView(slowMoButton, DataPack.Textures.Studio.SlowMotion)); Add(new KeyBinding(Keys.R, slowMoButton)); // sequence var seqPanel = horizontalBar.Add(new StackPanel(5) { Orientation = Orientation.Horizontal }); uiLayer.Add(new BackgroundView(seqPanel)); var previousButton = seqPanel.Add(new Button(sequence.Previous) { Size = _buttonSize }); uiLayer.Add(new PressButtonView(previousButton, DataPack.Textures.Studio.Previous)); Add(new KeyBinding(Keys.OemMinus, previousButton)); var nextButton = seqPanel.Add(new Button(sequence.Next) { Size = _buttonSize }); uiLayer.Add(new PressButtonView(nextButton, DataPack.Textures.Studio.Next)); Add(new KeyBinding(Keys.OemPlus, nextButton)); var reloadButton = seqPanel.Add(new Button(() => ReloadCurrentScene(sequence)) { Size = _buttonSize }); uiLayer.Add(new PressButtonView(reloadButton, DataPack.Textures.Studio.Reload)); Add(new KeyBinding(Keys.Back, reloadButton)); // tool bar var toolBar = horizontalBar.Add(new StackPanel(5) { Orientation = Orientation.Horizontal }); uiLayer.Add(new BackgroundView(toolBar)); // camera home position var homePosition = new Property<Vector2>(); uiLayer.Add(new PropertyRecorder<Vector2>("homePosition", homePosition)); uiLayer.Add(new KeyBinding(Keys.End, () => homePosition.Set(Render.Camera.Position))); uiLayer.Add(new KeyBinding(Keys.Home, () => Render.Camera.Position = homePosition.Get())); // grid var grid = new Node { new Grid(Color.White, size: .1f, minZoomLevel: .02f, fullZoomLevel: 9f), new Grid(Color.White, size: 1, minZoomLevel: .008f, fullZoomLevel: .8f), new Grid(Color.White, size: 10, minZoomLevel: .005f, fullZoomLevel: .1f), new Grid(Color.White, size: 100, minZoomLevel: .001f, fullZoomLevel: .01f), new Grid(Color.White, size: 1000, minZoomLevel: .0001f, fullZoomLevel: .001f), }; var gridSwitch = new ToggleComponent(() => gridLayer.Add(grid), () => gridLayer.Remove(grid)); var gridControl = toolBar.Add(new ToggleButton(gridSwitch) { Size = _buttonSize }); Add(gridControl); uiLayer.Add(new ToggleButonView(gridControl, DataPack.Textures.Studio.Grid)); Add(new PropertyRecorder<bool>("gridState", gridControl)); Add(new KeyBinding(Keys.G, gridControl.Toggle)); // annotation Add(Annotate.Update); var annotation = new ToggleComponent(() => annotationLayer.Add(Annotate.Layer), () => annotationLayer.Remove(Annotate.Layer)); var annotationControl = toolBar.Add((new ToggleButton(annotation) { Size = _buttonSize })); Add(annotationControl); uiLayer.Add(new ToggleButonView(annotationControl, DataPack.Textures.Studio.Annotate)); Add(new PropertyRecorder<bool>("showAnnotations", annotationControl)); Add(new KeyBinding(Keys.V, annotationControl.Toggle)); // live coding var liveCodingSwitch = toolBar.Add(new ToggleButton(true, v => LiveComponent.AutoRecompile = v) { Size = _buttonSize }); uiLayer.Add(new ToggleButonView(liveCodingSwitch, DataPack.Textures.Studio.LiveCoding)); Add(new KeyBinding(Keys.L, liveCodingSwitch.Toggle)); // auto-pause on window lost focus /* var autoPause = Add(new PauseAuto(pauseButton)); var autoPauseSwitch = toolBar.Add(new CheckBox(autoPause) { Size = _buttonSize }); uiLayer.Add(new IconUI.ToggleButon(autoPauseSwitch, DataPack.Textures.Studio.AutoPause)); Add(new KeyBinding(Keys.OemTilde, autoPauseSwitch.Toggle)); */ // serialization var savePanel = horizontalBar.Add(new StackPanel(5) { Orientation = Orientation.Horizontal }); uiLayer.Add(new BackgroundView(savePanel)); var saveButton = savePanel.Add(new Button(studio.Serialize) { Size = _buttonSize }); uiLayer.Add(new PressButtonView(saveButton, DataPack.Textures.Studio.Save)); Add(new KeyBinding(Keys.F6, saveButton)); var loadButton = savePanel.Add(new Button(studio.Unserialize) { Size = _buttonSize }); uiLayer.Add(new PressButtonView(loadButton, DataPack.Textures.Studio.Load)); Add(new KeyBinding(Keys.F7, loadButton)); // edition tools //var polytool = new PolyEditor(); //UIFocusableControl currentTool; //var polyButton = verticalBar.Add(new ToggleButton(v => { if (v) currentTool = polytool; }) { Size = _buttonSize }); //var toolButtons = new ToggleButtonList { polyButton }; // tree /*var tree = new Tree(); uiLayer.Add(tree);*/ // inspector _inspector = new Inspector(); gui.Scene.NodeSelected += _inspector.Inspect; //tree.NodeSelected += _inspector.Inspect; uiLayer.Add(_inspector); // debug //Add(new Watch()); Add(new FpsCounter(DataPack.Fonts.StudioFont)); // cursor _focusCursor = uiLayer.Add(new Cursor(DataPack.Textures.Cursors.Link) { IsVisible = false, Offset = new Vector2(-5, 0) }); gui.InteractionFocusedChanged += SetFocusCursor; }