Пример #1
0
 /// <summary>
 /// 请求数据绑定
 /// </summary>
 /// <param name="address"></param>
 /// <param name="value"></param>
 void requestBindDataAddr_ValueChanged(DbAddress address, string value)
 {
     //PrintInfo.DottedLine();
     PrintInfo.I("请求数据绑定:{0}->{1}", address.oldValue, address.value);
     if (address.value == "1")
     {
         BindDataResult(CommandValue.INITIAL_STATE);
         PrintInfo.I("托盘数据处理结果地址归1");
     }
     if (address.value == "2")
     {
         PrintInfo.I("请求数据绑定(自动)");
         BindData("2");
     }
     if (address.value == "3")
     {
         PrintInfo.I("请求数据绑定(手动)");
         BindData("3");
     }
     if (address.value == "4")
     {
         PrintInfo.I("请求清除数据");
         ClearCacheData();
         BindDataResult(CommandValue.CLEAR_DATA_COMPLETE);
     }
 }
Пример #2
0
 /// <summary>
 /// Gets true when the DbAddress entity or all property is Null otherwise false.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static bool IsEmpty(this DbAddress value) =>
 value == null ||
 (value.City.IsNullOrEmpty() &&
  value.Country.IsNullOrEmpty() &&
  value.Street.IsNullOrEmpty() &&
  value.Location == null
 );
Пример #3
0
 /// <summary>
 /// Gets Address entity from DbAddress entity.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static Address ToAddress(this DbAddress value) =>
 value.IsEmpty() ? null : new Address
 {
     Country  = value.Country,
     City     = value.City,
     Street   = value.Street,
     Location = value.Location.ToLocation()
 };
Пример #4
0
 private DbAddress GetAddressWithId(int id, DbAddress address)
 {
     return(new DbAddress()
     {
         Id = id,
         Street = address.Street,
         Number = address.Number,
         Type = address.Type,
         Country = address.Country,
         ZipCode = address.ZipCode,
         City = address.City
     });
 }
Пример #5
0
 /// <summary>
 /// 托盘到达请求扫码
 /// </summary>
 /// <param name="address"></param>
 /// <param name="value"></param>
 void trayArrivedAddr_ValueChanged(DbAddress address, string value)
 {
     //PrintInfo.DottedLine();
     PrintInfo.I("请求扫码:{0}->{1}", address.oldValue, address.value);
     if (address.value == "1")
     {
         ScanCodeFeedback(CommandValue.INITIAL_STATE, CommandValue.INITIAL_STATE);
         PrintInfo.I("扫码反馈归1,异常信息归1");
     }
     if (address.value == "2")
     {
         TrayArrived();
     }
 }
Пример #6
0
        public static DbAddress ToDbModel(this AddressDto dto)
        {
            var dbAddress = new DbAddress()
            {
                Id      = dto.Id,
                Street  = dto.Street,
                Number  = dto.Number,
                City    = dto.City,
                Country = dto.Country,
                ZipCode = dto.ZipCode,
                Type    = (EDbAddressType)(int)dto.Type
            };

            return(dbAddress);
        }
Пример #7
0
        public static AddressDto ToDto(this DbAddress dbAddress)
        {
            var dto = new AddressDto()
            {
                Id      = dbAddress.Id,
                Street  = dbAddress.Street,
                Number  = dbAddress.Number,
                City    = dbAddress.City,
                Country = dbAddress.Country,
                ZipCode = dbAddress.ZipCode,
                Type    = (EAddressTypeDto)(int)dbAddress.Type
            };

            return(dto);
        }
        public object ReadItem(string address)
        {
            lock (this)
            {
                try
                {
                    if (DbAddress.ContainsKey(address))
                    {
                        var addr  = DbAddress[address];
                        var db_id = addr.DBBlockID;

                        var offset = (short)(addr.Offset - _dbStartAddress[db_id]);

                        if (addr.Type == "bool")
                        {
                            var _buf         = _dbAreaBuf[db_id];
                            var _result_byte = _buf[offset];

                            var result = (_result_byte & (1 << addr.BitOffset)) != 0;
                            return(result);
                        }

                        if (addr.Type == "int16")
                        {
                            var _buf       = _dbAreaBuf[db_id];
                            var _low_byte  = _buf[offset];
                            var _high_byte = _buf[offset + 1];

                            //Int16 result = (Int16)(_high_byte << 8 + _low_byte);
                            var result = (short)((_low_byte << 8) + _high_byte);
                            return(result);
                        }

                        if (addr.Type == "int32")
                        {
                            var _buf   = _dbAreaBuf[db_id];
                            var _byte1 = _buf[offset];
                            var _byte2 = _buf[offset + 1];
                            var _byte3 = _buf[offset + 2];
                            var _byte4 = _buf[offset + 3];

                            //Int32 result = (Int32)(_byte4 << 24 + _byte3 << 16 + _byte2 << 8 + _byte1);
                            var result = (_byte1 << 24) + (_byte2 << 16) + (_byte3 << 8) + _byte4;
                            return(result);
                        }

                        if (addr.Type == "string")
                        {
                            var _buf   = _dbAreaBuf[db_id];
                            var result =
                                Encoding.ASCII.GetString(_buf, offset + 2,
                                                         _buf[offset + 1]); //西门子字符串前两位要空出来,读取长度根据第2个字节
                            return(result);
                        }

                        if (addr.Type == "ByteArray") //2020/6/11 ByteArray
                        {
                            var _buf   = _dbAreaBuf[db_id];
                            var result = Encoding.ASCII.GetString(_buf, offset, addr.BitOffset);
                            return(result);
                        }

                        throw new Exception("Tag类型不支持");
                    }

                    if (_mAddress.ContainsKey(address))
                    {
                        var addr   = _mAddress[address];
                        var offset = (short)(addr.Offset - _mAreaMinAddress);
                        var _buf   = _mAreaBuf;

                        if (addr.Type == "bool")
                        {
                            var _result_byte = _buf[offset];

                            var result = (_result_byte & (1 << addr.BitOffset)) != 0;
                            return(result);
                        }

                        if (addr.Type == "int16")
                        {
                            var _low_byte  = _buf[offset];
                            var _high_byte = _buf[offset + 1];

                            var result = (short)((_low_byte << 8) + _high_byte);
                            return(result);
                        }

                        if (addr.Type == "int32")
                        {
                            var _byte1 = _buf[offset];
                            var _byte2 = _buf[offset + 1];
                            var _byte3 = _buf[offset + 2];
                            var _byte4 = _buf[offset + 3];

                            //Int32 result = (Int32)(_byte4 << 24 + _byte3 << 16 + _byte2 << 8 + _byte1);
                            var result = (_byte1 << 24) + (_byte2 << 16) + (_byte3 << 8) + _byte4;
                            return(result);
                        }
                    }
                    else
                    {
                        throw new Exception("_dbAddress或_MAddress不包含该地址!");
                    }
                }
                catch (Exception ex)
                {
                    //LOG.Error(string.Format("地址{0}读取错:{1}", address, ex));
                    Log.Error($"Address:{address} readed error,Message:{ex},IP地址时{_plc.IP}");
                }

                return(null);
            }
        }
Пример #9
0
        public IEnumerable <DbDiscount> Get(uint count, List <string> listUserId, GeoCountry geo)
        {
            var locationGenerator = new Faker <DbLocation>("ru")
                                    .RuleFor(x => x.Latitude, f => f.Address.Latitude())
                                    .RuleFor(x => x.Longitude, f => f.Address.Longitude())
            ;

            var dbLocation = locationGenerator.Generate();

            var companyGenerator = new Faker <DbCompany>("ru")
                                   .RuleFor(x => x.Name, f => f.Company.CompanyName())
                                   .RuleFor(x => x.Description, f => string.Join(" ", f.Commerce.Categories(15).Distinct().ToList()))
                                   .RuleFor(x => x.PhoneNumber, f => f.Phone.PhoneNumber("+!!! !! !!!-!!-!!"))
                                   .RuleFor(x => x.Mail, f => f.Person.Email)
            ;

            var streetRu = new Faker <ValueString>("ru")
                           .RuleFor(x => x.Value, x => x.Address.StreetAddress())
                           .Generate();

            var addressRu = new DbAddress()
            {
                Country  = geo.CountryRu,
                City     = geo.CityRu,
                Street   = streetRu.Value,
                Location = dbLocation
            }
            ;

            var dbUserGenerator = new Faker <DbUser>("ru")
                                  .RuleFor(x => x.Id, f => Guid.NewGuid().ToString())
                                  .RuleFor(x => x.Name, f => f.Person.FirstName)
                                  .RuleFor(x => x.Surname, f => f.Person.LastName)
                                  .RuleFor(x => x.PhoneNumber, f => f.Phone.PhoneNumber("+!!! !! !!!-!!-!!"))
                                  .RuleFor(x => x.Mail, f => f.Person.Email)
            ;

            var companyTranslationGenerator = new Faker <DbTranslationCompany>("en")
                                              .RuleFor(x => x.Name, f => f.Company.CompanyName())
                                              .RuleFor(x => x.Description, f => f.Commerce.ProductDescription())
            ;

            var streetEn = new Faker <ValueString>("en")
                           .RuleFor(x => x.Value, x => x.Address.StreetAddress())
                           .Generate();

            var addressEn = new DbTranslationAddress()
            {
                Country = geo.CountryEn,
                City    = geo.CityEn,
                Street  = streetEn.Value
            }
            ;

            var translationGenerator = new Faker <DbTranslation>("en")
                                       .RuleFor(x => x.Language, f => "english")
                                       .RuleFor(x => x.Name, f => f.Commerce.ProductName())
                                       .RuleFor(x => x.Description, f => f.Commerce.ProductDescription())
                                       .RuleFor(x => x.Address, f => addressEn)
                                       .RuleFor(x => x.Company, f => companyTranslationGenerator.Generate())
                                       .RuleFor(x => x.Tags, f => f.Commerce.Categories(15).Distinct().ToList())
            ;

            var promocodeOptionGenerator = new Faker <DbPromocodeOptions>()
                                           .RuleFor(x => x.EnabledPromocodes, f => f.Random.Bool())
                                           .RuleFor(x => x.CountActivePromocodePerUser, f => f.Random.Int(1, 5))
                                           .RuleFor(x => x.CountSymbolsPromocode, f => f.Random.Int(4, 7))
                                           .RuleFor(x => x.DaysDurationPromocode, f => f.Random.Int(5, 15))
                                           .RuleFor(x => x.TimeLimitAddingInSeconds, f => f.Random.Int(1, 5))
            ;

            var discountGenerator = new Faker <DbDiscount>("ru")
                                    .StrictMode(true)
                                    .RuleFor(x => x.Id, f => Guid.NewGuid().ToString())
                                    .RuleFor(x => x.Name, f => f.Commerce.ProductName())
                                    .RuleFor(x => x.Description, f => string.Join(" ", f.Commerce.Categories(15).Distinct().ToList()))
                                    .RuleFor(x => x.AmountOfDiscount, f => f.Random.Int(500, 7000) / 100)
                                    .RuleFor(x => x.StartDate, f => f.Date.Between(DateTime.Now - TimeSpan.FromDays(700), DateTime.Now))
                                    .RuleFor(x => x.EndDate,
                                             f => f.Date.Between(DateTime.Now + TimeSpan.FromDays(1), DateTime.Now + TimeSpan.FromDays(700)))
                                    .RuleFor(x => x.Address, f => addressRu)
                                    .RuleFor(x => x.Company, f => companyGenerator.Generate())
                                    .RuleFor(x => x.PictureUrl, f => f.Image.LoremFlickrUrl())
                                    .RuleFor(x => x.WorkingDaysOfTheWeek,
                                             f => string.Join("", f.Random.Int(0, 1), f.Random.Int(0, 1), f.Random.Int(0, 1),
                                                              f.Random.Int(0, 1), f.Random.Int(0, 1), f.Random.Int(0, 1), f.Random.Int(0, 1)))
                                    .RuleFor(x => x.Tags, f => f.Commerce.Categories(15).Distinct().ToList())
                                    .RuleFor(x => x.RatingTotal, f => f.Random.Int(0, 4) + f.Random.Int(1, 9) / 10)
                                    .RuleFor(x => x.ViewsTotal, f => f.Random.Int(0, 100))
                                    .RuleFor(x => x.UsersSubscriptionTotal, f => f.Random.Int(0, 50))
                                    .RuleFor(x => x.SubscriptionsTotal, f => f.Random.Int(0, 50))
                                    .RuleFor(x => x.Language, f => "russian")
                                    .RuleFor(x => x.Deleted, f => false)

                                    .RuleFor(x => x.CreateDate,
                                             f => f.Date.Between(DateTime.Now - TimeSpan.FromDays(700),
                                                                 DateTime.Now - TimeSpan.FromDays(60)))
                                    .RuleFor(x => x.LastChangeDate,
                                             f => f.Date.Between(DateTime.Now - TimeSpan.FromDays(60), DateTime.Now))
                                    .RuleFor(x => x.UserCreateDate, f => dbUserGenerator.Generate())
                                    .RuleFor(x => x.UserLastChangeDate, f => dbUserGenerator.Generate())

                                    .RuleFor(x => x.UsersPromocodes, f => null)
                                    .RuleFor(x => x.FavoritesUsersId, f => RandomFromListUserId(listUserId, 3))
                                    .RuleFor(x => x.RatingUsersId, f => RandomFromListUserId(listUserId, 5))

                                    .RuleFor(x => x.Translations, f => translationGenerator.Generate(1))

                                    .RuleFor(x => x.PromocodeOptions, f => promocodeOptionGenerator.Generate())
            ;

            for (var i = 0; i < count; i++)
            {
                yield return(discountGenerator.Generate());
            }
        }