Пример #1
0
        public void ComponentModelCompatibilityTest()
        {
            var converter   = new TimeSpanConverter();
            var cmConverter = new System.ComponentModel.TimeSpanConverter();

            var propertyMapData = new MemberMapData(null);

            propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture;
            var row = new CsvReader(new ParserMock());

            Assert.Throws <FormatException>(() => cmConverter.ConvertFromString(""));
            Assert.Throws <TypeConverterException>(() => converter.ConvertFromString("", row, propertyMapData));
            Assert.Throws <NotSupportedException>(() => cmConverter.ConvertFromString(null));
            Assert.Throws <TypeConverterException>(() => converter.ConvertFromString(null, row, propertyMapData));
        }
Пример #2
0
        void TryProperty(XmlNode attr)
        {
            var f = _type.GetProperty(attr.Name, BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Public);

            if (f == null || Ignore(f))
            {
                return;
            }

            if (f.PropertyType.IsEnum)
            {
                var st = f.PropertyType;
                f.SetValue(Object, Enum.Parse(st, attr.InnerText), null);
                return;
            }

            if (f.PropertyType.Equals(typeof(TimeSpan?)))
            {
                var tc = new TimeSpanConverter();

                f.SetValue(Object, (TimeSpan?)tc.ConvertFromString(attr.InnerText), null);
                return;
            }

            if (f.PropertyType.Equals(typeof(TimeSpan)))
            {
                f.SetValue(Object, TimeSpan.Parse(attr.InnerText), null);
                return;
            }

            f.SetValue(Object, Convert.ChangeType(attr.InnerText, f.PropertyType), null);
        }
Пример #3
0
        bool TryField(XmlNode node)
        {
            var f = _type.GetField(node.Name, BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.Public);

            if (f == null || Ignore(f))
            {
                return(false);
            }

            if (f.FieldType.IsEnum)
            {
                var st = f.FieldType;
                f.SetValue(Object, Enum.Parse(st, node.InnerText));
                return(true);
            }

            if (f.FieldType.Equals(typeof(TimeSpan)))
            {
                var tc = new TimeSpanConverter();

                f.SetValue(Object, (TimeSpan?)tc.ConvertFromString(node.InnerText));
                return(true);
            }

            f.SetValue(Object, Convert.ChangeType(node.InnerText, f.FieldType));
            return(true);
        }
        // Shows how to use the ValidatorInstance method.
        public static void GetCustomValidatorInstance()
        {
            ConfigurationValidatorBase valBase;
            CustomValidatorAttribute   customValAttr;

            customValAttr = new CustomValidatorAttribute();

            SampleSection sampleSection =
                ConfigurationManager.GetSection("MyDailyProcess") as SampleSection;

            TimeSpanConverter myTSC          = new TimeSpanConverter();
            TimeSpan          StartTimeSpan  = (TimeSpan)myTSC.ConvertFromString(sampleSection.BuildStartTime.ToString());
            TimeSpan          EndTimeSpan    = (TimeSpan)myTSC.ConvertFromString(sampleSection.BuildEndTime.ToString());
            TimeSpan          resultTimeSpan = EndTimeSpan - StartTimeSpan;

            try
            {
                // <Snippet3>
                // Determine if the Validator can validate
                // the type it contains.
                valBase = customValAttr.ValidatorInstance;
                if (valBase.CanValidate(resultTimeSpan.GetType()))
                {
                    // <Snippet4>
                    // Validate the TimeSpan using a
                    // custom PositiveTimeSpanValidator.
                    valBase.Validate(resultTimeSpan);
                    // </Snippet4>
                }
                // </Snippet3>
            }
            catch (ArgumentException e)
            {
                // Store error message.
                string msg = e.Message.ToString();
#if DEBUG
                Console.WriteLine("Error: {0}", msg);
#endif
            }
        }
Пример #5
0
        public void ComponentModelCompatibilityTest()
        {
            var converter   = new TimeSpanConverter();
            var cmConverter = new System.ComponentModel.TimeSpanConverter();

            var propertyMapData = new MemberMapData(null);

            propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture;
            var rowMock = new Mock <IReaderRow>();

            try
            {
                cmConverter.ConvertFromString("");
                Assert.Fail();
            }
            catch (FormatException) {}

            try
            {
                var val = (DateTime)converter.ConvertFromString("", rowMock.Object, propertyMapData);
                Assert.Fail();
            }
            catch (TypeConverterException) {}

            try
            {
                cmConverter.ConvertFromString(null);
                Assert.Fail();
            }
            catch (NotSupportedException) { }

            try
            {
                converter.ConvertFromString(null, rowMock.Object, propertyMapData);
                Assert.Fail();
            }
            catch (TypeConverterException) { }
        }
Пример #6
0
        public void ComponentModelCompatibilityTest()
        {
            var converter   = new TimeSpanConverter();
            var cmConverter = new System.ComponentModel.TimeSpanConverter();

            var typeConverterOptions = new TypeConverterOptions
            {
                CultureInfo = CultureInfo.CurrentCulture
            };

            try
            {
                cmConverter.ConvertFromString("");
                Assert.Fail();
            }
            catch (FormatException) {}

            try
            {
                var val = (DateTime)converter.ConvertFromString(typeConverterOptions, "");
                Assert.Fail();
            }
            catch (CsvTypeConverterException) {}

            try
            {
                cmConverter.ConvertFromString(null);
                Assert.Fail();
            }
            catch (NotSupportedException) { }

            try
            {
                converter.ConvertFromString(typeConverterOptions, null);
                Assert.Fail();
            }
            catch (CsvTypeConverterException) { }
        }
Пример #7
0
        private async Task RunSteamStuff()
        {
            // this will map to the ISteamUser endpoint
            var steamInterface          = new SteamUser(config.ApiKey);
            var player                  = new PlayerService(config.ApiKey);
            TimeSpanConverter converter = new TimeSpanConverter();

            var playerSummaryResponse = await steamInterface.GetPlayerSummaryAsync(ulong.Parse(steamidInput.Text));

            var playerSummaryData = playerSummaryResponse.Data;

            outputText.Text = playerSummaryData.Nickname;

            timespan = (TimeSpan)converter.ConvertFromString(hourInput.Text + ":" + minuteInput.Text + ":" + secondInput.Text);
            var ownedgames = await player.GetOwnedGamesAsync(config.UserId, includeAppInfo : true, includeFreeGames : cb_freeGames.Checked);

            var gamesdata = ownedgames.Data;

            games = gamesdata.OwnedGames.ToList();
            if (radioSortNameA.Checked)
            {
                games = games.OrderBy(x => x.Name).ToList();
                DisplayGameList(games);
            }
            else if (radioSortTimeD.Checked)
            {
                games = games.OrderByDescending(x => x.PlaytimeForever).ToList();
                DisplayGameList(games);
            }
            else if (radioSortTimeA.Checked)
            {
                games = games.OrderBy(x => x.PlaytimeForever).ToList();
                DisplayGameList(games);
            }
            else if (radioSortNameD.Checked)
            {
                games = games.OrderByDescending(x => x.Name).ToList();
                DisplayGameList(games);
            }
            DisplayGameList(games);
        }
Пример #8
0
        private void btnAddTime_Click(object sender, EventArgs e)
        {
            String timeString = InputForm.GetInput("添加时间", "请输入时间(格式:15:31或15:31:21):", null);

            if (String.IsNullOrEmpty(timeString))
            {
                return;
            }

            TimeSpanConverter   tsc = new TimeSpanConverter();
            Nullable <TimeSpan> ts;

            try
            {
                ts = tsc.ConvertFromString(timeString) as Nullable <TimeSpan>;
            }
            catch (Exception ex)
            {
                MessageBox.Show("时间格式不正确!" + ex.Message);
                return;
            }

            lbEveryDayBackupTime.Items.Add(ts.Value);
        }