Exemplo n.º 1
0
        public void UpdateWorthInDepot(Depot _Depot, double _new_worth)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(DepotStorage);
            XmlNodeList DepotOwnerNodes = xmlDoc.SelectNodes("//Depots/Depot/Owner");

            foreach (XmlNode DepotOwnerNode in DepotOwnerNodes)
            {
                if ((DepotOwnerNode.InnerText == _Depot.Owner.ID.ToString()) && (DepotOwnerNode.PreviousSibling.InnerText == _Depot.ID.ToString()))
                {
                    XmlNode EStock = DepotOwnerNode.NextSibling;
                    XmlNode EOrder = EStock.NextSibling;
                    XmlNode ETime  = EOrder.NextSibling;
                    XmlNode EWorth = ETime.NextSibling;

                    foreach (XmlNode WorthNode in EWorth)
                    {
                        WorthNode.InnerText = _new_worth.ToString();
                    }
                }
            }

            xmlDoc.Save(DepotStorage);
        }
Exemplo n.º 2
0
        public void UpdateStockInDepot(Depot _Depot, KeyValuePair <Stock, uint> _Stock, int _diff)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(DepotStorage);
            XmlNodeList DepotOwnerNodes = xmlDoc.SelectNodes("//Depots/Depot/Owner");

            foreach (XmlNode DepotOwnerNode in DepotOwnerNodes)
            {
                if ((DepotOwnerNode.InnerText == _Depot.Owner.ID.ToString()) && (DepotOwnerNode.PreviousSibling.InnerText == _Depot.ID.ToString()))
                {
                    XmlNode EStock  = DepotOwnerNode.NextSibling;
                    bool    updated = false;
                    foreach (XmlNode StockNode in EStock)
                    {
                        if ((StockNode.Attributes["SID"].Value.ToString() == _Stock.Key.ID) && (uint.Parse(StockNode.Attributes["Amount"].Value.ToString()) == _Stock.Value))
                        {
                            int _new_amt = (int)_Stock.Value - _diff;
                            if ((_new_amt > 0) && (updated == false))
                            {
                                StockNode.Attributes["Amount"].Value = _new_amt.ToString();
                                updated = true;
                            }
                            else if ((_new_amt <= 0) && (updated == false))
                            {
                                EStock.RemoveChild(StockNode);
                                updated = true;
                            }
                        }
                    }
                }
            }

            xmlDoc.Save(DepotStorage);
        }
Exemplo n.º 3
0
        public void SaveStocksToDepot(Depot _Depot, List <KeyValuePair <Stock, uint> > _Stocks)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(DepotStorage);
            XmlNodeList DepotOwnerNodes = xmlDoc.SelectNodes("//Depots/Depot/Owner");

            foreach (XmlNode DepotOwnerNode in DepotOwnerNodes)
            {
                if ((DepotOwnerNode.InnerText == _Depot.Owner.ID.ToString()) && (DepotOwnerNode.PreviousSibling.InnerText == _Depot.ID.ToString()))
                {
                    foreach (KeyValuePair <Stock, uint> s in _Stocks)
                    {
                        XmlAttribute sid = xmlDoc.CreateAttribute("SID");
                        sid.Value = s.Key.ID;

                        XmlAttribute amount = xmlDoc.CreateAttribute("Amount");
                        amount.Value = s.Value.ToString();

                        XmlElement EStock = xmlDoc.CreateElement("Stock");
                        EStock.Attributes.Append(sid);
                        EStock.Attributes.Append(amount);
                        DepotOwnerNode.NextSibling.AppendChild(EStock);
                    }
                }
            }

            xmlDoc.Save(DepotStorage);
        }
Exemplo n.º 4
0
        public void SaveIssuedOrderToDepot(Depot _Depot, Order _Order)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(DepotStorage);
            XmlNodeList DepotOwnerNodes = xmlDoc.SelectNodes("//Depots/Depot/Owner");

            foreach (XmlNode DepotOwnerNode in DepotOwnerNodes)
            {
                if ((DepotOwnerNode.InnerText == _Depot.Owner.ID.ToString()) && (DepotOwnerNode.PreviousSibling.InnerText == _Depot.ID.ToString()))
                {
                    if (_Order.amount > 0)
                    {
                        XmlAttribute oid = xmlDoc.CreateAttribute("OID");
                        oid.Value = _Order.id;

                        XmlAttribute boerseid = xmlDoc.CreateAttribute("BoerseID");
                        boerseid.Value = _Order.idBoerse;

                        XmlAttribute type = xmlDoc.CreateAttribute("Type");
                        type.Value = _Order.type;

                        XmlAttribute amount = xmlDoc.CreateAttribute("Amount");
                        amount.Value = _Order.amount.ToString();

                        XmlElement EOrder = xmlDoc.CreateElement("IssuedOrder");
                        EOrder.Attributes.Append(oid);
                        EOrder.Attributes.Append(boerseid);
                        EOrder.Attributes.Append(type);
                        EOrder.Attributes.Append(amount);
                        XmlNode EStock = DepotOwnerNode.NextSibling;
                        EStock.NextSibling.AppendChild(EOrder);
                    }
                    else
                    {
                        XmlNode EStock = DepotOwnerNode.NextSibling;
                        XmlNode EOrder = EStock.NextSibling;
                        foreach (XmlNode OrderNode in EOrder)
                        {
                            if (OrderNode.Attributes["OID"].Value.ToString() == _Order.id)
                            {
                                EOrder.RemoveChild(OrderNode);
                            }
                        }
                    }
                }
            }
            xmlDoc.Save(DepotStorage);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Welcome to the Stock Deal App of dieBank!");
                List <Customer> Customers = DataControl.Instance.LoadAllCustomers();
                while (Customers.Count <= 0)
                {
                    String FirstName = "";
                    String LastName  = "";
                    Console.WriteLine("No customers found, please enter First Name and Last Name to create a customer: ");
                    while (FirstName.Length < 3)
                    {
                        Console.WriteLine("Enter First Name (atleast 3 characters): ");
                        FirstName = Console.ReadLine();
                    }

                    while (LastName.Length < 3)
                    {
                        Console.WriteLine("Enter Last Name (atleast 3 characters): ");
                        LastName = Console.ReadLine();
                    }

                    Customers.Add(new Customer(FirstName, LastName));
                }

                Console.WriteLine("Please choose a customer from the list or create a new customer: ");

                uint customercounter = 0;
                foreach (Customer _customer in Customers)
                {
                    Console.WriteLine("Customer Nr.: " + (customercounter++));
                    Console.WriteLine("Internal Customer Nr.: " + _customer.ID);
                    Console.WriteLine("First Name: " + _customer.FirstName);
                    Console.WriteLine("Last Name: " + _customer.LastName);
                }
                Console.WriteLine("Please enter the Customer Nr. (0-" + (--customercounter) + "): ");
                string CID_str = Console.ReadLine();

                uint CID = 0;



                while ((!uint.TryParse(CID_str, out CID)) || (CID < 0) || (CID > customercounter))
                {
                    Console.WriteLine("Please enter the Customer Nr. (0-" + (customercounter) + "): ");
                    CID_str = Console.ReadLine();
                }
                CID = uint.Parse(CID_str);
                Console.WriteLine("Chosen Customer: ");
                Customer CC = DataControl.Instance.LoadAllCustomers()[(int)CID];
                Console.WriteLine("Customer Nr.: " + CID);
                Console.WriteLine("Internal Customer Nr.: " + CC.ID);
                Console.WriteLine("First Name: " + CC.FirstName);
                Console.WriteLine("Last Name: " + CC.LastName);

                List <Depot> DepotsOfCustomers = DataControl.Instance.GetDepotsByCustomer(CC, GetAllOrders());

                if (DepotsOfCustomers.Count > 0)
                {
                    uint depotcounter = 0;
                    Console.WriteLine("Depots: ");
                    foreach (Depot _D in DepotsOfCustomers)
                    {
                        Console.WriteLine("--------------------------------------");
                        Console.WriteLine("Depot Nr.: " + (depotcounter++));
                        Console.WriteLine("Internal Depot Nr.: " + _D.ID);
                        Console.WriteLine("Internal Customer Nr.: " + _D.Owner.ID);
                        Console.WriteLine("Stocks: ");
                        foreach (KeyValuePair <Stock, uint> _S in _D.Stocks)
                        {
                            Console.WriteLine("             " + _S.Key.ID + " (" + _S.Value.ToString() + ")");
                        }
                        Console.WriteLine("Issued Orders: ");
                        foreach (Order _o in _D.IssuedOrders)
                        {
                            Console.WriteLine("             " + _o.id + " " + _o.idBoerse + " " + _o.type + " " + _o.amount);
                        }
                        _D.CalcCurrentWorth(GetAllStocks());
                        Console.WriteLine("Current Worth: " + _D.Worth);
                        Console.WriteLine("--------------------------------------");
                    }
                    Console.WriteLine("Please enter the Depot Nr. (0-" + (--depotcounter) + "): ");
                    string DID_str = Console.ReadLine();

                    uint DID = 0;



                    while ((!uint.TryParse(DID_str, out DID)) || (DID < 0) || (DID > depotcounter))
                    {
                        Console.WriteLine("Please enter the Depot Nr. (0-" + (depotcounter) + "): ");
                        DID_str = Console.ReadLine();
                    }
                    DID = uint.Parse(DID_str);
                    Console.WriteLine("Chosen Depot: ");
                    Depot _DD = DataControl.Instance.GetDepotsByCustomer(CC, GetAllOrders())[(int)DID];
                    Console.WriteLine("Depot Nr.: " + DID);
                    Console.WriteLine("Internal Depot Nr.: " + _DD.ID);
                    Console.WriteLine("Internal Customer Nr.: " + _DD.Owner.ID);
                    Console.WriteLine("Stocks: ");
                    if (_DD.IssuedOrders.Count > 0)
                    {
                        Console.WriteLine("- Evaluating Issued Orders...");
                        Order[] ALLORDERS = GetAllOrders();
                        foreach (Order _o in _DD.IssuedOrders)
                        {
                            for (int i = 0; i < ALLORDERS.Length; i++)
                            {
                                if (_o.id == ALLORDERS[i].id)
                                {
                                    if (ALLORDERS[i].amount == 0)
                                    {
                                        if (_o.type == "buy")
                                        {
                                            Stock _s = new Stock(_o.idStock);
                                            _s.IDBOERSE = _o.idBoerse;
                                            _s.Price    = _o.price;

                                            _DD.AddStock(_s, _o.amount);
                                            DataControl.Instance.SaveIssuedOrderToDepot(_DD, ALLORDERS[i]);
                                            _DD.CalcCurrentWorth(GetAllStocks());
                                        }
                                        else if (_o.type == "sell")
                                        {
                                            Stock _s = new Stock(_o.idStock);
                                            _s.IDBOERSE = _o.idBoerse;
                                            _s.Price    = _o.price;
                                            uint old_amount = 0;
                                            foreach (KeyValuePair <Stock, uint> _S in _DD.Stocks)
                                            {
                                                if (_s.ID == _S.Key.ID)
                                                {
                                                    old_amount = _S.Value;
                                                }
                                            }

                                            DataControl.Instance.UpdateStockInDepot(_DD, new KeyValuePair <Stock, uint>(_s, old_amount), (int)_o.amount);
                                            DataControl.Instance.SaveIssuedOrderToDepot(_DD, ALLORDERS[i]);
                                            _DD.CalcCurrentWorth(GetAllStocks());
                                        }
                                    }
                                }
                            }
                        }
                    }

                    _DD = DataControl.Instance.GetDepotsByCustomer(CC, GetAllOrders())[(int)DID];
                    _DD.CalcCurrentWorth(GetAllStocks());

                    if (_DD.Stocks.Count > 0)
                    {
                        Console.WriteLine("The following Stocks remain in the Depot: ");
                        uint stockcounter = 0;
                        foreach (KeyValuePair <Stock, uint> _S in _DD.Stocks)
                        {
                            Console.WriteLine("Stock Nr.: " + stockcounter++);
                            Console.WriteLine("             " + _S.Key.ID + " (" + _S.Value.ToString() + ")");
                        }

                        Console.WriteLine("...Resulting in a Worth of: " + _DD.Worth);

                        string WannaSellAStock = "";
                        while ((WannaSellAStock != "yes") && (WannaSellAStock != "no"))
                        {
                            Console.WriteLine("Do you want to sell any of the remaining Stocks?");
                            WannaSellAStock = Console.ReadLine();
                        }

                        if (WannaSellAStock == "yes")
                        {
                            Console.WriteLine("Please enter the Stock Nr. (0-" + (--stockcounter) + "): ");
                            string SID_str = Console.ReadLine();

                            uint SID = 0;



                            while ((!uint.TryParse(SID_str, out SID)) || (SID < 0) || (SID > stockcounter))
                            {
                                Console.WriteLine("Please enter the Stock Nr. (0-" + (stockcounter) + "): ");
                                SID_str = Console.ReadLine();
                            }
                            SID = uint.Parse(SID_str);
                            Stock[] _ALLSTOCKS = GetAllStocks();
                            double  curr_price = 0d;
                            foreach (Stock _S in _ALLSTOCKS)
                            {
                                if (_S.ID == _DD.Stocks[(int)SID].Key.ID)
                                {
                                    curr_price = _S.Price;
                                    _DD.Stocks[(int)SID].Key.Price = curr_price;
                                }
                            }



                            Console.WriteLine("Chosen Stock: ");
                            Console.WriteLine("--------------------------------------");
                            Console.WriteLine("Stock Nr.: " + SID);
                            Console.WriteLine("             " + _DD.Stocks[(int)SID].Key.ID + " (" + _DD.Stocks[(int)SID].Value.ToString() + ")");
                            Console.WriteLine("--------------------------------------");


                            Console.WriteLine("Please enter the amount of Stocks you would like to SELL (max." + _DD.Stocks[(int)SID].Value + "): ");
                            string amt_str = Console.ReadLine();

                            uint amt = 0;



                            while ((!uint.TryParse(amt_str, out amt)) || (amt < 1) || (amt > _DD.Stocks[(int)SID].Value))
                            {
                                Console.WriteLine("Please enter the amount of Stocks you would like to SELL (max." + _DD.Stocks[(int)SID].Value + "): ");
                                amt_str = Console.ReadLine();
                            }
                            amt = uint.Parse(amt_str);


                            Console.WriteLine("Please enter the price  you would like to SELL the stocks for (current: " + curr_price + "): ");
                            string prc_str = Console.ReadLine();

                            double prc = 0;



                            while ((!double.TryParse(prc_str, out prc)) || (prc < 0))
                            {
                                Console.WriteLine("Please enter the price  you would like to SELL the stocks for (current: " + curr_price + "): ");
                                prc_str = Console.ReadLine();
                            }
                            prc = double.Parse(prc_str);


                            string WannaSellStock = "";
                            while ((WannaSellStock != "yes") && (WannaSellStock != "no"))
                            {
                                Console.WriteLine("Send Order TO SELL Stock " + _DD.Stocks[(int)SID].Key.ID + " with the amount of " + amt + " for the price of " + prc + "?");
                                WannaSellStock = Console.ReadLine();
                            }

                            if (WannaSellStock == "yes")
                            {
                                Order SellOrder = new Order();
                                SellOrder.timestamp  = DateTimeOffset.Now;
                                SellOrder.idBoerse   = "datBoerse";
                                SellOrder.idBank     = "dieBank";
                                SellOrder.idStock    = _DD.Stocks[(int)SID].Key.ID;
                                SellOrder.price      = prc;
                                SellOrder.amount     = amt;
                                SellOrder.type       = "sell";
                                SellOrder.idCustomer = CC.ID;

                                SellOrder = JsonConvert.DeserializeObject <Order>(SendOrder(SellOrder));
                                _DD.AddSellOrder(SellOrder);

                                Console.WriteLine("Order has been sent!");
                                _DD.CalcCurrentWorth(GetAllStocks());
                                continue;
                            }
                            else
                            {
                                _DD.CalcCurrentWorth(GetAllStocks());
                            }
                        }
                    }

                    if (_DD.Stocks.Count <= 0)
                    {
                        Console.WriteLine("No Stocks found in Depot - Loading available Stocks from Boerse...");
                        Order[] Orders           = GetAllOrders();
                        uint    sellordercounter = 0;
                        for (int i = 0; i < Orders.Length; i++)
                        {
                            if (Orders[i].type == "sell")
                            {
                                sellordercounter++;
                            }
                        }
                        Console.WriteLine("Sells: " + sellordercounter);
                        Order[] SellOrders = new Order[sellordercounter];

                        sellordercounter = 0;
                        for (int i = 0; i < Orders.Length; i++)
                        {
                            if (Orders[i].type == "sell")
                            {
                                SellOrders[sellordercounter] = Orders[i];
                                sellordercounter++;
                            }
                        }


                        uint ordercounter = 0;
                        foreach (Order od in SellOrders)
                        {
                            Console.WriteLine("+++++++++++++++++++++++++++++++++++++++");
                            Console.WriteLine("Order Nr.: " + ordercounter++);
                            Console.WriteLine("ID: " + od.id);
                            Console.WriteLine("Time: " + od.timestamp);
                            Console.WriteLine("Type: " + od.type);
                            Console.WriteLine("Boerse: " + od.idBoerse);
                            Console.WriteLine("Customer: " + od.idCustomer);
                            Console.WriteLine("Stock: " + od.idStock);
                            Console.WriteLine("Amount: " + od.amount);
                            Console.WriteLine("Price: " + od.price);
                            Console.WriteLine("+++++++++++++++++++++++++++++++++++++++");
                        }

                        string WannaBuyAStock = "";
                        while ((WannaBuyAStock != "yes") && (WannaBuyAStock != "no"))
                        {
                            Console.WriteLine("Do you want to buy any Stocks?");
                            WannaBuyAStock = Console.ReadLine();
                        }

                        if (WannaBuyAStock == "yes")
                        {
                            Console.WriteLine("Please enter the Order Nr. (0-" + (--ordercounter) + "): ");
                            string OID_str = Console.ReadLine();

                            uint OID = 0;



                            while ((!uint.TryParse(OID_str, out OID)) || (OID < 0) || (OID > ordercounter))
                            {
                                Console.WriteLine("Please enter the Order Nr. (0-" + (ordercounter) + "): ");
                                OID_str = Console.ReadLine();
                            }
                            OID = uint.Parse(OID_str);
                            Console.WriteLine("Chosen Order: ");
                            Order OO = SellOrders[OID];
                            Console.WriteLine("Order Nr.: " + OID);
                            Console.WriteLine("ID: " + OO.id);
                            Console.WriteLine("Time: " + OO.timestamp);
                            Console.WriteLine("Type: " + OO.type);
                            Console.WriteLine("Boerse: " + OO.idBoerse);
                            Console.WriteLine("Customer: " + OO.idCustomer);
                            Console.WriteLine("Stock: " + OO.idStock);
                            Console.WriteLine("Amount: " + OO.amount);
                            Console.WriteLine("Price: " + OO.price);


                            Console.WriteLine("Please enter the amount of Stocks you would like to buy (max." + OO.amount + "): ");
                            string amt_str = Console.ReadLine();

                            uint amt = 0;



                            while ((!uint.TryParse(amt_str, out amt)) || (amt < 1) || (amt > OO.amount))
                            {
                                Console.WriteLine("Please enter the amount of Stocks you would like to buy (max." + OO.amount + "): ");
                                amt_str = Console.ReadLine();
                            }
                            amt = uint.Parse(amt_str);


                            Console.WriteLine("Please enter the price  you would like to buy the stocks for (current: " + OO.price + "): ");
                            string prc_str = Console.ReadLine();

                            double prc = 0;



                            while ((!double.TryParse(prc_str, out prc)) || (prc < 0))
                            {
                                Console.WriteLine("Please enter the price  you would like to buy the stocks for (current: " + OO.price + "): ");
                                prc_str = Console.ReadLine();
                            }
                            prc = double.Parse(prc_str);


                            string DoSendOrder = "";
                            while ((DoSendOrder != "yes") && (DoSendOrder != "no"))
                            {
                                Console.WriteLine("Send Order for Stock " + OO.idStock + " with the amount of " + amt + " for the price of " + prc + "?");
                                DoSendOrder = Console.ReadLine();
                            }

                            if (DoSendOrder == "yes")
                            {
                                Order BuyOrder = new Order();
                                BuyOrder.timestamp  = DateTimeOffset.Now;
                                BuyOrder.idBoerse   = "datBoerse";
                                BuyOrder.idBank     = "dieBank";
                                BuyOrder.idStock    = OO.idStock;
                                BuyOrder.price      = prc;
                                BuyOrder.amount     = amt;
                                BuyOrder.type       = "buy";
                                BuyOrder.idCustomer = CC.ID;

                                BuyOrder = JsonConvert.DeserializeObject <Order>(SendOrder(BuyOrder));
                                _DD.AddSellOrder(BuyOrder);

                                Console.WriteLine("Order has been sent!");
                                _DD.CalcCurrentWorth(GetAllStocks());
                                continue;
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine(CC.FirstName + " " + CC.LastName + " has no Depots");
                    string CreateDepot = "";
                    while ((CreateDepot != "yes") && (CreateDepot != "no"))
                    {
                        Console.WriteLine("Create Depot? Enter yes or no: ");
                        CreateDepot = Console.ReadLine();
                    }

                    if (CreateDepot == "yes")
                    {
                        new Depot(CC);
                        continue;
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            //Stock S1 = new Stock();
            //Stock S2 = new Stock();

            //Stock S3 = new Stock();
            //Stock S4 = new Stock();
            //Customer E = DataControl.Instance.LoadAllCustomers()[0];
            //Customer F = DataControl.Instance.LoadAllCustomers()[1];
            //Depot Depot = new Depot(E);
            //Depot.AddStock(S2, 2);
            //Depot.AddStock(S1, 1);
            //Console.WriteLine("TODO: Einlesen der gespeicherten Depots je Customer");
            //Depot Depot2 = new Depot(E);
            //List<KeyValuePair<Stock, int>> stockstoadd = new List<KeyValuePair<Stock,int>>();
            ////stockstoadd.Add(S1);
            //KeyValuePair<Stock, int> KPV1 = new KeyValuePair<Stock, int>(S3, 23);
            //KeyValuePair<Stock, int> KPV2 = new KeyValuePair<Stock, int>(S4, 4);

            //stockstoadd.Add(KPV1);
            //stockstoadd.Add(KPV2);

            //Depot2.AddStocks(stockstoadd);

            //List<Depot> DepotsVonF = DataControl.Instance.GetDepotsByCustomer(F);
            //if (DepotsVonF.Count > 0)
            //{
            //    foreach (Depot _D in DepotsVonF)
            //    {
            //        Console.WriteLine("--------------------------------------");
            //        Console.WriteLine(_D.ID);
            //        Console.WriteLine(_D.Owner);
            //        foreach (KeyValuePair<Stock, int> _S in _D.Stocks)
            //        {
            //            Console.WriteLine(_S.Key.ID + " (" + _S.Value.ToString() + ")");
            //        }
            //        Console.WriteLine("--------------------------------------");

            //    }
            //}
            //else
            //{
            //    Console.WriteLine(F.FirstName + " " + F.LastName + " has no Depots");
            //}

            //List<Depot> DepotsVonE = DataControl.Instance.GetDepotsByCustomer(E);
            //if (DepotsVonE.Count > 0)
            //{
            //    foreach (Depot _D in DepotsVonE)
            //    {
            //        Console.WriteLine("--------------------------------------");
            //        Console.WriteLine(_D.ID);
            //        Console.WriteLine(_D.Owner.ID);
            //        foreach (KeyValuePair<Stock, int> _S in _D.Stocks)
            //        {
            //            Console.WriteLine(_S.Key.ID + " (" + _S.Value.ToString() + ")");
            //        }
            //        Console.WriteLine("--------------------------------------");

            //    }
            //}
            //else
            //{
            //    Console.WriteLine(E.FirstName + " " + E.LastName + " has no Depots");
            //}



            //GetAllStocks();
            //GetAllOrders();
            //Order OD = new Order();
            //OD.timestamp = DateTimeOffset.Now;
            //OD.amount = 2;
            //OD.idBank = "dieBank";
            //OD.idBoerse = "datBoerse";
            //OD.idCustomer = "C-259261f5-21b0-486b-ba48-bad81dd3d824";
            //OD.idStock = "";
            //OD.price = 200d;
            //OD.signature = OD.idCustomer;
            //OD.type = "sell";

            //SendOrder(OD);
        }
Exemplo n.º 6
0
        public void SaveDepot(Depot _D)
        {
            if (!File.Exists(DepotStorage))
            {
                XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.Indent = true;
                xmlWriterSettings.NewLineOnAttributes = true;
                using (XmlWriter xmlWriter = XmlWriter.Create(DepotStorage, xmlWriterSettings))
                {
                    xmlWriter.WriteStartDocument();
                    xmlWriter.WriteStartElement("Depots");

                    xmlWriter.WriteStartElement("Depot");
                    xmlWriter.WriteElementString("DID", _D.ID);
                    xmlWriter.WriteElementString("Owner", _D.Owner.ID);
                    xmlWriter.WriteStartElement("Stocks");


                    foreach (KeyValuePair <Stock, uint> _s in _D.Stocks)
                    {
                        xmlWriter.WriteStartElement("Stock");
                        xmlWriter.WriteAttributeString("SID", _s.Key.ID);
                        xmlWriter.WriteAttributeString("Amount", _s.Value.ToString());
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("IssuedOrders");


                    foreach (Order _o in _D.IssuedOrders)
                    {
                        xmlWriter.WriteStartElement("IssuedOrder");
                        xmlWriter.WriteAttributeString("OID", _o.id);
                        xmlWriter.WriteAttributeString("BoerseID", _o.idBoerse);
                        xmlWriter.WriteAttributeString("Type", _o.type);
                        xmlWriter.WriteAttributeString("Amount", _o.amount.ToString());
                        xmlWriter.WriteEndElement();
                    }

                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteElementString("TimeStamp", DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString());
                    xmlWriter.WriteElementString("Worth", _D.Worth.ToString());
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndDocument();
                    xmlWriter.Flush();
                    xmlWriter.Close();
                }
            }
            else
            {
                System.Xml.Linq.XDocument xDocument = XDocument.Load(DepotStorage);
                XElement root = xDocument.Element("Depots");
                IEnumerable <XElement> rows      = root.Descendants("Depot");
                IEnumerable <XElement> stockrows = rows.Descendants("Stocks");
                XElement firstRow = rows.First();
                //firstRow.AddBeforeSelf(
                //   new XElement("Depot",
                //   new XElement("DID", _D.ID),
                //   new XElement("Owner", _D.Owner.ID),
                //   new XElement("Stocks",
                //   _D.Stocks.Select( stock => new XElement("kjasddkljsdafkj", stock.Key.ID) ),
                //   _D.Stocks.Select(stock => new XAttribute("Amount", stock.Value.ToString()))),
                //   new XElement("TimeStamp", DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString())));
                firstRow.AddBeforeSelf(
                    new XElement("Depot",
                                 new XElement("DID", _D.ID),
                                 new XElement("Owner", _D.Owner.ID),
                                 new XElement("Stocks",
                                              _D.Stocks.Select(stock => new XElement("Stock",
                                                                                     new XAttribute("SID", stock.Key.ID),
                                                                                     new XAttribute("Amount", stock.Value.ToString())))),
                                 new XElement("IssuedOrders",
                                              _D.IssuedOrders.Select(order => new XElement("IssuedOrder",
                                                                                           new XAttribute("OID", order.id),
                                                                                           new XAttribute("BoerseID", order.idBoerse),
                                                                                           new XAttribute("Type", order.type),
                                                                                           new XAttribute("Amount", order.amount)))),
                                 new XElement("TimeStamp", DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString()),
                                 new XElement("Worth", _D.Worth.ToString())));


                xDocument.Save(DepotStorage);
            }
        }