Ejemplo n.º 1
0
        public static DateTimeOffset?GetNullableTime(this Func <DdeTableColumn, object> func, DdeTable table, DdeTableColumn dateColumn, DdeTableColumn timeColumn, DdeTableColumn mcsColumn)
        {
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }

            var date = func.GetNullable2 <DateTime>(dateColumn);

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

            var time = func.GetNullable2 <TimeSpan>(timeColumn);

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

            var dateTime = date.Value + time.Value;

            if (table.Columns.Contains(mcsColumn))
            {
                dateTime = dateTime.AddMilliseconds(func.Get <double>(mcsColumn) / 1000);
            }

            return(dateTime.ApplyTimeZone(TimeHelper.Moscow));
        }
Ejemplo n.º 2
0
        public static void Deserialize(this DdeTable table, IList <IList <object> > rows, Action <IList <object>, Func <DdeTableColumn, object> > handler, Action <Exception> errorHandler, bool skipErrors)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            if (rows == null)
            {
                throw new ArgumentNullException("rows");
            }

            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            if (errorHandler == null)
            {
                throw new ArgumentNullException("errorHandler");
            }

            try
            {
                var errors = new List <Exception>();

                foreach (var r in rows)
                {
                    try
                    {
                        var row = r;

                        handler(row, column =>
                        {
                            var index = table.Columns.IndexOf(column);

                            if (index == -1)
                            {
                                throw new InvalidOperationException(LocalizedStrings.Str1711Params.Put(table.Caption, column.Name));
                            }

                            if (row.Count <= index)
                            {
                                throw new InvalidOperationException(LocalizedStrings.Str1703Params.Put(table.Caption, column.Name, row.Count, index));
                            }

                            return(row[index]);
                        });
                    }
                    catch (Exception ex)
                    {
                        if (skipErrors)
                        {
                            errors.Add(ex);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }

                foreach (var error in errors)
                {
                    errorHandler(error);
                }
            }
            catch (Exception ex)
            {
                errorHandler(ex);
            }
        }
Ejemplo n.º 3
0
 public static DateTimeOffset GetTime(this Func <DdeTableColumn, object> func, DdeTable table, DdeTableColumn dateColumn, DdeTableColumn timeColumn, DdeTableColumn mcsColumn)
 {
     return(func.GetNullableTime(table, dateColumn, timeColumn, mcsColumn) ?? DateTimeOffset.MinValue);
 }