Ejemplo n.º 1
0
    /// <summary>
    /// 生成配置表对应的脚本文件
    /// </summary>
    private void GenerateCSFile()
    {
        if (dataTable == null || dataTable.Count <= 0)
        {
            if (generateType == GenerateType.Single_File)
            {
                ReadFileTable();
            }
            else if (generateType == GenerateType.Folder_Files)
            {
                ReadFoldTable();
            }
        }
        if (dataTable == null || dataTable.Count <= 0)
        {
            Debug.LogError("Excel read error");
        }
        for (int i = 0; i < dataTable.Count; i++)
        {
            //获取表里的字段参数
            int row = dataTable[i].Rows.Count;
            int col = dataTable[i].Columns.Count;
            List <ParameterDto> parameters = new List <ParameterDto>();
            string parName = "";
            string parNote = "";
            for (int j = 0; j < col; j++)
            {
                parNote = dataTable[i].Rows[2][j].ToString();
                parName = dataTable[i].Rows[1][j].ToString();
                if (string.IsNullOrEmpty(parName))
                {
                    continue;
                }
                Type         parType   = GetTypeByString(dataTable[i].Rows[0][j].ToString());
                ParameterDto parameter = new ParameterDto(j, parName, parNote, parType.ToString());
                parameters.Add(parameter);
            }

            //生成配置脚本
            CSharpCodeDom sharpCodeDom = new CSharpCodeDom();
            //根
            sharpCodeDom.CreatCodeDomUnit();
            //命名空间
            sharpCodeDom.AddNamespace("ED");
            //配置脚本类
            object class1 = sharpCodeDom.CreateCustomerClass(dataTable[i].TableName);
            //添加字段
            sharpCodeDom.AddFieldForClass(class1, parameters);
            //添加特性
            sharpCodeDom.AddAttributrDeclaration(class1, typeof(System.SerializableAttribute));

            string outPath = csOutPath + "/" + dataTable[i].TableName + ".cs";
            //生成代码文件
            if (sharpCodeDom.CodeDomGenerate(outPath))
            {
                //生成配置列表类
                GenerateListCS(dataTable[i]);
            }
        }
    }
Ejemplo n.º 2
0
        private async Task <ActionResult <ParameterDto> > Update(ParameterDto parameter, Action <ParameterDto, ParameterBase> updateUnitAction = null)
        {
            if (parameter == null)
            {
                return(BadRequest());
            }

            var param = await _db.Parameters.SingleOrDefaultAsync(p => p.Id == parameter.Id);

            if (param == null)
            {
                return(BadRequest());
            }

            param.Name = parameter.Name;

            updateUnitAction?.Invoke(parameter, param);

            _db.Parameters.Update(param);
            var savedEntities = await _db.SaveChangesAsync();

            if (savedEntities <= 0)
            {
                return(BadRequest());
            }

            return(parameter);
        }
        public static ParameterDto GetParameters(JiewStoreEntities context)
        {
            ParameterDto result = new ParameterDto
            {
                PointPerAmount = 50f
            };

            result.PointPerAmount = GetPointPerAmount(context);

            var tierQry = from t in context.CustomerTiers
                          select new TierLevelDto()
            {
                ID        = t.ID,
                Name      = t.Name,
                MinAmount = t.MinAmount,
                MaxAmount = t.MaxAmount
            };

            if (tierQry.Any())
            {
                result.TierLevels = tierQry.ToArray();
            }

            return(result);
        }
Ejemplo n.º 4
0
        public void CanBeConstructed()
        {
            //Arrange
            ParameterDto sut;

            //Act
            sut = new ParameterDto();

            //Assert
            Assert.NotNull(sut);
        }
Ejemplo n.º 5
0
 private void UpdateUnitValue(ParameterDto parameter, ParameterBase param)
 {
     if (parameter is AnalogParameterDto analog &&
         param is AnalogParameter analogParameterEntity)
     {
         var unit = _mapper.Map <Unit>(analog.Unit);
         _db.Entry(unit)
         .State = EntityState.Unchanged;
         analogParameterEntity.Unit = unit;
     }
 }
Ejemplo n.º 6
0
 public async Task <IActionResult> ConvertTextToMorse([FromBody] ParameterDto parameter)
 {
     try
     {
         if (parameter.text == "" || parameter.text == null)
         {
             return(BadRequest("Debe ingresar un texto con el texto a traducir"));
         }
         string morse = decoderService.Translate2Morse(parameter.text.ToLower());
         return(Ok(morse));
     }
     catch (Exception ex)
     {
         return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
     }
 }
Ejemplo n.º 7
0
 public async Task <IActionResult> ConvertMorseToText([FromBody] ParameterDto parameter)
 {
     try
     {
         if (parameter.text == "" || parameter.text == null)
         {
             return(BadRequest("Debe ingresar un texto con el código morse a traducir"));
         }
         string text = decoderService.Translate2Human(parameter.text.ToLower());
         if (text == "")
         {
             return(BadRequest("Debe ingresar un texto válido en código morse para traducir"));
         }
         return(Ok(text));
     }
     catch (Exception ex)
     {
         return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
     }
 }
        public virtual ActionResult Update(ParameterDto dto)
        {
            var entityRepo = _repository.GetById(dto.Id);

            if (entityRepo == null)
            {
                return(NotFound());
            }

            if (string.IsNullOrEmpty(dto.Value))
            {
                return(ValidationProblem("Debe ingresar un valor"));
            }

            var entity = _mapper.Map <Parameter>(dto);

            _repository.Update(entity);

            return(Ok(dto));
        }
Ejemplo n.º 9
0
        public async Task Store(Subscription subscription, CancellationToken cancellationToken)
        {
            var parameters      = new List <ParameterDto>();
            var parameterValues = new List <ParameterValueDto>();

            using var transaction = _connection.BeginTransaction();
            var subscriptionId = await transaction.InsertAsync(SubscriptionDto.Create(subscription), cancellationToken);

            for (short id = 0; id < subscription.Parameters.Count; id++)
            {
                parameters.Add(ParameterDto.Create(subscription.Parameters[id], id, subscriptionId));
                parameterValues.AddRange(subscription.Parameters[id].Values.Select(x => ParameterValueDto.Create(x, id, subscriptionId)));
            }

            await transaction.BulkInsertAsync(parameters, cancellationToken);

            await transaction.BulkInsertAsync(parameterValues, cancellationToken);

            transaction.Commit();
        }
Ejemplo n.º 10
0
        public void CanBeSerialized()
        {
            //Arrange
            var sut = new ParameterDto()
            {
                Name      = "name",
                ParamType = "type",
                Value     = "value",
                Overwrite = true,
                Tags      = new Dictionary <string, string>().ToArray(),
                Version   = 1
            };

            //Act
            var payload = JsonSerializer.Serialize(sut, new JsonSerializerOptions {
                IgnoreNullValues = true
            });

            //Assert
            Assert.NotNull(JsonDocument.Parse(payload));
        }
Ejemplo n.º 11
0
        public PartialViewResult GetMapDetail(int?id, string name)
        {
            var model = TempData.Peek("List") as List <ParameterDto>;
            var data  = new ParameterDto
            {
                Name = "Bodrum",

                Phone = "23232",
                Url   = "csds"
            };

            if (model != null && id != null && name != "")
            {
                data = model.FirstOrDefault(x => x.Id == id && x.Name == name);
                if (data == null)
                {
                    throw new ArgumentNullException(nameof(data));
                }
            }
            return(PartialView("_GetMapDetail", data));
        }
Ejemplo n.º 12
0
 public IList <string> Resolve(Parameter source, ParameterDto destination, IList <string> destMember,
                               ResolutionContext context)
 {
     return(source.Values.Select(i => i.Value).ToList());
 }
Ejemplo n.º 13
0
 public Parameter(ParameterDto dto)
 {
     _dto = dto;
 }
Ejemplo n.º 14
0
        public void ProcessMethodString(string joinedString, MethodDto currentMethod)
        {
            var searchState = MethodSearchState.Begin;
            ParameterDto currentParameter = null;
            var wordBuilder = new Stack<char>();

            for (var i = joinedString.Length - 1; i >= 0; i--)
            {
                switch (searchState)
                {
                    case MethodSearchState.Begin:
                        if (joinedString[i] == ')')
                        {
                            searchState = MethodSearchState.ClosingParen;
                        }
                        break;
                    case MethodSearchState.ClosingParen:
                        if (char.IsWhiteSpace(joinedString[i]) || joinedString[i] == '(')
                        {
                            if (wordBuilder.Any())
                            {
                                var word = new string(wordBuilder.ToArray());
                                wordBuilder.Clear();
                                if (currentParameter == null)
                                {
                                    currentParameter = new ParameterDto
                                    {
                                        ParameterName = word,
                                        BelongsToMethod = currentMethod
                                    };
                                }
                                else
                                {
                                    currentParameter.ParamterType = word;
                                }
                            }
                            if (joinedString[i] == '(')
                            {
                                searchState = MethodSearchState.OpenParen;
                                if(currentParameter != null)
                                {
                                    currentMethod.Parameters.Add(currentParameter);
                                    currentParameter = null;
                                }
                            }
                        }
                        else if (joinedString[i] == ',')
                        {
                            currentMethod.Parameters.Add(currentParameter);
                            currentParameter = null;
                        }
                        else
                        {
                            wordBuilder.Push(joinedString[i]);
                        }
                        break;
                    case MethodSearchState.OpenParen:
                        if (char.IsWhiteSpace(joinedString[i]))
                        {
                            if (wordBuilder.Any())
                            {
                                var word = new string(wordBuilder.ToArray());
                                wordBuilder.Clear();
                                currentMethod.MethodName = word;
                                searchState = MethodSearchState.Name;
                            }
                        }
                        else
                        {
                            wordBuilder.Push(joinedString[i]);
                        }
                        break;
                    case MethodSearchState.Name:
                        if (char.IsWhiteSpace(joinedString[i]))
                        {
                            if (wordBuilder.Any())
                            {
                                var word = new string(wordBuilder.ToArray());
                                wordBuilder.Clear();
                                currentMethod.ReturnType = word;
                                searchState = MethodSearchState.Type;
                            }
                        }
                        else
                        {
                            wordBuilder.Push(joinedString[i]);
                        }
                        break;
                    case MethodSearchState.Type:
                        return;
                    default:
                        break;
                }
            }
        }