public LocationManager() { try { // Try to load the RILPositionProvider - will fail if no RIL.dll ril = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("PockeTwit.Position.RILPositionProvider") as IPositionProvider; } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// To create a rule for the position change event. /// </summary> /// <param name="position">The position to be traced for the change event.</param> /// <param name="provider">The position provider.</param> /// <returns>Rule.</returns> public static MarketRule <Position, Position> Changed(this Position position, IPositionProvider provider) { return(new PositionRule(position, provider)); }
protected override void OnStartup(StartupEventArgs e) { ReloadThemeResources(); TaskScheduler.UnobservedTaskException += OnTaskSchedulerUnobservedException; //#if DEBUG // Settings.Default.Reset(); //#endif PrepareStartup(e); base.OnStartup(e); BuildErrorHandler(); Converts.Repository .AddJsonPrimitivesSearchHandler() .AddJsonObjectSearchHandler() .AddJsonEnumSearchHandler() .AddEnumSearchHandler(false) .AddToStringSearchHandler() .Add(new AdditionalApplicationCollectionConverter()) .Add(new KeyViewModelConverter()) .Add(new ExceptionModelConverter()); EventManager.FilePinned += OnFilePinned; EventManager.ConfigurationSaved += OnConfigurationSaved; EventManager.ProcessStarted += OnProcessStarted; mainApplicationLoader = new ApplicationLoaderCollection() .Add(new VsVersionLoader()) .Add(new VsCodeLoader()); // Bind global hotkey. runHotKey = new DefaultRunHotKeyService(this, this); KeyViewModel runKey; if (Converts.Try(Settings.Default.RunKey, out runKey) && runKey != null) { try { runHotKey.Bind(runKey.Key, runKey.Modifier); } catch (Win32Exception) { runHotKey.UnBind(); Settings.Default.RunKey = null; Settings.Default.Save(); } } if (!runHotKey.IsSet) { startup.IsHidden = false; } configurationFactory = new ConfigurationViewModelFactory( mainApplicationLoader, shortcutService, runHotKey, Settings.Default, this ); mainFactory = new MainViewModelFactory( this, Settings.Default, mainApplicationLoader, GetPinnedFiles, OnMainViewModelPropertyChanged ); SettingsExtension.Settings = Settings.Default; positionProvider = new PositionService(Settings.Default); InitializeCounting(); if (Settings.Default.IsTrayIcon) { TryCreateTrayIcon(); } // Open window. if (String.IsNullOrEmpty(Settings.Default.SourceDirectoryPath)) { OpenConfiguration(); } else { OpenMain(); } startup.IsStartup = false; }
public PositionRule(Position position, IPositionProvider provider) : this(position, provider, p => true) { Name = LocalizedStrings.Str1042 + " " + position.Portfolio.Name; }
/// <summary> /// To create a rule for the event of position increase above the specific level. /// </summary> /// <param name="position">The position to be traced of the event of increase above the specific level.</param> /// <param name="provider">The position provider.</param> /// <param name="value">The level. If the <see cref="Unit.Type"/> type equals to <see cref="UnitTypes.Limit"/>, specified price is set. Otherwise, shift value is specified.</param> /// <returns>Rule.</returns> public static MarketRule <Position, Position> WhenMore(this Position position, IPositionProvider provider, Unit value) { if (position == null) { throw new ArgumentNullException(nameof(position)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } var finishPosition = value.Type == UnitTypes.Limit ? value : position.CurrentValue + value; return(new PositionRule(position, provider, pf => pf.CurrentValue > finishPosition) { Name = LocalizedStrings.Str1045Params.Put(position, finishPosition) }); }
private void StitchScreenshot_(Size stitchOffset, IPositionProvider stitchProvider, ICollection <SubregionForStitching> screenshotParts, Bitmap stitchedImage, double scaleRatio, ICutProvider scaledCutProvider, float sizeRatio) { int index = 0; logger_.Log(TraceLevel.Info, TestId, Stage.Check, StageType.CaptureScreenshot, new { stitchOffset, partCount = screenshotParts.Count, scaleRatio }); Stopwatch stopwatch = Stopwatch.StartNew(); foreach (SubregionForStitching partRegion in screenshotParts) { if (stopwatch.Elapsed > TimeSpan.FromMinutes(5)) { logger_.Log(TraceLevel.Notice, TestId, Stage.Check, StageType.CaptureScreenshot, new { message = "still running" }); // this is so CI systems won't kill the build due to lack of activity. stopwatch.Restart(); } logger_.Log(TraceLevel.Debug, TestId, Stage.Check, StageType.CaptureScreenshot, new { partRegion }); // Scroll to the part's top/left Point partAbsoluteLocationInCurrentFrame = partRegion.ScrollTo; partAbsoluteLocationInCurrentFrame += stitchOffset; Point scrollPosition = new Point( (int)Math.Round(partAbsoluteLocationInCurrentFrame.X * sizeRatio), (int)Math.Round(partAbsoluteLocationInCurrentFrame.Y * sizeRatio)); Point originPosition = stitchProvider.SetPosition(scrollPosition); int dx = scrollPosition.X - originPosition.X; int dy = scrollPosition.Y - originPosition.Y; Point partPastePosition = partRegion.PasteLocation; //partPastePosition.Offset(-fullarea.Left, -fullarea.Top); partPastePosition.Offset(-dx, -dy); // Actually taking the screenshot. Thread.Sleep(waitBeforeScreenshots_); using (Bitmap partImage = imageProvider_.GetImage()) using (Bitmap cutPart = scaledCutProvider.Cut(partImage)) { Bitmap croppedPart; Rectangle r = partRegion.PhysicalCropArea; r.Width += dx; r.Height += dy; if ((r.Width * r.Height) != 0) { croppedPart = BasicImageUtils.Crop(cutPart, r); } else { croppedPart = cutPart; } Rectangle r2 = partRegion.LogicalCropArea; r2.Width += dx; r2.Height += dy; using (Bitmap scaledPartImage = BasicImageUtils.ScaleImage(croppedPart, scaleRatio)) using (Bitmap scaledCroppedPartImage = BasicImageUtils.Crop(scaledPartImage, r2)) using (Graphics g = Graphics.FromImage(stitchedImage)) { debugScreenshotsProvider_.Save(partImage, "partImage-" + originPosition.X + "_" + originPosition.Y); debugScreenshotsProvider_.Save(cutPart, "cutPart-" + originPosition.X + "_" + originPosition.Y); debugScreenshotsProvider_.Save(croppedPart, "croppedPart-" + originPosition.X + "_" + originPosition.Y); debugScreenshotsProvider_.Save(scaledPartImage, "scaledPartImage-" + originPosition.X + "_" + originPosition.Y); debugScreenshotsProvider_.Save(scaledCroppedPartImage, "scaledCroppedPartImage-" + partPastePosition.X + "_" + partPastePosition.Y); logger_.Log(TraceLevel.Debug, TestId, Stage.Check, StageType.CaptureScreenshot, new { partPastePosition }); g.DrawImage(scaledCroppedPartImage, partPastePosition); } if (!object.ReferenceEquals(croppedPart, cutPart)) { croppedPart.Dispose(); } debugScreenshotsProvider_.Save(stitchedImage, $"stitched_{index}_({partPastePosition.X}_{partPastePosition.Y})"); index++; } } debugScreenshotsProvider_.Save(stitchedImage, "stitched"); }
public PersonPositionController(IPersonPositionProvider personPositionProvider, IPersonProvider personProvider, IPositionProvider positionProvider , ICheckProvider checkProvider , IMasterListProvider masterListProvider , IPersonPositionProvider PersonPositionProvider , IMasterProvider masterProvider , IClaimCheck claimCheck , IOrganizationProvider organizationProvider , Microsoft.AspNetCore.Identity.UserManager <SIPx.API.Models.SipUser> userManager) { _personPositionProvider = personPositionProvider; _personProvider = personProvider; _positionProvider = positionProvider; _checkProvider = checkProvider; _masterListProvider = masterListProvider; _PersonPositionProvider = PersonPositionProvider; _masterProvider = masterProvider; _claimCheck = claimCheck; _organizationProvider = organizationProvider; _userManager = userManager; }
public void ReturnToOriginalPosition(IPositionProvider positionProvider) { Logger_.Verbose("Ignored (no op)."); }
public override Bitmap GetImage() { Bitmap image = base.GetImage(); if (eyes_.CachedSessionDetails != null && eyes_.CachedSessionDetails.TryGetValue("deviceOrientation", out object orientation)) { if ("landscape".Equals(orientation as string, StringComparison.OrdinalIgnoreCase) && image.Width < image.Height) { logger_.Verbose("rotating image..."); image.RotateFlip(RotateFlipType.Rotate270FlipNone); } } logger_.Verbose("Bitmap Size: {0}x{1}", image.Width, image.Height); eyes_.DebugScreenshotProvider.Save(image, "SAFARI"); if (eyes_.IsCutProviderExplicitlySet) { return(image); } double scaleRatio = eyes_.DevicePixelRatio; Size originalViewportSize = GetViewportSize(); Size viewportSize = new Size( (int)Math.Ceiling(originalViewportSize.Width * scaleRatio), (int)Math.Ceiling(originalViewportSize.Height * scaleRatio)); logger_.Verbose("logical viewport size: " + originalViewportSize); Bitmap croppedImage = null; if (userAgent_.IsiOS || "ios".Equals(eyes_.PlatformName, StringComparison.OrdinalIgnoreCase) || (eyes_.CachedSessionDetails.TryGetValue("PlatformName", out object platformName) && "ios".Equals(platformName as string, StringComparison.OrdinalIgnoreCase))) { croppedImage = CropIOSImage(image, originalViewportSize, logger_); } else if (!eyes_.ForceFullPageScreenshot) { Point loc; FrameChain currentFrameChain = eyes_.GetDriver().GetFrameChain(); if (currentFrameChain.Count == 0) { IWebElement scrollRootElement = eyes_.GetCurrentFrameScrollRootElement(); IPositionProvider positionProvider = eyes_.GetPositionProvider( logger_, StitchModes.Scroll, jsExecutor_, scrollRootElement, userAgent_); loc = positionProvider.GetCurrentPosition(); } else { loc = currentFrameChain.GetDefaultContentScrollPosition(); } loc = new Point((int)Math.Ceiling(loc.X * scaleRatio), (int)Math.Ceiling(loc.Y * scaleRatio)); croppedImage = BasicImageUtils.Crop(image, new Rectangle(loc, viewportSize)); } if (croppedImage != null && !ReferenceEquals(croppedImage, image)) { image.Dispose(); image = croppedImage; } eyes_.DebugScreenshotProvider.Save(image, "SAFARI_CROPPED"); return(image); }
public FrameState(EyesWebDriver driver, IWebElement scrolledElement, IPositionProvider cssPositionProvider, IPositionProvider scrollPositionProvider, string overflow, FrameChain frameChain) { driver_ = driver; scrolledElement_ = scrolledElement; cssPositionProvider_ = cssPositionProvider; cssMemento_ = cssPositionProvider_.GetState(); scrollPositionProvider_ = scrollPositionProvider; scrollMemento_ = scrollPositionProvider_.GetState(); overflow_ = overflow; frameChain_ = frameChain; }
public void MoveToRegion(IPositionProvider positionProvider, Location location) { Logger_.Verbose("Ignored (no op)."); }
public LeftMovementStrategy(IPositionProvider positionProvider) { _positionProvider = positionProvider ?? throw new ArgumentNullException(nameof(positionProvider)); }
public void ReturnToOriginalPosition(IPositionProvider positionProvider) { Logger_.Verbose("Returning to original position..."); positionProvider.RestoreState(OriginalPosition_); Logger_.Verbose("Done!"); }
public Bitmap GetStitchedRegion(Region region, Region fullarea, IPositionProvider positionProvider, IPositionProvider originProvider) { return(GetStitchedRegion(region, fullarea, positionProvider, originProvider, Size.Empty)); }
/// <summary> /// Initializes a new instance of the <see cref="BasketBlackScholes"/>. /// </summary> /// <param name="underlyingAsset">Underlying asset.</param> /// <param name="dataProvider">The market data provider.</param> /// <param name="positionProvider">The position provider.</param> public BasketBlackScholes(Security underlyingAsset, IMarketDataProvider dataProvider, IPositionProvider positionProvider) : base(underlyingAsset, dataProvider) { if (positionProvider == null) { throw new ArgumentNullException(nameof(positionProvider)); } _innerModels = new InnerModelList(this); UnderlyingAsset = underlyingAsset; PositionProvider = positionProvider; }
/// <summary> /// Initializes a new instance of the <see cref="StorageEntityFactory"/>. /// </summary> /// <param name="securityProvider">The provider of information about instruments.</param> /// <param name="positionStorage">Position storage.</param> /// <param name="trackPositions">Track positions.</param> public StorageEntityFactory(ISecurityProvider securityProvider, IPositionProvider positionStorage, bool trackPositions) : this(securityProvider, positionStorage) { _positionStorage = positionStorage ?? throw new ArgumentNullException(nameof(positionStorage)); _trackPositions = trackPositions; }
/// <summary> /// Initializes a new instance of the <see cref="BasketBlackScholes"/>. /// </summary> /// <param name="securityProvider">The provider of information about instruments.</param> /// <param name="dataProvider">The market data provider.</param> /// <param name="positionProvider">The position provider.</param> public BasketBlackScholes(ISecurityProvider securityProvider, IMarketDataProvider dataProvider, IPositionProvider positionProvider) : base(securityProvider, dataProvider) { if (positionProvider == null) { throw new ArgumentNullException(nameof(positionProvider)); } _innerModels = new InnerModelList(this); PositionProvider = positionProvider; }
/// <summary> /// Encapsulates an algorithm for creating full-page images of a page. /// </summary> /// <param name="positionProvider">The position provider used for moving to the actual stitch points.</param> /// <param name="region">The region to stitch. If <see cref="Region.Empty"/>, the entire image will be stitched.</param> /// <param name="fullarea">The wanted area of the resulting image. If unknown, pass in <c>null</c> or <see cref="Region.Empty"/>.</param> /// <param name="originProvider">A position provider used for saving the state before /// starting the stitching, as well as moving to (0,0). The reason it is separated from /// the <c>stitchProvider</c>is that the stitchProvider might have side-effects /// (e.g., changing the CSS transform of the page can cause a layout change at the /// top of the page), which we can avoid for the first screenshot (since it might be a /// full page screenshot anyway).</param> /// <param name="stitchOffset"></param> /// <returns>The screenshot as Bitmap.</returns> public Bitmap GetStitchedRegion(Region region, Region fullarea, IPositionProvider positionProvider, IPositionProvider originProvider, Size stitchOffset) { ArgumentGuard.NotNull(region, nameof(region)); ArgumentGuard.NotNull(positionProvider, nameof(positionProvider)); Point originalStitchedState = positionProvider.GetCurrentPosition(); PositionMemento originProviderState = originProvider.GetState(); logger_.Log(TraceLevel.Notice, TestId, Stage.Check, StageType.CaptureScreenshot, new { region, fullarea, positionProvider = positionProvider.GetType().Name, originalStitchedState, originProviderState }); originProvider.SetPosition(Point.Empty); Thread.Sleep(waitBeforeScreenshots_); Bitmap initialScreenshot = imageProvider_.GetImage(); Size initialPhysicalSize = initialScreenshot.Size; SaveDebugScreenshotPart_(initialScreenshot, region.ToRectangle(), "initial"); IScaleProvider scaleProvider = scaleProviderFactory_.GetScaleProvider(initialScreenshot.Width); double pixelRatio = 1 / scaleProvider.ScaleRatio; Size initialSizeScaled = new Size((int)Math.Round(initialScreenshot.Width / pixelRatio), (int)Math.Round(initialScreenshot.Height / pixelRatio)); ICutProvider scaledCutProvider = cutProvider_.Scale(pixelRatio); if (pixelRatio != 1 && !(scaledCutProvider is NullCutProvider)) { Bitmap cutScreenshot = cutProvider_.Cut(initialScreenshot); initialScreenshot.Dispose(); initialScreenshot = cutScreenshot; debugScreenshotsProvider_.Save(initialScreenshot, "original-cut"); } Region regionInScreenshot = GetRegionInScreenshot_(region, initialScreenshot, pixelRatio); logger_.Log(TraceLevel.Info, TestId, Stage.Check, StageType.CaptureScreenshot, new { regionInScreenshot }); Bitmap croppedInitialScreenshot = CropScreenshot_(initialScreenshot, regionInScreenshot); debugScreenshotsProvider_.Save(croppedInitialScreenshot, "cropped"); Bitmap scaledInitialScreenshot = BasicImageUtils.ScaleImage(croppedInitialScreenshot, scaleProvider); if (!object.ReferenceEquals(scaledInitialScreenshot, croppedInitialScreenshot)) { SaveDebugScreenshotPart_(scaledInitialScreenshot, regionInScreenshot.ToRectangle(), "scaled"); } if (fullarea.IsEmpty) { Size entireSize; try { entireSize = positionProvider.GetEntireSize(); logger_.Verbose("Entire size of region context: {0}", entireSize); } catch (EyesException e) { logger_.Log(TraceLevel.Warn, TestId, Stage.Check, StageType.CaptureScreenshot, new { message = "Failed to extract entire size of region context. Using image size instead.", exception = e, imageSize = scaledInitialScreenshot }); entireSize = new Size(scaledInitialScreenshot.Width, scaledInitialScreenshot.Height); } // Notice that this might still happen even if we used // "getImagePart", since "entirePageSize" might be that of a frame. if (scaledInitialScreenshot.Width >= entireSize.Width && scaledInitialScreenshot.Height >= entireSize.Height) { logger_.Log(TraceLevel.Warn, TestId, Stage.Check, StageType.CaptureScreenshot, new { message = "Seems the image is already a full page screenshot." }); if (!object.ReferenceEquals(scaledInitialScreenshot, initialScreenshot)) { initialScreenshot.Dispose(); } return(scaledInitialScreenshot); } fullarea = new Region(Point.Empty, entireSize, CoordinatesTypeEnum.SCREENSHOT_AS_IS); } float currentFullWidth = fullarea.Width; fullarea = sizeAdjuster_.AdjustRegion(fullarea, initialSizeScaled); float sizeRatio = currentFullWidth / fullarea.Width; logger_.Log(TraceLevel.Info, TestId, Stage.Check, StageType.CaptureScreenshot, new { adjustedFullArea = fullarea }); Point scaledCropLocation = fullarea.Location; Point physicalCropLocation = new Point( (int)Math.Ceiling(scaledCropLocation.X * pixelRatio), (int)Math.Ceiling(scaledCropLocation.Y * pixelRatio)); Rectangle sourceRegion; if (regionInScreenshot.IsSizeEmpty) { Size physicalCropSize = new Size(initialPhysicalSize.Width - physicalCropLocation.X, initialPhysicalSize.Height - physicalCropLocation.Y); sourceRegion = new Rectangle(physicalCropLocation, physicalCropSize); } else { // Starting with the screenshot we already captured at (0,0). sourceRegion = regionInScreenshot.ToRectangle(); } Rectangle scaledCroppedSourceRect = cutProvider_.ToRectangle(sourceRegion.Size); scaledCroppedSourceRect.Offset(sourceRegion.Location); Rectangle scaledCroppedSourceRegion = new Rectangle( (int)Math.Ceiling(scaledCroppedSourceRect.X / pixelRatio), (int)Math.Ceiling(scaledCroppedSourceRect.Y / pixelRatio), (int)Math.Ceiling(scaledCroppedSourceRect.Width / pixelRatio), (int)Math.Ceiling(scaledCroppedSourceRect.Height / pixelRatio)); Size scaledCropSize = scaledCroppedSourceRegion.Size; // The screenshot part is a bit smaller than the screenshot size, in order to eliminate // duplicate bottom/right-side scroll bars, as well as fixed position footers. Size screenshotPartSize = new Size( Math.Max(scaledCropSize.Width, MinScreenshotPartSize_), Math.Max(scaledCropSize.Height, MinScreenshotPartSize_) ); logger_.Log(TraceLevel.Info, TestId, Stage.Check, StageType.CaptureScreenshot, new { screenshotPartSize }); // Getting the list of viewport regions composing the page (we'll take screenshot for each one). Rectangle rectInScreenshot; if (regionInScreenshot.IsSizeEmpty) { int x = Math.Max(0, fullarea.Left); int y = Math.Max(0, fullarea.Top); int w = Math.Min(fullarea.Width, scaledCropSize.Width); int h = Math.Min(fullarea.Height, scaledCropSize.Height); rectInScreenshot = new Rectangle( (int)Math.Round(x * pixelRatio), (int)Math.Round(y * pixelRatio), (int)Math.Round(w * pixelRatio), (int)Math.Round(h * pixelRatio)); } else { rectInScreenshot = regionInScreenshot.Rectangle; } fullarea = CoerceImageSize_(fullarea); ICollection <SubregionForStitching> screenshotParts = fullarea.GetSubRegions(screenshotPartSize, stitchOverlap_, pixelRatio, rectInScreenshot, logger_); Bitmap stitchedImage = new Bitmap(fullarea.Width, fullarea.Height); try { // Take screenshot and stitch for each screenshot part. StitchScreenshot_(stitchOffset, positionProvider, screenshotParts, stitchedImage, scaleProvider.ScaleRatio, scaledCutProvider, sizeRatio); positionProvider.SetPosition(originalStitchedState); originProvider.RestoreState(originProviderState); return(stitchedImage); } catch { stitchedImage.Dispose(); throw; } finally { croppedInitialScreenshot.Dispose(); } }