Exemplo n.º 1
0
        private void UserCommand_OnPreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Down || MatchedItems.Items.Count <= 0)
            {
                return;
            }

            MatchedItems.Focus();
            MatchedItems.SelectedIndex = 0;

            MatchedItems.UpdateLayout();
            var matchedItem = (ListBoxItem)MatchedItems.ItemContainerGenerator.ContainerFromItem(MatchedItems.SelectedItem);

            matchedItem.Focus();
        }
Exemplo n.º 2
0
        private void MatchedItems_OnPreviewKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Down)
            {
//                (DataContext as TestViewModel).DoCommand(e.Key.);
                return;
            }
            if (e.Key != Key.Down || MatchedItems.Items.Count <= 0)
            {
                return;
            }

            MatchedItems.Focus();
            MatchedItems.SelectedIndex = 0;

            MatchedItems.UpdateLayout();
            var matchedItem = (ListBoxItem)MatchedItems.ItemContainerGenerator.ContainerFromItem(MatchedItems.SelectedItem);

            matchedItem.Focus();
        }
Exemplo n.º 3
0
        private async void ParseCommand(string userCommand)
        {
            _cts?.Cancel();
            _cts = new CancellationTokenSource();

            MatchedItems.Clear();

            if (string.IsNullOrEmpty(userCommand))
            {
                return;
            }

            _log.Debug($"ParseCommand('{userCommand}')");

            var parts = userCommand.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Where(p => p.Length > 1).ToArray();

            //            Task.Run(() => ParseCommandAsync(userCommand, _cts.Token), _cts.Token);

            List <FolderMatch> survivors;

            try
            {
                survivors = await ParseCommandAsync(parts, _cts.Token);
            }
            catch (OperationCanceledException)
            {
                _log.Debug($"operation cancelled. search args:{userCommand}");
                return;
            }
            if (survivors == null)
            {
                return;
            }

            foreach (var item in survivors.OrderBy(f => f.MatchedFolder.Level).ThenBy(f => f.Position).Take(200))
            {
                MatchedItems.Add(new HyperJumpFolderViewModel(item.MatchedFolder, parts));
            }
            SelectedMatchedItem = MatchedItems.FirstOrDefault();
        }
Exemplo n.º 4
0
        internal ItemIconScan(Bitmap capture, Vector2 mouseVector2)
        {
            Logger.ClearDebugMats();

            Capture  = capture;
            MousePos = mouseVector2;

            var(iconPosition, iconSize) = LocateIcon(Capture);

            var padding = RatConfig.IconScan.ScanPadding;

            // Add padding
            var iconSlotSize = new Size();

            iconSlotSize.Width  = IconManager.PixelsToSlots(iconSize.X);
            iconSlotSize.Height = IconManager.PixelsToSlots(iconSize.Y);

            // Rectify icon position for padding
            iconPosition -= new Vector2(padding / 2, padding / 2);
            iconSize.X   += padding;
            iconSize.Y   += padding;

            if (iconPosition.X < 0)
            {
                iconPosition.X = 0;
            }
            if (iconPosition.Y < 0)
            {
                iconPosition.Y = 0;
            }
            if (iconSize.X + iconPosition.X > Capture.Width)
            {
                iconSize.X = Capture.Width - iconPosition.X;
            }
            if (iconSize.Y + iconPosition.Y > Capture.Height)
            {
                iconSize.Y = Capture.Height - iconPosition.Y;
            }

            if (iconSlotSize.Width == 0 || iconSlotSize.Height == 0)
            {
                return;
            }

            Logger.LogDebug("pX: " + iconPosition.X + " | pY: " + iconPosition.Y);
            Logger.LogDebug("pW: " + iconSize.X + " | pH: " + iconSize.Y);
            Logger.LogDebug("sW: " + iconSlotSize.Width + " | sH: " + iconSlotSize.Height);

            // Crop capture to icon
            var sourceBitmap = new Bitmap(Capture).Clone(new Rectangle(iconPosition, iconSize), Capture.PixelFormat);
            var croppedIcon  = sourceBitmap.ToMat();

            Logger.LogDebugMat(croppedIcon, "cropped_icon");

            // Rescale captured icon if resolution is not FHD
            if (RatConfig.ScreenResolution != RatConfig.Resolution.R1920x1080)
            {
                var invSSF      = RatConfig.GetInverseScreenScaleFactor();
                var croppedSize = new Size(croppedIcon.Width * invSSF, croppedIcon.Height * invSSF);
                croppedIcon = croppedIcon.Resize(croppedSize, 0, 0, InterpolationFlags.Area);
                Logger.LogDebugMat(croppedIcon, "resized_cropped_icon");
            }

            var iconWidthPixel  = IconManager.SlotsToPixels(iconSlotSize.Width);
            var iconHeightPixel = IconManager.SlotsToPixels(iconSlotSize.Height);

            IconRect.Size = new Size(iconWidthPixel, iconHeightPixel);

            // Actually scan the source
            var matchResult = ScanStaticAndDynamic(iconSlotSize, croppedIcon);

            if (RatConfig.IconScan.ScanRotatedIcons)
            {
                // Rotate source
                var croppedIconRotated = new Mat();
                Cv2.Rotate(croppedIcon, croppedIconRotated, RotateFlags.Rotate90Counterclockwise);
                var iconSlotSizeRotated = new Size(iconSlotSize.Height, iconSlotSize.Width);

                // Actually scan the source
                var matchResultRotated = ScanStaticAndDynamic(iconSlotSizeRotated, croppedIconRotated);

                if (matchResultRotated.conf > matchResult.conf)
                {
                    matchResult = matchResultRotated;

                    // Rotate match position when matched on rotated source
                    var xPos = matchResult.pos.X;
                    matchResult.pos.X = matchResult.pos.Y;
                    matchResult.pos.Y = xPos;
                    Rotated           = true;
                }
            }


            Logger.LogDebug("Icon Key: " + matchResult.iconKey);
            Logger.LogDebug("Conf: " + matchResult.conf);

            IconRect.X = MousePos.X - (RatConfig.IconScan.ScanWidth / 2) + iconPosition.X + matchResult.pos.X;
            IconRect.Y = MousePos.Y - (RatConfig.IconScan.ScanHeight / 2) + iconPosition.Y + matchResult.pos.Y;

            Confidence = matchResult.conf;

            var itemInfos = IconManager.GetItemInfo(matchResult.iconKey);

            if (!(itemInfos?.Length > 0))
            {
                return;
            }

            MatchedItems = Array.ConvertAll(itemInfos, itemInfo => itemInfo.GetItem());
            if (MatchedItems?.Length > 0)
            {
                MatchedItems = MatchedItems.Where(item => item != null).ToArray();
            }
            if (MatchedItems?.Length > 0)
            {
                ValidItem = true;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (Upc != null)
                {
                    hashCode = hashCode * 59 + Upc.GetHashCode();
                }
                if (Ean != null)
                {
                    hashCode = hashCode * 59 + Ean.GetHashCode();
                }
                if (Isbn != null)
                {
                    hashCode = hashCode * 59 + Isbn.GetHashCode();
                }
                if (Asin != null)
                {
                    hashCode = hashCode * 59 + Asin.GetHashCode();
                }
                if (Title != null)
                {
                    hashCode = hashCode * 59 + Title.GetHashCode();
                }
                if (Sku != null)
                {
                    hashCode = hashCode * 59 + Sku.GetHashCode();
                }
                if (Mpn != null)
                {
                    hashCode = hashCode * 59 + Mpn.GetHashCode();
                }
                if (PartNumber != null)
                {
                    hashCode = hashCode * 59 + PartNumber.GetHashCode();
                }
                if (Upcs != null)
                {
                    hashCode = hashCode * 59 + Upcs.GetHashCode();
                }
                if (Description != null)
                {
                    hashCode = hashCode * 59 + Description.GetHashCode();
                }
                if (Brand != null)
                {
                    hashCode = hashCode * 59 + Brand.GetHashCode();
                }
                if (Manufacturer != null)
                {
                    hashCode = hashCode * 59 + Manufacturer.GetHashCode();
                }
                if (Color != null)
                {
                    hashCode = hashCode * 59 + Color.GetHashCode();
                }

                hashCode = hashCode * 59 + NewPrice.GetHashCode();

                hashCode = hashCode * 59 + UsedPrice.GetHashCode();
                if (CurrencyCode != null)
                {
                    hashCode = hashCode * 59 + CurrencyCode.GetHashCode();
                }
                if (Url != null)
                {
                    hashCode = hashCode * 59 + Url.GetHashCode();
                }
                if (Features != null)
                {
                    hashCode = hashCode * 59 + Features.GetHashCode();
                }
                if (Dimensions != null)
                {
                    hashCode = hashCode * 59 + Dimensions.GetHashCode();
                }
                if (Images != null)
                {
                    hashCode = hashCode * 59 + Images.GetHashCode();
                }
                if (MatchedItems != null)
                {
                    hashCode = hashCode * 59 + MatchedItems.GetHashCode();
                }
                if (IsoCountryCodes != null)
                {
                    hashCode = hashCode * 59 + IsoCountryCodes.GetHashCode();
                }
                if (CompanyName != null)
                {
                    hashCode = hashCode * 59 + CompanyName.GetHashCode();
                }
                if (CompanyAddress != null)
                {
                    hashCode = hashCode * 59 + CompanyAddress.GetHashCode();
                }
                if (Categories != null)
                {
                    hashCode = hashCode * 59 + Categories.GetHashCode();
                }
                if (CategoryHierarchies != null)
                {
                    hashCode = hashCode * 59 + CategoryHierarchies.GetHashCode();
                }
                return(hashCode);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns true if Item instances are equal
        /// </summary>
        /// <param name="other">Instance of Item to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Item other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Upc == other.Upc ||
                     Upc != null &&
                     Upc.Equals(other.Upc)
                     ) &&
                 (
                     Ean == other.Ean ||
                     Ean != null &&
                     Ean.Equals(other.Ean)
                 ) &&
                 (
                     Isbn == other.Isbn ||
                     Isbn != null &&
                     Isbn.Equals(other.Isbn)
                 ) &&
                 (
                     Asin == other.Asin ||
                     Asin != null &&
                     Asin.Equals(other.Asin)
                 ) &&
                 (
                     Title == other.Title ||
                     Title != null &&
                     Title.Equals(other.Title)
                 ) &&
                 (
                     Sku == other.Sku ||
                     Sku != null &&
                     Sku.Equals(other.Sku)
                 ) &&
                 (
                     Mpn == other.Mpn ||
                     Mpn != null &&
                     Mpn.Equals(other.Mpn)
                 ) &&
                 (
                     PartNumber == other.PartNumber ||
                     PartNumber != null &&
                     PartNumber.Equals(other.PartNumber)
                 ) &&
                 (
                     Upcs == other.Upcs ||
                     Upcs != null &&
                     other.Upcs != null &&
                     Upcs.SequenceEqual(other.Upcs)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     Brand == other.Brand ||
                     Brand != null &&
                     Brand.Equals(other.Brand)
                 ) &&
                 (
                     Manufacturer == other.Manufacturer ||
                     Manufacturer != null &&
                     Manufacturer.Equals(other.Manufacturer)
                 ) &&
                 (
                     Color == other.Color ||
                     Color != null &&
                     Color.Equals(other.Color)
                 ) &&
                 (
                     NewPrice == other.NewPrice ||

                     NewPrice.Equals(other.NewPrice)
                 ) &&
                 (
                     UsedPrice == other.UsedPrice ||

                     UsedPrice.Equals(other.UsedPrice)
                 ) &&
                 (
                     CurrencyCode == other.CurrencyCode ||
                     CurrencyCode != null &&
                     CurrencyCode.Equals(other.CurrencyCode)
                 ) &&
                 (
                     Url == other.Url ||
                     Url != null &&
                     Url.Equals(other.Url)
                 ) &&
                 (
                     Features == other.Features ||
                     Features != null &&
                     other.Features != null &&
                     Features.SequenceEqual(other.Features)
                 ) &&
                 (
                     Dimensions == other.Dimensions ||
                     Dimensions != null &&
                     other.Dimensions != null &&
                     Dimensions.SequenceEqual(other.Dimensions)
                 ) &&
                 (
                     Images == other.Images ||
                     Images != null &&
                     other.Images != null &&
                     Images.SequenceEqual(other.Images)
                 ) &&
                 (
                     MatchedItems == other.MatchedItems ||
                     MatchedItems != null &&
                     other.MatchedItems != null &&
                     MatchedItems.SequenceEqual(other.MatchedItems)
                 ) &&
                 (
                     IsoCountryCodes == other.IsoCountryCodes ||
                     IsoCountryCodes != null &&
                     other.IsoCountryCodes != null &&
                     IsoCountryCodes.SequenceEqual(other.IsoCountryCodes)
                 ) &&
                 (
                     CompanyName == other.CompanyName ||
                     CompanyName != null &&
                     CompanyName.Equals(other.CompanyName)
                 ) &&
                 (
                     CompanyAddress == other.CompanyAddress ||
                     CompanyAddress != null &&
                     CompanyAddress.Equals(other.CompanyAddress)
                 ) &&
                 (
                     Categories == other.Categories ||
                     Categories != null &&
                     other.Categories != null &&
                     Categories.SequenceEqual(other.Categories)
                 ) &&
                 (
                     CategoryHierarchies == other.CategoryHierarchies ||
                     CategoryHierarchies != null &&
                     other.CategoryHierarchies != null &&
                     CategoryHierarchies.SequenceEqual(other.CategoryHierarchies)
                 ));
        }
        public MainWindowViewModel()
        {
            Services.Instance.AddMainWindowModel(this);
            Services.Instance.AddManualUserInput(ManualResolveViewModel);

            ImgProcessing = new ImageProcessor(SelectedShopRuleset);
            Services.Instance.ServerHandler.StartServer();

            Services.Instance.ServerHandler.OnImageReceived += (s, e) => { ImageSource = e; };
            ImgProcessing.OnImageParsed += OnImageParsed;

            Finalize = new ParametrizedCommand((obj) => {
                Purchase purchase = new Purchase(SelectedShopRuleset.Shop, ImgProcessing.CurrentParsingResult.Meta.PurchasedAt,
                                                 _matchedItems.Select(s => s.ItemPurchase).ToArray());
                purchase.FinalizePurchase();
                ClearButtonVisible    = true;
                FinalizeButtonVisible = false;
            });

            Clear = new ParametrizedCommand((obj) => {
                ImageSource                 = ResourceNames.TRANSPARENT_IMAGE;
                FinalizeButtonVisible       = false;
                SendToMTDBButtonVisible     = false;
                ClearButtonVisible          = false;
                ManualPurchaseButtonVisible = true;
                AnalyzeButtonVisible        = true;
                UnknownItems.Clear();
                MatchedItems.Clear();
            });

            Analyze = new ParametrizedCommand((obj) => {
                if (string.IsNullOrEmpty(ImageSource) || ImageSource == ResourceNames.TRANSPARENT_IMAGE)
                {
                    //TODO
                    return;
                }
                _ = ImgProcessing.Analyze(ImageSource);
            });

            SendToMTDB = new ParametrizedCommand(async(obj) => {
                using (CPCServer server = new CrossProcessCommunication().StartServer(5689)) {
                    server.StartListening();
                    await server.ListenForClient();
                    server.SendString(SenderHelper.GetString(ImgProcessing.CurrentParsingResult));
                    server.StopListening();
                }
            });

            OnMouseRightClickImage += (s, e) => {
                if (string.IsNullOrEmpty(ImageSource) || ImageSource == ResourceNames.TRANSPARENT_IMAGE)
                {
                    //TODO
                    return;
                }
                new Process {
                    StartInfo = new ProcessStartInfo(ImageSource)
                }.Start();
            };

            Instance = this;
        }