コード例 #1
0
ファイル: Updater.cs プロジェクト: krazana/eXpand
        public override void UpdateDatabaseBeforeUpdateSchema() {
            base.UpdateDatabaseBeforeUpdateSchema();
            if (CurrentDBVersion > new Version(0, 0, 0, 0) && CurrentDBVersion <= new Version(10, 1, 6)) {
                var differenceObjects = new Dictionary<object, string>();
                using (var reader = ExecuteReader("select [Oid], [Model] from [ModelDifferenceObject] where [Model] is not null", false)) {
                    while (reader.Read()) {
                        differenceObjects.Add(reader[0], reader[1] as string);
                    }
                }

                using (var uow = new UnitOfWork(((ObjectSpace)ObjectSpace).Session.DataLayer)) {
                    foreach (var differenceObject in differenceObjects) {
                        var modelDifferenceObject = uow.GetObjectByKey<ModelDifferenceObject>(differenceObject.Key);
                        var serializableDictionary = new SerializableDictionary<string, string>();
                        var xmlReader = XmlReader.Create(new StringReader(differenceObject.Value), new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Auto });
                        serializableDictionary.ReadXml(xmlReader);
                        var aspects = serializableDictionary["aspects"].Split(',').ToList();
                        var defaultAspect = serializableDictionary["DefaultAspect"];
                        defaultAspect = GetDefaultAspectFromVersion9(serializableDictionary, aspects, defaultAspect);

                        if (!string.IsNullOrEmpty(defaultAspect))
                            modelDifferenceObject.AspectObjects.Add(new AspectObject(uow) { Name = CaptionHelper.DefaultLanguage, Xml = defaultAspect });

                        foreach (var aspect in aspects.Where(aspect => !string.IsNullOrEmpty(aspect) && !string.IsNullOrEmpty(serializableDictionary[aspect]))) {
                            modelDifferenceObject.AspectObjects.Add(new AspectObject(uow) { Name = aspect, Xml = serializableDictionary[aspect] });
                        }
                    }

                    uow.CommitChanges();
                }
            }
        }
コード例 #2
0
        public static T deserialize <T>(ContentResponse response)
        {
            if (response.type == (int)ContentType.DictInt)
            {
                SerializableDictionary <int, string> newAsset = new SerializableDictionary <int, string>();
                StringReader reader = new StringReader(PyNet.DecompressString(response.content));
                newAsset.ReadXml(XmlReader.Create(reader));
                return((T)(object)newAsset);
            }

            if (response.type == (int)ContentType.DictString)
            {
                SerializableDictionary <string, string> newAsset = new SerializableDictionary <string, string>();
                StringReader reader = new StringReader(PyNet.DecompressString(response.content));
                newAsset.ReadXml(XmlReader.Create(reader));
                return((T)(object)newAsset);
            }

            if (response.type == (int)ContentType.Texture)
            {
                SerializationTexture2D sTexture = JsonConvert.DeserializeObject <SerializationTexture2D>(PyNet.DecompressString(response.content));
                return((T)(object)sTexture.getTexture());
            }

            if (response.type == (int)ContentType.Map)
            {
                NewTiledTmxFormat format = new NewTiledTmxFormat();
                StringReader      reader = new StringReader(PyNet.DecompressString(response.content));
                Map map = format.Load(XmlReader.Create(reader));
                return((T)(object)map);
            }

            return((T)(object)null);
        }
コード例 #3
0
        public void ReadWriteTest()
        {
            SerializableDictionary <string, string> dict1 = new SerializableDictionary <string, string>();

            dict1.Add("Dict1Key1", "Dict1Value1");
            dict1.Add("Dict1Key2", "Dict1Value2");
            dict1.Add("Dict1Key3", "Dict1Value3");
            dict1.Add("Dict1Key4", "Dict1Value4");

            MemoryStream ms     = new MemoryStream();
            XmlWriter    writer = XmlWriter.Create(ms);

            writer.WriteStartElement("root", string.Empty);
            dict1.WriteXml(writer);
            writer.WriteEndElement();
            writer.Flush();

            SerializableDictionary <string, string> dict2 = new SerializableDictionary <string, string>();

            ms.Position = 0;

            XmlReader reader = XmlReader.Create(ms);

            dict2.ReadXml(reader);

            Assert.AreEqual(dict2["Dict1Key1"], "Dict1Value1");
            Assert.AreEqual(dict2["Dict1Key2"], "Dict1Value2");
            Assert.AreEqual(dict2["Dict1Key3"], "Dict1Value3");
            Assert.AreEqual(dict2["Dict1Key4"], "Dict1Value4");
        }
コード例 #4
0
        public override object ConvertFromStorageType(object value)
        {
            var masterModel = ModelDifferenceModule.MasterModel;
            var layer       = masterModel.CreatorInstance.CreateModelApplication();

            if (!(string.IsNullOrEmpty(value as string)))
            {
                masterModel.AddLayerBeforeLast(layer);
                var serializableDictionary = new SerializableDictionary <string, string>();
                var xmlReader = XmlReader.Create(new StringReader((string)value), new XmlReaderSettings {
                    ConformanceLevel = ConformanceLevel.Auto
                });
                serializableDictionary.ReadXml(xmlReader);
                var aspects       = serializableDictionary["aspects"].Split(',').ToList();
                var defaultAspect = serializableDictionary["DefaultAspect"];
                defaultAspect = GetDefaultAspectFromVersion9(serializableDictionary, aspects, defaultAspect);

                if (!string.IsNullOrEmpty(defaultAspect))
                {
                    new ModelXmlReader().ReadFromString(layer, String.Empty, defaultAspect);
                }

                foreach (var aspect in aspects.Where(aspect => !string.IsNullOrEmpty(aspect) && !string.IsNullOrEmpty(serializableDictionary[aspect])))
                {
                    new ModelXmlReader().ReadFromString(layer, aspect, serializableDictionary[aspect]);
                }
            }

            return(layer);
        }
コード例 #5
0
        protected override object DoDeserializeValue(XmlReader reader, bool isSimpleValue)
        {
            var result = new SerializableDictionary <TKey, TValue>();

            result.ReadXml(reader);
            return(result);
        }
コード例 #6
0
        public override object ConvertFromStorageType(object value)
        {
            var masterModel = ModelDifferenceModule.MasterModel;
            var layer = masterModel.CreatorInstance.CreateModelApplication();
            
            if (!(string.IsNullOrEmpty(value as string)))
            {
                masterModel.AddLayerBeforeLast(layer);
                var serializableDictionary = new SerializableDictionary<string, string>();
                var xmlReader = XmlReader.Create(new StringReader((string)value), new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Auto });
                serializableDictionary.ReadXml(xmlReader);
                var aspects = serializableDictionary["aspects"].Split(',').ToList();
                var defaultAspect = serializableDictionary["DefaultAspect"];
                defaultAspect = GetDefaultAspectFromVersion9(serializableDictionary, aspects, defaultAspect);

                if (!string.IsNullOrEmpty(defaultAspect))
                    new ModelXmlReader().ReadFromString(layer, String.Empty, defaultAspect);

                foreach (var aspect in aspects.Where(aspect => !string.IsNullOrEmpty(aspect) && !string.IsNullOrEmpty(serializableDictionary[aspect]))){
                    new ModelXmlReader().ReadFromString(layer, aspect, serializableDictionary[aspect]);
                }

            }

            return layer;
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: tiago156/OptionsOracle
        private void Load()
        {
            // get config directory path
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\OptionsOracle\";
            string conf = path + CONFIG_FILE;

            // check if config directory exist, if not create it
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // load / create-new configuration
            try
            {
                if (File.Exists(conf))
                {
                    // load configuration
                    XmlTextReader reader = new XmlTextReader(conf);
                    config.ReadXml(reader);
                }
                else
                {
                    // default config
                    config.Add("MonthsCount", "4");
                    config.Add("StrikeLowerLimit", "80");
                    config.Add("StrikeUpperLimit", "120");
                    config.Add("HideOptionsWithNoMarket", true.ToString());
                }
            }
            catch { }
        }
コード例 #8
0
        public override object ConvertFromStorageType(object value){
            if (!(string.IsNullOrEmpty(value as string)))
            {
                var settings = new XmlReaderSettings{ConformanceLevel = ConformanceLevel.Auto};
                var reader = XmlReader.Create(new StringReader((string) value), settings);
                var serializableDictionary = new SerializableDictionary<string, string>();
                serializableDictionary.ReadXml(reader);
                var schema = new Schema(new DictionaryXmlReader().ReadFromString(serializableDictionary["Schema"].Replace(":","")));
                var commonSchema = Schema.GetCommonSchema();
                commonSchema.CombineWith(schema);
                var helper = new DictionaryHelper();
                var aspects = serializableDictionary["aspects"].Split(',').ToList();

                string aspectFromXml = helper.GetAspectFromXml(aspects, serializableDictionary["DefaultAspect"]);
                var dictionary = new Dictionary(new DictionaryXmlReader().ReadFromString(aspectFromXml), commonSchema);
                foreach (var aspectValue in aspects.Where(s => !string.IsNullOrEmpty(s))){
                    string xml = serializableDictionary[aspectValue];
                    if (!(string.IsNullOrEmpty(xml)))
                        dictionary.AddAspect(aspectValue, new DictionaryXmlReader().ReadFromString(xml));
                }

                return dictionary;

            }
            return null;
        }
コード例 #9
0
ファイル: Updater.cs プロジェクト: xwagner2/eXpand
        public override void UpdateDatabaseBeforeUpdateSchema()
        {
            base.UpdateDatabaseBeforeUpdateSchema();
            if (CurrentDBVersion > new Version(0, 0, 0, 0) && CurrentDBVersion <= new Version(10, 1, 6))
            {
                var differenceObjects = new Dictionary <object, string>();

                if (ExecuteScalarCommand("Select COLUMNPROPERTY(OBJECT_ID('ModelDifferenceObject'), 'Model','ColumnId')", false) is int)
                {
                    using (var reader = ExecuteReader("select [Oid], [Model] from [ModelDifferenceObject] where [Model] is not null", false)) {
                        while (reader.Read())
                        {
                            differenceObjects.Add(reader[0], reader[1] as string);
                        }
                    }
                }

                using (var uow = new UnitOfWork(((XPObjectSpace)ObjectSpace).Session.DataLayer)) {
                    foreach (var differenceObject in differenceObjects)
                    {
                        var modelDifferenceObject  = uow.GetObjectByKey <ModelDifferenceObject>(differenceObject.Key);
                        var serializableDictionary = new SerializableDictionary <string, string>();
                        var xmlReader = XmlReader.Create(new StringReader(differenceObject.Value), new XmlReaderSettings {
                            ConformanceLevel = ConformanceLevel.Auto
                        });
                        serializableDictionary.ReadXml(xmlReader);
                        var aspects       = serializableDictionary["aspects"].Split(',').ToList();
                        var defaultAspect = serializableDictionary["DefaultAspect"];
                        defaultAspect = GetDefaultAspectFromVersion9(serializableDictionary, aspects, defaultAspect);

                        if (!string.IsNullOrEmpty(defaultAspect))
                        {
                            modelDifferenceObject.AspectObjects.Add(new AspectObject(uow)
                            {
                                Name = CaptionHelper.DefaultLanguage, Xml = defaultAspect
                            });
                        }

                        foreach (var aspect in aspects.Where(aspect => !string.IsNullOrEmpty(aspect) && !string.IsNullOrEmpty(serializableDictionary[aspect])))
                        {
                            modelDifferenceObject.AspectObjects.Add(new AspectObject(uow)
                            {
                                Name = aspect, Xml = serializableDictionary[aspect]
                            });
                        }
                    }

                    uow.CommitChanges();
                }
            }
        }
コード例 #10
0
ファイル: Main.cs プロジェクト: zdomokos/OptionsOracle
        private void Load()
        {
            // get config directory path
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\OptionsOracle\";
            string conf = path + CONFIG_FILE;

            // check if config directory exist, if not create it
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // load / create-new configuration
            try
            {
                if (File.Exists(conf))
                {
                    // load configuration
                    XmlTextReader reader = new XmlTextReader(conf);
                    config.ReadXml(reader);
                }
            }
            catch { }

            // default config
            if (!config.ContainsKey("DownloadHistoryFromYahoo"))
            {
                config.Add("DownloadHistoryFromYahoo", bool.FalseString);
            }
            if (!config.ContainsKey("LoginOnStartUp"))
            {
                config.Add("LoginOnStartUp", bool.FalseString);
            }
            if (!config.ContainsKey("YahooExchangeSuffix"))
            {
                config.Add("YahooExchangeSuffix", "");
            }
            if (!config.ContainsKey("DefaultUsername"))
            {
                config.Add("DefaultUsername", "");
            }

            try
            {
                yho.YahooExchangeSuffix = config["YahooExchangeSuffix"];
                tda.Username            = config["DefaultUsername"];
            }
            catch { }
        }
コード例 #11
0
 /// <summary>
 /// Loads the scores lists.
 /// </summary>
 public void Load()
 {
     using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
     {
         if (storage.FileExists(SCORES_FILE))
         {
             using (IsolatedStorageFileStream fileStream = storage.OpenFile(SCORES_FILE, FileMode.Open))
             {
                 using (XmlReader reader = XmlReader.Create(fileStream))
                 {
                     scoreLists.ReadXml(reader);
                 }
             }
         }
     }
 }
コード例 #12
0
ファイル: Main.cs プロジェクト: tiago156/OptionsOracle
        private void Load()
        {
            // get config directory path
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\OptionsOracle\";
            string conf = path + CONFIG_FILE;

            // check if config directory exist, if not create it
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // load / create-new configuration
            try
            {
                if (File.Exists(conf))
                {
                    // load configuration
                    XmlTextReader reader = new XmlTextReader(conf);
                    config.ReadXml(reader);
                }
            }
            catch { }

            // default config
            if (!config.ContainsKey("QuoteDataSource"))
            {
                config.Add("QuoteDataSource", "Default");
            }
            if (!config.ContainsKey("StockOptionChainDataSource"))
            {
                config.Add("StockOptionChainDataSource", "Default");
            }
            if (!config.ContainsKey("IndexOptionChainDataSource"))
            {
                config.Add("IndexOptionChainDataSource", "Default");
            }
            if (!config.ContainsKey("FundOptionChainDataSource"))
            {
                config.Add("FundOptionChainDataSource", "Default");
            }
        }
コード例 #13
0
    public TexScaleWriter()
    {
        texScaleMapX = new SerializableDictionary <int, float> ();
        texScaleMapY = new SerializableDictionary <int, float> ();

        if (File.Exists(Application.dataPath + c_fileName))
        {
            FileStream file = File.Open(Application.dataPath + c_fileName, FileMode.Open);
            //XmlDocument doc = new XmlDocument ();
            XmlReader xmlReader = XmlReader.Create(file);
            xmlReader.ReadStartElement("document");
            texScaleMapX.ReadXml(xmlReader);
            texScaleMapY.ReadXml(xmlReader);
            file.Close();
        }
        else
        {
            Debug.LogWarning("Tex scale data file not found.");
        }
    }
コード例 #14
0
ファイル: QData.cs プロジェクト: nkf/deep-unity
    public static void Load <K, V>(string path, SerializableDictionary <K, V> dictionary)
    {
        path = Path.Combine(QDataFolder, path);
        FileStream fileStream = null;
        XmlReader  reader     = null;

        try {
            fileStream = File.Open(path, FileMode.Open, FileAccess.Read);
            reader     = XmlReader.Create(fileStream);
            dictionary.ReadXml(reader);
        } catch (Exception e) {
            Debug.Log(e);
        } finally {
            if (fileStream != null)
            {
                fileStream.Close();
            }
            if (reader != null)
            {
                reader.Close();
            }
        }
    }
コード例 #15
0
        private void Load()
        {
            // get config directory path
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\OptionsOracle\";
            string conf = path + LOOKUP_FILE;

            // check if config directory exist, if not create it
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // load / create-new configuration
            try
            {
                if (File.Exists(conf))
                {
                    // load configuration
                    XmlTextReader reader = new XmlTextReader(conf);
                    name_cache.ReadXml(reader);
                }
            }
            catch { }
        }
コード例 #16
0
ファイル: Main.cs プロジェクト: zdomokos/OptionsOracle
        private void Load()
        {
            // get config directory path
            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\OptionsOracle\";
            string conf = path + CONFIG_FILE;

            // check if config directory exist, if not create it
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // load / create-new configuration
            try
            {
                if (File.Exists(conf))
                {
                    // load configuration
                    XmlTextReader reader = new XmlTextReader(conf);
                    config.ReadXml(reader);
                }
            }
            catch { }

            // default config
            if (!config.ContainsKey("Exchange.Underlying"))
            {
                config.Add("Exchange.Underlying", "SMART");
            }
            if (!config.ContainsKey("Exchange.Option"))
            {
                config.Add("Exchange.Option", "CBOE");
            }
            if (!config.ContainsKey("Currency"))
            {
                config.Add("Currency", "USD");
            }

            if (!config.ContainsKey("QuoteTimeout"))
            {
                config.Add("QuoteTimeout", "5");
            }
            if (!config.ContainsKey("BackOffTime"))
            {
                config.Add("BackOffTime", "0");
            }
            if (!config.ContainsKey("MaxParallelTickers"))
            {
                config.Add("MaxParallelTickers", "100");
            }

            if (!config.ContainsKey("DownloadMode"))
            {
                config.Add("DownloadMode", "0");
            }
            if (!config.ContainsKey("MaxExpirationLimit"))
            {
                config.Add("MaxExpirationLimit", DateTime.MaxValue.Date.ToShortDateString());
            }
            if (!config.ContainsKey("MinExpirationLimit"))
            {
                config.Add("MinExpirationLimit", DateTime.MinValue.Date.ToShortDateString());
            }
            if (!config.ContainsKey("MaxStrikeLimit"))
            {
                config.Add("MaxStrikeLimit", Double.NaN.ToString());
            }
            if (!config.ContainsKey("MinStrikeLimit"))
            {
                config.Add("MinStrikeLimit", Double.NaN.ToString());
            }
            if (!config.ContainsKey("DownloadOpenInt"))
            {
                config.Add("DownloadOpenInt", bool.TrueString);
            }
            if (!config.ContainsKey("FilterNoPriceOptions"))
            {
                config.Add("FilterNoPriceOptions", bool.TrueString);
            }

            if (!config.ContainsKey("DownloadHistoryFromYahoo"))
            {
                config.Add("DownloadHistoryFromYahoo", bool.TrueString);
            }
            if (!config.ContainsKey("YahooExchangeSuffix"))
            {
                config.Add("YahooExchangeSuffix", "");
            }

            try
            {
                tws.DownloadOpenInt     = bool.Parse(config["DownloadOpenInt"]);
                tws.QuoteTimeout        = int.Parse(config["QuoteTimeout"]);
                tws.BackOffTime         = int.Parse(config["BackOffTime"]);
                yho.YahooExchangeSuffix = config["YahooExchangeSuffix"];
            }
            catch { }
        }