Exemplo n.º 1
0
        public static void SaveConfigSetting(string strConfigFile, PlateInfo[] plateInfos)
        {
            if (plateInfos == null)
            {
                return;
            }

            if (File.Exists(strConfigFile) == true)
            {
                File.SetAttributes(strConfigFile, FileAttributes.Archive);
                File.Delete(strConfigFile);
            }

            XElement elementRoot = new XElement("Demo.Stock", new XAttribute("Ver", "0.0.1.0"));

            for (int iIndex = 0; iIndex < plateInfos.Length; iIndex++)
            {
                PlateInfo plateInfo = plateInfos[iIndex];

                XElement elementPlate = new XElement("StockPlate", new XAttribute("Name", plateInfo.Name));

                if (plateInfo.VarietyInfos == null)
                {
                    continue;
                }

                for (int iIndex2 = 0; iIndex2 < plateInfo.VarietyInfos.Length; iIndex2++)
                {
                    VarietyInfo varietyInfo = plateInfo.VarietyInfos[iIndex2];

                    XElement elementVariety = new XElement("StockVariety", new XAttribute("Name", varietyInfo.Name));

                    if (varietyInfo.FileInfos == null)
                    {
                        continue;
                    }

                    for (int iIndex3 = 0; iIndex3 < varietyInfo.FileInfos.Length; iIndex3++)
                    {
                        FileInfo fileInfo = varietyInfo.FileInfos[iIndex3];

                        XElement elementFileInfo = new XElement("FileInfo", fileInfo.FilePath);
                        elementFileInfo.Add(new XAttribute("Name", fileInfo.StockName));
                        elementFileInfo.Add(new XAttribute("Symbol", fileInfo.StockSymbol));

                        elementVariety.Add(elementFileInfo);
                    }

                    elementPlate.Add(elementVariety);
                }

                elementRoot.Add(elementPlate);
            }

            XDocument documentConfig = new XDocument(new XDeclaration("1.0", "utf - 8", "yes"), elementRoot);

            documentConfig.Save(strConfigFile);
        }
Exemplo n.º 2
0
        public static bool LoadGlobalSetting()
        {
            PlateInfo[] plateInfos = LoadConfigSetting(GlobalSetting.ConfigFilePath);
            if (plateInfos == null)
            {
                return(false);
            }

            if (LoadingGlobalSetting != null)
            {
                LoadingGlobalSetting(null, EventArgs.Empty);
            }

            s_SecurityDictionary.Clear();
            s_PriceDictionary.Clear();
            GlobalStockManager.Clear();

            s_PlateInfos = plateInfos;

            for (int iIndex = 0; iIndex < s_PlateInfos.Length; iIndex++)
            {
                PlateInfo plateInfo = s_PlateInfos[iIndex];

                for (int iIndex2 = 0; iIndex2 < plateInfo.VarietyInfos.Length; iIndex2++)
                {
                    VarietyInfo varietyInfo = plateInfo.VarietyInfos[iIndex2];

                    StockManager stockManager = new StockManager();
                    stockManager.StockPlate   = plateInfo.Name;
                    stockManager.StockVariety = varietyInfo.Name;

                    for (int iIndex3 = 0; iIndex3 < varietyInfo.FileInfos.Length; iIndex3++)
                    {
                        FileInfo FileInfo = varietyInfo.FileInfos[iIndex3];

                        StockInfo stockInfo = new StockInfo();
                        if (StockInfo.LoadFileFormatForMetaStock(FileInfo.StockName, FileInfo.StockSymbol, FileInfo.FilePath, ref stockInfo) == true)
                        {
                            stockManager.AddStockInfo(stockInfo);
                        }
                    }

                    GlobalStockManager.AddStockManager(stockManager);
                }
            }

            s_IsLoadGlobalSetting = true;

            if (LoadedGlobalSetting != null)
            {
                LoadedGlobalSetting(null, EventArgs.Empty);
            }

            return(true);
        }
Exemplo n.º 3
0
        public static PlateInfo[] LoadConfigSetting( string strConfigFile )
        {
            if ( File.Exists( strConfigFile ) == false )
            {
                if ( strConfigFile == GlobalSetting.ConfigFilePath )
                    SaveConfigSetting( GlobalSetting.ConfigFilePath, GlobalSetting.PlateInfos );
                else
                    return null;
            }

            XDocument documentConfig = XDocument.Load( strConfigFile );
            if ( documentConfig == null )
                return null;

            XElement elementRoot = documentConfig.Element( (XName)"Demo.Stock" );
            if ( elementRoot == null )
                return null;

            XAttribute attributeVer = elementRoot.Attribute( (XName)"Ver" );
            if ( attributeVer == null )
                return null;

            //////////////////////////////////////////////////////////////////////////
            // <Settings>
            IEnumerable<XElement> elementStockPlates = elementRoot.Elements( (XName)"StockPlate" );
            if ( elementStockPlates == null )
                return null;

            List<PlateInfo> plateInfoList = new List<PlateInfo>();
            foreach ( var elementPlate in elementStockPlates )
            {
                XAttribute attributePlateName = elementPlate.Attribute( (XName)"Name" );
                if ( attributePlateName == null )
                    continue;

                PlateInfo plateInfo = new PlateInfo();
                plateInfo.Name = attributePlateName.Value;
                plateInfoList.Add( plateInfo );

                IEnumerable<XElement> elementStockVarietys = elementPlate.Elements( (XName)"StockVariety" );
                if ( elementStockVarietys == null )
                    continue;

                List<VarietyInfo> varietyInfoList = new List<VarietyInfo>();
                foreach ( var elementVariety in elementStockVarietys )
                {
                    XAttribute attributeVarietyName = elementVariety.Attribute( (XName)"Name" );
                    if ( attributeVarietyName == null )
                        continue;

                    VarietyInfo varietyInfo = new VarietyInfo();
                    varietyInfo.Name = attributeVarietyName.Value;
                    varietyInfoList.Add( varietyInfo );

                    IEnumerable<XElement> elementFileInfos = elementVariety.Elements( (XName)"FileInfo" );
                    if ( elementFileInfos == null )
                        continue;

                    List<FileInfo> fileInfoList = new List<FileInfo>();
                    foreach ( var elementFileInfo in elementFileInfos )
                    {
                        FileInfo fileInfo = new FileInfo();

                        XAttribute attributeInfoName = elementFileInfo.Attribute( (XName)"Name" );
                        if ( attributeInfoName != null )
                            fileInfo.StockName = attributeInfoName.Value;

                        XAttribute attributeInfoSymbol = elementFileInfo.Attribute( (XName)"Symbol" );
                        if ( attributeInfoSymbol != null )
                            fileInfo.StockSymbol = attributeInfoSymbol.Value;

                        fileInfo.FilePath = elementFileInfo.Value;

                        fileInfoList.Add( fileInfo );
                    }

                    varietyInfo.FileInfos = fileInfoList.ToArray();
                }

                plateInfo.VarietyInfos = varietyInfoList.ToArray();
            }

            return plateInfoList.ToArray();
        }
        private void SaveConfigFormInfo()
        {
            List<PlateInfo> plateInfoList = new List<PlateInfo>();

            for ( int iIndex = 0; iIndex < this.TreeView.Nodes.Count; iIndex++ )
            {
                TreeNode treeNodeParent = this.TreeView.Nodes[iIndex];
                if ( treeNodeParent == null )
                    continue;

                PlateInfo plateInfo = new PlateInfo();
                plateInfo.Name = treeNodeParent.Text;
                plateInfo.VarietyInfos = new VarietyInfo[0];

                plateInfoList.Add( plateInfo );

                List<VarietyInfo> varietyInfoList = new List<VarietyInfo>();

                for ( int iIndex2 = 1; iIndex2 < treeNodeParent.Nodes.Count; iIndex2++ )
                {
                    TreeNode treeNodeParentSub = treeNodeParent.Nodes[iIndex2];
                    if ( treeNodeParentSub == null )
                        continue;

                    VarietyInfo varietyInfo = new VarietyInfo();
                    varietyInfo.Name = treeNodeParentSub.Text;
                    varietyInfo.FileInfos = new FileInfo[0];

                    varietyInfoList.Add( varietyInfo );

                    UserControl outUserControl = null;
                    if ( m_AllConfigControlInfo.TryGetValue( treeNodeParentSub, out outUserControl ) == true )
                    {
                        ConfigAControl outConfigAControl = outUserControl as ConfigAControl;
                        if ( outConfigAControl != null )
                        {
                            List<FileInfo> fileInfoList = new List<FileInfo>();

                            for ( int iIndex3 = 0; iIndex3 < outConfigAControl.ListView.Items.Count; iIndex3++ )
                            {
                                ListViewItem listViewItem = outConfigAControl.ListView.Items[iIndex3];

                                FileInfo fileInfo = new FileInfo();
                                fileInfo.StockName = listViewItem.Text;
                                fileInfo.StockSymbol = listViewItem.SubItems[1].Text;
                                fileInfo.FilePath = listViewItem.SubItems[2].Text;

                                fileInfoList.Add( fileInfo );
                            }

                            varietyInfo.FileInfos = fileInfoList.ToArray();
                        }
                    }
                }

                plateInfo.VarietyInfos = varietyInfoList.ToArray();
            }

            GlobalSetting.SaveConfigSetting( GlobalSetting.ConfigFilePath, plateInfoList.ToArray() );
        }
Exemplo n.º 5
0
        public static PlateInfo[] LoadConfigSetting(string strConfigFile)
        {
            if (File.Exists(strConfigFile) == false)
            {
                if (strConfigFile == GlobalSetting.ConfigFilePath)
                {
                    SaveConfigSetting(GlobalSetting.ConfigFilePath, GlobalSetting.PlateInfos);
                }
                else
                {
                    return(null);
                }
            }

            XDocument documentConfig = XDocument.Load(strConfigFile);

            if (documentConfig == null)
            {
                return(null);
            }

            XElement elementRoot = documentConfig.Element((XName)"Demo.Stock");

            if (elementRoot == null)
            {
                return(null);
            }

            XAttribute attributeVer = elementRoot.Attribute((XName)"Ver");

            if (attributeVer == null)
            {
                return(null);
            }

            //////////////////////////////////////////////////////////////////////////
            // <Settings>
            IEnumerable <XElement> elementStockPlates = elementRoot.Elements((XName)"StockPlate");

            if (elementStockPlates == null)
            {
                return(null);
            }

            List <PlateInfo> plateInfoList = new List <PlateInfo>();

            foreach (var elementPlate in elementStockPlates)
            {
                XAttribute attributePlateName = elementPlate.Attribute((XName)"Name");
                if (attributePlateName == null)
                {
                    continue;
                }

                PlateInfo plateInfo = new PlateInfo();
                plateInfo.Name = attributePlateName.Value;
                plateInfoList.Add(plateInfo);

                IEnumerable <XElement> elementStockVarietys = elementPlate.Elements((XName)"StockVariety");
                if (elementStockVarietys == null)
                {
                    continue;
                }

                List <VarietyInfo> varietyInfoList = new List <VarietyInfo>();
                foreach (var elementVariety in elementStockVarietys)
                {
                    XAttribute attributeVarietyName = elementVariety.Attribute((XName)"Name");
                    if (attributeVarietyName == null)
                    {
                        continue;
                    }

                    VarietyInfo varietyInfo = new VarietyInfo();
                    varietyInfo.Name = attributeVarietyName.Value;
                    varietyInfoList.Add(varietyInfo);

                    IEnumerable <XElement> elementFileInfos = elementVariety.Elements((XName)"FileInfo");
                    if (elementFileInfos == null)
                    {
                        continue;
                    }

                    List <FileInfo> fileInfoList = new List <FileInfo>();
                    foreach (var elementFileInfo in elementFileInfos)
                    {
                        FileInfo fileInfo = new FileInfo();

                        XAttribute attributeInfoName = elementFileInfo.Attribute((XName)"Name");
                        if (attributeInfoName != null)
                        {
                            fileInfo.StockName = attributeInfoName.Value;
                        }

                        XAttribute attributeInfoSymbol = elementFileInfo.Attribute((XName)"Symbol");
                        if (attributeInfoSymbol != null)
                        {
                            fileInfo.StockSymbol = attributeInfoSymbol.Value;
                        }

                        fileInfo.FilePath = elementFileInfo.Value;

                        fileInfoList.Add(fileInfo);
                    }

                    varietyInfo.FileInfos = fileInfoList.ToArray();
                }

                plateInfo.VarietyInfos = varietyInfoList.ToArray();
            }

            return(plateInfoList.ToArray());
        }