Beispiel #1
0
 /// <summary>
 /// Validates the state of the model.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns>true or false</returns>
 protected bool ValidateModelState(ISection model)
 {
     if (model != null && model.ActionStatus == ButtonActionStatus.SaveAsDraft)
     {
         List <string> listOfError = this.GetErrorKeys();
         ModelState.Clear();
         foreach (PropertyInfo prop in model.GetType().GetProperties())
         {
             if (prop.GetCustomAttribute <RequiredOnDraft>() != null && listOfError.Contains(prop.Name))
             {
                 ModelState.AddModelError(prop.Name, prop.Name);
             }
         }
     }
     else if (model != null && model.ActionStatus == ButtonActionStatus.SendBack)
     {
         //List<string> listOfError = this.GetErrorKeys();
         ModelState.Clear();
         foreach (PropertyInfo prop in model.GetType().GetProperties())
         {
             // Here, check if required on send back attribute is true and the respective field is null then throw validation.
             if (prop.GetCustomAttribute <RequiredOnSendBack>() != null && prop.GetValue(model) == null)
             {
                 ModelState.AddModelError(prop.Name, prop.Name);
             }
         }
     }
     else if (model != null && model.ActionStatus == ButtonActionStatus.Delegate)
     {
         //List<string> listOfError = this.GetErrorKeys();
         ModelState.Clear();
         foreach (PropertyInfo prop in model.GetType().GetProperties())
         {
             // Here, check if required on delegate attribute is true and the respective field is null then throw validation.
             if (prop.GetCustomAttribute <RequiredOnDelegate>() != null && prop.GetValue(model) == null)
             {
                 ModelState.AddModelError(prop.Name, prop.Name);
             }
         }
     }
     else if (model != null && model.ActionStatus == ButtonActionStatus.SaveAndNoStatusUpdate)
     {
         //List<string> listOfError = this.GetErrorKeys();
         ModelState.Clear();
         foreach (PropertyInfo prop in model.GetType().GetProperties())
         {
             ModelState.Remove(prop.Name);
         }
     }
     return(ModelState.IsValid);
 }
Beispiel #2
0
        public OsuFile(string filePath)
        {
            const string verFlag = "osu file format v";

            string[]       lines = File.ReadAllLines(filePath).Where(l => l.Trim() != "").ToArray();
            PropertyInfo[] t     = GetType().GetProperties().Where(p =>
                                                                   p.PropertyType.GetInterfaces().Contains(typeof(ISection)) ||
                                                                   p.PropertyType.BaseType == typeof(KeyValueSection)).ToArray();
            ISection currentSecion = null;

            foreach (var line in lines)
            {
                if (MatchedSection(line, out var sectionName))
                {
                    if (currentSecion != null)
                    {
                        t.First(p => p.Name == currentSecion.GetType().Name).SetValue(this, currentSecion);
                    }


                    if (t.Select(p => p.Name).Contains(sectionName))
                    {
                        var      type = t.First(p => p.Name == sectionName).PropertyType;
                        object[] args = { };
                        if (type == typeof(HitObjects))
                        {
                            args = new object[] { this }
                        }
                        ;
                        currentSecion = Activator.CreateInstance(type, args) as ISection;
                    }
                    else
                    {
                        throw new BadOsuFormatException("存在未知的节点: " + sectionName);
                    }
                }
                else
                {
                    switch (currentSecion)
                    {
                    case null when line.StartsWith(verFlag):
                        var str = line.Replace(verFlag, "");

                        if (!int.TryParse(str, out var verNum))
                        {
                            throw new BadOsuFormatException("未知的osu版本: " + str);
                        }
                        if (verNum < 7)
                        {
                            throw new VersionNotSupportedException(verNum);
                        }
                        Version = verNum;
                        break;

                    case null:
                        throw new BadOsuFormatException("存在问题头声明: " + line);

                    default:
                        currentSecion.Match(line);
                        break;
                    }
                }
            }

            if (currentSecion != null)
            {
                t.First(p => p.Name == currentSecion.GetType().Name).SetValue(this, currentSecion);
            }
        }
Beispiel #3
0
        public object Property1DToNative(Property1D property1D)
        {
            int numbMaterial = 0;

            string[] materials = null;
            Model.PropFrame.GetNameList(ref numbMaterial, ref materials);
            if (property1D.material != null)
            {
                if (!materials.Contains(property1D.material.name))
                {
                    MaterialToNative(property1D.material);
                }
            }
            else
            {
                Material material = new Material("default", Structural.MaterialType.Steel, "Grade 50", "United States", "ASTM A992");
                property1D.material = material;
                MaterialToNative(property1D.material);
            }

            var catalogue = new Catalogue();

            if (property1D.profile.GetType().Equals(catalogue.GetType()))
            {
                Catalogue sectionProfile = (Catalogue)property1D.profile;

                switch (sectionProfile.catalogueName)
                {
                case "CA":
                    sectionProfile.catalogueName = "CISC10";
                    break;
                }


                Model.PropFrame.ImportProp(property1D.name, property1D.material.name, sectionProfile.catalogueName + ".xml", sectionProfile.sectionName.ToUpper());
                return(property1D.name);
            }
            var rectangle = new Rectangular();

            if (property1D.profile.GetType().Equals(rectangle.GetType()))
            {
                if (property1D.material.materialType == Structural.MaterialType.Concrete)
                {
                    Rectangular sectionProfile = (Rectangular)property1D.profile;
                    Model.PropFrame.SetRectangle(property1D.name, property1D.material.name, sectionProfile.depth, sectionProfile.width);
                    return(property1D.name);
                }
                else
                {
                    Rectangular sectionProfile = (Rectangular)property1D.profile;
                    Model.PropFrame.SetTube(property1D.name, property1D.material.name, sectionProfile.depth, sectionProfile.width, sectionProfile.flangeThickness, sectionProfile.webThickness);
                    return(property1D.name);
                }
            }

            var circular = new Circular();

            if (property1D.profile.GetType().Equals(circular.GetType()))
            {
                if (property1D.material.materialType == Structural.MaterialType.Concrete)
                {
                    Circular sectionProfile = (Circular)property1D.profile;
                    Model.PropFrame.SetCircle(property1D.name, property1D.material.name, sectionProfile.radius * 2);
                    return(property1D.name);
                }
                else
                {
                    Circular sectionProfile = (Circular)property1D.profile;
                    Model.PropFrame.SetPipe(property1D.name, property1D.material.name, sectionProfile.radius * 2, sectionProfile.wallThickness);
                    return(property1D.name);
                }
            }

            var T = new Tee();

            if (property1D.profile.GetType().Equals(T.GetType()))
            {
                Tee sectionProfile = (Tee)property1D.profile;
                Model.PropFrame.SetConcreteTee(property1D.name, property1D.material.name, sectionProfile.depth, sectionProfile.width, sectionProfile.flangeThickness, sectionProfile.webThickness, sectionProfile.webThickness, false);
                return(property1D.name);
            }

            var I = new ISection();

            if (property1D.profile.GetType().Equals(I.GetType()))
            {
                ISection sectionProfile = (ISection)property1D.profile;
                Model.PropFrame.SetISection(property1D.name, property1D.material.name, sectionProfile.depth, sectionProfile.width, sectionProfile.flangeThickness, sectionProfile.webThickness, sectionProfile.width, sectionProfile.flangeThickness);
                return(property1D.name);
            }

            var Channel = new Channel();

            if (property1D.profile.GetType().Equals(Channel.GetType()))
            {
                Channel sectionProfile = (Channel)property1D.profile;
                Model.PropFrame.SetChannel(property1D.name, property1D.material.name, sectionProfile.depth, sectionProfile.width, sectionProfile.flangeThickness, sectionProfile.webThickness);
                return(property1D.name);
            }

            var Angle = new Angle();

            if (property1D.profile.GetType().Equals(Channel.GetType()))
            {
                Angle sectionProfile = (Angle)property1D.profile;
                Model.PropFrame.SetAngle(property1D.name, property1D.material.name, sectionProfile.depth, sectionProfile.width, sectionProfile.flangeThickness, sectionProfile.webThickness);
                return(property1D.name);
            }

            return(null);
        }