Exemplo n.º 1
0
        void BuildViewCtrl_Populated(INodeItem nodeItem, NodeItemView node, bool bPopulatedFieldsOnly)
        {
            if (null == nodeItem)
            {
                return;
            }

            ISchemaItem  item    = nodeItem.Schema;
            NodeItemView subNode = null;

            if ((item.IsGroup && nodeItem.AnySubItemHasRepetition) || item.IsMessage || (!item.RepetitionContainerNode && !item.StructureDefOnlyNode))
            {
                if (null == item)
                {
                    return;//dead end
                }

                subNode = new NodeItemView();

                FillViewInfo(nodeItem, subNode);
                BuildViewCtrl_Fields(nodeItem, subNode, bPopulatedFieldsOnly);

                node.Nodes.Add(subNode);
            }
            else
            {
                subNode = node;
            }

            foreach (INodeItem sub in nodeItem.Nodes)
            {
                BuildViewCtrl_Populated(sub, subNode, bPopulatedFieldsOnly);
            }
        }
        private string FormatOneToOne(ISchemaItem row, int indent)
        {
            var result = string.Empty;

            if ((row.IsPrimaryKey && row.IsForeignKey && !row.RelatedTable.IsBlank()))
            {
                var relatedTable = row.RelatedTable;
                if (row.RelatedTable == row.TableName)  //Indicating a table related to itself
                {
                    relatedTable = row.ColumnName + NavigationLabel();
                }

                result += Environment.NewLine;
                result += Indent(indent - 4) + "// OneToOne (" + relatedTable + "<->" + _table + ")".AddCarriage();
                result += Indent(indent - 4) + "entity.HasOne(p => p." + relatedTable + ")".AddCarriage();
                result += Indent(indent) + ".WithOne(i => i." + _table + ")".AddCarriage();
                result += Indent(indent) + ".HasForeignKey<" + _table + ">(b => b." + GetPrimaryKey(_table) + ")";

                if (row.ConstraintName.IsBlank())
                {
                    result += ";";
                }
                else
                {
                    result += "".AddCarriage() + Indent(indent) + ".HasConstraintName(" + row.ConstraintName.AddQuotes() + ");";
                }
            }
            return(result);
        }
 protected override void Context()
 {
     _context    = A.Fake <IExecutionContext>();
     _schemaItem = A.Fake <ISchemaItem>();
     _schema     = A.Fake <Schema>();
     sut         = new AddSchemaItemToSchemaCommand(_schemaItem, _schema, _context);
 }
Exemplo n.º 4
0
        private void copyParameterValues(ISchemaItem schemaItem, IContainer targetContainer)
        {
            _parameterSetUpdater.UpdateValuesByName(schemaItem, targetContainer);

            //now that parameter have been set, we need to update the dose by hand according to the selected unit
            var inputDose         = schemaItem.Dose;
            var doseDimension     = _dimensionRepository.Mass;
            var dose              = targetContainer.Parameter(CoreConstants.Parameter.DOSE);
            var dosePerBodyWeight = targetContainer.Parameter(CoreConstants.Parameter.DOSE_PER_BODY_WEIGHT);

            //dose exists in the dose dimension=> we need to set the parameter dose in the target container

            //We have a dose in mg
            if (doseDimension.GetUnitNames().Contains(inputDose.DisplayUnit.Name))
            {
                //we have to create a constant value for the dose parameter
                dose.Formula = _objectBaseFactory.Create <ConstantFormula>().WithValue(inputDose.Value).WithDimension(_dimensionRepository.Mass);
                _parameterSetUpdater.UpdateValue(inputDose, dose);
                dose.Visible = true;
                dosePerBodyWeight.Visible           = false;
                dosePerBodyWeight.BuildingBlockType = PKSimBuildingBlockType.Simulation;
            }
            else
            {
                //in that case. We have a dose in mg/kg
                _parameterSetUpdater.UpdateValue(inputDose, dosePerBodyWeight);
                dosePerBodyWeight.Visible = true;
                dose.Visible           = false;
                dose.BuildingBlockType = PKSimBuildingBlockType.Simulation;
            }
        }
        /// <summary>
        /// Dls the tag detail.
        /// </summary>
        /// <param name="column">The column.</param>
        private void DlTagDetail(ISchemaItem column)
        {
            if (column == null)
            {
                return;
            }
            var foreignKeyTable = column.RelatedTable;

            AppendText(Indent(8) + "<dt>");
            if (column.IsForeignKey)
            {
                AppendText(Indent(12) + DisplayNameFor(foreignKeyTable, 0, null, null));
            }
            else
            {
                AppendText(Indent(12) + DisplayNameFor(column.ColumnName, 0, null, null));
            }
            AppendText(Indent(8) + "</dt>");

            AppendText(Indent(8) + "<dd>");
            if (column.IsForeignKey)
            {
                var label = GetTableLabel(foreignKeyTable);
                if (string.IsNullOrEmpty(label))
                {
                    label = column.ColumnName;
                }
                AppendText(Indent(12) + DisplayForModel(foreignKeyTable + "." + label, 0, null, null));
            }
            else
            {
                AppendText(Indent(12) + DisplayForModel(column.ColumnName, 0, null, null));
            }
            AppendText(Indent(8) + "</dd>");
        }
        /// <summary>
        /// Displays for model item.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <returns>System.String.</returns>
        public string DisplayForModelItem(ISchemaItem column)
        {
            var foreignKeyTable = column.RelatedTable;

            if (column.IsForeignKey)
            {
                var label = GetTableLabel(foreignKeyTable);
                if (string.IsNullOrEmpty(label))
                {
                    label = column.ColumnName;
                }

                if (column.RelatedTable == column.TableName) //A Table related to itself
                {
                    return(DisplayForModelItem(GetSelfRelatedColumnName(column), 0, null, null));
                }
                else
                {
                    //return DisplayForModelItem(foreignKeyTable + "." + label, 0, null, null);
                    return(DisplayForModelItem(GetLookupDisplayColumnWithPath(column.TableName, column.ColumnName), 0, null, null));
                }
            }
            else
            {
                return(DisplayForModelItem(column.ColumnName, 0, null, null));
            }
            //
        }
Exemplo n.º 7
0
 public static string ColumnField(this ISchemaItem schemaItem)
 {
     //return  _space + "Field=@nameof(" + schemaItem.TableName + "." + schemaItem.ColumnName + ")";
     return(_space +
            General.SetValue("Field", schemaItem.ColumnName)); //+
     //General.SetValue("TValue", schemaItem.TableName) + ")";
 }
Exemplo n.º 8
0
        private void updateDose(ISchemaItem schemaItem, IContainer targetContainer, IFormulaCache formulaCache)
        {
            //now that parameter have been set, we need to update the dose by hand according to the selected unit
            var inputDose = schemaItem.Dose;

            var dose = targetContainer.Parameter(CoreConstants.Parameters.DOSE);
            var dosePerBodyWeight      = targetContainer.Parameter(CoreConstants.Parameters.DOSE_PER_BODY_WEIGHT);
            var dosePerBodySurfaceArea = targetContainer.Parameter(CoreConstants.Parameters.DOSE_PER_BODY_SURFACE_AREA);

            if (schemaItem.DoseIsInMass())
            {
                //we have to create a constant value for the dose parameter
                dose.Formula = _formulaFactory.ValueFor(inputDose.Value, _dimensionRepository.Mass);
                updateDoseParameter(inputDose, dose, dosePerBodyWeight, dosePerBodySurfaceArea);
            }
            else if (schemaItem.DoseIsPerBodyWeight())
            {
                dose.Formula = _formulaFactory.DoseFromDosePerBodyWeightFor(formulaCache);
                updateDoseParameter(inputDose, dosePerBodyWeight, dose, dosePerBodySurfaceArea);
            }
            else if (schemaItem.DoseIsPerBodySurfaceArea())
            {
                dose.Formula = _formulaFactory.DoseFromDosePerBodySurfaceAreaFor(formulaCache);
                updateDoseParameter(inputDose, dosePerBodySurfaceArea, dose, dosePerBodyWeight);
            }
        }
        private string GetHttpGet(ISchemaItem column, int indent)
        {
            var relatedTable = column.RelatedTable;
            var tableVar     = relatedTable.ToLower();
            var table        = (tableVar + "/{id}").AddQuotes();

            var result = string.Empty;

            result += Indent(indent) + "[HttpGet(" + table + ")]".AddCarriage();
            result += Indent(indent) + "[Produces(typeof(List<" + column.TableName + "ApiModel>))]".AddCarriage();
            result += Indent(indent) + "public async Task<ActionResult<" + column.TableName + "ApiModel>> GetBy" + relatedTable + "Id(int id, CancellationToken ct = default)".AddCarriage();
            result += Indent(indent) + "{".AddCarriage();
            result += Indent(indent + 4) + "try".AddCarriage();
            result += Indent(indent + 4) + "{".AddCarriage();
            result += Indent(indent + 8) + "var " + tableVar + " = await _" + GetProjectNameLower() + "Supervisor.Get" + relatedTable + "ByIdAsync(id, ct);".AddCarriage();
            result += Indent(indent + 8) + "if (" + tableVar + " == null)".AddCarriage();
            result += Indent(indent + 8) + "{".AddCarriage();
            result += Indent(indent + 12) + "return NotFound();".AddCarriage();
            result += Indent(indent + 8) + "}".AddCarriage();
            result += Indent(indent + 8) + "return Ok(" + tableVar + ");".AddCarriage();
            result += Indent(indent + 4) + "}".AddCarriage();
            result += Indent(indent + 4) + "catch (Exception ex)".AddCarriage();
            result += Indent(indent + 4) + "{".AddCarriage();
            result += Indent(indent + 8) + "return StatusCode(500, ex);".AddCarriage();
            result += Indent(indent + 4) + "}".AddCarriage();
            result += Indent(indent) + "}".AddCarriage();
            return(result);
        }
Exemplo n.º 10
0
        string ConvertType(ISchemaItem column, string col)
        {
            var convertType = string.Empty;

            switch (column.ColumnType)
            {
            case "long":
                convertType = "ToInt64";
                break;

            case "string":
                convertType = "ToString";
                break;

            case "DateTime":
                convertType = "ToDateTime";
                break;

            case "bool":
                convertType = "ToBoolean";
                break;

            case "int":
                convertType = "ToInt32";
                break;

            case "decimal":
                convertType = "ToDecimal";
                break;

            case "double":
                convertType = "ToDouble";
                break;
            }
            var convert = "Convert." + convertType + "(values[" + col + "])";

            if (column.AllowDbNull)
            {
                switch (column.ColumnType)
                {
                case "string":
                    convertType = "null;";
                    break;

                case "short":
                    convertType = "(short)values[" + col + "] != null ? " + convert + " : (" + column.ColumnType + "?)null;";
                    break;

                default:
                    convertType = "values[" + col + "] != null ? " + convert + " : (" + column.ColumnType + "?)null;";
                    break;
                }
            }
            else
            {
                convertType = convert + ";";
            }

            return(convertType);
        }
Exemplo n.º 11
0
 protected override void Context()
 {
     base.Context();
     _schemaItem = A.Fake <ISchemaItem>();
     _schema     = A.Fake <Schema>();
     A.CallTo(() => _schema.SchemaItems).Returns(new[] { _schemaItem });
 }
Exemplo n.º 12
0
 public SetSchemaItemApplicationTypeCommand(ISchemaItem schemaItem, ApplicationType newApplicationType)
 {
     ObjectType          = PKSimConstants.ObjectTypes.AdministrationProtocol;
     CommandType         = PKSimConstants.Command.CommandTypeEdit;
     _schemaItem         = schemaItem;
     _newApplicationType = newApplicationType;
 }
Exemplo n.º 13
0
        void BuildViewCtrl_Schema(INodeItem nodeItem, NodeItemView node)
        {
            if (null == nodeItem)
            {
                return;
            }

            ISchemaItem  item    = nodeItem.Schema;
            NodeItemView subNode = null;

            if (!item.RepetitionContainerNode && (item.StructureDefOnlyNode || item.IsMessage))
            {
                if (null == item)
                {
                    return;//dead end
                }

                subNode = new NodeItemView();

                FillViewInfo(nodeItem, subNode);
                BuildViewCtrl_Fields(nodeItem, subNode, false);

                node.Nodes.Add(subNode);
            }
            else
            {
                subNode = node;
            }

            foreach (INodeItem sub in nodeItem.Nodes)
            {
                BuildViewCtrl_Schema(sub, subNode);
            }
        }
Exemplo n.º 14
0
 protected override void Context()
 {
     _context        = A.Fake <IExecutionContext>();
     _schemaItem     = A.Fake <ISchemaItem>();
     _formulationKey = "tralala";
     sut             = new SetSchemaItemFormulationKeyCommand(_schemaItem, _formulationKey, _context);
 }
        private void GetCollectionNavigation(ISchemaItem item)
        {
            var column  = Singularize(item.TableName, _preserveTableName);
            var columns = Pluralize(item.TableName, _preserveTableName);

            BuildSnippet(_iCollectionList, _public + "virtual ICollection<" + column + "> " + columns + _getSet + " = new HashSet<" + column + ">();", 8);
        }
 /// <summary>
 /// Gets the null sign.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>System.String.</returns>
 public string GetNullSign(ISchemaItem item)
 {
     return
         (item.AllowDbNull && (item.ColumnType == "DateTime" || item.ColumnType == "int") &&
          !item.IsPrimaryKey //disallow nullablity for primary keys
             ? "?" : string.Empty);
 }
        public ISchemaItem SchemaItemUpdater(ISchemaItem schemaitem)
        {
            return(UpdateSchemaItem(schemaitem));

            //MessageBox.Show(schemaitem.ParentId + ", " + schemaitem.TableName);
            //throw new NotImplementedException(schemaitem.ParentId+", "+schemaitem.TableName);
        }
Exemplo n.º 18
0
        private string GetFluentProperties(ISchemaItem row, int indent)
        {
            var result = string.Empty;

            result += Indent(indent) + ".HasColumnName(" + row.ColumnName.AddQuotes() + ")".AddCarriage();
            result += Indent(indent) + ".HasColumnType(" + row.ColumnType.AddQuotes() + ")".AddCarriage();
            if (row.IsRequired)
            {
                result += Indent(indent) + ".IsRequired()".AddCarriage();
            }

            //if (!row.ConstraintName.IsBlank())
            //    result += Indent(indent) + ".ConstraintName(" + row.ConstraintName.AddQuotes() + ")";

            if (row.ColumnType == "string" && row.ColumnSize > 0)
            {
                result += Indent(indent) + ".HasMaxLength(" + row.ColumnSize + ")";
            }

            var lastChar = result.Substring(result.Length - 2);

            if (lastChar == Environment.NewLine)
            {
                result = result.Remove(result.Length - 2, 2);
            }

            result += ";".AddCarriage();

            result += Indent(indent) + FormatOneToMany(row, indent);
            //result += Indent(indent) + FormatOneToOne(row, indent);
            return(result);
        }
 /// <summary>
 /// Selfs the reference nav property.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>System.String.</returns>
 public static string SelfRefNavProperty(this ISchemaItem item)
 {
     if (item.TableName != item.RelatedTable)
     {
         return(string.Empty);
     }
     return("Inverse" + item.ColumnName + "Navigation");
 }
Exemplo n.º 20
0
        public SchemaItemDTO MapFrom(ISchemaItem schemaItem)
        {
            var schemaItemDTO = new SchemaItemDTO(schemaItem);

            schemaItemDTO.DoseParameter      = _parameterDTOMapper.MapFrom(schemaItem.Dose, schemaItemDTO, x => x.Dose, x => x.DoseParameter);
            schemaItemDTO.StartTimeParameter = _parameterDTOMapper.MapFrom(schemaItem.StartTime, schemaItemDTO, x => x.StartTime, x => x.StartTimeParameter);
            return(schemaItemDTO);
        }
 /// <summary>
 /// Selfs the reference column.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>System.String.</returns>
 public static string SelfReferenceColumn(this ISchemaItem item)
 {
     if (item.TableName != item.RelatedTable)
     {
         return(string.Empty);
     }
     return(item.ColumnName + "Navigation");
 }
Exemplo n.º 22
0
 private void convertSchemaItem(ISchemaItem schemaItem)
 {
     if (schemaItem == null)
     {
         return;
     }
     schemaItem.Dose.Visible = true;
 }
Exemplo n.º 23
0
        public IPKSimCommand RemoveSchemaItemFrom(ISchemaItem schemaItemToDelete, Schema schema)
        {
            if (schema.SchemaItems.Count() <= 1)
            {
                throw new CannotDeleteSchemaItemException();
            }

            return(new RemoveSchemaItemFromSchemaCommand(schemaItemToDelete, schema, _executionContext).Run(_executionContext));
        }
        private static bool isIntravenous(ISchemaItem schemaItem)
        {
            if (schemaItem == null)
            {
                return(false);
            }

            return(schemaItem.ApplicationType == ApplicationTypes.Intravenous || schemaItem.ApplicationType == ApplicationTypes.IntravenousBolus);
        }
        private static bool isOral(ISchemaItem schemaItem)
        {
            if (schemaItem == null)
            {
                return(false);
            }

            return(schemaItem.ApplicationType == ApplicationTypes.Oral);
        }
Exemplo n.º 26
0
        public static bool ParameterShouldBeExported(this ISchemaItem schemaItem, IParameter parameter)
        {
            if (parameter.IsNamed(Constants.Parameters.START_TIME))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 27
0
 protected override void Context()
 {
     base.Context();
     _container         = new Container();
     _schemaItemToClone = A.Fake <ISchemaItem>();
     _clone             = A.Fake <ISchemaItem>();
     A.CallTo(() => _cloner.Clone(_schemaItemToClone)).Returns(_clone);
     A.CallTo(_containerTask).WithReturnType <string>().Returns("NEW NAME");
 }
 protected override void Context()
 {
     _executionContext = A.Fake <IExecutionContext>();
     _schemaItem       = new SchemaItem {
         ApplicationType = ApplicationTypes.IntravenousBolus
     };
     _newApplicationType = ApplicationTypes.Intravenous;
     sut = new ChangeApplicationTypeCommand(_schemaItem, _newApplicationType, _executionContext);
 }
 public SetSchemaItemFormulationKeyCommand(ISchemaItem schemaItem, string newFormulationKey, IExecutionContext context)
 {
     _schemaItem        = schemaItem;
     _newFormulationKey = newFormulationKey;
     _schemaItemId      = _schemaItem.Id;
     ObjectType         = PKSimConstants.ObjectTypes.AdministrationProtocol;
     CommandType        = PKSimConstants.Command.CommandTypeEdit;
     BuildingBlockId    = context.BuildingBlockIdContaining(schemaItem);
     context.UpdateBuildinBlockPropertiesInCommand(this, context.BuildingBlockContaining(schemaItem));
 }
 public SetSchemaItemTargetCompartmentCommand(ISchemaItem schemaItem, string newTargetCompartment, IExecutionContext context)
 {
     _schemaItem           = schemaItem;
     _newTargetCompartment = newTargetCompartment;
     _schemaItemId         = _schemaItem.Id;
     ObjectType            = PKSimConstants.ObjectTypes.AdministrationProtocol;
     CommandType           = PKSimConstants.Command.CommandTypeEdit;
     BuildingBlockId       = context.BuildingBlockIdContaining(schemaItem);
     context.UpdateBuildinBlockProperties(this, context.BuildingBlockContaining(schemaItem));
 }