Пример #1
0
        // ReSharper restore EmptyGeneralCatchClause


        public static bool TrySave([NotNull] Map mapToSave, [NotNull] string fileName, MapFormat format)
        {
            if (mapToSave == null)
            {
                throw new ArgumentNullException("mapToSave");
            }
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (format == MapFormat.Unknown)
            {
                throw new ArgumentException("Format may not be \"Unknown\"", "format");
            }

            if (AvailableConverters.ContainsKey(format))
            {
                IMapConverter converter = AvailableConverters[format];
                try {
                    return(converter.Save(mapToSave, fileName));
                } catch (Exception ex) {
                    Logger.LogAndReportCrash("Map failed to save", "MapConversion", ex, false);
                    return(false);
                }
            }

            throw new MapFormatException("Unknown map format for saving.");
        }
 public ArrayConverter(Func <int, Array> allocator, int length, byte filler, int elementSize, IMapConverter elementConverter)
 {
     this.allocator        = allocator;
     this.length           = length;
     this.filler           = filler;
     this.elementSize      = elementSize;
     this.elementConverter = elementConverter;
 }
Пример #3
0
        public MapBuilder(IList<IMapBuilderCommand> commands, IMapConverter converter)
        {
            Throw.IfNullOrHasNull(commands, nameof(commands));
            Throw.IfNull(converter, nameof(converter));

            this.commands = commands;
            this.converter = converter;
        }
Пример #4
0
 /// <summary> Registers a new map importer or exporter.
 /// Only one importer/exporter may be registered for each supported format.
 /// If an importer/exporter for the given format has already been registered, it will be replaced. </summary>
 /// <param name="converter"> New converter to add. </param>
 /// <exception cref="ArgumentException"> Given IMapConverter is nether an IMapImporter, nor an IMapExporter. </exception>
 public static void RegisterConverter( IMapConverter converter ) {
     IMapImporter asImporter = converter as IMapImporter;
     IMapExporter asExporter = converter as IMapExporter;
     if( asImporter != null ) Importers.Add( asImporter.Format, asImporter );
     if( asExporter != null ) Exporters.Add( asExporter.Format, asExporter );
     if( asImporter == null && asExporter == null ) {
         throw new ArgumentException( "Given converter is neither an IMapImporter nor an IMapExporter." );
     }
 }
 public MemberMapper(
     int offset,
     IMapConverter converter,
     Func <object, object> getter,
     Action <object, object> setter)
 {
     this.offset    = offset;
     this.converter = converter;
     this.getter    = getter;
     this.setter    = setter;
 }
Пример #6
0
        public void Update <T>(IEnumerable <IEnumerable <T> > input, IMapConverter <T, Organization> converter = null)
        {
            int counter = 0;

            foreach (var block in input)
            {
                Update <T>(block, converter);
                Logger.Logger.Info(string.Join(" ", typeof(Data_Organization_2748).Name, "Обработан", counter.ToString(), "блок из", input.Count().ToString()));
                counter++;
            }
        }
Пример #7
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public DungeonGenerator()
        {
            mPreProcessors = new List <IMapPreProcessor <BinaryCell> >()
            {
                new MazeGenerator <BinaryCell>(),
                new SparsenessReducer <BinaryCell>(),
                new DeadendsRemover <BinaryCell>()
            };

            mMapConverter = new MapDoubler <T, BinaryCell>();

            mPostProcessors = new List <IMapProcessor <T> >()
            {
                new RoomGenerator <T>(),
                new DoorGenerator <T>()
            };
        }
Пример #8
0
        public static void RegisterConverter(IMapConverter converter)
        {
            IMapImporter asImporter = converter as IMapImporter;
            IMapExporter asExporter = converter as IMapExporter;

            if (asImporter != null)
            {
                Importers.Add(asImporter.Format, asImporter);
            }
            if (asExporter != null)
            {
                Exporters.Add(asExporter.Format, asExporter);
            }
            if (asImporter == null && asExporter == null)
            {
                throw new ArgumentException("Given converter is neither an IMapImporter nor an IMapExporter.");
            }
        }
        public void Setup()
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var context = CreateBuilderContext();

            // Default

            // Binary
            var intBinaryBuilder = new BinaryConverterBuilder();

            intBinaryConverter = intBinaryBuilder.CreateConverter(context, typeof(int));
            intBinaryBuffer    = new byte[intBinaryBuilder.CalcSize(typeof(int))];

            // Boolean
            var booleanBuilder = new BooleanConverterBuilder();

            booleanConverter = booleanBuilder.CreateConverter(context, typeof(bool));
            booleanBuffer    = new byte[] { 0x30 };

            // bytes
            var bytes10Builder = new BytesConverterBuilder {
                Length = 10
            };

            bytes10Converter = bytes10Builder.CreateConverter(context, typeof(byte[]));
            bytes10Buffer    = new byte[bytes10Builder.CalcSize(typeof(byte[]))];

            var bytes20Builder = new BytesConverterBuilder {
                Length = 20
            };

            bytes20Converter = bytes20Builder.CreateConverter(context, typeof(byte[]));
            bytes20Buffer    = new byte[bytes20Builder.CalcSize(typeof(byte[]))];

            // Text
            var text20Builder = new TextConverterBuilder {
                Length = 20
            };

            text20Converter      = text20Builder.CreateConverter(context, typeof(string));
            text20Single20Buffer = SjisEncoding.GetFixedBytes(Text20Single10, 20);
            text20Wide10Buffer   = SjisEncoding.GetFixedBytes(Text20Wide5, 20);
            text20EmptyBuffer    = SjisEncoding.GetFixedBytes(Text20Empty, 20);

            // Number
            var numberTextShort4Builder = new NumberTextConverterBuilder {
                Length = 4
            };

            numberTextShort4Converter  = numberTextShort4Builder.CreateConverter(context, typeof(short));
            numberTextShort4MaxBuffer  = SjisEncoding.GetFixedBytes(Length4Integer.ToString(CultureInfo.InvariantCulture), 4, FixedAlignment.Right);
            numberTextShort4ZeroBuffer = SjisEncoding.GetFixedBytes(ZeroInteger.ToString(CultureInfo.InvariantCulture), 4, FixedAlignment.Right);

            var numberTextInt8Builder = new NumberTextConverterBuilder {
                Length = 8
            };

            numberTextInt8Converter  = numberTextInt8Builder.CreateConverter(context, typeof(int));
            numberTextInt8MaxBuffer  = SjisEncoding.GetFixedBytes(Length8Integer.ToString(CultureInfo.InvariantCulture), 8, FixedAlignment.Right);
            numberTextInt8ZeroBuffer = SjisEncoding.GetFixedBytes(ZeroInteger.ToString(CultureInfo.InvariantCulture), 8, FixedAlignment.Right);

            var numberTextLong18Builder = new NumberTextConverterBuilder {
                Length = 18
            };

            numberTextLong18Converter  = numberTextLong18Builder.CreateConverter(context, typeof(long));
            numberTextLong18MaxBuffer  = SjisEncoding.GetFixedBytes(Length18Integer.ToString(CultureInfo.InvariantCulture), 18, FixedAlignment.Right);
            numberTextLong18ZeroBuffer = SjisEncoding.GetFixedBytes(ZeroInteger.ToString(CultureInfo.InvariantCulture), 18, FixedAlignment.Right);

            var numberTextDecimal8Builder = new NumberTextConverterBuilder {
                Length = 8
            };

            numberTextDecimal8Converter  = numberTextDecimal8Builder.CreateConverter(context, typeof(decimal));
            numberTextDecimal8MaxBuffer  = SjisEncoding.GetFixedBytes(Length8Decimal.ToString(CultureInfo.InvariantCulture), 8, FixedAlignment.Right);
            numberTextDecimal8ZeroBuffer = SjisEncoding.GetFixedBytes("0.00", 10, FixedAlignment.Right);

            var numberTextDecimal18Builder = new NumberTextConverterBuilder {
                Length = 18
            };

            numberTextDecimal18Converter  = numberTextDecimal18Builder.CreateConverter(context, typeof(decimal));
            numberTextDecimal18MaxBuffer  = SjisEncoding.GetFixedBytes(Length18Decimal.ToString(CultureInfo.InvariantCulture), 19, FixedAlignment.Right);
            numberTextDecimal18ZeroBuffer = SjisEncoding.GetFixedBytes("0.000", 19, FixedAlignment.Right);

            var numberTextDecimal28Builder = new NumberTextConverterBuilder {
                Length = 28
            };

            numberTextDecimal28Converter  = numberTextDecimal28Builder.CreateConverter(context, typeof(decimal));
            numberTextDecimal28MaxBuffer  = SjisEncoding.GetFixedBytes(Length28Decimal.ToString(CultureInfo.InvariantCulture), 29, FixedAlignment.Right);
            numberTextDecimal28ZeroBuffer = SjisEncoding.GetFixedBytes("0.0000", 29, FixedAlignment.Right);

            // DateTime
            var dateTimeText8Builder = new DateTimeTextConverterBuilder {
                Length = 8, Format = "yyyyMMdd"
            };

            dateTimeText8Converter = dateTimeText8Builder.CreateConverter(context, typeof(DateTime));
            dateTimeText8Buffer    = SjisEncoding.GetFixedBytes(DateTime8.ToString("yyyyMMdd"), 8);

            var dateTimeText14Builder = new DateTimeTextConverterBuilder {
                Length = 14, Format = "yyyyMMddHHmmss"
            };

            dateTimeText14Converter = dateTimeText14Builder.CreateConverter(context, typeof(DateTime));
            dateTimeText14Buffer    = SjisEncoding.GetFixedBytes(DateTime14.ToString("yyyyMMddHHmmss"), 14);

            var dateTimeText17Builder = new DateTimeTextConverterBuilder {
                Length = 17, Format = "yyyyMMddHHmmssfff"
            };

            dateTimeText17Converter = dateTimeText17Builder.CreateConverter(context, typeof(DateTime));
            dateTimeText17Buffer    = SjisEncoding.GetFixedBytes(DateTime17.ToString("yyyyMMddHHmmssfff"), 17);

            // Options

            // ASCII
            var text13Builder = new TextConverterBuilder {
                Length = 13, Encoding = Encoding.ASCII
            };

            text13Converter = text13Builder.CreateConverter(context, typeof(string));
            var ascii13Builder = new AsciiConverterBuilder {
                Length = 13
            };

            ascii13Converter = ascii13Builder.CreateConverter(context, typeof(string));
            ascii13Buffer    = new byte[ascii13Builder.CalcSize(typeof(string))];

            // Unicode
            var text30Builder = new TextConverterBuilder {
                Length = 30, Encoding = Encoding.Unicode
            };

            text30Converter = text30Builder.CreateConverter(context, typeof(string));
            var ascii30Builder = new UnicodeConverterBuilder {
                Length = 30
            };

            unicode30Converter = ascii30Builder.CreateConverter(context, typeof(string));
            unicode30Buffer    = new byte[ascii30Builder.CalcSize(typeof(string))];

            // Integer
            var short4Builder = new IntegerConverterBuilder {
                Length = 4
            };

            short4Converter  = short4Builder.CreateConverter(context, typeof(short));
            short4MaxBuffer  = SjisEncoding.GetFixedBytes(Length4Integer.ToString(CultureInfo.InvariantCulture), 4, FixedAlignment.Right);
            short4ZeroBuffer = SjisEncoding.GetFixedBytes(ZeroShort.ToString(CultureInfo.InvariantCulture), 4, FixedAlignment.Right);

            var int8Builder = new IntegerConverterBuilder {
                Length = 8
            };

            int8Converter  = int8Builder.CreateConverter(context, typeof(int));
            int8MaxBuffer  = SjisEncoding.GetFixedBytes(Length8Integer.ToString(CultureInfo.InvariantCulture), 8, FixedAlignment.Right);
            int8ZeroBuffer = SjisEncoding.GetFixedBytes(ZeroInteger.ToString(CultureInfo.InvariantCulture), 8, FixedAlignment.Right);

            var long18Builder = new IntegerConverterBuilder {
                Length = 18
            };

            long18Converter  = long18Builder.CreateConverter(context, typeof(long));
            long18MaxBuffer  = SjisEncoding.GetFixedBytes(Length18Integer.ToString(CultureInfo.InvariantCulture), 18, FixedAlignment.Right);
            long18ZeroBuffer = SjisEncoding.GetFixedBytes(ZeroLong.ToString(CultureInfo.InvariantCulture), 18, FixedAlignment.Right);

            // Decimal
            var decimal8Builder = new DecimalConverterBuilder {
                Length = 10, Scale = 2
            };

            decimal8Converter  = decimal8Builder.CreateConverter(context, typeof(decimal));
            decimal8MaxBuffer  = SjisEncoding.GetFixedBytes(Length8Decimal.ToString(CultureInfo.InvariantCulture), 10, FixedAlignment.Right);
            decimal8ZeroBuffer = SjisEncoding.GetFixedBytes("0.00", 10, FixedAlignment.Right);

            var decimal18Builder = new DecimalConverterBuilder {
                Length = 19, Scale = 3
            };

            decimal18Converter  = decimal18Builder.CreateConverter(context, typeof(decimal));
            decimal18MaxBuffer  = SjisEncoding.GetFixedBytes(Length18Decimal.ToString(CultureInfo.InvariantCulture), 19, FixedAlignment.Right);
            decimal18ZeroBuffer = SjisEncoding.GetFixedBytes("0.000", 19, FixedAlignment.Right);

            var decimal28Builder = new DecimalConverterBuilder {
                Length = 29, Scale = 4
            };

            decimal28Converter  = decimal28Builder.CreateConverter(context, typeof(decimal));
            decimal28MaxBuffer  = SjisEncoding.GetFixedBytes(Length28Decimal.ToString(CultureInfo.InvariantCulture), 29, FixedAlignment.Right);
            decimal28ZeroBuffer = SjisEncoding.GetFixedBytes("0.0000", 29, FixedAlignment.Right);

            // DateTime
            var dateTime8Builder = new DateTimeConverterBuilder {
                Format = "yyyyMMdd"
            };

            dateTime8Converter = dateTime8Builder.CreateConverter(context, typeof(DateTime));
            dateTime8Buffer    = SjisEncoding.GetFixedBytes(DateTime8.ToString("yyyyMMdd"), 8);

            var dateTime14Builder = new DateTimeConverterBuilder {
                Format = "yyyyMMddHHmmss"
            };

            dateTime14Converter = dateTime14Builder.CreateConverter(context, typeof(DateTime));
            dateTime14Buffer    = SjisEncoding.GetFixedBytes(DateTime14.ToString("yyyyMMddHHmmss"), 14);

            var dateTime17Builder = new DateTimeConverterBuilder {
                Format = "yyyyMMddHHmmssfff"
            };

            dateTime17Converter = dateTime17Builder.CreateConverter(context, typeof(DateTime));
            dateTime17Buffer    = SjisEncoding.GetFixedBytes(DateTime17.ToString("yyyyMMddHHmmssfff"), 17);
        }
Пример #10
0
        public void Update <T>(IEnumerable <T> input, IMapConverter <T, Organization> converter = null)
        {
            int counter = 0;
            IEnumerable <Organization> mappedblock;

            mappedblock = (converter == null)? input.Select(s => Mapper.Map <T, Organization>(s)).ToList(): converter.Convert(input).ToList();
            foreach (var itemUpserted in mappedblock)
            {
                if (itemUpserted.PersonPositions == null)
                {
                    itemUpserted.PersonPositions = new List <PersonPosition>();
                }
                if (itemUpserted.PhoneItems == null)
                {
                    itemUpserted.PhoneItems = new List <UNS.Models.Entities.PhoneItem>();
                }
                if (itemUpserted.EmailItems == null)
                {
                    itemUpserted.EmailItems = new List <UNS.Models.Entities.EmailItem>();
                }
                if (itemUpserted.FaxItems == null)
                {
                    itemUpserted.FaxItems = new List <UNS.Models.Entities.FaxItem>();
                }
                var family     = itemUpserted.PersonPositions.Any() ? itemUpserted.PersonPositions.FirstOrDefault().Person.Family : null;
                var name       = itemUpserted.PersonPositions.Any() ? itemUpserted.PersonPositions.FirstOrDefault().Person.Name : null;
                var patronimic = itemUpserted.PersonPositions.Any() ? itemUpserted.PersonPositions.FirstOrDefault().Person.Patronymic : null;

                var itemsFinded = ContexUNS.Organizations
                                  .Include("PhoneItems")
                                  .Include("FaxItems")
                                  .Include("EmailItems")
                                  .Include("OwnerRawAddresses")
                                  .Include("PersonPositions")
                                  .Where(W => W.FullName.ToLower().Trim() == itemUpserted.FullName.ToLower().Trim()).ToList();
                if (itemsFinded.Any())
                {
                    if (itemsFinded.Count() == 1)
                    {
                        try
                        {
                            var y = itemsFinded.FirstOrDefault();
                            var t = Mapper.Map <Organization, Organization>(itemUpserted, y);
                            ContexUNS.Organizations.AddOrUpdate(t);
                            //ContexUNS.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            Logger.Logger.Error(e.Message);

                            /*var changedEntries = ContexUNS.ChangeTracker.Entries()
                             *  .Where(x => x.State != EntityState.Unchanged).ToList();
                             *
                             * foreach (var entry in changedEntries)
                             * {
                             *  switch (entry.State)
                             *  {
                             *      case EntityState.Modified:
                             *          entry.CurrentValues.SetValues(entry.OriginalValues);
                             *          entry.State = EntityState.Unchanged;
                             *          break;
                             *      case EntityState.Added:
                             *          entry.State = EntityState.Detached;
                             *          break;
                             *      case EntityState.Deleted:
                             *          entry.State = EntityState.Unchanged;
                             *          break;
                             *  }
                             * }*/
                        }
                        Logger.Logger.Info(string.Join(" ", typeof(T).Name, "Изменено", input.Count().ToString(), "всего", counter.ToString()));
                        counter++;
                    }
                }
                else
                {
                    ContexUNS.Organizations.Add(itemUpserted);
                    try
                    {
                        //ContexUNS.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Logger.Logger.Error(e.Message);

                        /*var changedEntries = ContexUNS.ChangeTracker.Entries()
                         *  .Where(x => x.State != EntityState.Unchanged).ToList();
                         *
                         * foreach (var entry in changedEntries)
                         * {
                         *  switch (entry.State)
                         *  {
                         *      case EntityState.Modified:
                         *          entry.CurrentValues.SetValues(entry.OriginalValues);
                         *          entry.State = EntityState.Unchanged;
                         *          break;
                         *      case EntityState.Added:
                         *          entry.State = EntityState.Detached;
                         *          break;
                         *      case EntityState.Deleted:
                         *          entry.State = EntityState.Unchanged;
                         *          break;
                         *  }
                         * }*/
                    }
                    Logger.Logger.Info(string.Join(" ", typeof(T).Name, "Добавлено", counter.ToString(), "Из", input.Count().ToString()));
                    counter++;
                }
            }
            ContexUNS.SaveChanges();
        }
Пример #11
0
 public SedimentologicalDataImporter(string filePath, string[] headerNames, IMapConverter <TSedimentologicalData> mapConverter)
 {
     _filePath     = filePath;
     _headerNames  = headerNames;
     _mapConverter = mapConverter;
 }