示例#1
0
 public AMix(int? inputs, double? dropoutTransition, DurationType duration)
     : this()
 {
     Inputs = inputs;
     Duration = duration;
     DropoutTransition = dropoutTransition;
 }
示例#2
0
 public Effect(Characteristic target, int amount, EffectType type, int duration, DurationType durType)
 {
     Target = target;
     Amount = amount;
     Type = type;
     Duration = duration;
     DurType = durType;
 }
示例#3
0
 /// <summary>
 /// Creates a Duration from a TimeSpan.
 /// </summary>
 /// <param name="timeSpan"></param>
 public Duration(TimeSpan timeSpan)
 {
     if (timeSpan < TimeSpan.Zero)
     {
         throw new ArgumentException(SR.Get(SRID.Timing_InvalidArgNonNegative), "timeSpan");
     }
     _durationType = DurationType.TimeSpan;
     _timeSpan = timeSpan;
 }
示例#4
0
        /// <summary>
        /// Construct an XsdDuration from a TimeSpan value that represents an xsd:duration, an xdt:dayTimeDuration, or
        /// an xdt:yearMonthDuration.
        /// </summary>
        public XsdDuration(TimeSpan timeSpan, DurationType durationType)
        {
            long ticks = timeSpan.Ticks;
            ulong ticksPos;
            bool isNegative;

            if (ticks < 0)
            {
                // Note that (ulong) -Int64.MinValue = Int64.MaxValue + 1, which is what we want for that special case
                isNegative = true;
                ticksPos = (ulong)-ticks;
            }
            else
            {
                isNegative = false;
                ticksPos = (ulong)ticks;
            }

            if (durationType == DurationType.YearMonthDuration)
            {
                int years = (int)(ticksPos / ((ulong)TimeSpan.TicksPerDay * 365));
                int months = (int)((ticksPos % ((ulong)TimeSpan.TicksPerDay * 365)) / ((ulong)TimeSpan.TicksPerDay * 30));

                if (months == 12)
                {
                    // If remaining days >= 360 and < 365, then round off to year
                    years++;
                    months = 0;
                }

                this = new XsdDuration(isNegative, years, months, 0, 0, 0, 0, 0);
            }
            else
            {
                Debug.Assert(durationType == DurationType.Duration || durationType == DurationType.DayTimeDuration);

                // Tick count is expressed in 100 nanosecond intervals
                _nanoseconds = (uint)(ticksPos % 10000000) * 100;
                if (isNegative)
                    _nanoseconds |= NegativeBit;

                _years = 0;
                _months = 0;
                _days = (int)(ticksPos / (ulong)TimeSpan.TicksPerDay);
                _hours = (int)((ticksPos / (ulong)TimeSpan.TicksPerHour) % 24);
                _minutes = (int)((ticksPos / (ulong)TimeSpan.TicksPerMinute) % 60);
                _seconds = (int)((ticksPos / (ulong)TimeSpan.TicksPerSecond) % 60);
            }
        }
        public static DashboardItem AddRequestResponseTime(
            ApiToken apiToken,
            string name = "Response time",
            Action <DashboardItem>?options = null,
            string whereQuery         = "",
            DurationType durationType = DurationType.Percentile_90)
        {
            var averageString = "avg(duration)";

            switch (durationType)
            {
            case DurationType.Percentile_50:
                averageString = "percentile(duration, 50)";
                break;

            case DurationType.Percentile_90:
                averageString = "percentile(duration, 90)";
                break;

            case DurationType.Percentile_95:
                averageString = "percentile(duration, 95)";
                break;

            case DurationType.Percentile_99:
                averageString = "percentile(duration, 99)";
                break;
            }

            var query = $@"
                requests
                | where timestamp > ago(1h)
                | where client_Type == 'PC'
                {whereQuery}
                | summarize _duration = {averageString} by bin(timestamp, 2m)
                | project timestamp, _duration";

            var item = new DashboardItem(name, apiToken, query)
            {
                Postfix          = "ms",
                Total            = ItemTotal.Average,
                MinChartValue    = 1000,
                WarningThreshold = 5000,
                ErrorThreshold   = 0
            };

            options?.Invoke(item);
            return(item);
        }
示例#6
0
        public void AddViewerItem(DurationType durationType, string durationDesc)
        {
            MovingAverage ma = new MovingAverage(durationType, false);

            ma.MovingAverageChangedEvent    += MovingAverageChangedEventHandler;
            ma.MovingAverageMaxChangedEvent += MovingAverageMaxChangedEventHandler;

            // Initialize and add item to ListView
            ViewerListViewItem lvi = new ViewerListViewItem(new ViewerItem(durationDesc));

            this.lvViewer.Items.Add(lvi);

            Collector collector = ZAMsettings.Settings.Collectors[durationDesc];

            m_maCollection.Add(durationType, new MovingAverageWrapper(ma, lvi, collector));
        }
        protected override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            duration        = ConfigNodeUtil.ParseValue(node, "duration", 0.0);
            allowedDowntime = ConfigNodeUtil.ParseValue(node, "allowedDowntime", 0.0);
            waitDuration    = ConfigNodeUtil.ParseValue(node, "waitDuration", 0.0);
            allowReset      = ConfigNodeUtil.ParseValue(node, "allowReset", true);
            durationType    = Lib.ConfigEnum(node, "durationType", DurationType.countdown);

            doneAfter           = ConfigNodeUtil.ParseValue(node, "doneAfter", 0.0);
            failAfter           = ConfigNodeUtil.ParseValue(node, "failAfter", 0.0);
            startAfter          = ConfigNodeUtil.ParseValue(node, "startAfter", 0.0);
            accumulatedDuration = ConfigNodeUtil.ParseValue(node, "accumulatedDuration", 0.0);
            durationState       = Lib.ConfigEnum(node, "durationState", DurationState.off);
        }
示例#8
0
        private DurationType GetDurationType()
        {
            DurationType duration = default;

            switch (int.Parse(_duration))
            {
            case (int)DurationType.OneYear: duration = DurationType.OneYear; break;

            case (int)DurationType.TwoYears: duration = DurationType.TwoYears; break;

            case (int)DurationType.FiveYears: duration = DurationType.FiveYears; break;

            case (int)DurationType.TenYears: duration = DurationType.TenYears; break;
            }
            return(duration);
        }
示例#9
0
        /// <summary>
        /// Waits the specified duration.
        /// </summary>
        /// <param name="durationType">Type of the duration.</param>
        /// <param name="duration">The duration.</param>
        internal void Wait(DurationType durationType, int duration)
        {
            switch (durationType)
            {
            case DurationType.Millisecond:
                System.Threading.Thread.Sleep(TimeSpan.FromMilliseconds(duration));
                break;

            case DurationType.Second:
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(duration));
                break;

            case DurationType.Minute:
                System.Threading.Thread.Sleep(TimeSpan.FromMinutes(duration));
                break;
            }
        }
示例#10
0
        public DomainDurationType MapTypeToDomainType(DurationType originalDurationType)
        {
            switch (originalDurationType)
            {
            case DurationType.Weeks:
                return(DomainDurationType.Weeks);

            case DurationType.Months:
                return(DomainDurationType.Months);

            case DurationType.Years:
                return(DomainDurationType.Years);

            default:
                throw new ArgumentOutOfRangeException(nameof(originalDurationType), originalDurationType, null);
            }
        }
        public static string ToDurationTypeString(this DurationType type)
        {
            switch (type)
            {
            case DurationType.OnAir:
                return("onair");

            case DurationType.Reserved:
                return("reserved");

            case DurationType.Closed:
                return("closed");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#12
0
        /// <summary>Construct an Duration from a TimeSpan value that represents an xsd:duration, an xdt:dayTimeDuration, or an xdt:yearMonthDuration.</summary>
        internal Duration(TimeSpan timeSpan, DurationType durationType)
        {
            long  ticks = timeSpan.Ticks;
            ulong ticksPos;
            bool  isNegative;

            if (ticks < 0)
            {
                isNegative = true;
                ticksPos   = (ulong)-ticks;
            }
            else
            {
                isNegative = false;
                ticksPos   = (ulong)ticks;
            }

            if (durationType == DurationType.YearMonthDuration)
            {
                int years  = (int)(ticksPos / ((ulong)TimeSpan.TicksPerDay * 365));
                int months = (int)((ticksPos % ((ulong)TimeSpan.TicksPerDay * 365)) / ((ulong)TimeSpan.TicksPerDay * 30));
                if (months == 12)
                {
                    years++;
                    months = 0;
                }

                this = new Duration(isNegative, years, months, 0, 0, 0, 0, 0);
            }
            else
            {
                this.nanoseconds = (uint)(ticksPos % 10000000) * 100;
                if (isNegative)
                {
                    this.nanoseconds |= NegativeBit;
                }

                this.years   = 0;
                this.months  = 0;
                this.days    = (int)(ticksPos / (ulong)TimeSpan.TicksPerDay);
                this.hours   = (int)((ticksPos / (ulong)TimeSpan.TicksPerHour) % 24);
                this.minutes = (int)((ticksPos / (ulong)TimeSpan.TicksPerMinute) % 60);
                this.seconds = (int)((ticksPos / (ulong)TimeSpan.TicksPerSecond) % 60);
            }
        }
示例#13
0
        public void BuildServiceType(string name, char dp)
        {
            foreach (var sTypes in DataHolder.GetInstance().ServiceTypes.Where(sTypes => sTypes.Name == name))
            {
                Type = sTypes;
                return;
            }

            Type = new DurationType {
                Name = name
            };
            IServiceProperty props = new ServiceProperty {
                Name = "name", Type = "string", ServiceType = Type
            };

            Type.ServiceProperties.Add("name", props);
            props = new ServiceProperty {
                Name = "location", Type = "string", ServiceType = Type
            };
            Type.ServiceProperties.Add("location", props);
            props = new ServiceProperty {
                Name = "price", Type = "double", ServiceType = Type
            };
            Type.ServiceProperties.Add("price", props);
            props = new ServiceProperty {
                Name = "description", Type = "string", ServiceType = Type
            };
            Type.ServiceProperties.Add("description", props);
            props = new ServiceProperty {
                Name = "intialdate", Type = "date", ServiceType = Type
            };
            Type.ServiceProperties.Add("initialdate", props);
            props = new ServiceProperty {
                Name = "enddate", Type = "date", ServiceType = Type
            };
            Type.ServiceProperties.Add("enddate", props);
            props = new ServiceProperty {
                Name = "n_rooms", Type = "double", ServiceType = Type
            };
            Type.ServiceProperties.Add("n_rooms", props);
            Type.TwoDates = true;
            DataHolder.GetInstance().ServiceTypes.Add(Type);
        }
示例#14
0
        public XsdDuration(TimeSpan timeSpan, DurationType durationType)
        {
            ulong num2;
            bool  flag;
            long  ticks = timeSpan.Ticks;

            if (ticks < 0L)
            {
                flag = true;
                num2 = (ulong)-ticks;
            }
            else
            {
                flag = false;
                num2 = (ulong)ticks;
            }
            if (durationType == DurationType.YearMonthDuration)
            {
                int years  = (int)(num2 / ((ulong)0x11ed178c6c000L));
                int months = (int)((num2 % ((ulong)0x11ed178c6c000L)) / ((ulong)0x1792f8648000L));
                if (months == 12)
                {
                    years++;
                    months = 0;
                }
                this = new XsdDuration(flag, years, months, 0, 0, 0, 0, 0);
            }
            else
            {
                this.nanoseconds = ((uint)(num2 % ((ulong)0x989680L))) * 100;
                if (flag)
                {
                    this.nanoseconds |= 0x80000000;
                }
                this.years   = 0;
                this.months  = 0;
                this.days    = (int)(num2 / ((ulong)0xc92a69c000L));
                this.hours   = (int)((num2 / ((ulong)0x861c46800L)) % ((ulong)0x18L));
                this.minutes = (int)((num2 / ((ulong)0x23c34600L)) % ((ulong)60L));
                this.seconds = (int)((num2 / ((ulong)0x989680L)) % ((ulong)60L));
            }
        }
示例#15
0
        /// <summary>
        /// Generic moving average collector
        /// </summary>
        /// <param name="durationType"></param>The duration of collection
        /// <param name="excludeZeroPowerValues"></param>Whether to exclude zeros when collecting
        /// <param name="allowHighRes"></param>Whether to allow use of high-res packets.  Currently only collectors under 30 seconds use these.
        public MovingAverage(DurationType durationType, bool excludeZeroPowerValues, bool allowHighRes = true)
        {
            Logger = ZAMsettings.LoggerFactory.CreateLogger <MovingAverage>();

            m_durationType           = durationType;
            m_duration               = MovingAverage.GetDuration(durationType);
            m_excludeZeroPowerValues = excludeZeroPowerValues;

            m_statsQueue = new Queue <Statistics>();

            if (m_duration <= 30 && allowHighRes)
            {
                ZAMsettings.ZPMonitorService.HighResRiderStateEvent += RiderStateEventHandler;
                Logger.LogInformation($"{m_duration} seconds moving average collector using high-res packets.");
            }
            else
            {
                ZAMsettings.ZPMonitorService.RiderStateEvent += RiderStateEventHandler;
            }
        }
示例#16
0
        private void BuildDefendXUnitsObjective(GameObject parent, JObject objective, string name, string title, string guid,
                                                bool isPrimaryObjectve, int priority, bool displayToUser, string contractObjectiveGuid)
        {
            string[] requiredTagsOnUnit    = (objective.ContainsKey("RequiredTagsOnUnit")) ? ((JArray)objective["RequiredTagsOnUnit"]).ToObject <string[]>() : null;
            int      numberOfUnitsToDefend = (objective.ContainsKey("NumberOfUnitsToDefend")) ? ((int)objective["NumberOfUnitsToDefend"]) : 1;
            int      durationToDefend      = (objective.ContainsKey("DurationToDefend")) ? (int)objective["DurationToDefend"] : 0;
            string   durationTypeStr       = (objective.ContainsKey("DurationType")) ? objective["DurationType"].ToString() : "Rounds";
            string   progressFormat        = (objective.ContainsKey("ProgressFormat")) ? objective["ProgressFormat"].ToString() : "";
            string   description           = objective["Description"].ToString();

            if (durationToDefend <= 0)
            {
                ObjectiveFactory.CreateDefendXUnitsForeverObjective(guid, parent, contractObjectiveGuid, name, title, priority, progressFormat, description, requiredTagsOnUnit, numberOfUnitsToDefend);
            }
            else
            {
                DurationType durationType = (DurationType)Enum.Parse(typeof(DurationType), durationTypeStr);
                ObjectiveFactory.CreateDefendXUnitsObjective(guid, parent, contractObjectiveGuid, name, title, priority, progressFormat, description, requiredTagsOnUnit, numberOfUnitsToDefend, durationToDefend, durationType);
            }
        }
 public XsdDuration(TimeSpan timeSpan, DurationType durationType)
 {
     ulong num2;
     bool flag;
     long ticks = timeSpan.Ticks;
     if (ticks < 0L)
     {
         flag = true;
         num2 = (ulong) -ticks;
     }
     else
     {
         flag = false;
         num2 = (ulong) ticks;
     }
     if (durationType == DurationType.YearMonthDuration)
     {
         int years = (int) (num2 / ((ulong) 0x11ed178c6c000L));
         int months = (int) ((num2 % ((ulong) 0x11ed178c6c000L)) / ((ulong) 0x1792f8648000L));
         if (months == 12)
         {
             years++;
             months = 0;
         }
         this = new XsdDuration(flag, years, months, 0, 0, 0, 0, 0);
     }
     else
     {
         this.nanoseconds = ((uint) (num2 % ((ulong) 0x989680L))) * 100;
         if (flag)
         {
             this.nanoseconds |= 0x80000000;
         }
         this.years = 0;
         this.months = 0;
         this.days = (int) (num2 / ((ulong) 0xc92a69c000L));
         this.hours = (int) ((num2 / ((ulong) 0x861c46800L)) % ((ulong) 0x18L));
         this.minutes = (int) ((num2 / ((ulong) 0x23c34600L)) % ((ulong) 60L));
         this.seconds = (int) ((num2 / ((ulong) 0x989680L)) % ((ulong) 60L));
     }
 }
示例#18
0
        public XsdDuration(string s, DurationType durationType)
        {
            XsdDuration duration;
            Exception   exception = TryParse(s, durationType, out duration);

            if (exception != null)
            {
                throw exception;
            }
            this.years       = duration.Years;
            this.months      = duration.Months;
            this.days        = duration.Days;
            this.hours       = duration.Hours;
            this.minutes     = duration.Minutes;
            this.seconds     = duration.Seconds;
            this.nanoseconds = (uint)duration.Nanoseconds;
            if (duration.IsNegative)
            {
                this.nanoseconds |= 0x80000000;
            }
        }
        /// <summary>
        ///     If the component doest specifies a DTEND so it should has a DURATION.
        ///     Use this to add the duration to the DTSTART property of a component.
        /// </summary>
        /// <param name="dtStart"></param>
        /// <param name="duration"></param>
        /// <returns></returns>
        public static DateTime AddDuration(this DateTime dtStart, DurationType duration)
        {
            if (duration.Weeks != null)
            {
                if (duration.IsPositive)
                {
                    return(dtStart.AddDays(7 * duration.Weeks.Value));
                }
                else
                {
                    return(dtStart.Subtract(new TimeSpan(7 * duration.Weeks.Value, 0, 0, 0)));
                }
            }
            var durationSpan = new TimeSpan(
                duration.Days ?? 0,
                duration.Hours ?? 0,
                duration.Minutes ?? 0,
                duration.Seconds ?? 0);

            return(duration.IsPositive ? dtStart.Add(durationSpan) : dtStart.Subtract(durationSpan));
        }
示例#20
0
        public PlayableEntry(XmlElement node) : base(node)
        {
            foreach (XmlElement propertyNode in node.ChildNodes)
            {
                switch (propertyNode.Name)
                {
                case "plays":
                    this._Plays = ParseInt(propertyNode.InnerText);
                    continue;

                case "views":
                    this._Views = ParseInt(propertyNode.InnerText);
                    continue;

                case "lastPlayedAt":
                    this._LastPlayedAt = ParseInt(propertyNode.InnerText);
                    continue;

                case "width":
                    this._Width = ParseInt(propertyNode.InnerText);
                    continue;

                case "height":
                    this._Height = ParseInt(propertyNode.InnerText);
                    continue;

                case "duration":
                    this._Duration = ParseInt(propertyNode.InnerText);
                    continue;

                case "msDuration":
                    this._MsDuration = ParseInt(propertyNode.InnerText);
                    continue;

                case "durationType":
                    this._DurationType = (DurationType)StringEnum.Parse(typeof(DurationType), propertyNode.InnerText);
                    continue;
                }
            }
        }
示例#21
0
        public static void ShowAndClear(float duration = 5.0f, DurationType type = DurationType.CONST, String color = null, bool log = true)
        {
            if (log)
            {
                string message = String.Join(", ", from m in messages select m.Value.Message.Replace("\n", ", "));
                Log(message);
            }

            switch (type)
            {
            case DurationType.CONST:
            {
                string message = String.Join("\n", from m in messages select m.Value.Message);

                QuickPost(message, duration, color);
                break;
            }

            case DurationType.CLEVERCONSTPERLINE:
            {
                string message      = String.Join("\n", from m in messages select m.Value.Message);
                var    countOfLines = (from m in messages select m.Value.Message.Split('\n').Length).Sum();

                QuickPost(message, countOfLines * duration, color);
                break;
            }

            case DurationType.INCREMENT:
            {
                int i = 1;
                foreach (var pair in messages)
                {
                    QuickPost(pair.Value.Message, i++ *duration, color ?? pair.Value.Color);
                }
                break;
            }
            }
            messages.Clear();
        }
示例#22
0
        public void ValidateDurationType(DurationType value, string errorMessage, bool shouldError)
        {
            var request = new CreateApprenticeshipRequest
            {
                DurationType = value
            };
            var sut = new Fixture().Customize(new AutoMoqCustomization())
                      .Create <CreateApprenticeshipRequestValidator>();

            sut.Validate(request);

            if (shouldError)
            {
                sut.ShouldHaveValidationErrorFor(req => req.DurationType, request)
                .WithErrorCode(ErrorCodes.CreateApprenticeship.DurationType)
                .WithErrorMessage(errorMessage);
            }
            else
            {
                sut.ShouldNotHaveValidationErrorFor(req => req.DurationType, request);
            }
        }
示例#23
0
        /// <summary>
        /// Constructs an XsdDuration from a string in the xsd:duration format.  Components are stored without loss
        /// of fidelity (except in the case of overflow).
        /// </summary>
        public XsdDuration(string s, DurationType durationType)
        {
            XsdDuration result;
            Exception   exception = TryParse(s, durationType, out result);

            if (exception != null)
            {
                throw exception;
            }
            this.years       = result.Years;
            this.months      = result.Months;
            this.days        = result.Days;
            this.hours       = result.Hours;
            this.minutes     = result.Minutes;
            this.seconds     = result.Seconds;
            this.nanoseconds = (uint)result.Nanoseconds;
            if (result.IsNegative)
            {
                this.nanoseconds |= NegativeBit;
            }
            return;
        }
        public static Duration ToDuration(this DurationType durationType)
        {
            double value = double.TryParse(durationType.DurationValue, out value) ? value : 0;

            if (value > 0 &&
                !string.IsNullOrWhiteSpace(durationType.DurationUnit) &&
                !string.IsNullOrWhiteSpace(durationType.DurationDescription))
            {
                return(new Duration(value, durationType.DurationUnit, durationType.DurationDescription));
            }

            if (value > 0 && !string.IsNullOrWhiteSpace(durationType.DurationUnit))
            {
                return(new Duration(value, durationType.DurationUnit));
            }

            if (!string.IsNullOrWhiteSpace(durationType.DurationDescription))
            {
                return(new Duration(durationType.DurationDescription));
            }

            return(Duration.Default);
        }
        public static PeriodType MapToPeriodType(DurationType type)
        {
            switch (type)
            {
            case DurationType.Days:
                return(PeriodType.Days);

            case DurationType.Hours:
                return(PeriodType.Hours);

            case DurationType.Minutes:
                return(PeriodType.Minutes);

            case DurationType.Seconds:
                return(PeriodType.Seconds);

            case DurationType.Milliseconds:
                return(PeriodType.Milliseconds);

            default:
                throw new ArgumentException(Utils.SRGetStr("ExceptionMapPeriodTypeArgument"));
            }
        }
 public DataSet select_DurationType(DurationType _obj)
 {
     try
     {
         _cn.Open();
         SqlCommand _cmd = new SqlCommand("select_DurationType", _cn);
         _cmd.CommandType = CommandType.StoredProcedure;
         SqlDataAdapter _adp = new SqlDataAdapter(_cmd);
         DataSet        _ds  = new DataSet();
         _adp.Fill(_ds);
         _adp.Dispose();
         _cmd.Dispose();
         return(_ds);
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         _cn.Close();
     }
 }
        public void SetUp()
        {
            var fixture = new Fixture().Customize(new AutoMoqCustomization());

            _randomWageType       = fixture.Create <int>();
            _randomLegacyWageType = fixture.Create <int>();
            _randomWageUnit       = fixture.Create <int>();

            _randomDurationType = (DurationType) new Random().Next(1, 4);
            var durationTypeMapper = new DurationMapper();

            _randomDomainDurationType = durationTypeMapper.MapTypeToDomainType(_randomDurationType);

            _request = fixture.Build <CreateApprenticeshipRequest>()
                       .With(request => request.WageType, (WageType)_randomWageType)
                       .With(request => request.WageUnit, (WageUnit)_randomWageUnit)
                       .With(request => request.DurationType, _randomDurationType)
                       .With(request => request.IsEmployerDisabilityConfident, fixture.Create <bool>())
                       .Create();

            _mockWageTypeMapper = fixture.Freeze <Mock <IWageTypeMapper> >();
            _mockWageTypeMapper
            .Setup(typeMapper => typeMapper.MapToLegacy(It.IsAny <CreateApprenticeshipRequest>()))
            .Returns((LegacyWageType)_randomLegacyWageType);

            _mockWageTextFormatter = fixture.Freeze <Mock <IWageTextFormatter> >();


            fixture.Inject <IDurationMapper>(durationTypeMapper);

            _employerInformation = fixture.Create <EmployerInformation>();

            var mapper = fixture.Create <CreateApprenticeshipParametersMapper>();

            _mappedParameters = mapper.MapFromRequest(_request, _employerInformation);
        }
示例#28
0
    public void SetAnimationDuration(DurationType durationType, int durationValue)
    {
        isHasALimitedDuration = true;

        switch (durationType)
        {
        case DurationType.Loops:
            amountOfLoopsToExit = durationValue;
            break;

        case DurationType.Seconds:
            int _amountOfLoopsToExit = Mathf.RoundToInt(durationValue / AnimatorBlinkingData.blinkingAnimationLoopDuration);
            if (_amountOfLoopsToExit == 0)
            {
                Debug.LogWarning("Внимание! Вы пытаетесь использовать слишком короткую длительность анимации!");
            }
            amountOfLoopsToExit = _amountOfLoopsToExit;
            break;

        default:
            Debug.LogError($"Unknown durationType {durationType}!");
            break;
        }
    }
示例#29
0
 /// <summary>
 ///     Constructor, which allow to setup duration with <see cref="System.TimeSpan" /> value
 /// </summary>
 /// <param name="timeSpan">Explicit <see cref="System.TimeSpan" /> value, defined as duration</param>
 public Duration(TimeSpan timeSpan)
 {
     _timeSpan     = timeSpan;
     _durationType = DurationType.TimeSpan;
 }
示例#30
0
        internal string ToString(DurationType durationType)
        {
            StringBuilder sb = new StringBuilder(20);
            int           nanoseconds, digit, zeroIdx, len;

            if (IsNegative)
            {
                sb.Append('-');
            }

            sb.Append('P');

            if (durationType != DurationType.DayTimeDuration)
            {
                if (_years != 0)
                {
                    sb.Append(XmlConvert.ToString(_years));
                    sb.Append('Y');
                }

                if (_months != 0)
                {
                    sb.Append(XmlConvert.ToString(_months));
                    sb.Append('M');
                }
            }

            if (durationType != DurationType.YearMonthDuration)
            {
                if (_days != 0)
                {
                    sb.Append(XmlConvert.ToString(_days));
                    sb.Append('D');
                }

                if (_hours != 0 || _minutes != 0 || _seconds != 0 || Nanoseconds != 0)
                {
                    sb.Append('T');
                    if (_hours != 0)
                    {
                        sb.Append(XmlConvert.ToString(_hours));
                        sb.Append('H');
                    }

                    if (_minutes != 0)
                    {
                        sb.Append(XmlConvert.ToString(_minutes));
                        sb.Append('M');
                    }

                    nanoseconds = Nanoseconds;
                    if (_seconds != 0 || nanoseconds != 0)
                    {
                        sb.Append(XmlConvert.ToString(_seconds));
                        if (nanoseconds != 0)
                        {
                            sb.Append('.');

                            len        = sb.Length;
                            sb.Length += 9;
                            zeroIdx    = sb.Length - 1;

                            for (int idx = zeroIdx; idx >= len; idx--)
                            {
                                digit   = nanoseconds % 10;
                                sb[idx] = (char)(digit + '0');

                                if (zeroIdx == idx && digit == 0)
                                {
                                    zeroIdx--;
                                }

                                nanoseconds /= 10;
                            }

                            sb.Length = zeroIdx + 1;
                        }
                        sb.Append('S');
                    }
                }

                // Zero is represented as "PT0S"
                if (sb[sb.Length - 1] == 'P')
                {
                    sb.Append("T0S");
                }
            }
            else
            {
                // Zero is represented as "T0M"
                if (sb[sb.Length - 1] == 'P')
                {
                    sb.Append("0M");
                }
            }

            return(sb.ToString());
        }
示例#31
0
 public MoveArchetype(string name, MoveType moveType, ElementType elementType,
     int maxPp, int power, int accuracy, DurationType durationType, int turnDuration, BattleEffectStageEffect battleEffectStageEffect, 
     EffectType effectType, EffectStart effectStart, MoveTarget moveTarget, 
     BattleEffectType battleEffectType, string battleEffectText)
 {
     Name = name;
     MoveType = moveType;
     ElementType = elementType;
     MaxPP = maxPp;
     Power = power;
     Accuracy = accuracy;
     TurnDuration = turnDuration;
     BattleEffectStageEffect = battleEffectStageEffect;
     EffectType = effectType;
     EffectStart = effectStart;
     MoveTarget = moveTarget;
     DurationType = durationType;
     BattleEffectType = battleEffectType;
     BattleEffectText = battleEffectText;
 }
示例#32
0
 public Duration(TimeSpan timeSpan)
 {
     _durationType = DurationType.TimeSpan;
     _timeSpan = timeSpan;
 }
示例#33
0
        internal static Exception TryParse(string s, DurationType durationType, out XsdDuration result) {
            string errorCode; 
            int length;
            int value, pos, numDigits;
            Parts parts = Parts.HasNone;

            result = new XsdDuration();

            s = s.Trim();
            length = s.Length;

            pos = 0;
            numDigits = 0;

            if (pos >= length) goto InvalidFormat;

            if (s[pos] == '-') {
                pos++;
                result.nanoseconds = NegativeBit;
            }
            else {
                result.nanoseconds = 0;
            }

            if (pos >= length) goto InvalidFormat;

            if (s[pos++] != 'P') goto InvalidFormat;

            errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
            if (errorCode != null) goto Error;

            if (pos >= length) goto InvalidFormat;

            if (s[pos] == 'Y') {
                if (numDigits == 0) goto InvalidFormat;

                parts |= Parts.HasYears;
                result.years = value;
                if (++pos == length) goto Done;

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null) goto Error;

                if (pos >= length) goto InvalidFormat;
            }

            if (s[pos] == 'M') {
                if (numDigits == 0) goto InvalidFormat;

                parts |= Parts.HasMonths;
                result.months = value;
                if (++pos == length) goto Done;

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null) goto Error;

                if (pos >= length) goto InvalidFormat;
            }

            if (s[pos] == 'D') {
                if (numDigits == 0) goto InvalidFormat;

                parts |= Parts.HasDays;
                result.days = value;
                if (++pos == length) goto Done;

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null) goto Error;

                if (pos >= length) goto InvalidFormat;
            }

            if (s[pos] == 'T') {
                if (numDigits != 0) goto InvalidFormat;

                pos++;
                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null) goto Error;

                if (pos >= length) goto InvalidFormat;

                if (s[pos] == 'H') {
                    if (numDigits == 0) goto InvalidFormat;

                    parts |= Parts.HasHours;
                    result.hours = value;
                    if (++pos == length) goto Done;

                    errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                    if (errorCode != null) goto Error;

                    if (pos >= length) goto InvalidFormat;
                }

                if (s[pos] == 'M') {
                    if (numDigits == 0) goto InvalidFormat;

                    parts |= Parts.HasMinutes;
                    result.minutes = value;
                    if (++pos == length) goto Done;

                    errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                    if (errorCode != null) goto Error;

                    if (pos >= length) goto InvalidFormat;
                }

                if (s[pos] == '.') {
                    pos++;

                    parts |= Parts.HasSeconds;
                    result.seconds = value;

                    errorCode = TryParseDigits(s, ref pos, true, out value, out numDigits);
                    if (errorCode != null) goto Error;

                    if (numDigits == 0) { //If there are no digits after the decimal point, assume 0
                        value = 0;
                    }
                    // Normalize to nanosecond intervals
                    for (; numDigits > 9; numDigits--)
                        value /= 10;

                    for (; numDigits < 9; numDigits++)
                        value *= 10;

                    result.nanoseconds |= (uint) value;

                    if (pos >= length) goto InvalidFormat;

                    if (s[pos] != 'S') goto InvalidFormat;
                    if (++pos == length) goto Done;
                }
                else if (s[pos] == 'S') {
                    if (numDigits == 0) goto InvalidFormat;

                    parts |= Parts.HasSeconds;
                    result.seconds = value;
                    if (++pos == length) goto Done;
                }
            }

            // Duration cannot end with digits
            if (numDigits != 0) goto InvalidFormat;

            // No further characters are allowed
            if (pos != length) goto InvalidFormat;

        Done:
            // At least one part must be defined
            if (parts == Parts.HasNone) goto InvalidFormat;

            if (durationType == DurationType.DayTimeDuration) {
                if ((parts & (Parts.HasYears | Parts.HasMonths)) != 0)
                    goto InvalidFormat;
            }
            else if (durationType == DurationType.YearMonthDuration) {
                if ((parts & ~(XsdDuration.Parts.HasYears | XsdDuration.Parts.HasMonths)) != 0)
                    goto InvalidFormat;
            }
            return null;

        InvalidFormat:
            return new FormatException(Res.GetString(Res.XmlConvert_BadFormat, s, durationType));

        Error:
            return new OverflowException(Res.GetString(Res.XmlConvert_Overflow, s, durationType));
        }
示例#34
0
        internal Exception TryToTimeSpan(DurationType durationType, out TimeSpan result) {
            Exception exception = null; 
            ulong ticks = 0;

            // Throw error if result cannot fit into a long
            try {
                checked {
                    // Discard year and month parts if constructing TimeSpan for DayTimeDuration
                    if (durationType != DurationType.DayTimeDuration) {
                        ticks += ((ulong) this.years + (ulong) this.months / 12) * 365;
                        ticks += ((ulong) this.months % 12) * 30;
                    }

                    // Discard day and time parts if constructing TimeSpan for YearMonthDuration
                    if (durationType != DurationType.YearMonthDuration) {
                        ticks += (ulong) this.days;

                        ticks *= 24;
                        ticks += (ulong) this.hours;

                        ticks *= 60;
                        ticks += (ulong) this.minutes;

                        ticks *= 60;
                        ticks += (ulong) this.seconds;

                        // Tick count interval is in 100 nanosecond intervals (7 digits)
                        ticks *= (ulong) TimeSpan.TicksPerSecond;
                        ticks += (ulong) Nanoseconds / 100;
                    }
                    else {
                        // Multiply YearMonth duration by number of ticks per day
                        ticks *= (ulong) TimeSpan.TicksPerDay;
                    }

                    if (IsNegative) {
                        // Handle special case of Int64.MaxValue + 1 before negation, since it would otherwise overflow
                        if (ticks == (ulong) Int64.MaxValue + 1) {
                            result = new TimeSpan(Int64.MinValue);
                        }
                        else {
                            result = new TimeSpan(-((long) ticks));
                        }
                    }
                    else {
                        result = new TimeSpan((long) ticks);
                    }
                    return null;
                }
            }
            catch (OverflowException) {
                result = TimeSpan.MinValue;
                exception = new OverflowException(Res.GetString(Res.XmlConvert_Overflow, durationType, "TimeSpan"));
            }
            return exception;
        }
示例#35
0
文件: Duration.cs 项目: koush/Xaml
 private Duration(DurationType duration)
 {
     myDurationType = duration;
     myTimeSpan = System.TimeSpan.Zero;
 }
示例#36
0
文件: Duration.cs 项目: koush/Xaml
 public Duration(TimeSpan timeSpan)
 {
     myTimeSpan = timeSpan;
     myDurationType = DurationType.TimeSpan;
 }
示例#37
0
 protected IDuration(DurationType type, IStep parent)
 {
     Debug.Assert(type != DurationType.DurationTypeCount);
     m_Type = type;
     m_ParentStep = parent;
 }
示例#38
0
 private Duration(DurationType durationType, TimeSpan timeSpan)
 {
     this.TimeSpan = timeSpan;
     this.durationType = durationType;
 }
 public TimeSpan ToTimeSpan(DurationType durationType)
 {
     TimeSpan span;
     Exception exception = this.TryToTimeSpan(durationType, out span);
     if (exception != null)
     {
         throw exception;
     }
     return span;
 }
 internal Exception TryToTimeSpan(DurationType durationType, out TimeSpan result)
 {
     Exception exception = null;
     ulong num = 0L;
     try
     {
         if (durationType != DurationType.DayTimeDuration)
         {
             num += (((ulong) this.years) + (((ulong) this.months) / 12L)) * ((ulong) 0x16dL);
             num += (((ulong) this.months) % 12L) * ((ulong) 30L);
         }
         if (durationType != DurationType.YearMonthDuration)
         {
             num += (ulong) this.days;
             num *= (ulong) 0x18L;
             num += (ulong) this.hours;
             num *= (ulong) 60L;
             num += (ulong) this.minutes;
             num *= (ulong) 60L;
             num += (ulong) this.seconds;
             num *= (ulong) 0x989680L;
             num += ((ulong) this.Nanoseconds) / 100L;
         }
         else
         {
             num *= (ulong) 0xc92a69c000L;
         }
         if (this.IsNegative)
         {
             if (num == 9223372036854775808L)
             {
                 result = new TimeSpan(-9223372036854775808L);
             }
             else
             {
                 result = new TimeSpan(0L - ((long) num));
             }
         }
         else
         {
             result = new TimeSpan((long) num);
         }
         return null;
     }
     catch (OverflowException)
     {
         result = TimeSpan.MinValue;
         exception = new OverflowException(Res.GetString("XmlConvert_Overflow", new object[] { durationType, "TimeSpan" }));
     }
     return exception;
 }
 internal static Exception TryParse(string s, DurationType durationType, out XsdDuration result)
 {
     int num2;
     Parts hasNone = Parts.HasNone;
     result = new XsdDuration();
     s = s.Trim();
     int length = s.Length;
     int offset = 0;
     int numDigits = 0;
     if (offset >= length)
     {
         goto Label_02D8;
     }
     if (s[offset] == '-')
     {
         offset++;
         result.nanoseconds = 0x80000000;
     }
     else
     {
         result.nanoseconds = 0;
     }
     if ((offset >= length) || (s[offset++] != 'P'))
     {
         goto Label_02D8;
     }
     if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null)
     {
         goto Label_0301;
     }
     if (offset >= length)
     {
         goto Label_02D8;
     }
     if (s[offset] == 'Y')
     {
         if (numDigits == 0)
         {
             goto Label_02D8;
         }
         hasNone |= Parts.HasYears;
         result.years = num2;
         if (++offset == length)
         {
             goto Label_02BB;
         }
         if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null)
         {
             goto Label_0301;
         }
         if (offset >= length)
         {
             goto Label_02D8;
         }
     }
     if (s[offset] == 'M')
     {
         if (numDigits == 0)
         {
             goto Label_02D8;
         }
         hasNone |= Parts.HasMonths;
         result.months = num2;
         if (++offset == length)
         {
             goto Label_02BB;
         }
         if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null)
         {
             goto Label_0301;
         }
         if (offset >= length)
         {
             goto Label_02D8;
         }
     }
     if (s[offset] == 'D')
     {
         if (numDigits == 0)
         {
             goto Label_02D8;
         }
         hasNone |= Parts.HasDays;
         result.days = num2;
         if (++offset == length)
         {
             goto Label_02BB;
         }
         if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null)
         {
             goto Label_0301;
         }
         if (offset >= length)
         {
             goto Label_02D8;
         }
     }
     if (s[offset] == 'T')
     {
         if (numDigits != 0)
         {
             goto Label_02D8;
         }
         offset++;
         if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null)
         {
             goto Label_0301;
         }
         if (offset >= length)
         {
             goto Label_02D8;
         }
         if (s[offset] == 'H')
         {
             if (numDigits == 0)
             {
                 goto Label_02D8;
             }
             hasNone |= Parts.HasHours;
             result.hours = num2;
             if (++offset == length)
             {
                 goto Label_02BB;
             }
             if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null)
             {
                 goto Label_0301;
             }
             if (offset >= length)
             {
                 goto Label_02D8;
             }
         }
         if (s[offset] == 'M')
         {
             if (numDigits == 0)
             {
                 goto Label_02D8;
             }
             hasNone |= Parts.HasMinutes;
             result.minutes = num2;
             if (++offset == length)
             {
                 goto Label_02BB;
             }
             if (TryParseDigits(s, ref offset, false, out num2, out numDigits) != null)
             {
                 goto Label_0301;
             }
             if (offset >= length)
             {
                 goto Label_02D8;
             }
         }
         if (s[offset] == '.')
         {
             offset++;
             hasNone |= Parts.HasSeconds;
             result.seconds = num2;
             if (TryParseDigits(s, ref offset, true, out num2, out numDigits) != null)
             {
                 goto Label_0301;
             }
             if (numDigits == 0)
             {
                 num2 = 0;
             }
             while (numDigits > 9)
             {
                 num2 /= 10;
                 numDigits--;
             }
             while (numDigits < 9)
             {
                 num2 *= 10;
                 numDigits++;
             }
             result.nanoseconds |= (uint) num2;
             if ((offset >= length) || (s[offset] != 'S'))
             {
                 goto Label_02D8;
             }
             if (++offset != length)
             {
                 goto Label_02B3;
             }
             goto Label_02BB;
         }
         if (s[offset] == 'S')
         {
             if (numDigits == 0)
             {
                 goto Label_02D8;
             }
             hasNone |= Parts.HasSeconds;
             result.seconds = num2;
             if (++offset == length)
             {
                 goto Label_02BB;
             }
         }
     }
 Label_02B3:
     if ((numDigits != 0) || (offset != length))
     {
         goto Label_02D8;
     }
 Label_02BB:
     if (hasNone == Parts.HasNone)
     {
         goto Label_02D8;
     }
     if (durationType == DurationType.DayTimeDuration)
     {
         if ((hasNone & (Parts.HasMonths | Parts.HasYears)) == Parts.HasNone)
         {
             goto Label_02D6;
         }
         goto Label_02D8;
     }
     if ((durationType == DurationType.YearMonthDuration) && ((hasNone & ~(Parts.HasMonths | Parts.HasYears)) != Parts.HasNone))
     {
         goto Label_02D8;
     }
 Label_02D6:
     return null;
 Label_02D8:;
     return new FormatException(Res.GetString("XmlConvert_BadFormat", new object[] { s, durationType }));
 Label_0301:;
     return new OverflowException(Res.GetString("XmlConvert_Overflow", new object[] { s, durationType }));
 }
示例#42
0
 /// <summary>
 /// Internal helper method that converts an Xsd duration to a TimeSpan value.  This code uses the estimate
 /// that there are 365 days in the year and 30 days in a month.
 /// </summary>
 public TimeSpan ToTimeSpan(DurationType durationType) {
     TimeSpan result;
     Exception exception = TryToTimeSpan(durationType, out result);
     if (exception != null) {
         throw exception;
     }
     return result;
 }
 public XsdDuration(string s, DurationType durationType)
 {
     XsdDuration duration;
     Exception exception = TryParse(s, durationType, out duration);
     if (exception != null)
     {
         throw exception;
     }
     this.years = duration.Years;
     this.months = duration.Months;
     this.days = duration.Days;
     this.hours = duration.Hours;
     this.minutes = duration.Minutes;
     this.seconds = duration.Seconds;
     this.nanoseconds = (uint) duration.Nanoseconds;
     if (duration.IsNegative)
     {
         this.nanoseconds |= 0x80000000;
     }
 }
示例#44
0
        /// <summary>
        /// Return the string representation according to xsd:duration rules, xdt:dayTimeDuration rules, or
        /// xdt:yearMonthDuration rules.
        /// </summary>
        internal string ToString(DurationType durationType) {
            StringBuilder sb = new StringBuilder(20);
            int nanoseconds, digit, zeroIdx, len;

            if (IsNegative)
                sb.Append('-');

            sb.Append('P');

            if (durationType != DurationType.DayTimeDuration) {
                
                if (this.years != 0) {
                    sb.Append(XmlConvert.ToString(this.years));
                    sb.Append('Y');
                }

                if (this.months != 0) {
                    sb.Append(XmlConvert.ToString(this.months));
                    sb.Append('M');
                }
            }

            if (durationType != DurationType.YearMonthDuration) {
                if (this.days != 0) {
                    sb.Append(XmlConvert.ToString(this.days));
                    sb.Append('D');
                }

                if (this.hours != 0 || this.minutes != 0 || this.seconds != 0 || Nanoseconds != 0) {
                    sb.Append('T');
                    if (this.hours != 0) {
                        sb.Append(XmlConvert.ToString(this.hours));
                        sb.Append('H');
                    }

                    if (this.minutes != 0) {
                        sb.Append(XmlConvert.ToString(this.minutes));
                        sb.Append('M');
                    }

                    nanoseconds = Nanoseconds;
                    if (this.seconds != 0 || nanoseconds != 0) {
                        sb.Append(XmlConvert.ToString(this.seconds));
                        if (nanoseconds != 0) {
                            sb.Append('.');

                            len = sb.Length;
                            sb.Length += 9;
                            zeroIdx = sb.Length - 1;

                            for (int idx = zeroIdx; idx >= len; idx--) {
                                digit = nanoseconds % 10;
                                sb[idx] = (char) (digit + '0');

                                if (zeroIdx == idx && digit == 0)
                                    zeroIdx--;

                                nanoseconds /= 10;
                            }

                            sb.Length = zeroIdx + 1;
                        }
                        sb.Append('S');
                    }
                }

                // Zero is represented as "PT0S"
                if (sb[sb.Length - 1] == 'P')
                    sb.Append("T0S");
            }
            else {
                // Zero is represented as "T0M"
                if (sb[sb.Length - 1] == 'P')
                    sb.Append("0M");
            }

            return sb.ToString();
        }
示例#45
0
		public Duration (TimeSpan timeSpan)
		{
			this.durationType = DurationType.Timespan;
			this.timeSpan = timeSpan;
		}
示例#46
0
文件: Chord.cs 项目: LimmaPaulus/Capo
 public Chord(DurationType duration, List<Note> notes)
 {
     Duration = duration;
     Notes = notes;
 }
示例#47
0
        internal Exception TryToTimeSpan(DurationType durationType, out TimeSpan result)
        {
            Exception exception = null;
            ulong ticks = 0;
            try
            {
                checked
                {
                    if (durationType != DurationType.DayTimeDuration)
                    {
                        ticks += ((ulong)this.years + ((ulong)this.months / 12)) * 365;
                        ticks += ((ulong)this.months % 12) * 30;
                    }

                    if (durationType != DurationType.YearMonthDuration)
                    {
                        ticks += (ulong)this.days;
                        ticks *= 24;
                        ticks += (ulong)this.hours;
                        ticks *= 60;
                        ticks += (ulong)this.minutes;
                        ticks *= 60;
                        ticks += (ulong)this.seconds;
                        ticks *= (ulong)TimeSpan.TicksPerSecond;
                        ticks += (ulong)Nanoseconds / 100;
                    }
                    else
                    {
                        ticks *= (ulong)TimeSpan.TicksPerDay;
                    }

                    if (IsNegative)
                    {
                        if (ticks == (ulong)Int64.MaxValue + 1)
                        {
                            result = new TimeSpan(Int64.MinValue);
                        }
                        else
                        {
                            result = new TimeSpan(-((long)ticks));
                        }
                    }
                    else
                    {
                        result = new TimeSpan((long)ticks);
                    }

                    return null;
                }
            }
            catch (OverflowException)
            {
                result = TimeSpan.MinValue;
                exception = new OverflowException();
            }

            return exception;
        }
 public static T SetAdditionalConditionDurationType <T>(this T entity, DurationType value)
     where T : ConditionDefinition
 {
     entity.SetField("additionalConditionDurationType", value);
     return(entity);
 }
示例#49
0
        internal static Exception TryParse(string s, DurationType durationType, out Duration result)
        {
            string errorCode;
            int length;
            int value, pos, numDigits;
            Parts parts = Parts.HasNone;
            result = new Duration();
            s = s.Trim();
            length = s.Length;
            pos = 0;
            numDigits = 0;
            if (pos >= length)
            {
                goto InvalidFormat;
            }

            if (s[pos] == '-')
            {
                pos++;
                result.nanoseconds = NegativeBit;
            }
            else
            {
                result.nanoseconds = 0;
            }

            if (pos >= length)
            {
                goto InvalidFormat;
            }

            if (s[pos++] != 'P')
            {
                goto InvalidFormat;
            }

            errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
            if (errorCode != null)
            {
                goto Error;
            }

            if (pos >= length)
            {
                goto InvalidFormat;
            }

            if (s[pos] == 'Y')
            {
                if (numDigits == 0)
                {
                    goto InvalidFormat;
                }

                parts |= Parts.HasYears;
                result.years = value;
                if (++pos == length)
                {
                    goto Done;
                }

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null)
                {
                    goto Error;
                }

                if (pos >= length)
                {
                    goto InvalidFormat;
                }
            }

            if (s[pos] == 'M')
            {
                if (numDigits == 0)
                {
                    goto InvalidFormat;
                }

                parts |= Parts.HasMonths;
                result.months = value;
                if (++pos == length)
                {
                    goto Done;
                }

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null)
                {
                    goto Error;
                }

                if (pos >= length)
                {
                    goto InvalidFormat;
                }
            }

            if (s[pos] == 'D')
            {
                if (numDigits == 0)
                {
                    goto InvalidFormat;
                }

                parts |= Parts.HasDays;
                result.days = value;
                if (++pos == length)
                {
                    goto Done;
                }

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null)
                {
                    goto Error;
                }

                if (pos >= length)
                {
                    goto InvalidFormat;
                }
            }

            if (s[pos] == 'T')
            {
                if (numDigits != 0)
                {
                    goto InvalidFormat;
                }

                pos++;
                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null)
                {
                    goto Error;
                }

                if (pos >= length)
                {
                    goto InvalidFormat;
                }

                if (s[pos] == 'H')
                {
                    if (numDigits == 0)
                    {
                        goto InvalidFormat;
                    }

                    parts |= Parts.HasHours;
                    result.hours = value;
                    if (++pos == length)
                    {
                        goto Done;
                    }

                    errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                    if (errorCode != null)
                    {
                        goto Error;
                    }

                    if (pos >= length)
                    {
                        goto InvalidFormat;
                    }
                }

                if (s[pos] == 'M')
                {
                    if (numDigits == 0)
                    {
                        goto InvalidFormat;
                    }

                    parts |= Parts.HasMinutes;
                    result.minutes = value;
                    if (++pos == length)
                    {
                        goto Done;
                    }

                    errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                    if (errorCode != null)
                    {
                        goto Error;
                    }

                    if (pos >= length)
                    {
                        goto InvalidFormat;
                    }
                }

                if (s[pos] == '.')
                {
                    pos++;
                    parts |= Parts.HasSeconds;
                    result.seconds = value;
                    errorCode = TryParseDigits(s, ref pos, true, out value, out numDigits);
                    if (errorCode != null)
                    {
                        goto Error;
                    }

                    if (numDigits == 0)
                    {
                        value = 0;
                    }

                    for (; numDigits > 9; numDigits--)
                    {
                        value /= 10;
                    }

                    for (; numDigits < 9; numDigits++)
                    {
                        value *= 10;
                    }

                    result.nanoseconds |= (uint)value;
                    if (pos >= length)
                    {
                        goto InvalidFormat;
                    }

                    if (s[pos] != 'S')
                    {
                        goto InvalidFormat;
                    }

                    if (++pos == length)
                    {
                        goto Done;
                    }
                }
                else if (s[pos] == 'S')
                {
                    if (numDigits == 0)
                    {
                        goto InvalidFormat;
                    }

                    parts |= Parts.HasSeconds;
                    result.seconds = value;
                    if (++pos == length)
                    {
                        goto Done;
                    }
                }
            }

            if (numDigits != 0)
            {
                goto InvalidFormat;
            }

            if (pos != length)
            {
                goto InvalidFormat;
            }

        Done:
            if (parts == Parts.HasNone)
            {
                goto InvalidFormat;
            }

            if (durationType == DurationType.DayTimeDuration)
            {
                if ((parts & (Parts.HasYears | Parts.HasMonths)) != 0)
                {
                    goto InvalidFormat;
                }
            }
            else if (durationType == DurationType.YearMonthDuration)
            {
                if ((parts & ~(Duration.Parts.HasYears | Duration.Parts.HasMonths)) != 0)
                {
                    goto InvalidFormat;
                }
            }

            return null;
        InvalidFormat:
            return new FormatException();
        Error:
            return new OverflowException();
        }
示例#50
0
        internal Exception?TryToTimeSpan(DurationType durationType, out TimeSpan result)
        {
            Exception?exception = null;
            ulong     ticks     = 0;

            // Throw error if result cannot fit into a long
            try
            {
                checked
                {
                    // Discard year and month parts if constructing TimeSpan for DayTimeDuration
                    if (durationType != DurationType.DayTimeDuration)
                    {
                        ticks += ((ulong)_years + (ulong)_months / 12) * 365;
                        ticks += ((ulong)_months % 12) * 30;
                    }

                    // Discard day and time parts if constructing TimeSpan for YearMonthDuration
                    if (durationType != DurationType.YearMonthDuration)
                    {
                        ticks += (ulong)_days;

                        ticks *= 24;
                        ticks += (ulong)_hours;

                        ticks *= 60;
                        ticks += (ulong)_minutes;

                        ticks *= 60;
                        ticks += (ulong)_seconds;

                        // Tick count interval is in 100 nanosecond intervals (7 digits)
                        ticks *= (ulong)TimeSpan.TicksPerSecond;
                        ticks += (ulong)Nanoseconds / 100;
                    }
                    else
                    {
                        // Multiply YearMonth duration by number of ticks per day
                        ticks *= (ulong)TimeSpan.TicksPerDay;
                    }

                    if (IsNegative)
                    {
                        // Handle special case of Int64.MaxValue + 1 before negation, since it would otherwise overflow
                        if (ticks == (ulong)long.MaxValue + 1)
                        {
                            result = new TimeSpan(long.MinValue);
                        }
                        else
                        {
                            result = new TimeSpan(-((long)ticks));
                        }
                    }
                    else
                    {
                        result = new TimeSpan((long)ticks);
                    }
                    return(null);
                }
            }
            catch (OverflowException)
            {
                result    = TimeSpan.MinValue;
                exception = new OverflowException(SR.Format(SR.XmlConvert_Overflow, durationType, "TimeSpan"));
            }
            return(exception);
        }
示例#51
0
        /// <summary>Construct an Duration from a TimeSpan value that represents an xsd:duration, an xdt:dayTimeDuration, or an xdt:yearMonthDuration.</summary> 
        internal Duration(TimeSpan timeSpan, DurationType durationType)
        {
            long ticks = timeSpan.Ticks;
            ulong ticksPos;
            bool isNegative;

            if (ticks < 0)
            {
                isNegative = true;
                ticksPos = (ulong)-ticks;
            }
            else
            {
                isNegative = false;
                ticksPos = (ulong)ticks;
            }

            if (durationType == DurationType.YearMonthDuration)
            {
                int years = (int)(ticksPos / ((ulong)TimeSpan.TicksPerDay * 365));
                int months = (int)((ticksPos % ((ulong)TimeSpan.TicksPerDay * 365)) / ((ulong)TimeSpan.TicksPerDay * 30));
                if (months == 12)
                {
                    years++;
                    months = 0;
                }

                this = new Duration(isNegative, years, months, 0, 0, 0, 0, 0);
            }
            else
            {
                this.nanoseconds = (uint)(ticksPos % 10000000) * 100;
                if (isNegative)
                {
                    this.nanoseconds |= NegativeBit;
                }

                this.years = 0;
                this.months = 0;
                this.days = (int)(ticksPos / (ulong)TimeSpan.TicksPerDay);
                this.hours = (int)((ticksPos / (ulong)TimeSpan.TicksPerHour) % 24);
                this.minutes = (int)((ticksPos / (ulong)TimeSpan.TicksPerMinute) % 60);
                this.seconds = (int)((ticksPos / (ulong)TimeSpan.TicksPerSecond) % 60);
            }
        }
示例#52
0
        internal static Exception?TryParse(string s, DurationType durationType, out XsdDuration result)
        {
            string?errorCode;
            int    length;
            int    value, pos, numDigits;
            Parts  parts = Parts.HasNone;

            result = default;

            s      = s.Trim();
            length = s.Length;

            pos       = 0;
            numDigits = 0;

            if (pos >= length)
            {
                goto InvalidFormat;
            }

            if (s[pos] == '-')
            {
                pos++;
                result._nanoseconds = NegativeBit;
            }
            else
            {
                result._nanoseconds = 0;
            }

            if (pos >= length)
            {
                goto InvalidFormat;
            }

            if (s[pos++] != 'P')
            {
                goto InvalidFormat;
            }

            errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
            if (errorCode != null)
            {
                goto Error;
            }

            if (pos >= length)
            {
                goto InvalidFormat;
            }

            if (s[pos] == 'Y')
            {
                if (numDigits == 0)
                {
                    goto InvalidFormat;
                }

                parts        |= Parts.HasYears;
                result._years = value;
                if (++pos == length)
                {
                    goto Done;
                }

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null)
                {
                    goto Error;
                }

                if (pos >= length)
                {
                    goto InvalidFormat;
                }
            }

            if (s[pos] == 'M')
            {
                if (numDigits == 0)
                {
                    goto InvalidFormat;
                }

                parts         |= Parts.HasMonths;
                result._months = value;
                if (++pos == length)
                {
                    goto Done;
                }

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null)
                {
                    goto Error;
                }

                if (pos >= length)
                {
                    goto InvalidFormat;
                }
            }

            if (s[pos] == 'D')
            {
                if (numDigits == 0)
                {
                    goto InvalidFormat;
                }

                parts       |= Parts.HasDays;
                result._days = value;
                if (++pos == length)
                {
                    goto Done;
                }

                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null)
                {
                    goto Error;
                }

                if (pos >= length)
                {
                    goto InvalidFormat;
                }
            }

            if (s[pos] == 'T')
            {
                if (numDigits != 0)
                {
                    goto InvalidFormat;
                }

                pos++;
                errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                if (errorCode != null)
                {
                    goto Error;
                }

                if (pos >= length)
                {
                    goto InvalidFormat;
                }

                if (s[pos] == 'H')
                {
                    if (numDigits == 0)
                    {
                        goto InvalidFormat;
                    }

                    parts        |= Parts.HasHours;
                    result._hours = value;
                    if (++pos == length)
                    {
                        goto Done;
                    }

                    errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                    if (errorCode != null)
                    {
                        goto Error;
                    }

                    if (pos >= length)
                    {
                        goto InvalidFormat;
                    }
                }

                if (s[pos] == 'M')
                {
                    if (numDigits == 0)
                    {
                        goto InvalidFormat;
                    }

                    parts          |= Parts.HasMinutes;
                    result._minutes = value;
                    if (++pos == length)
                    {
                        goto Done;
                    }

                    errorCode = TryParseDigits(s, ref pos, false, out value, out numDigits);
                    if (errorCode != null)
                    {
                        goto Error;
                    }

                    if (pos >= length)
                    {
                        goto InvalidFormat;
                    }
                }

                if (s[pos] == '.')
                {
                    pos++;

                    parts          |= Parts.HasSeconds;
                    result._seconds = value;

                    errorCode = TryParseDigits(s, ref pos, true, out value, out numDigits);
                    if (errorCode != null)
                    {
                        goto Error;
                    }

                    if (numDigits == 0)
                    { //If there are no digits after the decimal point, assume 0
                        value = 0;
                    }
                    // Normalize to nanosecond intervals
                    for (; numDigits > 9; numDigits--)
                    {
                        value /= 10;
                    }

                    for (; numDigits < 9; numDigits++)
                    {
                        value *= 10;
                    }

                    result._nanoseconds |= (uint)value;

                    if (pos >= length)
                    {
                        goto InvalidFormat;
                    }

                    if (s[pos] != 'S')
                    {
                        goto InvalidFormat;
                    }
                    if (++pos == length)
                    {
                        goto Done;
                    }
                }
                else if (s[pos] == 'S')
                {
                    if (numDigits == 0)
                    {
                        goto InvalidFormat;
                    }

                    parts          |= Parts.HasSeconds;
                    result._seconds = value;
                    if (++pos == length)
                    {
                        goto Done;
                    }
                }
            }

            // Duration cannot end with digits
            if (numDigits != 0)
            {
                goto InvalidFormat;
            }

            // No further characters are allowed
            if (pos != length)
            {
                goto InvalidFormat;
            }

Done:
            // At least one part must be defined
            if (parts == Parts.HasNone)
            {
                goto InvalidFormat;
            }

            if (durationType == DurationType.DayTimeDuration)
            {
                if ((parts & (Parts.HasYears | Parts.HasMonths)) != 0)
                {
                    goto InvalidFormat;
                }
            }
            else if (durationType == DurationType.YearMonthDuration)
            {
                if ((parts & ~(XsdDuration.Parts.HasYears | XsdDuration.Parts.HasMonths)) != 0)
                {
                    goto InvalidFormat;
                }
            }

            return(null);

InvalidFormat:
            return(new FormatException(SR.Format(SR.XmlConvert_BadFormat, s, durationType)));

Error:
            return(new OverflowException(SR.Format(SR.XmlConvert_Overflow, s, durationType)));
        }
示例#53
0
		internal Duration (DurationType t)
		{
			this.durationType = t;
			timeSpan = TimeSpan.Zero;
		}
 private CoatingScheduleProduct(string thickness, string description, string productCode, string grades, string units,
                                bool hasBarcode, string notes, string placement, bool trial, bool backbrand, int masterId, string coatingLine, double unitsPerHour,
                                DurationType durationType, Machine machine, Configuration config)
 {
     InitializeMembers(thickness, description, productCode, grades, units, hasBarcode, notes, placement, unitsPerHour, masterId, backbrand, trial, coatingLine, durationType, machine, config);
 }
示例#55
0
 /// <summary>
 /// Constructs an XsdDuration from a string in the xsd:duration format.  Components are stored without loss
 /// of fidelity (except in the case of overflow).
 /// </summary>
 public XsdDuration(string s, DurationType durationType) {
     XsdDuration result;
     Exception exception = TryParse(s, durationType, out result);
     if (exception != null) {
         throw exception;
     }
     this.years = result.Years;
     this.months = result.Months;
     this.days = result.Days;
     this.hours = result.Hours;
     this.minutes = result.Minutes;
     this.seconds = result.Seconds;
     this.nanoseconds = (uint)result.Nanoseconds;
     if (result.IsNegative) {
         this.nanoseconds |= NegativeBit;
     }
     return;
 }
示例#56
0
 private Duration(DurationType type)
 {
     _durationType = type;
 }
 internal string ToString(DurationType durationType)
 {
     StringBuilder builder = new StringBuilder(20);
     if (this.IsNegative)
     {
         builder.Append('-');
     }
     builder.Append('P');
     if (durationType != DurationType.DayTimeDuration)
     {
         if (this.years != 0)
         {
             builder.Append(XmlConvert.ToString(this.years));
             builder.Append('Y');
         }
         if (this.months != 0)
         {
             builder.Append(XmlConvert.ToString(this.months));
             builder.Append('M');
         }
     }
     if (durationType != DurationType.YearMonthDuration)
     {
         if (this.days != 0)
         {
             builder.Append(XmlConvert.ToString(this.days));
             builder.Append('D');
         }
         if (((this.hours != 0) || (this.minutes != 0)) || ((this.seconds != 0) || (this.Nanoseconds != 0)))
         {
             builder.Append('T');
             if (this.hours != 0)
             {
                 builder.Append(XmlConvert.ToString(this.hours));
                 builder.Append('H');
             }
             if (this.minutes != 0)
             {
                 builder.Append(XmlConvert.ToString(this.minutes));
                 builder.Append('M');
             }
             int nanoseconds = this.Nanoseconds;
             if ((this.seconds != 0) || (nanoseconds != 0))
             {
                 builder.Append(XmlConvert.ToString(this.seconds));
                 if (nanoseconds != 0)
                 {
                     builder.Append('.');
                     int length = builder.Length;
                     builder.Length += 9;
                     int num3 = builder.Length - 1;
                     for (int i = num3; i >= length; i--)
                     {
                         int num2 = nanoseconds % 10;
                         builder[i] = (char) (num2 + 0x30);
                         if ((num3 == i) && (num2 == 0))
                         {
                             num3--;
                         }
                         nanoseconds /= 10;
                     }
                     builder.Length = num3 + 1;
                 }
                 builder.Append('S');
             }
         }
         if (builder[builder.Length - 1] == 'P')
         {
             builder.Append("T0S");
         }
     }
     else if (builder[builder.Length - 1] == 'P')
     {
         builder.Append("0M");
     }
     return builder.ToString();
 }