Esempio n. 1
0
 public void SetDateTimeEx(DateTimeEx value)
 {
     _values[_curWriteField] = value;
     Changed();
 }
Esempio n. 2
0
		public DateTimeEx ConvertToTimeZone(string targetTimeZoneID)
		{
			DateTimeEx result = null;

			if (targetTimeZoneID != null)
			{
				var tzDiff = TimeZoneCache.GetTimeZoneByID(targetTimeZoneID).GetUtcOffset(DateTime) - TimeZoneCache.GetTimeZoneByID(TimeZoneID).GetUtcOffset(DateTime);
				result = new DateTimeEx((DateTime + tzDiff), timeZoneID: targetTimeZoneID);
			}
			else
			{
				result = new DateTimeEx(DateTime);
			}

			result.OutFormat = OutFormat;
			result.OutLocale = OutLocale;

			return result;
		}
Esempio n. 3
0
        public static DateTimeEx ParseCustomized(string value, string format, DateTimeFormatInfo dtfi)
        {
            var lexer = new DateTimeLexer(value);
            DateTimeEx res = new DateTimeEx();

            int num2;
            bool isbc = false;
            for (int i = 0; i < format.Length; i += num2)
            {
                char patternChar = format[i];
                switch (patternChar)
                {
                    case 'F':
                    case 'f':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            if (num2 > 7)
                            {
                                throw new FormatException("DBSH-00039 Bad format");
                            }
                            int parsed = lexer.ReadNumber(num2);
                            res.Nanosecond = (int)Math.Pow(10.0, (double)(7 - num2)) * 100 * parsed;
                            break;
                        }
                    case 'H':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            res.Hour = lexer.ReadNumber(num2);
                            break;
                        }
                    case ':':
                        {
                            lexer.Skip(dtfi.TimeSeparator);
                            num2 = 1;
                            break;
                        }
                    case '/':
                        {
                            lexer.Skip(dtfi.DateSeparator);
                            num2 = 1;
                            break;
                        }
                    case '\'':
                    case '"':
                        {
                            StringBuilder result = new StringBuilder();
                            num2 = DateTimeExFormat.ParseQuoteString(format, i, result);
                            lexer.Skip(result.ToString());
                            break;
                        }
                    case 'M':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            res.Month = lexer.ReadNumber(num2);
                            break;
                        }

                    case '\\':
                        {
                            int ch = DateTimeExFormat.ParseNextChar(format, i);
                            if (ch < 0)
                            {
                                throw new FormatException("DBSH-00040 Invalid format");
                            }
                            lexer.Skip((char)ch);
                            num2 = 2;
                            break;
                        }
                    case 'd':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            res.Day = lexer.ReadNumber(num2);
                            break;
                        }
                    case 'g':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            if (lexer.Skip("A.D")) { }
                            else if (lexer.Skip("B.C")) { isbc = true; }
                            break;
                        }
                    case 'h':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            res.Hour = lexer.ReadNumber(num2);
                            break;
                        }
                    case 's':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            res.Second = lexer.ReadNumber(num2);
                            break;
                        }
                    case 'm':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            res.Minute = lexer.ReadNumber(num2);
                            break;
                        }
                    case 'y':
                        {
                            num2 = DateTimeExFormat.ParseRepeatPattern(format, i, patternChar);
                            if (num2 == 2)
                            {
                                int num3=lexer.ReadNumber(2);
                                if (num3 < 69) res.Year = 2000 + num3;
                                else res.Year = 1900 + num3;
                            }
                            if (num2 == 3)
                            {
                                int num3 = lexer.ReadNumber(2);
                                if (num3 < 500) res.Year = 2000 + num3;
                                else res.Year = 1000 + num3;
                            }
                            if (num2 >= 4) res.Year = lexer.ReadNumber(num2);
                            break;
                        }
                    default:
                        {
                            lexer.Skip(patternChar);
                            num2 = 1;
                            break;
                        }
                }
            }
            if (isbc) res.Year = -res.Year;
            return res;
        }
		/// <summary>
		/// Создание нового объекта и заполнение его данными из SSR DOCS строки
		/// </summary>
		/// <param name="docsString">SSR DOCS строка</param>
		/// <param name="supplier">Поставщик, из которого была получена SSR DOCS строка</param>
		public DocumentInfoDataItem(string docsString, AviaSuppliers? supplier = null)
		{
			int index = 0;
			//ибо только Сэйбр на данный момент добавляет в SSR строку статус SSRки
			if (supplier.HasValue && supplier.Value == AviaSuppliers.Sabre)
			{
				index = 1;
			}
			var tmp = docsString.Split('/');

			Type = (DocTypes)Enum.Parse(typeof(DocTypes), tmp[index]);
			Number = tmp[index + 2];
			IssueCountryCode = tmp[index + 1];

			var tmpElapsedDate = DateTime.Parse(tmp[index + 6], Locale.UsCulture);
			if (tmpElapsedDate < DateTime.Now)
			{
				tmpElapsedDate = tmpElapsedDate.AddYears(100);
			}
			ElapsedTime = new DateTimeEx(tmpElapsedDate, Formats.DATE_FORMAT);

			AddedAsDOCS = true;
		}
Esempio n. 5
0
 public virtual void SetDateTimeEx(DateTimeEx value)
 {
     m_text = "'" + value.ToStringNormalized() + "'";
 }
Esempio n. 6
0
 public static DateTimeEx FromStream(BinaryReader stream)
 {
     DateTimeEx res = new DateTimeEx();
     res.m_flags = (DateTimeExFlags)stream.ReadByte();
     if (!res.SkipDate)
     {
         res.m_year = stream.ReadInt16();
         res.m_month = stream.ReadByte();
         res.m_day = stream.ReadByte();
     }
     if (!res.SkipTime)
     {
         res.m_hour = stream.ReadByte();
         res.m_minute = stream.ReadByte();
         res.m_second = stream.ReadByte();
     }
     if (!res.SkipNanoSecond)
     {
         res.m_nanosecond = stream.ReadInt32();
     }
     if (!res.SkipOffset)
     {
         res.m_offset = stream.ReadInt16();
     }
     return res;
 }
Esempio n. 7
0
 public void MakeRestriction(DateTimeEx minval, DateTimeEx maxval)
 {
     if (this <= minval) this = minval;
     if (this >= maxval) this = maxval;
 }
Esempio n. 8
0
        public static List <Column> ParseLayout(string layout)
        {
            string[]      layoutParts = layout.Split(',');
            List <Column> cols        = new List <Column>();

            for (int i = 0; i < layoutParts.Length; i = i + 3)
            {
                Column col = new Column();
                col.Id       = layoutParts[i];
                col.MinWidth = 10;
                col.Name     = layoutParts[i + 1];
                col.Width    = int.Parse(layoutParts[i + 2]);
                col.MinWidth = col.Width;
                //col.MaxWidth = col.Width; // This forces the column to stay the same size when resizing
                col.Field     = layoutParts[i];
                col.Sortable  = true;
                col.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext)
                {
                    string typeName = value.GetType().Name;


                    switch (typeName)
                    {
                    case "String":
                        return(value.ToString());

                    case "bool":
                        return(value + "bool");

                    case "Date":
                        DateTime dateValue  = (DateTime)value;
                        string   dateFormat = "dd/mm/yy";
                        string   timeFormat = "hh:MM";
                        if (OrganizationServiceProxy.UserSettings != null)
                        {
                            dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString;
                            timeFormat = OrganizationServiceProxy.UserSettings.TimeFormatString;
                        }
                        return(DateTimeEx.FormatDateSpecific(dateValue, dateFormat) + " " + DateTimeEx.FormatTimeSpecific(dateValue, timeFormat));



                    case "decimal":
                        return(value.ToString());

                    case "double":
                        return(value.ToString());

                    case "int":
                        return(value.ToString());

                    case "Guid":
                        return(value.ToString());

                    case AttributeTypes.EntityReference:
                        EntityReference refValue = (EntityReference)value;
                        return(@"<a href=""#"">" + refValue.Name + "</a>");

                    case AttributeTypes.OptionSetValue:
                        OptionSetValue optionValue = (OptionSetValue)value;
                        return(optionValue.Name);


                    default:
                        return("null");
                    }
                };
                ArrayEx.Add(cols, col);
            }
            return(cols);
        }
Esempio n. 9
0
        public static CalendarOpPlusFastAddResult ComputeNextDue(
            long currentTime,
            TimePeriod timePeriod,
            DateTimeEx reference,
            TimeAbacus timeAbacus,
            long remainder)
        {
            if (timeAbacus.DateTimeGet(reference, remainder) > currentTime) {
                return new CalendarOpPlusFastAddResult(0, reference);
            }

            // add one time period
            DateTimeEx work = reference.Clone();
            if (DEBUG && Log.IsDebugEnabled) {
                Log.Debug("Work date is " + work);
            }

            CalendarPlusMinusForgeOp.ActionSafeOverflow(work, 1, timePeriod);
            long inMillis = timeAbacus.DateTimeGet(work, remainder);
            if (inMillis > currentTime) {
                return new CalendarOpPlusFastAddResult(1, work);
            }

            if (DEBUG && Log.IsDebugEnabled) {
                Log.Debug("Work date is {0}", work);
            }

            long factor = 1;

            // determine multiplier
            long refTime = timeAbacus.DateTimeGet(reference, remainder);
            long deltaCurrentToStart = currentTime - refTime;
            long deltaAddedOne = timeAbacus.DateTimeGet(work, remainder) - refTime;
            double multiplierDbl = (deltaCurrentToStart / deltaAddedOne) - 1;
            var multiplierRoundedLong = (long) multiplierDbl;

            // handle integer max
            while (multiplierRoundedLong > Int32.MaxValue) {
                CalendarPlusMinusForgeOp.ActionSafeOverflow(work, Int32.MaxValue, timePeriod);
                factor += Int32.MaxValue;
                multiplierRoundedLong -= Int32.MaxValue;
                if (DEBUG && Log.IsDebugEnabled) {
                    Log.Debug("Work date is {0} factor {1}", work, factor);
                }
            }

            // add
            var multiplierRoundedInt = (int) multiplierRoundedLong;
            CalendarPlusMinusForgeOp.ActionSafeOverflow(work, multiplierRoundedInt, timePeriod);
            factor += multiplierRoundedInt;

            // if below, add more
            if (timeAbacus.DateTimeGet(work, remainder) <= currentTime) {
                while (timeAbacus.DateTimeGet(work, remainder) <= currentTime) {
                    CalendarPlusMinusForgeOp.ActionSafeOverflow(work, 1, timePeriod);
                    factor += 1;
                    if (DEBUG && Log.IsDebugEnabled) {
                        Log.Debug("Work date is {0} factor {1}", work, factor);
                    }
                }

                return new CalendarOpPlusFastAddResult(factor, work);
            }

            // we are over
            while (timeAbacus.DateTimeGet(work, remainder) > currentTime) {
                CalendarPlusMinusForgeOp.ActionSafeOverflow(work, -1, timePeriod);
                factor -= 1;
                if (DEBUG && Log.IsDebugEnabled) {
                    Log.Debug("Work date is {0} factor {1}", work, factor);
                }
            }

            CalendarPlusMinusForgeOp.ActionSafeOverflow(work, 1, timePeriod);
            if (DEBUG && Log.IsDebugEnabled) {
                Log.Debug("Work date is {0} factor {1}", work, factor);
            }

            return new CalendarOpPlusFastAddResult(factor + 1, work);
        }
Esempio n. 10
0
 public object EvaluateInternal(DateTimeEx dateTime) => ProcEvaluateInternal?.Invoke(dateTime);
Esempio n. 11
0
 public object Evaluate(DateTimeEx dtx, EventBean[] eventsPerStream, bool newData, ExprEvaluatorContext exprEvaluatorContext)
 {
     return(_dateTimeEval.Invoke(dtx.DateTime.TranslateTo(_timeZone)));
 }
Esempio n. 12
0
 public void Add(
     DateTimeEx dtx,
     int value)
 {
     dtx.AddMonths(value);
 }
Esempio n. 13
0
        internal static string FormatCustomized(DateTimeEx dateTime, string format, DateTimeFormatInfo dtfi)
        {
            int num2;
            StringBuilder outputBuffer = new StringBuilder();
            for (int i = 0; i < format.Length; i += num2)
            {
                char patternChar = format[i];
                switch (patternChar)
                {
                    case 'F':
                    case 'f':
                        {
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            if (num2 > 7)
                            {
                                throw new FormatException("DBSH-00035 Bad format");
                            }
                            long num5 = dateTime.Nanosecond / 100;
                            num5 /= (long)Math.Pow(10.0, (double)(7 - num2));
                            outputBuffer.Append(((int)num5).ToString(fixedNumberFormats[num2 - 1], CultureInfo.InvariantCulture));
                            break;
                        }
                    case 'H':
                        {
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            FormatDigits(outputBuffer, dateTime.Hour, num2);
                            break;
                        }
                    case ':':
                        {
                            outputBuffer.Append(dtfi.TimeSeparator);
                            num2 = 1;
                            break;
                        }
                    case '/':
                        {
                            outputBuffer.Append(dtfi.DateSeparator);
                            num2 = 1;
                            break;
                        }
                    case '\'':
                    case '"':
                        {
                            StringBuilder result = new StringBuilder();
                            num2 = ParseQuoteString(format, i, result);
                            outputBuffer.Append(result);
                            break;
                        }
                    case 'M':
                        {
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            int month = dateTime.Month;
                            FormatDigits(outputBuffer, month, num2);
                            break;
                        }

                    case '\\':
                        {
                            int ch = ParseNextChar(format, i);
                            if (ch < 0)
                            {
                                throw new FormatException("DBSH-00036 Invalid format");
                            }
                            outputBuffer.Append((char)ch);
                            num2 = 2;
                            break;
                        }
                    case 'd':
                        {
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            int dayOfMonth = dateTime.Day;
                            FormatDigits(outputBuffer, dayOfMonth, num2);
                            break;
                        }
                    case 'g':
                        {
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            outputBuffer.Append(dateTime.Year >= 0 ? "A.D" : "B.C");
                            break;
                        }
                    case 'h':
                        {
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            int num3 = dateTime.Hour % 12;
                            if (num3 == 0)
                            {
                                num3 = 12;
                            }
                            FormatDigits(outputBuffer, num3, num2);
                            break;
                        }
                    case 's':
                        {
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            FormatDigits(outputBuffer, dateTime.Second, num2);
                            break;
                        }
                    case 'm':
                        {
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            FormatDigits(outputBuffer, dateTime.Minute, num2);
                            break;
                        }
                    case 'y':
                        {
                            int year = dateTime.Year;
                            num2 = ParseRepeatPattern(format, i, patternChar);
                            if (num2 == 2) FormatDigits(outputBuffer, year % 100, 2);
                            if (num2 == 3) FormatDigits(outputBuffer, year % 1000, 3);
                            if (num2 == 4) FormatDigits(outputBuffer, year, 4);
                            break;
                        }
                    default:
                        outputBuffer.Append(patternChar);
                        num2 = 1;
                        break;
                }
            }
            return outputBuffer.ToString();
        }
Esempio n. 14
0
        public bool Parse()
        {
            FileInfo i = new FileInfo(this.FileName);
            string[] secs = i.Name.Split(new char[] { '.' });
            if (secs.Length != 5)
            {
                return false;
            }
            try
            {
                string s = secs[secs.Length - 2];
                long n = Convert.ToInt32(s);
                this.mTimeStamp = new DateTimeEx(n);

                this.mOwnerID = string.Format("{0}.{1}", secs[0], secs[1]);
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
Esempio n. 15
0
        public static void SetUpGrids(TimeSheetViewModel vm)
        {
            GridOptions daysGridOpts = new GridOptions();

            daysGridOpts.EnableCellNavigation = true;
            daysGridOpts.EnableColumnReorder  = false;
            daysGridOpts.AutoEdit             = false;
            daysGridOpts.Editable             = true;
            daysGridOpts.RowHeight            = 20;
            daysGridOpts.HeaderRowHeight      = 25;
            daysGridOpts.ForceFitColumns      = false;
            daysGridOpts.EnableAddRow         = true;



            // Create Timesheet Grid
            DataViewBase daysDataView = vm.Days;

            List <Column> columns = new List <Column>();

            GridDataViewBinder.BindRowIcon(GridDataViewBinder.AddColumn(columns, "", 50, "icon"), "activity");
            XrmLookupEditor.BindColumn(GridDataViewBinder.AddColumn(columns, "Activity", 300, "activity"), vm.ActivitySearchCommand, "activityid", "subject", "activitytypecode");

            GridDataViewBinder.AddColumn(columns, "Mon", 50, "day0");
            GridDataViewBinder.AddColumn(columns, "Tue", 50, "day1");
            GridDataViewBinder.AddColumn(columns, "Wed", 50, "day2");
            GridDataViewBinder.AddColumn(columns, "Thu", 50, "day3");
            GridDataViewBinder.AddColumn(columns, "Fri", 50, "day4");
            GridDataViewBinder.AddColumn(columns, "Sat", 50, "day5");
            GridDataViewBinder.AddColumn(columns, "Sun", 50, "day6");

            daysGrid = new Grid("#timesheetGridContainer", daysDataView, columns, daysGridOpts);

            GridDataViewBinder daysDataBinder = new GridDataViewBinder();

            daysDataBinder.DataBindEvents(daysGrid, daysDataView, "timesheetGridContainer");

            // Set the totals row meta data
            daysDataView.OnGetItemMetaData += delegate(object item)
            {
                DayEntry day = (DayEntry)item;
                if (day != null && day.isTotalRow)
                {
                    ItemMetaData metaData = new ItemMetaData();
                    metaData.Editor    = null;
                    metaData.Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext)
                    {
                        if (columnDef.Field == "activity")
                        {
                            return("Total");
                        }
                        else
                        {
                            return(Formatters.DefaultFormatter(row, cell, value, columnDef, dataContext));
                        }
                    };
                    metaData.CssClasses = "days_total_row";
                    return(metaData);
                }

                else
                {
                    return(null);
                }
            };

            daysDataBinder.DataBindSelectionModel(daysGrid, daysDataView);


            // ---------------------------------------
            // Sessions Grid
            // ---------------------------------------
            DataViewBase sessionsDataView = vm.SessionDataView;

            List <Column> sessionGridCols = new List <Column>();

            GridDataViewBinder.AddEditIndicatorColumn(sessionGridCols);

            XrmTextEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Description", 200, "dev1_description"));

            XrmDateEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Date", 200, "dev1_starttime"), true);

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Start", 100, "dev1_starttime")).Validator =
                delegate(object value, object item)
            {
                dev1_session     session      = (dev1_session)item;
                DateTime         newStartTime = (DateTime)value;
                ValidationResult result       = new ValidationResult();

                if (session.dev1_EndTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(newStartTime) < DateTimeEx.GetTimeDuration(session.dev1_EndTime);

                    result.Valid   = isValid;
                    result.Message = "The start time must be before the end time";
                }
                else
                {
                    result.Valid = true;
                }
                return(result);
            };

            XrmTimeEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "End", 100, "dev1_endtime")).Validator =
                delegate(object value, object item)
            {
                dev1_session session    = (dev1_session)item;
                DateTime     newEndTime = (DateTime)value;

                ValidationResult result = new ValidationResult();

                if (session.dev1_StartTime != null)
                {
                    result.Valid = true;
                    string valueText = (string)value;
                    // Check if the end time is before the start time

                    bool isValid = DateTimeEx.GetTimeDuration(session.dev1_StartTime) < DateTimeEx.GetTimeDuration(newEndTime);

                    result.Valid   = isValid;
                    result.Message = "The end time must be after the start time";
                }
                else
                {
                    result.Valid = true;
                }

                return(result);
            };


            XrmDurationEditor.BindColumn(GridDataViewBinder.AddColumn(sessionGridCols, "Duration", 200, "dev1_duration"));



            GridDataViewBinder sessionsDataBinder = new GridDataViewBinder();

            sessionsGrid = sessionsDataBinder.DataBindXrmGrid(sessionsDataView, sessionGridCols, "sessionsGridContainer", null, true, true);
            sessionsDataBinder.DataBindSelectionModel(sessionsGrid, sessionsDataView);


            daysGrid.OnActiveCellChanged.Subscribe(delegate(EventData e, object args)
            {
                CellSelection activeCell = daysGrid.GetActiveCell();
                if (activeCell != null)
                {
                    if (activeCell.Cell < 2)
                    {
                        // Whole activity is selected
                        vm.Days.SelectedDay = null;
                    }
                    else
                    {
                        vm.Days.SelectedDay = activeCell.Cell - 1;
                    }
                }
            });
        }
Esempio n. 16
0
        public override void Refresh()
        {
            if (weeks[WeekStart.GetTime()] == null)
            {
                this.OnDataLoading.Notify(null, null, null);

                // We need to load the data from the server
                OrganizationServiceProxy.BeginRetrieveMultiple(String.Format(Queries.SessionsByWeekStartDate, DateTimeEx.ToXrmString(WeekStart), DateTimeEx.ToXrmString(WeekEnd)), delegate(object result)
                {
                    try
                    {
                        EntityCollection results = OrganizationServiceProxy.EndRetrieveMultiple(result, typeof(dev1_session));

                        // Set data
                        List <dev1_session> sessions = new List <dev1_session>();
                        weeks[WeekStart.GetTime()]   = sessions;
                        foreach (Entity e in results.Entities)
                        {
                            AddSession(sessions, (dev1_session)e);
                        }

                        RefreshActivityView();
                    }
                    catch (Exception ex)
                    {
                        // Show error
                        Script.Alert("There was an error loading the Timesheet sessions\n" + ex.Message);
                    }
                });
            }
            else
            {
                RefreshActivityView();
            }
            // Only show the selected
        }
Esempio n. 17
0
 /// <summary>
 /// Formats the specified date time.
 /// </summary>
 /// <param name="timeInMillis">The time in milliseconds.</param>
 public string Format(long?timeInMillis)
 {
     return(timeInMillis == null ? null : Format(DateTimeEx.UtcInstance(timeInMillis.Value)));
 }
Esempio n. 18
0
 public long DateTimeGet(
     DateTimeEx dateTime,
     long remainder)
 {
     return dateTime.UtcMillis;
 }
Esempio n. 19
0
 public static DateTimeEx FromDateTime(DateTime value)
 {
     DateTimeEx res = new DateTimeEx();
     res.AsDateTime = value;
     string s = res.ToStringNormalized();
     return res;
 }
Esempio n. 20
0
 public DateTimeEx ToDateTimeEx(long ts)
 {
     return DateTimeEx.UtcInstance(ts);
 }
Esempio n. 21
0
 public static void SetDateTimeValue(this ICdlValueWriter writer, TypeStorage type, DateTimeEx value)
 {
     switch (type)
     {
         case TypeStorage.DateEx:
             writer.SetDateEx(value.DatePart);
             break;
         case TypeStorage.TimeEx:
             writer.SetTimeEx(value.TimePart);
             break;
         case TypeStorage.DateTime:
             writer.SetDateTime(value.AsDateTime);
             break;
         case TypeStorage.DateTimeEx:
             writer.SetDateTimeEx(value);
             break;
     }
 }
Esempio n. 22
0
        public static TimerScheduleSpec Parse(string iso)
        {
            if (iso == null)
            {
                throw new ScheduleParameterException("Received a null value");
            }
            iso = iso.Trim();
            if (string.IsNullOrEmpty(iso))
            {
                throw new ScheduleParameterException("Received an empty string");
            }

            var split = iso.Split('/');

            long?      optionalRepeats    = null;
            DateTimeEx optionalDate       = null;
            TimePeriod optionalTimePeriod = null;

            try
            {
                if (iso.Equals("/"))
                {
                    throw new ScheduleParameterException("Invalid number of parts");
                }
                if (iso.EndsWith("/"))
                {
                    throw new ScheduleParameterException("Missing the period part");
                }

                if (split.Length == 3)
                {
                    optionalRepeats    = ParseRepeat(split[0]);
                    optionalDate       = ParseDate(split[1]);
                    optionalTimePeriod = ParsePeriod(split[2]);
                }
                else if (split.Length == 2)
                {
                    // there are two forms:
                    // partial-form-1: "R<?>/P<period>"
                    // partial-form-2: "<date>/P<period>"
                    if (string.IsNullOrEmpty(split[0]))
                    {
                        throw new ScheduleParameterException("Expected either a recurrence or a date but received an empty string");
                    }
                    if (split[0][0] == 'R')
                    {
                        optionalRepeats = ParseRepeat(split[0]);
                    }
                    else
                    {
                        optionalDate = ParseDate(split[0]);
                    }
                    optionalTimePeriod = ParsePeriod(split[1]);
                }
                else if (split.Length == 1)
                {
                    // there are two forms:
                    // just date: "<date>"
                    // just period: "P<period>"
                    if (split[0][0] == 'P')
                    {
                        optionalTimePeriod = ParsePeriod(split[0]);
                    }
                    else
                    {
                        optionalDate = ParseDate(split[0]);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ScheduleParameterException("Failed to parse '" + iso + "': " + ex.Message, ex);
            }

            // parse repeating interval
            return(new TimerScheduleSpec(optionalDate, null, optionalRepeats, optionalTimePeriod));
        }
Esempio n. 23
0
 public void SetDateTimeEx(DateTimeEx value)
 {
     m_dateTimeExVal = value;
     _type = TypeStorage.DateTimeEx;
 }
Esempio n. 24
0
 /// <summary>
 /// Простановка ТЛ услуги
 /// </summary>
 /// <param name="timeLimit">Новый ТЛ услуги</param>
 public void SetTimeLimit(string timeLimit)
 {
     ticketTimeLimit = new DateTimeEx(timeLimit, Formats.FULL_DATE_TIME_FORMAT);
 }
Esempio n. 25
0
 public void SetDateTimeEx(DateTimeEx value)
 {
     m_stream.Write((byte)TypeStorage.DateTimeEx);
     value.WriteTo(m_stream);
 }
Esempio n. 26
0
        private DeploymentResult DeployInternalLockTaken(
            Module module,
            DeploymentOptions options,
            string deploymentId,
            DateTimeEx addedDate)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug("Deploying module " + module);
            }
            IList <string> imports;

            if (module.Imports != null)
            {
                foreach (string imported in module.Imports)
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug("Adding import " + imported);
                    }
                    _epService.Configuration.AddImport(imported);
                }
                imports = new List <string>(module.Imports);
            }
            else
            {
                imports = Collections.GetEmptyList <string>();
            }

            if (options.IsCompile)
            {
                var exceptionsX = new List <DeploymentItemException>();
                foreach (ModuleItem item in module.Items)
                {
                    if (item.IsCommentOnly)
                    {
                        continue;
                    }

                    try
                    {
                        _epService.CompileEPL(item.Expression);
                    }
                    catch (Exception ex)
                    {
                        exceptionsX.Add(new DeploymentItemException(ex.Message, item.Expression, ex, item.LineNumber));
                    }
                }

                if (!exceptionsX.IsEmpty())
                {
                    throw BuildException("Compilation failed", module, exceptionsX);
                }
            }

            if (options.IsCompileOnly)
            {
                return(null);
            }

            var exceptions           = new List <DeploymentItemException>();
            var statementNames       = new List <DeploymentInformationItem>();
            var statements           = new List <EPStatement>();
            var eventTypesReferenced = new HashSet <string>();

            foreach (ModuleItem item in module.Items)
            {
                if (item.IsCommentOnly)
                {
                    continue;
                }

                string statementName = null;
                Object userObject    = null;
                if (options.StatementNameResolver != null || options.StatementUserObjectResolver != null)
                {
                    var ctx = new StatementDeploymentContext(item.Expression, module, item, deploymentId);
                    statementName = options.StatementNameResolver != null
                        ? options.StatementNameResolver.GetStatementName(ctx)
                        : null;

                    userObject = options.StatementUserObjectResolver != null
                        ? options.StatementUserObjectResolver.GetUserObject(ctx)
                        : null;
                }

                try
                {
                    EPStatement stmt;
                    if (options.IsolatedServiceProvider == null)
                    {
                        stmt = _epService.CreateEPL(item.Expression, statementName, userObject);
                    }
                    else
                    {
                        EPServiceProviderIsolated unit =
                            _statementIsolationService.GetIsolationUnit(options.IsolatedServiceProvider, -1);
                        stmt = unit.EPAdministrator.CreateEPL(item.Expression, statementName, userObject);
                    }
                    statementNames.Add(new DeploymentInformationItem(stmt.Name, stmt.Text));
                    statements.Add(stmt);

                    string[] types = _statementEventTypeRef.GetTypesForStatementName(stmt.Name);
                    if (types != null)
                    {
                        eventTypesReferenced.AddAll(types);
                    }
                }
                catch (EPException ex)
                {
                    exceptions.Add(new DeploymentItemException(ex.Message, item.Expression, ex, item.LineNumber));
                    if (options.IsFailFast)
                    {
                        break;
                    }
                }
            }

            if (!exceptions.IsEmpty())
            {
                if (options.IsRollbackOnFail)
                {
                    Log.Debug("Rolling back intermediate statements for deployment");
                    foreach (EPStatement stmt in statements)
                    {
                        try
                        {
                            stmt.Dispose();
                        }
                        catch (Exception ex)
                        {
                            Log.Debug("Failed to destroy created statement during rollback: " + ex.Message, ex);
                        }
                    }
                    EPLModuleUtil.UndeployTypes(
                        eventTypesReferenced, _statementEventTypeRef, _eventAdapterService, _filterService);
                }
                string text = "Deployment failed";
                if (options.IsValidateOnly)
                {
                    text = "Validation failed";
                }
                throw BuildException(text, module, exceptions);
            }

            if (options.IsValidateOnly)
            {
                Log.Debug("Rolling back created statements for validate-only");
                foreach (EPStatement stmt in statements)
                {
                    try
                    {
                        stmt.Dispose();
                    }
                    catch (Exception ex)
                    {
                        Log.Debug("Failed to destroy created statement during rollback: " + ex.Message, ex);
                    }
                }
                EPLModuleUtil.UndeployTypes(
                    eventTypesReferenced, _statementEventTypeRef, _eventAdapterService, _filterService);
                return(null);
            }

            DeploymentInformationItem[] deploymentInfoArr = statementNames.ToArray();
            var desc = new DeploymentInformation(
                deploymentId, module, addedDate, DateTimeEx.GetInstance(_timeZone), deploymentInfoArr,
                DeploymentState.DEPLOYED);

            _deploymentStateService.AddUpdateDeployment(desc);

            if (Log.IsDebugEnabled)
            {
                Log.Debug("Module " + module + " was successfully deployed.");
            }
            return(new DeploymentResult(desc.DeploymentId, statements.AsReadOnlyList(), imports));
        }
Esempio n. 27
0
		public object Clone()
		{
			var result = new DateTimeEx(DateTime);

			result.OutFormat = this.OutFormat;
			result.OutLocale = this.OutLocale;
			result.TimeZoneID = this.TimeZoneID;

			return result;
		}
Esempio n. 28
0
        public Object Evaluate(DateTimeOffset d, EventBean[] eventsPerStream, bool newData, ExprEvaluatorContext exprEvaluatorContext)
        {
            DateTimeEx dtx = DateTimeEx.GetInstance(_timeZone, d);

            return(dtx);
        }
Esempio n. 29
0
 public override void SetDateTimeEx(DateTimeEx value)
 {
     m_text = "'" + value.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture) + "'";
 }
Esempio n. 30
0
 public Object Evaluate(DateTimeEx dtx, EventBean[] eventsPerStream, bool newData, ExprEvaluatorContext exprEvaluatorContext)
 {
     return(dtx);
 }
Esempio n. 31
0
 public void SetDateTimeEx(DateTimeEx value)
 {
     m_text = value.ToString(m_settings.DateTimeFormat, CultureInfo.InvariantCulture);
 }
        public static string ColumnFormatter(int row, int cell, object value, Column columnDef, object dataContext)
        {
            string typeName;
            string returnValue = String.Empty;

            if (columnDef.DataType != null)
            {
                typeName = columnDef.DataType;
            }
            else
            {
                typeName = value.GetType().Name;
            }

            Entity entityContext = (Entity)dataContext;
            bool   unchanged     = (entityContext.EntityState == null) || (entityContext.EntityState == EntityStates.Unchanged);

            // If unchanged we can get values from the formatted values
            if (unchanged && entityContext.FormattedValues != null && entityContext.FormattedValues.ContainsKey(columnDef.Field + "name"))
            {
                returnValue = entityContext.FormattedValues[columnDef.Field + "name"];
                return(returnValue);
            }
            if (value != null)
            {
                switch (typeName.ToLowerCase())
                {
                case "string":
                    returnValue = value.ToString();
                    break;

                case "boolean":
                case "bool":
                    returnValue = value.ToString();
                    break;

                case "dateTime":
                case "date":
                    DateTime dateValue  = (DateTime)value;
                    string   dateFormat = "dd/mm/yy";
                    string   timeFormat = "hh:MM";
                    if (OrganizationServiceProxy.UserSettings != null)
                    {
                        dateFormat = OrganizationServiceProxy.UserSettings.DateFormatString;
                        timeFormat = OrganizationServiceProxy.UserSettings.TimeFormatString;
                    }
                    returnValue = DateTimeEx.FormatDateSpecific(dateValue, dateFormat) + " " + DateTimeEx.FormatTimeSpecific(dateValue, timeFormat);
                    break;

                case "decimal":
                    returnValue = value.ToString();
                    break;

                case "double":
                    returnValue = value.ToString();
                    break;

                case "int":
                    returnValue = value.ToString();
                    break;

                case "guid":
                    returnValue = value.ToString();
                    break;

                case "money":
                    Money moneyValue = (Money)value;

                    returnValue = moneyValue.Value.ToString();
                    break;

                case "customer":
                case "owner":
                case "lookup":
                case "entityreference":
                    EntityReference refValue = (EntityReference)value;
                    returnValue = @"<a class=""sparkle-grid-link"" href=""#"" logicalName=""" + refValue.LogicalName + @""" id=""" + refValue.Id + @""">" + refValue.Name + "</a>";
                    break;

                case "picklist":
                case "status":
                case "state":
                case "optionsetvalue":
                    OptionSetValue optionValue = (OptionSetValue)value;
                    returnValue = optionValue.Name;
                    break;

                case "primarynamelookup":
                    string lookupName = value == null ? "" : value.ToString();
                    returnValue = @"<a class=""sparkle-grid-link"" href=""#"" primaryNameLookup=""1"">" + lookupName + "</a>";
                    break;
                }
            }
            return(returnValue);
        }