/// <summary> /// Finds any connected mouse devices. /// </summary> private void FindMouse() { try { this.DirectInput = new DirectInput(); this.Mouse = new Mouse(this.DirectInput); this.Mouse.Acquire(); OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Mouse device found"); } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "No (optional) mouse found: " + ex.ToString()); } }
/// <summary> /// A wrapper function for the start callback. This will call the start function and update required state information. /// </summary> internal void Begin() { lock (this.AccessLock) { if (!this.IsBusy) { String error = "Error in task scheduler. Attempting to start before flagging action as busy."; OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, error); throw new Exception(error); } this.OnBegin(); this.IsBusy = false; } }
public void RoundOutputViewModel(OutputViewModel outputViewModel) { outputViewModel.Z = Math.Round(outputViewModel.Z, 4); outputViewModel.Kxy = Math.Round(outputViewModel.Kxy, 4); outputViewModel.S0x = Math.Round(outputViewModel.S0x, 4); outputViewModel.S0y = Math.Round(outputViewModel.S0y, 4); outputViewModel.Rxy = Math.Round(outputViewModel.Rxy, 4); outputViewModel.R1xy001 = Math.Round(outputViewModel.R1xy001, 4); outputViewModel.R2xy001 = Math.Round(outputViewModel.R2xy001, 4); outputViewModel.R1xy005 = Math.Round(outputViewModel.R1xy005, 4); outputViewModel.R2xy005 = Math.Round(outputViewModel.R2xy005, 4); outputViewModel.RomCoef = Math.Round(outputViewModel.RomCoef, 4); }
/// <summary> /// Finds any connected keyboard devices. /// </summary> private void FindKeyboard() { try { this.DirectInput = new DirectInput(); this.Keyboard = new Keyboard(this.DirectInput); this.Keyboard.Acquire(); OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Keyboard device found"); } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unable to acquire keyboard device", ex); } }
/// <summary> /// Gets all modules in the opened process /// </summary> /// <returns>A collection of modules in the process</returns> public IEnumerable <NormalizedModule> GetModules() { List <NormalizedModule> normalizedModules = new List <NormalizedModule>(); if (this.SystemProcess == null) { return(normalizedModules); } // Query all modules in the target process IntPtr[] modulePointers = new IntPtr[0]; Int32 bytesNeeded = 0; try { // Determine number of modules if (!Native.NativeMethods.EnumProcessModulesEx(this.SystemProcess.Handle, modulePointers, 0, out bytesNeeded, (UInt32)Enumerations.ModuleFilter.ListModulesAll)) { return(normalizedModules); } Int32 totalNumberofModules = bytesNeeded / IntPtr.Size; modulePointers = new IntPtr[totalNumberofModules]; if (Native.NativeMethods.EnumProcessModulesEx(this.SystemProcess.Handle, modulePointers, bytesNeeded, out bytesNeeded, (UInt32)Enumerations.ModuleFilter.ListModulesAll)) { for (Int32 index = 0; index < totalNumberofModules; index++) { StringBuilder moduleFilePath = new StringBuilder(1024); Native.NativeMethods.GetModuleFileNameEx(this.SystemProcess.Handle, modulePointers[index], moduleFilePath, (UInt32)moduleFilePath.Capacity); String moduleName = Path.GetFileName(moduleFilePath.ToString()); ModuleInformation moduleInformation = new ModuleInformation(); Native.NativeMethods.GetModuleInformation(this.SystemProcess.Handle, modulePointers[index], out moduleInformation, (UInt32)(IntPtr.Size * modulePointers.Length)); // Convert to a normalized module and add it to our list NormalizedModule module = new NormalizedModule(moduleName, moduleInformation.ModuleBase, unchecked ((Int32)moduleInformation.SizeOfImage)); normalizedModules.Add(module); } } } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error fetching modules from selected process: " + ex.ToString()); } return(normalizedModules); }
/// <summary> /// Prevents a default instance of the <see cref="MainViewModel" /> class from being created. /// </summary> private MainViewModel() { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Squalr developer tools started"); // Note: These cannot be async, as the logic to update the layout or window cannot be on a new thread this.CloseCommand = new RelayCommand <Window>((window) => this.Close(window), (window) => true); this.MaximizeRestoreCommand = new RelayCommand <Window>((window) => this.MaximizeRestore(window), (window) => true); this.MinimizeCommand = new RelayCommand <Window>((window) => this.Minimize(window), (window) => true); this.ResetLayoutCommand = new RelayCommand <DockingManager>((dockingManager) => DockingViewModel.GetInstance().LoadLayoutFromResource(dockingManager, MainViewModel.DefaultLayoutResource), (dockingManager) => true); this.LoadLayoutCommand = new RelayCommand <DockingManager>((dockingManager) => DockingViewModel.GetInstance().LoadLayoutFromFile(dockingManager, MainViewModel.LayoutSaveFile, MainViewModel.DefaultLayoutResource), (dockingManager) => true); this.SaveLayoutCommand = new RelayCommand <DockingManager>((dockingManager) => DockingViewModel.GetInstance().SaveLayout(dockingManager, MainViewModel.LayoutSaveFile), (dockingManager) => true); }
/// <summary> /// Starts the scan using the current constraints. /// </summary> private void StartScan() { // Create a constraint manager that includes the current active constraint ScanConstraintManager allScanConstraints = this.ScanConstraintManager.Clone(); allScanConstraints.AddConstraint(this.CurrentScanConstraint); if (!allScanConstraints.IsValid()) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Unable to start scan with given constraints"); return; } ManualScannerModel.SetScanConstraintManager(allScanConstraints); ManualScannerModel.Start(); }
/// <summary> /// Called when the scan updates. /// </summary> /// <param name="cancellationToken">The cancellation token for handling canceled tasks.</param> protected override void OnUpdate(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Int32 processedPages = 0; Int32 regionCount = this.Snapshot.RegionCount; ConcurrentBag <IList <SnapshotRegion> > regions = new ConcurrentBag <IList <SnapshotRegion> >(); Parallel.ForEach( this.Snapshot.OptimizedSnapshotRegions, SettingsViewModel.GetInstance().ParallelSettingsFastest, (region) => { // Perform comparisons IList <SnapshotRegion> results = region.CompareAll(this.ScanConstraintManager); if (!results.IsNullOrEmpty()) { regions.Add(results); } // Update progress every N regions if (Interlocked.Increment(ref processedPages) % 32 == 0) { // Check for canceled scan if (cancellationToken.IsCancellationRequested) { return; } this.UpdateProgress(processedPages, regionCount, canFinalize: false); } }); //// End foreach Region // Exit if canceled cancellationToken.ThrowIfCancellationRequested(); this.Snapshot = new Snapshot(this.TaskName, regions.SelectMany(region => region)); stopwatch.Stop(); OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Scan complete in: " + stopwatch.Elapsed); }
/// <summary> /// Opens a process for editing. /// </summary> /// <param name="process">The process to be opened.</param> public void OpenProcess(NormalizedProcess process) { if (process != null) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Attached to process: " + process.ProcessName); } this.OpenedProcess = process; if (this.processListeners != null) { foreach (IProcessObserver listener in this.processListeners) { listener.Update(process); } } }
/// <summary> /// Prevents a default instance of the <see cref="MainViewModel" /> class from being created. /// </summary> private MainViewModel() { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Anathena Started"); this.tools = new HashSet <ToolViewModel>(); // Note: These cannot be async, as the logic to update the layout or window cannot be on a new thread this.CloseCommand = new RelayCommand <Window>((window) => this.Close(window), (window) => true); this.MaximizeRestoreCommand = new RelayCommand <Window>((window) => this.MaximizeRestore(window), (window) => true); this.MinimizeCommand = new RelayCommand <Window>((window) => this.Minimize(window), (window) => true); this.ResetLayoutStandardCommand = new RelayCommand <DockingManager>((dockingManager) => this.ResetLayoutStandard(dockingManager), (dockingManager) => true); this.ResetLayoutDeveloperCommand = new RelayCommand <DockingManager>((dockingManager) => this.ResetLayoutDeveloper(dockingManager), (dockingManager) => true); this.LoadLayoutCommand = new RelayCommand <DockingManager>((dockingManager) => this.LoadLayout(dockingManager), (dockingManager) => true); this.DisplayChangeLogCommand = new RelayCommand(() => this.DisplayChangeLog(), () => true); this.SaveLayoutCommand = new RelayCommand <DockingManager>((dockingManager) => this.SaveLayout(dockingManager), (dockingManager) => true); this.StartBackgroundServices(); }
/// <summary> /// Adds a new library to the current selected game. /// </summary> private void AddNewLibrary() { Task.Run(() => { try { AccessTokens accessTokens = SettingsViewModel.GetInstance().AccessTokens; Library newLibrary = SqualrApi.CreateLibrary(accessTokens?.AccessToken, this.SelectedGame.GameId); this.libraries.Add(newLibrary); this.RaisePropertyChanged(nameof(this.Libraries)); } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error creating library", ex); } }); }
/// <summary> /// Attempts to load icons from the Squalr api. /// </summary> private void LoadIcons() { Task.Run(() => { try { this.streamIcons = SqualrApi.GetStreamIcons(); this.RaisePropertyChanged(nameof(this.FilteredStreamIconList)); this.IsStreamIconListLoading = false; this.NotifyIconsLoaded(); } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error loading icons", ex); } }); }
/// <summary> /// A wrapper function for the update callback. This will call the update function and update required state information. /// </summary> private void Update() { lock (this.AccessLock) { if (!this.IsBusy) { String error = "Error in task scheduler. Attempting to update before flagging action as busy."; OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, error); throw new Exception(error); } this.InternalUpdateAction(); Thread.Sleep(this.ScheduledTask.UpdateInterval); this.IsBusy = false; } }
/// <summary> /// Gets the twitch oauth access tokens using the provided code. /// </summary> /// <param name="code">The one time use exchange code to receive the access tokens.</param> private void PerformLogin(String code) { try { AccessTokens accessTokens = SqualrApi.GetAccessTokens(code); User user = SqualrApi.GetTwitchUser(accessTokens.AccessToken); SqualrApi.Connect(accessTokens.AccessToken); SettingsViewModel.GetInstance().AccessTokens = accessTokens; BrowseViewModel.GetInstance().ActiveUser = user; BrowseViewModel.GetInstance().IsLoggedIn = true; } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Fatal, "Error authorizing Twitch", ex); } }
/// <summary> /// Prevents a default instance of the <see cref="MainViewModel" /> class from being created. /// </summary> private MainViewModel() : base() { // Attach the logger view model to the engine's output Logger.Subscribe(OutputViewModel.GetInstance()); ApplicationUpdater.UpdateApp(); Squalr.Engine.Projects.Compiler.Compile(true); if (Vectors.HasVectorSupport) { Logger.Log(LogLevel.Info, "Hardware acceleration enabled (vector size: " + Vector <Byte> .Count + ")"); } Logger.Log(LogLevel.Info, "Squalr started"); // this.DisplayChangeLogCommand = new RelayCommand(() => ChangeLogViewModel.GetInstance().DisplayChangeLog(new Content.ChangeLog().TransformText()), () => true); }
/// <summary> /// Compiles a script. Will compress the file and convert to base64. This will compile using CodeDOM becuase this /// generates a file that we can read to create the assembly. /// </summary> /// <param name="script">The input script in plaintext.</param> /// <returns>The compiled script. Returns null on failure.</returns> public String CompileScript(String script) { String result = null; try { script = this.PrecompileScript(script); String compiledScriptFile = CSScript.CompileCode(script); Byte[] compressedScript = Compression.Compress(File.ReadAllBytes(compiledScriptFile)); result = Convert.ToBase64String(compressedScript); } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error compiling script", ex); } return(result); }
private OutputViewModel AnalysisURL(InputViewModel model) { var outputModel = new OutputViewModel(); if (model.IsCalculateNoOfWordInPage) { outputModel.WordsInPages = _mapper.Map <IEnumerable <WordsInPageViewModel> >(_analysisService.CalculateNoOfWordInPage(model.Input, model.IsFilterStopWords)); } if (model.IsCalculateNoOfWordInMetaTags) { outputModel.WordsInMetaTags = _mapper.Map <IEnumerable <WordsInMetaTagsViewModel> >(_analysisService.CalculateNoOfWordsInMetaTags(model.Input)); } if (model.IsCalculateNoOfExternalLinks) { outputModel.ExternalLinks = _mapper.Map <IEnumerable <ExternalLinksViewModel> >(_analysisService.CalculateNoOfExternalLinks(model.Input)); } return(outputModel); }
/// <summary> /// Prevents a default instance of the <see cref="EngineCore" /> class from being created. /// </summary> private EngineCore() { this.Processes = ProcessAdapterFactory.GetProcessAdapter(); this.VirtualMemory = VirtualMemoryAdapterFactory.GetVirtualMemoryAdapter(); this.Debugger = DebuggerFactory.GetDebugger(); this.Graphics = new GraphicsAdapter(); this.Network = new Network(); this.Architecture = ArchitectureFactory.GetArchitecture(); this.Input = new InputManager(); if (this.Architecture.HasVectorSupport()) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Hardware acceleration enabled"); OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Info, "Vector size: " + System.Numerics.Vector <Byte> .Count); } this.StartBackgroundServices(); }
public void Setup() { // Create VMs mainVM = new MainViewModel(); dataVM = new DataViewModel(); controlVM = new ControlViewModel(); outputVM = new OutputViewModel(); graphVM = new GraphViewModel(); // Link VMs to VMs dataVM.ControlVM = controlVM; dataVM.GraphVM = graphVM; //controlVM.DataVM = dataVM; controlVM.MainVM = mainVM; // Create models yearsModel = new YearsModel(); dataModel = new DataModel(); graphModel = new GraphModel(); // Link models to VMs dataVM.YearsModel = yearsModel; dataVM.DataModel = dataModel; dataVM.GraphModel = graphModel; controlVM.YearsModel = yearsModel; controlVM.DataModel = dataModel; controlVM.GraphModel = graphModel; outputVM.DataModel = dataModel; graphVM.YearsModel = yearsModel; graphVM.GraphModel = graphModel; graphVM.DataModel = dataModel; string[] filePaths = Directory.GetFiles("res\\TaxCSV", "*.csv"); for (int i = 0; i < filePaths.Length; i++) { IncomeYearModel year = Parser.ParseCSV(filePaths[i]); yearsModel.Years.Add(year.Year, year); } }
/// <summary> /// Displays the change log to the user if there has been a recent update. /// </summary> public void DisplayChangeLog() { try { if (!ApplicationDeployment.IsNetworkDeployed || !ApplicationDeployment.CurrentDeployment.IsFirstRun) { return; } } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Error displaying change log", ex); return; } View.ChangeLog changeLog = new View.ChangeLog(); changeLog.Owner = Application.Current.MainWindow; changeLog.ShowDialog(); }
private void CalcSum() { if (comboBoxProduct.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) { try { int id = Convert.ToInt32(comboBoxProduct.SelectedValue); OutputViewModel product = serviceP.GetElement(id); int count = Convert.ToInt32(textBoxCount.Text); textBoxSum.Text = (count * product.Cost).ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Loads and deserializes the saved layout from disk. If no layout found, the default is loaded from resources. /// </summary> /// <param name="dockManager">The docking root to which content is loaded.</param> /// <param name="resource">Resource to load the layout from. This is optional.</param> public void LoadLayoutFromResource(DockingManager dockManager, String resource) { try { // Attempt to load layout from resource name using (Stream stream = Assembly.GetEntryAssembly().GetManifestResourceStream(resource)) { if (stream != null) { XmlLayoutSerializer serializer = new XmlLayoutSerializer(dockManager); serializer.Deserialize(stream); } } } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error loading layout resource", ex); } }
public ActionResult Index() { var model = new OutputViewModel { InputTable = ExperimentResultsService.GetInputTable(), Q = ExperimentResultsService.Q, Q1 = ExperimentResultsService.Q1, Q2 = ExperimentResultsService.Q2, S0 = ExperimentResultsService.S0, S1 = ExperimentResultsService.S1, S2 = ExperimentResultsService.S2, Fem = ExperimentResultsService.Fem, Fcr = ExperimentResultsService.Fcr }; ExperimentResultsService.RoundOutputViewModel(model); return(View(model)); }
private void WritePage(OutputViewModel model, string pathOverride) { if (model == null) { throw new ArgumentNullException("model"); } if (model.Filename == null) { return; } var toUse = !pathOverride.IsNullOrEmpty() ? pathOverride : _currentRoot.ToLower(); if (toUse == null) { throw new ArgumentNullException("toUse"); } var fullFilePath = String.Format("{0}{1}{2}", toUse, model.FriendlyFilename, ".html"); if (model.FriendlyFilename == null) { return; } var contents = PrepareModel(model); if (contents == null) { throw new ArgumentNullException("contents"); } model = null; FileSystemHelper.WriteFile(fullFilePath, contents); }
public ActionResult Index() { var model = new OutputViewModel { Z = ExperimentResultsService.Z, Kxy = ExperimentResultsService.Kxy, S0x = ExperimentResultsService.S0x, S0y = ExperimentResultsService.S0y, Rxy = ExperimentResultsService.rxy, R1xy001 = ExperimentResultsService.GetR1xy(0.01), R2xy001 = ExperimentResultsService.GetR2xy(0.01), R1xy005 = ExperimentResultsService.GetR1xy(0.05), R2xy005 = ExperimentResultsService.GetR2xy(0.05), RomCoef = ExperimentResultsService.RomCoef }; ExperimentResultsService.RoundOutputViewModel(model); return(View(model)); }
public MainShellViewModel(IResultFactory resultFactory, IEventAggregator eventAggregator, IPersistanceManager persistanceManager, ISettingsManager settingsManager, MainMenuViewModel mainMenuViewModel, ScriptEditorViewModel scriptEditorViewModel, OutputViewModel outputViewModel) : base(resultFactory) { this.eventAggregator = eventAggregator; eventAggregator.Subscribe(this); this.persistanceManager = persistanceManager; Menu = mainMenuViewModel; Menu.Plugins = settingsManager.ListConfigurablePluginSettings().Select(ps => new PluginSettingsMenuViewModel(ps)); Menu.HelpFiles = settingsManager.ListPluginSettingsWithHelpFile().Select(ps => new PluginHelpFileViewModel(ps)).ToList(); ScriptEditor = scriptEditorViewModel; Output = outputViewModel; DisplayName = "FreePIE - Programmable Input Emulator"; }
/// <summary> /// Called when the scheduled task is updated. /// </summary> /// <param name="cancellationToken">The cancellation token for handling canceled tasks.</param> protected override void OnUpdate(CancellationToken cancellationToken) { try { AccessTokens accessTokens = SettingsViewModel.GetInstance().AccessTokens; if (accessTokens == null || accessTokens.AccessToken.IsNullOrEmpty()) { return; } User user = SqualrApi.GetTwitchUser(accessTokens.AccessToken); this.UpdateAction?.Invoke(user.Coins); } catch (Exception ex) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Error refreshing user", ex); } }
/// <summary> /// Schedules a given task. /// </summary> /// <param name="scheduledTask">The task to be scheduled.</param> /// <param name="startAction">The start callback function.</param> /// <param name="updateAction">The update callback function.</param> /// <param name="endAction">The end callback function.</param> public void ScheduleAction(ScheduledTask scheduledTask) { lock (this.AccessLock) { // Do not schedule actions of the same type if (this.Actions.Select(x => x.GetType()).Any(x => x == scheduledTask.GetType())) { OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Warn, "Action not scheduled. This action is already queued."); return; } scheduledTask.ResetState(); this.Actions.AddLast(scheduledTask); this.RaisePropertyChanged(nameof(this.ActiveTasks)); foreach (ScheduledTask task in scheduledTask.Dependencies) { this.ScheduleAction(task); } } }
/// <summary> /// Adds a new address to the project items. /// </summary> private void AddNewProjectItem(Type projectItemType) { switch (projectItemType) { case Type _ when projectItemType == typeof(PointerItem): this.AddNewProjectItems(true, new PointerItem()); break; case Type _ when projectItemType == typeof(ScriptItem): this.AddNewProjectItems(true, new ScriptItem()); break; case Type _ when projectItemType == typeof(InstructionItem): this.AddNewProjectItems(true, new InstructionItem()); break; default: OutputViewModel.GetInstance().Log(OutputViewModel.LogLevel.Error, "Unknown project item type - " + projectItemType.ToString()); break; } }
public ActionResult LoadView() { var user = sessionManager.User; if (user == null) { return(PartialView("Login")); } DatabaseInterface db = new DatabaseInterface(); var model = new OutputViewModel() { Username = user.Username, Routes = db.GetAvailableRoutes(), Buses = db.GetAvailableBuses(), Employees = db.GetAvailableEmployees(), Stops = db.GetAvailableStops(), Drivers = db.GetAvailableDrivers() }; return(PartialView("AdminView", model)); }
public ToolbarListReportViewer(OutputViewModel model, IResultToolbar toolbar) { _model = model; _toolbar = toolbar; }