//Methods //Commands private void AddItemToList(object param) { var item = param as string; switch (param) { case "Scenario": Scenarios.Add(new Scenario()); SelectedScenario = Scenarios.Last(); CommandEditItem.Execute(SelectedScenario); break; case "Macro": MacroList.Add(new Macro()); SelectedMacro = MacroList.Last(); CommandEditItem.Execute(SelectedMacro); break; case "ActionTemplate": ActionTemplate newTemplate = new ActionTemplate(); ActionTemplates.Insert(ActionTemplates.Count - 1, newTemplate); SelectedTemplate = newTemplate; CommandEditItem.Execute(SelectedTemplate); break; default: Logger.GetLogger().CatchException("ViewModel", "AddItemToList", $"Unknown param{{{item}}}"); throw new Exception(); } }
public void Test_ScenarioToXml() { Scenarios.Add(new Scenario("name", "MA", "residence", "fid", "http://www.someInsuranceCo.com/scenarios")); XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("root"); XmlElement contextElem = doc.CreateElement("context"); doc.AppendChild(root); root.AppendChild(contextElem); WriteScenarios(contextElem, root, doc, false, null); System.IO.StringWriter writer = new System.IO.StringWriter(); doc.Save(writer); Console.WriteLine(writer.ToString()); string expectedXml = @"<?xml version=""1.0"" encoding=""utf-16""?> <root xmlns:fid=""http://www.someInsuranceCo.com/scenarios""> <context> <scenario> <fid:residence>MA</fid:residence> </scenario> </context> </root>"; Assert.AreEqual(expectedXml, writer.ToString()); }
public void Add(Scenario scenario) { if (Scenarios.ContainsKey(scenario.Id)) { return; } Scenarios.Add(scenario.Id, scenario); }
public ScreenshotScenarioViewModel( Screenshot1 screenshot1, Screenshot2 screenshot2) : base() { DisplayName = "Screenshots"; Scenarios.Add(screenshot1); Scenarios.Add(screenshot2); }
public EncryptionScenarioViewModel( DESEncryption desEncryption, AESEncryption aesEncryption, TrueCrypt trueCrypt) : base() { DisplayName = "Encryption"; Scenarios.Add(desEncryption); Scenarios.Add(aesEncryption); Scenarios.Add(trueCrypt); }
public void PrepareData(IEnumerable <XMLParse.EAScenario> result) { var currentDate = DateTime.Now; try { foreach (var scenario in result) { var db = new DatabaseOperations(); scenario.Timestamp = currentDate; scenario.PreviousVersionId = db.GetActive_EAscenarios(Project) .Where(s => s.ProjectId == scenario.ProjectId && s.XmiId == scenario.XmiId) .Select(s => s.Id) .FirstOrDefault(); Scenarios.Add(DataMapper.MapEAScenario(scenario)); foreach (var useCase in scenario.UseCase) { useCase.Id = Guid.NewGuid(); useCase.Timestamp = currentDate; useCase.EAScenarioId = scenario.Id; UseCases.Add(useCase); } foreach (var step in scenario.Steps) { step.Id = Guid.NewGuid(); step.Timestamp = currentDate; step.EAScenarioId = scenario.Id; step.PreviousVersionId = db.GetActive_Steps() .Where(s => s.EAScenarioId == scenario.Id && s.Guid == step.Id) .Select(s => s.Id) .FirstOrDefault(); Steps.Add(step); } } InsertEAData(); } catch (Exception e) { MessageBox.Show( "W aplikacji wystąpił błąd!\n" + e, "Błąd!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); throw; } }
void AddNewMorality(object sender, EventArgs e) { var moralityToAdd = ((ComboBoxItem)ToAdd.SelectedItem).Name; if (moralityToAdd == null) { return; } int newMoralityNumber = 1; // Set it to one in case there aren't any var previousChoice = Scenarios .Where(scenario => scenario.Name.Contains(moralityToAdd)) .ToList(); // If there already are choices if (previousChoice.Count() != 0) { var previousMoralityNumber = previousChoice .Select(scenario => scenario.Name) .Last() .Remove(0, moralityToAdd.Length + 1); // + 1 to remove the underscore as well newMoralityNumber = int.Parse(previousMoralityNumber) + 1; } var newScene = Scenario.CreateEmpty(moralityToAdd, newMoralityNumber); var response = Responses.FirstOrDefault(r => r.Title.ToLower() == newScene.Name.ToLower()); if (response == null) { response = Response.CreateEmpty(moralityToAdd, newMoralityNumber); } SelectedScene = newScene; Scenarios.Add(newScene); Responses.Add(response); SortResponses(); }
/// <summary> /// Асинхронная загрузка сценария /// </summary> /// <param name="cancellation"></param> /// <param name="progress"></param> /// <returns></returns> private async Task LoadAsync(CancellationToken cancellation, IProgress <string> progress) { await await Task.Factory.StartNew(async() => { await DataHolder.Instance.ReleaseMedia(false, progress, cancellation); progress.Report("Загрузка данных"); Thread.Sleep(3000); if (DataHolder.Instance.LoadAllData(mFileName, progress, cancellation)) { Debug.Assert(Path.GetDirectoryName(mFileName) != null, "Path.GetDirectoryName(mFileName) != null"); } else { while (true) { if (cancellation.IsCancellationRequested) { break; } Thread.Sleep(100); } } if (cancellation.IsCancellationRequested) { await DataHolder.Instance.ClearAllData(); return(TaskExtension.Delay(1)); } DispatcherServices.BeginInvoke(() => { DynamicText = Constants.cChangeScenarioText; IndicatorLoad = Indicators.Warn.GetColor(); IndicatorCreate = Indicators.Warn.GetColor(); IndicatorSave = Indicators.Accept.GetColor(); ScenarioItem loadedScenario = Scenarios.FirstOrDefault(s => s.ScenarioInfo.Key.Equals(mFileName)); if (loadedScenario == null) { loadedScenario = new ScenarioItem(new KeyValuePair <string, string>(mFileName, DataHolder.Instance.ScenarioProperties.ScenarioName)); loadedScenario.Selecting += NewScenatioItemOnSelecting; Scenarios.Add(loadedScenario); } loadedScenario.SelecteItem(); }); return(TaskExtension.Delay(1)); }, cancellation).ConfigureAwait(false); }
private void RouteList_SelectionChanged(object sender, SelectionChangedEventArgs e) { Scenarios.Clear(); var routeId = ((Route)RouteList.SelectedItem).Id; var scenarioIds = Scenario.ListAllScenarios(routeId); foreach (var id in scenarioIds) { try { Scenarios.Add(new Scenario(routeId, id)); } catch (Exception ex) { Log.Debug("Exception caught when trying to list scenario {0}\\{1}: {2}", routeId, id, ex.Message); } } }
public InternetSecurityViewModel( ReverseShell reverseShell, ReverseShellVictim reverseShellVictim, SQLInjection injection, Browser browser, BrowserNavigation browserNavigation, NmapScanSS nmapSS, NmapScanST nmapST, NmapScanSU nmapSU) { DisplayName = "Internet Security"; Scenarios.Add(reverseShell); Scenarios.Add(reverseShellVictim); Scenarios.Add(injection); Scenarios.Add(browser); Scenarios.Add(browserNavigation); Scenarios.Add(nmapSS); Scenarios.Add(nmapST); Scenarios.Add(nmapSU); }
/// <summary> /// Create new next scenario! /// </summary> public Scenario CreateNewScenario() { // Id and position is actual scenario list size int _scenarioId = 1, _position = 1; // There are some members of scenario in list if (Scenarios.Count > 0) { _scenarioId = Scenarios.Max(x => x.Id) + 1; _position = Scenarios.Max(x => x.Position) + 1; } // Create a new one var newScenario = new Scenario(_scenarioId, _position, Director.Properties.Resources.NewScenarioName) { ParentServer = this }; // Add to list Scenarios.Add(newScenario); // Return scenario return(newScenario); }
public ShellbagScenarioViewModel(Shellbag shellbag) : base() { DisplayName = "Shellbags"; Scenarios.Add(shellbag); }