Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            ImperaturData oNewSystem      = null;
            bool          CreateNewSystem = ShowSystemLoad();

            ImperaturContainer.SystemNotificationEvent += ImperaturContainer_SystemNotificationEvent;
            oWaitLoadingSystem = new dialog.WaitDialog();
            oWaitLoadingSystem.Show();
            oWaitLoadingSystem.Refresh();
            if (CreateNewSystem)
            {
                oWaitLoadingSystem.SetSystemNotificationText("Creating the new system...");
                oWaitLoadingSystem.Refresh();
                oNewSystem = CreateNewImperaturMarket(oNewSystem);
            }

            if (oNewSystem != null)
            {
                oWaitLoadingSystem.SetSystemNotificationText("Loading the Imperatur Market system...");
                oWaitLoadingSystem.Refresh();
                m_Ic = (ImperaturMarket)ImperaturContainer.BuildImperaturContainer(oNewSystem);
            }
            else
            {
                oWaitLoadingSystem.SetSystemNotificationText("Loading the Imperatur Market system...");
                oWaitLoadingSystem.Refresh();
                m_Ic = (ImperaturMarket)ImperaturContainer.BuildImperaturContainer(SystemLocation);
            }
            oWaitLoadingSystem.SetSystemNotificationText("Loading is done, opening the system for you");
            oWaitLoadingSystem.Refresh();
            m_Ic.SystemNotificationEvent += M_Ic_SystemNotificationEvent;
            oWaitLoadingSystem.Close();
            //this far we save the systemlocation to the clients application folder for easy access
            //SystemLocationCacheFile
            SaveSystemLocationToCache(oNewSystem);

            this.toolStripStatusLabel_system.Text =
                string.Format("{0} | {1} | {2}", m_Ic.GetSystemData().SystemDirectory, m_Ic.GetSystemData().SystemCurrency, m_Ic.SystemExchangeStatus.ToString());

            if (m_Ic.SystemExchangeStatus.ToString() == "Closed")
            {
                toolStripStatusLabel_system.BackColor = Color.IndianRed;
            }
            else
            {
                toolStripStatusLabel_system.BackColor = this.BackColor;
            }

            //add the controls to the different areas
            m_oAccountTab      = new AccountTab(m_Ic.GetAccountHandler(), m_Ic.GetTradeHandler(), m_Ic.OrderQueue);
            m_oAccountTab.Dock = DockStyle.Fill;
            tabPage_account.Controls.Add(m_oAccountTab);
            m_Ic.QuoteUpdateEvent += M_Ic_QuoteUpdateEvent;
            this.checkBox_automaticTrading.Checked = m_Ic.GetSystemData().IsAutomaticMaintained;
        }
        internal static void Initialize(ImperaturData SystemDataToCache, StandardKernel NinjectKernel, List <account.AccountCacheType> BusinessAccounts)
        {
            if (SystemData == null)
            {
                SystemData = SystemDataToCache;
            }

            if (Instruments == null)
            {
                Instruments = ReadInstrumentsFromAssembly();
            }

            if (m_oKernel == null)
            {
                m_oKernel = NinjectKernel;
            }

            BuildCurrencyCodeCache();

            try
            {
                BuildHistoricalPriceCache();
            }
            catch (Exception ex)
            {
                GetLog().Error("Error ", ex);
            }

            InitializeBusinessAccount(BusinessAccounts);

            if (!GlobalCachingProvider.Instance.FindItem(ImperaturGlobal.CountryCache))
            {
                GlobalCachingProvider.Instance.AddItem(ImperaturGlobal.CountryCache, new CountryCache());
            }

            m_oCurrencyRates = new CurrencyDataFromExternalSource().GetCurrentCurrencyExchangeRate();

            //month, day
            BankDays = new List <Tuple <int, int> >();
            HalfDay  = new List <Tuple <int, int> >();

            BankDays.Add(new Tuple <int, int>(1, 1));
            BankDays.Add(new Tuple <int, int>(1, 6));
            BankDays.Add(new Tuple <int, int>(3, 28));
            BankDays.Add(new Tuple <int, int>(5, 5));
            BankDays.Add(new Tuple <int, int>(6, 6));
            BankDays.Add(new Tuple <int, int>(6, 24));
            BankDays.Add(new Tuple <int, int>(6, 26));

            //to 13:00
            HalfDay.Add(new Tuple <int, int>(1, 5));
            HalfDay.Add(new Tuple <int, int>(3, 24));
            HalfDay.Add(new Tuple <int, int>(5, 4));
            HalfDay.Add(new Tuple <int, int>(11, 4));
        }
Example #3
0
        private void SaveSystemLocationToCache(ImperaturData oNewSystem)
        {
            string DefaultMarker = ":def:";
            string SystemLocationCacheFilePath = AppDomain.CurrentDomain.BaseDirectory + @"\" + this.SystemLocationCacheFile;
            string PossibleNewSystem           = (oNewSystem != null && oNewSystem.SystemDirectory != null && oNewSystem.SystemDirectory != "") ?
                                                 oNewSystem.SystemDirectory
                    : SystemLocation;

            if (!File.Exists(SystemLocationCacheFilePath))
            {
                try
                {
                    File.AppendAllText(SystemLocationCacheFilePath, DefaultMarker + PossibleNewSystem + Environment.NewLine);
                }
                catch (Exception ex)
                {
                    int gg = 0;
                }
            }
            else
            {
                //is the directory already in the cache?
                try {
                    string[] SystemLocationsFromFile = File.ReadAllLines(SystemLocationCacheFilePath);

                    //system exists without default marker
                    if (Array.Find(SystemLocationsFromFile, element => element.Equals(PossibleNewSystem)) != null)
                    {
                        //add the defaultmarker and save
                        //first remove file
                        File.Delete(SystemLocationCacheFilePath);
                        File.AppendAllText(SystemLocationCacheFilePath, string.Join(Environment.NewLine, SystemLocationsFromFile
                                                                                    .Where(element => !element.Equals(PossibleNewSystem)).ToArray()) + Environment.NewLine);
                        File.AppendAllText(SystemLocationCacheFilePath, DefaultMarker + PossibleNewSystem + Environment.NewLine);
                        return;
                    }
                    //system does not exists with default marker
                    else if (Array.Find(SystemLocationsFromFile, element => element.Equals(DefaultMarker + PossibleNewSystem)) == null)
                    {
                        File.AppendAllText(SystemLocationCacheFilePath, PossibleNewSystem + Environment.NewLine);
                    }
                }
                catch (Exception ex)
                {
                    int gg2 = 0;
                }
            }
        }
Example #4
0
        private ImperaturData CreateNewImperaturMarket(ImperaturData oNewSystem)
        {
            using (var form = new dialog.NewSystem())
            {
                form.Icon = this.Icon;
                GroupBox oB = new GroupBox()
                {
                    Dock    = DockStyle.Fill,
                    Text    = "Create new System",
                    Name    = "gp",
                    Visible = true,
                    Padding = new Padding()
                    {
                        All = 20
                    },
                    Margin = new Padding()
                    {
                        All = 20
                    },
                    Bounds = form.Bounds
                };

                TableLayoutPanel tlp = new TableLayoutPanel
                {
                    Name         = "tlp",
                    Dock         = DockStyle.Fill,
                    RowCount     = typeof(ImperaturData).GetFields().Count() + 1,
                    ColumnCount  = 2,
                    Visible      = true,
                    AutoSize     = true,
                    AutoSizeMode = AutoSizeMode.GrowAndShrink,
                };

                int indexcount = 0;
                foreach (var prop in typeof(ImperaturData).GetFields())
                {
                    if (prop.Name != "")
                    {
                        if (prop.FieldType.Equals(typeof(string)))
                        {
                            string Value = prop.Name.Equals("SystemDirectory") ? SystemLocation : typeof(ImperaturDataStandard).GetFields().FirstOrDefault(t => t.Name == prop.Name).GetValue(null).ToString();
                            tlp.Controls.Add(new TextBox()
                            {
                                Text =
                                    Value
                                ,
                                Name     = prop.Name,
                                Anchor   = AnchorStyles.Left,
                                Width    = 300,
                                AutoSize = true,
                                ReadOnly = prop.Name.Equals("SystemDirectory") && SystemLocation.Length > 0 ? true : false
                            }, 1, indexcount);
                            tlp.Controls.Add(new Label()
                            {
                                Text = prop.Name, Anchor = AnchorStyles.Left, AutoSize = true
                            }, 0, indexcount);
                        }
                    }
                    indexcount++;
                }

                Button oButtonOk = new Button()
                {
                    Name         = "buttonok",
                    Text         = "OK",
                    AutoSizeMode = AutoSizeMode.GrowAndShrink,
                    DialogResult = DialogResult.OK
                };

                Button oButtonCancel = new Button()
                {
                    Name         = "buttoncancel",
                    Text         = "Cancel",
                    AutoSizeMode = AutoSizeMode.GrowAndShrink
                };

                oButtonOk.Click     += OButtonOk_Click;
                oButtonCancel.Click += OButtonCancel_Click;

                tlp.Controls.Add(oButtonOk, 0, indexcount);
                tlp.Controls.Add(oButtonCancel, 1, indexcount);

                oB.Controls.Add(tlp);
                form.Controls.Add(oB);

                form.Height = tlp.Height;


                try
                {
                    var result = form.ShowDialog();
                    while (!result.Equals(DialogResult.OK) && !result.Equals(DialogResult.Cancel))
                    {
                    }

                    if (result == DialogResult.OK)
                    {
                        oNewSystem = form.SystemData;
                    }
                    else
                    {
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    int gg = 0;
                }
            }

            return(oNewSystem);
        }