示例#1
0
        /// <summary>
        /// </summary>
        public static void StartMemoryWorkers()
        {
            StopMemoryWorkers();
            var id = SettingsView.View.PIDSelect.Text == "" ? GetProcessID() : Constants.ProcessID;

            Constants.IsOpen = true;
            if (id < 0)
            {
                Constants.IsOpen = false;
                return;
            }
            var process = Process.GetProcessById(id);

            MemoryHandler.Instance.SetProcess(process);
            MemoryHandler.Instance.SigScanner.LoadOffsets(AppViewModel.Instance.Signatures);
            _chatLogWorker = new ChatLogWorker();
            _chatLogWorker.StartScanning();
            //_actionWorker = new ActionWorker();
            //_actionWorker.StartScanning();
            _actorWorker = new ActorWorker();
            _actorWorker.StartScanning();
            _monsterWorker = new MonsterWorker();
            _monsterWorker.StartScanning();
            _playerInfoWorker = new PlayerInfoWorker();
            _playerInfoWorker.StartScanning();
            _targetWorker = new TargetWorker();
            _targetWorker.StartScanning();
            _partyInfoWorker = new PartyInfoWorker();
            _partyInfoWorker.StartScanning();
            _inventoryWorker = new InventoryWorker();
            _inventoryWorker.StartScanning();
        }
示例#2
0
        /// <summary>
        /// </summary>
        public static void StartMemoryWorkers()
        {
            StopMemoryWorkers();
            var id = SettingsView.View.PIDSelect.Text == string.Empty
                         ? GetProcessID()
                         : Constants.ProcessModel.ProcessID;

            Constants.IsOpen = true;
            if (id < 0)
            {
                Constants.IsOpen = false;
                return;
            }

            MemoryHandler.Instance.ExceptionEvent       += MemoryHandler_ExceptionEvent;
            MemoryHandler.Instance.SignaturesFoundEvent += MemoryHandler_SignaturesFoundEvent;

            MemoryHandler.Instance.SetProcess(Constants.ProcessModel, Settings.Default.GameLanguage, "latest", Settings.Default.UseLocalMemoryJSONDataCache);

            _chatLogWorker = new ChatLogWorker();
            _chatLogWorker.StartScanning();
            _actorWorker = new ActorWorker();
            _actorWorker.StartScanning();
            _playerInfoWorker = new PlayerInfoWorker();
            _playerInfoWorker.StartScanning();
            _targetWorker = new TargetWorker();
            _targetWorker.StartScanning();
            _partyInfoWorker = new PartyInfoWorker();
            _partyInfoWorker.StartScanning();
            _inventoryWorker = new InventoryWorker();
            _inventoryWorker.StartScanning();
            _hotBarRecastWorker = new HotBarRecastWorker();
            _hotBarRecastWorker.StartScanning();
        }
示例#3
0
        /// <summary>
        /// </summary>
        public static void StartMemoryWorkers()
        {
            StopMemoryWorkers();
            var id = SettingsView.View.PIDSelect.Text == "" ? GetProcessID() : Constants.ProcessModel.ProcessID;

            Constants.IsOpen = true;
            if (id < 0)
            {
                Constants.IsOpen = false;
                return;
            }
            MemoryHandler.Instance.SetProcess(Constants.ProcessModel, Settings.Default.GameLanguage);
            _chatLogWorker = new ChatLogWorker();
            _chatLogWorker.StartScanning();
            _actorWorker = new ActorWorker();
            _actorWorker.StartScanning();
            _playerInfoWorker = new PlayerInfoWorker();
            _playerInfoWorker.StartScanning();
            _targetWorker = new TargetWorker();
            _targetWorker.StartScanning();
            _partyInfoWorker = new PartyInfoWorker();
            _partyInfoWorker.StartScanning();
            _inventoryWorker = new InventoryWorker();
            _inventoryWorker.StartScanning();
        }
示例#4
0
        public void StartMemoryWorkers()
        {
            this.StopMemoryWorkers();

            this.ActionWorker        = new ActionWorker(this._memoryHandler);
            this.ActorWorker         = new ActorWorker(this._memoryHandler);
            this.ChatLogWorker       = new ChatLogWorker(this._memoryHandler);
            this.CurrentPlayerWorker = new CurrentPlayerWorker(this._memoryHandler);
            this.InventoryWorker     = new InventoryWorker(this._memoryHandler);
            this.JobResourceWorker   = new JobResourceWorker(this._memoryHandler);
            this.PartyWorker         = new PartyWorker(this._memoryHandler);
            this.TargetWorker        = new TargetWorker(this._memoryHandler);

            this.ActionWorker.StartScanning();
            this.ActorWorker.StartScanning();
            this.ChatLogWorker.StartScanning();
            this.CurrentPlayerWorker.StartScanning();
            this.InventoryWorker.StartScanning();
            this.JobResourceWorker.StartScanning();
            this.PartyWorker.StartScanning();
            this.TargetWorker.StartScanning();
        }
示例#5
0
        public ActionResult Available(long id, string description, int quantity)
        {
            var ilocitem = repository.GetInventoryLocationItem(id, subdomainid.Value);

            if (ilocitem == null)
            {
                return(Json("Could not find item".ToJsonFail()));
            }

            // get difference
            int diff = quantity;

            if (ilocitem.available.HasValue)
            {
                diff = quantity - ilocitem.available.Value;
            }

            var invWorker = new InventoryWorker(ilocitem, subdomainid.Value, ilocitem.product_variant.product.trackInventory, ilocitem.product_variant.IsDigital());

            invWorker.SetValues(description, diff, null, null, null);

            repository.Save();
            return(Json("Inventory level updated".ToJsonOKMessage()));
        }
示例#6
0
        private void Update()
        {
            if (string.IsNullOrEmpty(warehouse))
            {
                Syslog.Write(string.Format("Shipwire warehouse not specified: {0}", subdomainid));
                return;
            }
            service.CreateInventoryUpdate(warehouse);
            var resp = service.SubmitInventoryUpdate();

            if (resp != null)
            {
                // check for Error
                if (resp.Status == ShipwireService.StatusError && resp.ErrorMessage.ToLower().Contains("password"))
                {
                    // clear invalid credentials
                    using (var repository = new TradelrRepository())
                    {
                        var sd = repository.GetSubDomain(subdomainid);
                        if (sd != null)
                        {
                            sd.shipwireEmail    = "";
                            sd.shipwirePassword = "";
                            repository.Save();
                        }
                    }
                }

                // we want to create a location only if there are products
                if (resp.Products.Count != 0)
                {
                    Debug.WriteLine(string.Format("{0}: {1} products", warehouse, resp.Products.Count));
                    using (var repository = new TradelrRepository())
                    {
                        // if items not zero then we create inventory location if it does not already exist
                        var inventoryloc = new inventoryLocation
                        {
                            subdomain  = subdomainid,
                            name       = warehouse,
                            lastUpdate = DateTime.UtcNow
                        };
                        var locid = repository.AddInventoryLocation(inventoryloc, subdomainid);
                        // we go through each product
                        foreach (var product in resp.Products)
                        {
                            var variant = repository.GetProductVariant(product.code, subdomainid, ProductFlag.ARCHIVED);
                            // if product exist and not archived
                            if (variant != null)
                            {
                                Debug.WriteLine("Existing product: " + product.code);
                                // then we just update the inventorylocitem
                                var ilocitem =
                                    repository.GetInventoryLocationItems(locid, subdomainid).SingleOrDefault(x => x.variantid == variant.id);
                                if (ilocitem == null)
                                {
                                    // can be null from do these updates from Shipwire as we're doing on a per location basis
                                    // anyway create an entry
                                    ilocitem = new inventoryLocationItem
                                    {
                                        variantid  = variant.id,
                                        locationid = locid,
                                        lastUpdate = DateTime.UtcNow,
                                        available  = product.quantity
                                    };
                                    repository.AddInventoryLocationItem(ilocitem, subdomainid);
                                }
                                else
                                {
                                    // just update as this is a sync
                                    ilocitem.available  = product.quantity;
                                    ilocitem.lastUpdate = DateTime.UtcNow;
                                    repository.Save("InventoryUpdate Update");
                                }
                            }
                            else
                            {
                                Debug.WriteLine("New product: " + product.code);

                                // create new product
                                var productInfo = new ProductInfo();

                                // do product
                                var p = new product
                                {
                                    subdomainid = subdomainid,
                                    title       = product.code,
                                    details     = "",
                                    created     = DateTime.UtcNow
                                };
                                productInfo.p = p;
                                variant       = new product_variant();
                                variant.sku   = product.code;

                                // do inventory location item
                                var ilocitem = new inventoryLocationItem
                                {
                                    variantid  = variant.id,
                                    locationid = locid,
                                    lastUpdate = DateTime.UtcNow
                                };
                                var invWorker = new InventoryWorker(ilocitem, subdomainid, true, false); // assume not digital
                                invWorker.SetValues("Shipwire Update", product.quantity, null, null, null);
                                variant.inventoryLocationItems.Add(ilocitem);
                                productInfo.p.product_variants.Add(variant);

                                // finally add to db
                                repository.AddProduct(productInfo, subdomainid);
                            }
                        }
                    }
                }
                else
                {
                    //Syslog.Write(ErrorLevel.WARNING,string.Format("{0}: No products", warehouse));
                }
            }
            else
            {
                Syslog.Write("No response from warehouse " + warehouse);
            }
        }
示例#7
0
        public void DeleteInventoryLocation(long id, long subdomainid)
        {
            var loc = GetInventoryLocation(id, subdomainid);

            if (loc == null)
            {
                throw new Exception("Cannot find location");
            }
            // move all entries to main location
            // external variant types does not affect this because it does not have entries
            var mainloc = GetInventoryLocation(GeneralConstants.INVENTORY_LOCATION_DEFAULT, subdomainid);

            foreach (var entry in loc.inventoryLocationItems)
            {
                var variantid     = entry.variantid;
                var inventoryItem = mainloc.inventoryLocationItems.SingleOrDefault(x => x.variantid == variantid);
                var newEntry      = false;
                if (inventoryItem == null)
                {
                    inventoryItem = new inventoryLocationItem
                    {
                        variantid  = variantid,
                        locationid = mainloc.id,
                        alarmLevel = entry.alarmLevel,
                        lastUpdate = DateTime.UtcNow
                    };
                    newEntry = true;
                }
                var invWorker = new InventoryWorker(inventoryItem, subdomainid, entry.product_variant.product.trackInventory, entry.product_variant.IsDigital());
                invWorker.SetValues(string.Format("From deleted inventory location {0}", entry.inventoryLocation.name),
                                    entry.available, entry.onOrder, entry.reserved, entry.sold);

                if (newEntry)
                {
                    db.inventoryLocationItems.InsertOnSubmit(inventoryItem);
                }
            }

            // delete items
            db.inventoryLocationItems.DeleteAllOnSubmit(loc.inventoryLocationItems);

            // delete history
            var histories = loc.inventoryLocationItems.SelectMany(x => x.inventoryHistories);

            db.inventoryHistories.DeleteAllOnSubmit(histories);

            // TODO: this is unused at the moment
            // update orders that are using this inventory location
            var affectedOrders = db.orders.Where(x => x.inventoryLocation.HasValue &&
                                                 x.inventoryLocation.Value == id);

            foreach (var order in affectedOrders)
            {
                order.inventoryLocation     = null;
                order.inventoryLocation_del = loc.name;
            }

            // delete inventory location
            db.inventoryLocationItems.DeleteAllOnSubmit(loc.inventoryLocationItems);
            db.inventoryLocations.DeleteOnSubmit(loc);

            Save();
        }
示例#8
0
        public List <ProductInfo> Import(Stream inputStream, long owner, long subdomain)
        {
            var templateWorkbook = new HSSFWorkbook(inputStream, true);
            var sheet            = templateWorkbook.GetSheet("Products");
            int count            = 0;
            var productsList     = new List <ProductInfo>();

            using (var repository = new TradelrRepository())
            {
                while (true)
                {
                    var row = sheet.GetRow(count++);
                    if (row == null)
                    {
                        break;
                    }
                    var sku = GetCellValueAsString(row.GetCell(0, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    if (sku.StartsWith(";"))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(sku))
                    {
                        break;
                    }

                    var title        = GetCellValueAsString(row.GetCell(1, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    var description  = GetCellValueAsString(row.GetCell(2, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    var maincategory = GetCellValueAsString(row.GetCell(3, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    var subcategory  = GetCellValueAsString(row.GetCell(4, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    var stockunit    = GetCellValueAsString(row.GetCell(5, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    var costprice    = GetCellValueAsDecimal(row.GetCell(6, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    var sellingprice = GetCellValueAsDecimal(row.GetCell(7, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    var instock      = GetCellValueAsInt(row.GetCell(8, MissingCellPolicy.RETURN_NULL_AND_BLANK));
                    var photos       = GetCellValueAsString(row.GetCell(9, MissingCellPolicy.RETURN_NULL_AND_BLANK));

                    var product = new product
                    {
                        subdomainid  = subdomain,
                        details      = description,
                        title        = title,
                        costPrice    = costprice,
                        sellingPrice = sellingprice
                    };

                    if (!string.IsNullOrEmpty(stockunit))
                    {
                        var masterunit = repository.AddMasterStockUnit(stockunit);
                        var su         = new stockUnit {
                            unitID = masterunit.id, subdomainid = subdomain
                        };
                        product.stockUnitId = repository.AddStockUnit(su);
                    }

                    product.otherNotes = "";
                    var inventoryloc =
                        repository.GetInventoryLocation(GeneralConstants.INVENTORY_LOCATION_DEFAULT,
                                                        subdomain);

                    // create inventoryLocItem
                    var inventoryLocItem = new inventoryLocationItem
                    {
                        locationid = inventoryloc.id,
                        lastUpdate = DateTime.UtcNow
                    };
                    var invWorker = new InventoryWorker(inventoryLocItem, subdomain, true, false);
                    invWorker.SetValues("product created", instock, null, null, null);

                    MASTERproductCategory mastercat;
                    long?catid = null;
                    if (!string.IsNullOrEmpty(maincategory))
                    {
                        mastercat = repository.AddMasterProductCategory(maincategory);
                        var cat = new productCategory()
                        {
                            masterID  = mastercat.id,
                            subdomain = subdomain
                        };
                        catid = repository.AddProductCategory(cat, subdomain);
                    }

                    // add sub category
                    if (!string.IsNullOrEmpty(subcategory) && !string.IsNullOrEmpty(maincategory))
                    {
                        mastercat = repository.AddMasterProductCategory(subcategory);
                        var subcat = new productCategory()
                        {
                            masterID  = mastercat.id,
                            subdomain = subdomain,
                            parentID  = catid
                        };
                        catid = repository.AddProductCategory(subcat, subdomain);
                    }
                    product.category = catid;
                    product.created  = DateTime.UtcNow;
                    product.updated  = product.created;
                    if (!productsList.Where(x => x.p.product_variants.Count(y => y.sku == sku) != 0).Any())
                    {
                        var pi = new ProductInfo()
                        {
                            p = product
                        };

                        if (!string.IsNullOrEmpty(photos))
                        {
                            var photourls = photos.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var photourl in photourls)
                            {
                                pi.AddPhotoUrl(photourl);
                            }
                        }

                        var variant = new product_variant {
                            sku = sku
                        };
                        variant.inventoryLocationItems.Add(inventoryLocItem);
                        pi.p.product_variants.Add(variant);
                        productsList.Add(pi);
                    }
                }
            }
            return(productsList);
        }
示例#9
0
        public void UpdateInventoryItem(orderItem orderItem, int inventoryDelta)
        {
            // no need for updates if delta is zero
            if (inventoryDelta == 0)
            {
                return;
            }

            inventoryLocation location;

            // throws null if we just check on value. happens when creating a new order
            if (orderItem.order.inventoryLocation1 != null)
            {
                location = orderItem.order.inventoryLocation1;
            }
            else
            {
                if (orderItem.order.inventoryLocation.HasValue)
                {
                    location = repository.GetInventoryLocation(orderItem.order.inventoryLocation.Value, senderDomain.id);
                }
                else
                {
                    location = repository.GetInventoryLocation(GeneralConstants.INVENTORY_LOCATION_DEFAULT, senderDomain.id);
                }
            }

            inventoryLocationItem locationItem;
            bool trackInventory;
            bool isDigital;

            if (orderItem.product_variant == null)
            {
                var variant = repository.GetProductVariant(orderItem.variantid, senderDomain.id);
                locationItem   = variant.inventoryLocationItems.SingleOrDefault(x => x.locationid == location.id);
                trackInventory = variant.product.trackInventory;
                isDigital      = variant.IsDigital();
            }
            else
            {
                locationItem   = orderItem.product_variant.inventoryLocationItems.SingleOrDefault(x => x.locationid == location.id);
                trackInventory = orderItem.product_variant.product.trackInventory;
                isDigital      = orderItem.product_variant.IsDigital();
            }

            if (locationItem == null)
            {
                locationItem = new inventoryLocationItem
                {
                    locationid = location.id,
                    lastUpdate = DateTime.UtcNow
                };
                if (orderItem.product_variant == null)
                {
                    var variant = repository.GetProductVariant(orderItem.variantid, senderDomain.id);
                    variant.inventoryLocationItems.Add(locationItem);
                }
                else
                {
                    orderItem.product_variant.inventoryLocationItems.Add(locationItem);
                }
            }

            var isNewEntry  = orderItem.id == 0;
            var isDelete    = orderItem.quantity == 0;
            var invWorker   = new InventoryWorker(locationItem, senderDomain.id, trackInventory, isDigital);
            var description = order.ToHtmlLink();

            switch (GetOrderStatus())
            {
            case OrderStatus.DRAFT:
                if (isNewEntry)
                {
                    description += " created";
                }
                else if (isDelete)
                {
                    description += string.Format(": {0} deleted", orderItem.product_variant.ToHtmlLink());
                }
                else
                {
                    description += " updated";
                }

                if (transactionType == TransactionType.INVOICE)
                {
                    invWorker.SetValues(description,
                                        -inventoryDelta, // available
                                        null,            // on order
                                        inventoryDelta,  // reserved
                                        null);           // sold
                }
                else
                {
                    invWorker.SetValues(description,
                                        null,           // available
                                        inventoryDelta, // on order
                                        null,           // reserved
                                        null);          // sold
                }
                break;

            case OrderStatus.SENT:
                if (transactionType == TransactionType.INVOICE)
                {
                    if (isNewEntry)
                    {
                        invWorker.SetValues(order.ToHtmlLink() + " created",
                                            -inventoryDelta, // available
                                            null,            // on order
                                            inventoryDelta,  // reserved
                                            null);           // sold
                    }
                }
                else
                {
                    if (isNewEntry)
                    {
                        invWorker.SetValues(order.ToHtmlLink() + " created",
                                            null,           // available
                                            inventoryDelta, // on order
                                            null,           // reserved
                                            null);          // sold
                    }
                }
                break;

            case OrderStatus.VIEWED:
                break;

            case OrderStatus.PARTIAL:
                break;

            case OrderStatus.PAID:
                if (transactionType == TransactionType.INVOICE)
                {
                    if (isNewEntry)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        invWorker.SetValues(order.ToHtmlLink() + " paid",
                                            null,            // available
                                            null,            // on order
                                            -inventoryDelta, // reserved
                                            inventoryDelta); // sold
                    }
                }
                break;

            case OrderStatus.SHIPPED:
                if (transactionType == TransactionType.ORDER)
                {
                    if (isNewEntry)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        invWorker.SetValues(order.ToHtmlLink() + " received",
                                            inventoryDelta,  // available
                                            -inventoryDelta, // on order
                                            null,            // reserved
                                            null);           // sold
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("status");
            }
        }