Пример #1
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnUpdateOrderFinished != null)
                {
                    OnUpdateOrderFinished(OrderId);
                }
                break;

            case State.Begin:

                // Don't close the market window if its already up
                if (marketWindow != null)
                {
                    Logging.Log("UpdateOrder:Process", "Market already open no need to open the market", Logging.White);
                }
                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    Logging.Log("UpdateOrder:Process", "Opening Market", Logging.White);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    break;
                }

                _state = State.LoadOrders;
                break;

            case State.LoadOrders:

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        break;
                    }

                    Logging.Log("UpdateOrder:Process", "Load orders", Logging.White);

                    if (marketWindow.LoadOrders() == true)
                    {
                        _state = State.MarketInfo;
                    }

                    break;
                }
                else
                {
                    Logging.Log("UpdateOrder:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.MarketInfo:
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        break;
                    }

                    List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList();

                    if (orders == null)
                    {
                        Logging.Log("UpdateOrder:Process", "Something is wrong, order list is empty, ending update order action", Logging.White);
                        _state = State.Done;
                    }

                    DirectOrder order = orders.FirstOrDefault(o => o.OrderId == OrderId);

                    if (order == null)
                    {
                        Logging.Log("UpdateOrder:Process", "Order doesn't exist, ending update order action OrderId - " + OrderId, Logging.White);
                        _state = State.Done;
                        break;
                    }

                    Logging.Log("UpdateOrder:Process", "Load orders for TypeId - " + order.TypeId.ToString(), Logging.White);

                    if (marketWindow.DetailTypeId != order.TypeId)
                    {
                        if (marketWindow.LoadTypeId(order.TypeId) == true)
                        {
                            _state = State.Update;
                        }
                    }
                    else
                    {
                        _state = State.Update;
                    }

                    break;
                }
                else
                {
                    Logging.Log("MarketItemInfo:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.Update:

                // We keep getting the popup saying we can't modify many orders in a minute, so this needs to be at 6 or higher, probably higher
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 1)
                {
                    break;
                }

                if (marketWindow != null)
                {
                    if (!marketWindow.IsReady)
                    {
                        break;
                    }

                    try
                    {
                        _lastAction = DateTime.UtcNow;

                        List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList();
                        DirectOrder        order  = orders.FirstOrDefault(o => o.OrderId == OrderId);

                        if (order != null)
                        {
                            Logging.Log("UpdateOrder:Process", "Loaded order, OrderId - " + order.OrderId + " OrderPrice - " + order.Price, Logging.White);

                            if (IsBid)
                            {
                                UpdateBuyOrder(order, marketWindow.SellOrders, marketWindow.BuyOrders);
                            }
                            else
                            {
                                UpdateSellOrder(order, marketWindow.SellOrders, marketWindow.BuyOrders);
                            }
                        }
                        else
                        {
                            Logging.Log("UpdateOrder:Process", "Order no longer exists, exiting modify action", Logging.White);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Log("UpdateOrder:Process", "Exception [" + ex + "] - Ending modify order script", Logging.Debug);
                    }

                    _state = State.Done;
                }
                else
                {
                    _state = State.OpenMarket;
                }

                break;
            }
        }
Пример #2
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnCancelOrderFinished != null)
                {
                    OnCancelOrderFinished(OrderId);
                }
                break;

            case State.Begin:

                // Don't close the market window if its already up
                if (marketWindow != null)
                {
                    Logging.Log("CancelOrder:Process", "Market already open no need to open the market", Logging.White);
                }
                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    Logging.Log("CancelOrder:Process", "Opening Market", Logging.White);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    break;
                }

                _state = State.LoadOrders;
                break;

            case State.LoadOrders:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    Logging.Log("CancelOrder:Process", "Load orders", Logging.White);

                    if (marketWindow.LoadOrders() == true)
                    {
                        _state = State.Cancel;
                    }

                    break;
                }
                else
                {
                    Logging.Log("CancelOrder:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.Cancel:

                // We keep getting the popup saying we can't modify many orders in a minute, so this needs to be at 6 or higher, probably higher
                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                if (marketWindow != null)
                {
                    try
                    {
                        _lastAction = DateTime.UtcNow;

                        List <DirectOrder> orders = marketWindow.GetMyOrders(IsBid).ToList();
                        DirectOrder        order  = orders.FirstOrDefault(o => o.OrderId == OrderId);

                        if (order != null)
                        {
                            Logging.Log("CancelOrder:Process", "Loaded order, OrderId - " + order.OrderId, Logging.White);

                            bool success = order.CancelOrder();

                            if (success)
                            {
                                Logging.Log("CancelOrder:Process", "Canceling order successful", Logging.White);
                            }
                            else
                            {
                                Logging.Log("CancelOrder:Process", "Canceling order failure", Logging.White);
                            }
                        }
                        else
                        {
                            Logging.Log("CancelOrder:Process", "Order no longer exists, exiting modify action", Logging.White);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logging.Log("CancelOrder:Process", "Exception [" + ex + "] - Ending modify order script", Logging.Debug);
                    }

                    _state = State.Done;
                }
                else
                {
                    _state = State.OpenMarket;
                }

                break;
            }
        }
Пример #3
0
        public void Process()
        {
            if (!Status.Instance.InStation)
            {
                return;
            }

            if (Status.Instance.InSpace)
            {
                return;
            }

            DirectMarketWindow marketWindow = Cache.Instance.DirectEve.Windows.OfType <DirectMarketWindow>().FirstOrDefault();

            switch (_state)
            {
            case State.Idle:
                break;

            case State.Done:
                _done = true;

                if (OnMyOrdersFinished != null)
                {
                    OnMyOrdersFinished(_mySellOrders, _myBuyOrders);
                }
                break;

            case State.Begin:

                // Don't close the market window if its already up
                if (marketWindow != null)
                {
                    Logging.Log("MyOrders:Process", "Market already open no need to open the market", Logging.White);
                }

                _state = State.OpenMarket;
                break;

            case State.OpenMarket:

                if (marketWindow == null)
                {
                    Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.OpenMarket);
                    Logging.Log("MyOrders:Process", "Opening Market", Logging.White);
                    break;
                }

                if (!marketWindow.IsReady)
                {
                    Logging.Log("MyOrders:Process", "Market window is not ready", Logging.White);
                    break;
                }

                _state = State.LoadOrders;
                break;

            case State.LoadOrders:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                _lastAction = DateTime.UtcNow;

                if (marketWindow != null)
                {
                    Logging.Log("MyOrders:Process", "Load orders", Logging.White);

                    if (marketWindow.LoadOrders() == true)
                    {
                        _state = State.CacheOrders;
                    }

                    break;
                }
                else
                {
                    Logging.Log("MyOrders:Process", "MarketWindow is not open, going back to open market state", Logging.White);

                    _state = State.OpenMarket;
                }

                break;

            case State.CacheOrders:

                if (DateTime.UtcNow.Subtract(_lastAction).TotalSeconds < 2)
                {
                    break;
                }

                if (marketWindow != null)
                {
                    _lastAction = DateTime.UtcNow;

                    Cache.Instance.OrderCap = Cache.Instance.DirectEve.GetOrderCap();

                    Logging.Log("MyOrders:Process", "Get list of my orders", Logging.White);

                    _myBuyOrders  = marketWindow.GetMyOrders(true).ToList();
                    _mySellOrders = marketWindow.GetMyOrders(false).ToList();

                    if (_mySellOrders != null)
                    {
                        Logging.Log("MyOrders:Process", "Get list of my sell orders successful", Logging.White);
                        Cache.Instance.MySellOrders = _mySellOrders;
                    }

                    if (_myBuyOrders != null)
                    {
                        Logging.Log("MyOrders:Process", "Get list of my buy orders successful", Logging.White);
                        Cache.Instance.MyBuyOrders = _myBuyOrders;
                    }

                    _state = State.Done;
                }
                else
                {
                    _state = State.OpenMarket;
                }
                break;
            }
        }