private void LinkRemoved(ILinksContainer container, IDataFlow dataFlow) { if (dataFlow != null) { HandleLinkEvent(dataFlow); } }
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); }
private void ApplyThreatEvent([NotNull] IDataFlow target, [NotNull] IThreatEvent threatEvent) { var newEvent = target.AddThreatEvent(threatEvent.ThreatType); if (newEvent != null) { newEvent.Name = threatEvent.Name; newEvent.Description = threatEvent.Description; ApplyProperties(threatEvent, newEvent); var scenarios = threatEvent.Scenarios?.ToArray(); if (scenarios?.Any() ?? false) { foreach (var scenario in scenarios) { var newScenario = newEvent.AddScenario(scenario.Actor, scenario.Severity, scenario.Name); newScenario.Description = scenario.Description; ApplyProperties(scenario, newScenario); } } var mitigations = threatEvent.Mitigations?.ToArray(); if (mitigations?.Any() ?? false) { foreach (var mitigation in mitigations) { var newMitigation = newEvent.AddMitigation(mitigation.Mitigation, mitigation.Strength, mitigation.Status); newMitigation.Directives = mitigation.Directives; ApplyProperties(mitigation, newMitigation); } } } }
public SignUpPageViewModel(IAccountService accountService, Func <int, ConfirmationCodeEntryViewModel> createConfirmationCodeEntryViewModel, IDataFlow dataFlow, IViewService viewService, Func <IPhoneService> phoneService, IDeviceInfo deviceInfo, IConnectivity connectivity, IAppInfo appInfo) { this.accountService = accountService; this.createConfirmationCodeEntryViewModel = createConfirmationCodeEntryViewModel; this.dataFlow = dataFlow; this.viewService = viewService; this.phoneService = phoneService; this.deviceInfo = deviceInfo; this.connectivity = connectivity; this.appInfo = appInfo; SignUpCommand = new XCommand(async() => await SignUp(), CanSignUp); BusinessName = new Property <string>("Buiness Name").RequiredString("Business Name is required"); FirstName = new Property <string>("First Name").RequiredString("First Name is required"); LastName = new Property <string>("Last Name").RequiredString("Last Name is required"); Country = new Property <CountryDetails>("Country").Required("Choose a country"); MobileNumber = new Property <string>("Mobile Number").RequiredString("Mobile Number is required").RequiredFormat(@"^(\d|\s|-)*$", "Please just enter digits"); EmailAddress = new Property <string>("Email Address").RequiredString("Email address is required"); SignUpCommand.SetDependency(this, FirstName, LastName, MobileNumber, EmailAddress); AllCountries = CountriesData.List.OrderBy(c => c.CountryName).ToArray(); var countryCode = GetCountryCode(); var country = AllCountries.SingleOrDefault(c => c.DialingCode == countryCode) ?? AllCountries.SingleOrDefault(c => c.CountryCode == "AU"); Country.InitializeValue(country); }
public ILink AddLink(IDataFlow dataFlow) { 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); if (Instance is IDirty dirtyObject) { dirtyObject.SetDirty(); } if (Instance is ILinksContainer container) { _linkAdded?.Invoke(container, result); } } return(result); }
private void AddGridRow([NotNull] IDataFlow dataFlow, [NotNull] GridPanel panel) { var row = new GridRow( dataFlow.Name, dataFlow.Source?.Name ?? string.Empty, dataFlow.Target?.Name ?? string.Empty, dataFlow.FlowType.GetEnumLabel()); ((INotifyPropertyChanged)dataFlow).PropertyChanged += OnFlowPropertyChanged; if (dataFlow.Source != null) { ((INotifyPropertyChanged)dataFlow.Source).PropertyChanged += OnEntityPropertyChanged; dataFlow.Source.ImageChanged += OnImageChanged; } if (dataFlow.Target != null) { ((INotifyPropertyChanged)dataFlow.Target).PropertyChanged += OnEntityPropertyChanged; dataFlow.Target.ImageChanged += OnImageChanged; } row.Tag = dataFlow; row.Cells[0].CellStyles.Default.Image = dataFlow.GetImage(ImageSize.Small); row.Cells[1].CellStyles.Default.Image = dataFlow.Source?.GetImage(ImageSize.Small); row.Cells[2].CellStyles.Default.Image = dataFlow.Target?.GetImage(ImageSize.Small); for (int i = 0; i < row.Cells.Count; i++) { row.Cells[i].PropertyChanged += OnPropertyChanged; } AddSuperTooltipProvider(dataFlow, row.Cells[0]); AddSuperTooltipProvider(dataFlow.Source, row.Cells[1]); AddSuperTooltipProvider(dataFlow.Target, row.Cells[2]); panel.Rows.Add(row); }
public ValidationServiceTest() { departureValidationService = new DepartureValidationRules(); arrivalValidationService = new ArrivalValidationRules(); validationService = new ValidationService(departureValidationService, arrivalValidationService); dataFlow = new FlightDataFlowBlock(validationService, null); }
public Link([NotNull] IDataFlow dataFlow) : this() { _dataFlow = dataFlow; _modelId = dataFlow.Model.Id; _model = dataFlow.Model; _associatedId = _dataFlow.Id; }
public Spider AddDataFlow(IDataFlow dataFlow) { CheckIfRunning(); dataFlow.Logger = _loggerFactory.CreateLogger(dataFlow.GetType()); _dataFlows.Add(dataFlow); return(this); }
public FlightEventProcessor(IConfiguration configuration, IDataFlow dataFlowBlockProvider, IValidationService validationService) { this.dataFlowBlockProvider = dataFlowBlockProvider; this.validationService = validationService; this.configuration = configuration; }
private string GetKey([NotNull] IDataFlow dataFlow) { var first = dataFlow.SourceId.ToString("N"); var second = dataFlow.TargetId.ToString("N"); return((string.CompareOrdinal(first, second) > 0) ? $"{first}{second}" : $"{second}{first}"); }
public string GetMsTmtDataFlowId([NotNull] IDataFlow dataFlow) { var schema = GetSchema(); var propertyType = schema.GetPropertyType(ThreatModelDataFlowId); var property = dataFlow.GetProperty(propertyType); return(property?.StringValue); }
/// <summary> /// Add DataFlow /// </summary> /// <param name="dataFlow">数据流处理器</param> /// <returns></returns> public Spider AddDataFlow(IDataFlow dataFlow) { Check.NotNull(dataFlow, nameof(dataFlow)); CheckIfRunning(); dataFlow.Logger = _services.GetRequiredService <ILoggerFactory>().CreateLogger(dataFlow.GetType()); _dataFlows.Add(dataFlow); return(this); }
/// <inheritdoc/> public override void Bind(IDataFlow dataFlow, object db, object r) { var record = Data?.Record ?? r; dataFlow.Bind(this, db, record); base.Bind(dataFlow, db, record); }
public SpiderFactory AddDataFlow(IDataFlow dataFlow) { if (dataFlow == null) { throw new ArgumentNullException(nameof(dataFlow)); } _dataFlows.Add(dataFlow); return(this); }
public void StreamDataFlowReadsDataCorrectly(string anyText) { StreamDataFlowProvider provider = new StreamDataFlowProvider(() => new MemoryStream(Encoding.UTF8.GetBytes(anyText))); using (IDataFlow flow = provider.CreateFlow()) { flow .ToArray() .ShouldHaveMatchingItems(anyText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); } }
private bool AreEquivalentFlows([NotNull] IDataFlow left, [NotNull] IDataFlow right) { bool result = false; if (left.FlowType == right.FlowType) { result = AreEquivalent(left, right); } return(result); }
public void ApplyTo([NotNull] IDataFlow flow) { flow.FlowType = FlowType; flow.ClearProperties(); this.CloneProperties(flow); if (flow is DataFlow internalFlow) { internalFlow._templateId = Id; internalFlow._template = this; } }
public DataFlowBlockTests() { departureValidationService = new DepartureValidationRules(); arrivalValidationService = new ArrivalValidationRules(); validationService = new ValidationService(departureValidationService, arrivalValidationService); var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider(); var factory = serviceProvider.GetService <ILoggerFactory>(); var logger = factory.CreateLogger <FlightDataFlowBlock>(); dataFlow = new FlightDataFlowBlock(validationService, logger); }
public ConfirmationCodeEntryViewModel(int requestId, Func <SetPinViewModel> createSetPinViewModel, IAccountService accountService, IViewService viewService, IDataFlow dataFlow, IDeviceInfo deviceInfo, IConnectivity connectivity) : base() { this.accountService = accountService; this.viewService = viewService; this.dataFlow = dataFlow; this.deviceInfo = deviceInfo; this.connectivity = connectivity; this.requestId = requestId; this.createSetPinViewModel = createSetPinViewModel; Initialize(); }
private void RemoveRelated([NotNull] IDataFlow flow) { var diagrams = _diagrams?.ToArray(); if (diagrams != null) { foreach (var diagram in diagrams) { diagram.RemoveLink(flow.Id); } } }
private bool AreEquivalent([NotNull] IEntity left, IEnumerable <IDataFlow> leftFlows, [NotNull] IEntity right, IEnumerable <IDataFlow> rightFlows, bool incoming) { bool result = false; if (leftFlows?.Any() ?? false) { if (rightFlows?.Any() ?? false) { if (leftFlows.Count() == rightFlows.Count()) { result = true; foreach (var flow in leftFlows) { IDataFlow rightFlow = null; if (incoming) { if (flow.Source is IEntity source) { rightFlow = rightFlows.FirstOrDefault(x => x.Source == source); } } else { if (flow.Target is IEntity target) { rightFlow = rightFlows.FirstOrDefault(x => x.Target == target); } } if (rightFlow == null || (flow.FlowType != rightFlow.FlowType) || !AreEquivalent(flow, rightFlow)) { result = false; break; } } } } } else { if (!(rightFlows?.Any() ?? false)) { result = true; } } return(result); }
public IDataFlow CreateFlow([Required] string name, Guid sourceId, Guid targetId) { IDataFlow result = _model.AddDataFlow(name, sourceId, targetId, this); if (result != null) { result.Description = Description; result.FlowType = FlowType; this.CloneProperties(result); } return(result); }
public void Add(IDataFlow dataFlow) { if (dataFlow is IThreatModelChild child && child.Model != this) { throw new ArgumentException(); } if (_dataFlows == null) { _dataFlows = new List <IDataFlow>(); } _dataFlows.Add(dataFlow); }
private bool IsSelected([NotNull] IDataFlow item, string filter, DataFlowListFilter filterSpecial) { bool result; if (string.IsNullOrWhiteSpace(filter)) { result = true; } else { result = (!string.IsNullOrWhiteSpace(item.Name) && item.Name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0) || (!string.IsNullOrWhiteSpace(item.Description) && item.Description.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0); if (!result && (item.Properties?.Any() ?? false)) { var properties = item.Properties.ToArray(); foreach (var property in properties) { var stringValue = property.StringValue; if ((!string.IsNullOrWhiteSpace(stringValue) && stringValue.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)) { result = true; break; } } } } if (result) { switch (filterSpecial) { case DataFlowListFilter.NoDiagram: result = _model.Diagrams?.All(x => x.Links?.All(y => y.AssociatedId != item.Id) ?? true) ?? true; break; case DataFlowListFilter.NoThreatEvents: result = !(item.ThreatEvents?.Any() ?? false); break; case DataFlowListFilter.MissingMitigations: result = item.ThreatEvents?.Any(x => !(x.Mitigations?.Any() ?? false)) ?? false; break; } } return(result); }
public void SetMsTmtDataFlowId([NotNull] IDataFlow dataFlow, [Required] string value) { var schema = GetSchema(); var propertyType = schema.GetPropertyType(ThreatModelDataFlowId); var property = dataFlow.GetProperty(propertyType); if (property == null) { property = dataFlow.AddProperty(propertyType, value); } else { property.StringValue = value; } }
public static bool GenerateThreatEvents(this IDataFlow flow) { bool result = false; if (flow.Model is IThreatModel model) { var threatTypesWithRules = GetThreatTypesWithRules(model)?.ToArray(); if (threatTypesWithRules?.Any() ?? false) { ApplyThreatTypes(flow, threatTypesWithRules); result = true; } } return(result); }
private void CopyFlowDetails([NotNull] IDataFlow source, [NotNull] IDataFlow target) { target.FlowType = source.FlowType; target.Description = source.Description; ApplyProperties(source, target); var threatEvents = source.ThreatEvents?.ToArray(); if (threatEvents?.Any() ?? false) { foreach (var threatEvent in threatEvents) { ApplyThreatEvent(target, threatEvent); } } }
private GridRow GetRow([NotNull] IDataFlow dataFlow) { GridRow result = null; var rows = _grid.PrimaryGrid.Rows.OfType <GridRow>().ToArray(); foreach (var row in rows) { if (row.Tag == dataFlow) { result = row; break; } } return(result); }
private FlowMergeInfo GetFlowMergeInfo([NotNull] GridRow row) { FlowMergeInfo result = null; if (!((bool)row.Cells["Ignore"].Value)) { var name = (string)row.Cells["Name"].Value; var rows = row.Rows.OfType <GridPanel>().FirstOrDefault()?.Rows.OfType <GridRow>().ToArray(); if (rows?.Any() ?? false) { IDataFlow master = null; List <IDataFlow> slaves = null; foreach (var curr in rows) { if (curr.Tag is IDataFlow dataFlow) { if ((bool)curr.Cells["Master"].Value) { master = dataFlow; if (string.IsNullOrWhiteSpace(name)) { name = dataFlow.Name; } } else { if (slaves == null) { slaves = new List <IDataFlow>(); } slaves.Add(dataFlow); } } } if (master != null && slaves != null) { result = new FlowMergeInfo(name, master, slaves); } } } return(result); }