public static PropertyTemplate ReadOnlyWithCode(this PropertyTemplate property, ICodeFragment expression)
 {
     property.HasGetter  = false;
     property.HasSetter  = false;
     property.Expression = expression;
     return(property);
 }
        public static PropertyTemplate AddProperty(this ClassTemplate classTemplate, string name, TypeTemplate type)
        {
            PropertyTemplate property = new PropertyTemplate(classTemplate, name, type);

            classTemplate.Properties.Add(property);
            return(property);
        }
Ejemplo n.º 3
0
        public List <string> GetAttributes(PropertyTemplate property) =>
        property.IsKey ? new List <string>
        {
            "[MyKey]"
        }

                                                            : new List <string>();
Ejemplo n.º 4
0
    protected void SetTemplatesForAircraft(Aircraft ac, Controls_mfbEditPropSet editPropSet)
    {
        if (ac == null)
        {
            return;
        }

        if (editPropSet == null)
        {
            throw new ArgumentNullException(nameof(editPropSet));
        }

        editPropSet.RemoveAllTemplates();
        IEnumerable <PropertyTemplate> rgpt = UserPropertyTemplate.TemplatesForUser(Page.User.Identity.Name, false);

        HashSet <PropertyTemplate> aircraftTemplates = new HashSet <PropertyTemplate>();

        foreach (int id in ac.DefaultTemplates)
        {
            PropertyTemplate pt = rgpt.FirstOrDefault(pt1 => pt1.ID == id);
            if (pt != null)
            {
                aircraftTemplates.Add(pt);
            }
        }

        HashSet <PropertyTemplate> defaultTemplates = new HashSet <PropertyTemplate>(UserPropertyTemplate.DefaultTemplatesForUser(Page.User.Identity.Name));

        // if the aircraft has valid templates specified, use those
        if (aircraftTemplates.Count > 0)
        {
            editPropSet.AddTemplates(aircraftTemplates);
        }
        else if (defaultTemplates.Count > 0)
        {
            editPropSet.AddTemplates(defaultTemplates);
        }
        else
        {
            editPropSet.AddTemplate(new MRUPropertyTemplate(Page.User.Identity.Name));
        }

        editPropSet.RemoveTemplate((int)KnownTemplateIDs.ID_ANON);
        editPropSet.RemoveTemplate((int)KnownTemplateIDs.ID_SIM);

        if (ac.InstanceType == AircraftInstanceTypes.RealAircraft)
        {
            if (ac.IsAnonymous)
            {
                editPropSet.AddTemplate(new AnonymousPropertyTemplate());
            }
        }
        else
        {
            editPropSet.AddTemplate(new SimPropertyTemplate());
        }

        editPropSet.Refresh();
    }
Ejemplo n.º 5
0
        public void AttributeOnProperty()
        {
            PropertyTemplate template = new PropertyTemplate(null, "Property", Code.Type("string"))
                                        .WithAttribute("Attribute", Code.String("value"));

            this.output.Add(template);
            Assert.AreEqual("[Attribute(\"value\")]\r\npublic string Property { get; set; }", this.output.ToString());
        }
Ejemplo n.º 6
0
        public void PropertyWithEmptyComment()
        {
            PropertyTemplate template = new PropertyTemplate(null, "Property", Code.Type("string"))
                                        .WithComment("");

            this.output.Language.Write(template, this.output);
            Assert.AreEqual("public string Property { get; set; }", this.output.ToString());
        }
Ejemplo n.º 7
0
        public List <string> GetAttributes(PropertyTemplate property) =>
        string.IsNullOrEmpty(property.OriginalName) || property.OriginalName == property.PropName
        ? new List <string>
        {
            $"[JsonPropertyName({property.PropName.Quote()})]"
        }

        : new List <string>();
Ejemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptInclude("ListDrag", ResolveClientUrl("~/Public/Scripts/listdrag.js?v=5"));
        Page.ClientScript.RegisterClientScriptInclude("filterDropdown", ResolveClientUrl("~/Public/Scripts/DropDownFilter.js?v=3"));
        searchProps.TextBoxControl.Attributes["onkeyup"] = String.Format(CultureInfo.InvariantCulture, "FilterProps(this, '{0}', '{1}', '{2}')", divAvailableProps.ClientID, lblFilteredLabel.ClientID, Resources.LogbookEntry.PropertiesFound);
        divAvailableProps.Attributes["ondrop"]           = String.Format(CultureInfo.InvariantCulture, "javascript:lstDropTemplate.moveProp(event, 'cptT', this, '{0}', '{1}')", hdnUsedProps.ClientID, hdnAvailableProps.ClientID);
        divCurrentProps.Attributes["ondrop"]             = String.Format(CultureInfo.InvariantCulture, "javascript:lstDropTemplate.moveProp(event, 'cptT', this, '{0}', '{1}')", hdnAvailableProps.ClientID, hdnUsedProps.ClientID);

        if (!IsPostBack)
        {
            if (ActiveTemplate == null)
            {
                ActiveTemplate = new UserPropertyTemplate()
                {
                    Owner = Page.User.Identity.Name, OriginalOwner = string.Empty
                }
            }
            ;

            PropertyTemplateGroup[] rgGroups = (PropertyTemplateGroup[])Enum.GetValues(typeof(PropertyTemplateGroup));

            foreach (PropertyTemplateGroup ptg in rgGroups)
            {
                if (ptg != PropertyTemplateGroup.Automatic)
                {
                    cmbCategories.Items.Add(new ListItem(PropertyTemplate.NameForGroup(ptg), ptg.ToString()));
                }
            }
            cmbCategories.SelectedIndex = 0;

            ToForm();

            locTemplateDescription1.Text = Branding.ReBrand(Resources.LogbookEntry.TemplateDescription);
            locTemplateDescription2.Text = Branding.ReBrand(Resources.LogbookEntry.TemplateDescription2);
        }
        else
        {
            if (ActiveTemplate == null)
            {
                throw new NullReferenceException("Active Template is null - how? ");
            }
            ActiveTemplate.PropertyTypes.Clear();
            if (hdnUsedProps.Value == null)
            {
                throw new NullReferenceException("hdnUsedProps.Value is null");
            }
            int[] props = JsonConvert.DeserializeObject <int[]>(hdnUsedProps.Value);
            if (props == null)
            {
                throw new NullReferenceException("props is null");
            }
            foreach (int propid in props)
            {
                ActiveTemplate.PropertyTypes.Add(propid);
            }
            UpdateLists();
        }
    }
    protected void SetTemplatesForAircraft(int idAircraft)
    {
        UserAircraft ua = new UserAircraft(Page.User.Identity.Name);
        Aircraft     ac = ua.GetUserAircraftByID(idAircraft);

        if (ac != null)
        {
            mfbEditPropSet1.RemoveAllTemplates();
            IEnumerable <PropertyTemplate> rgpt = UserPropertyTemplate.TemplatesForUser(Page.User.Identity.Name, false);

            HashSet <PropertyTemplate> aircraftTemplates = new HashSet <PropertyTemplate>();
            foreach (int id in ac.DefaultTemplates)
            {
                PropertyTemplate pt = rgpt.FirstOrDefault(pt1 => pt1.ID == id);
                if (pt != null)
                {
                    aircraftTemplates.Add(pt);
                }
            }

            HashSet <PropertyTemplate> defaultTemplates = new HashSet <PropertyTemplate>(UserPropertyTemplate.DefaultTemplatesForUser(Page.User.Identity.Name));
            // if the aircraft has valid templates specified, use those
            if (aircraftTemplates.Count > 0)
            {
                mfbEditPropSet1.AddTemplates(aircraftTemplates);
            }
            else if (defaultTemplates.Count > 0)
            {
                mfbEditPropSet1.AddTemplates(defaultTemplates);
            }
            else
            {
                mfbEditPropSet1.AddTemplate(new MRUPropertyTemplate(Page.User.Identity.Name));
            }

            mfbEditPropSet1.RemoveTemplate((int)KnownTemplateIDs.ID_ANON);
            mfbEditPropSet1.RemoveTemplate((int)KnownTemplateIDs.ID_SIM);

            // Expand for tailwheel
            if (ac.IsTailwheel)
            {
                cpeLandingDetails.ClientState = "false";
            }
            if (ac.InstanceType == AircraftInstanceTypes.RealAircraft)
            {
                if (ac.IsAnonymous)
                {
                    mfbEditPropSet1.AddTemplate(new AnonymousPropertyTemplate());
                }
            }
            else
            {
                mfbEditPropSet1.AddTemplate(new SimPropertyTemplate());
            }

            mfbEditPropSet1.Refresh();
        }
    }
 public List <string> GetAttributes(PropertyTemplate property)
 {
     return(new List <string>
     {
         property.OriginalName != property.PropName
         //  ? $"//[OriginalName({property.OriginalName})]"
             ? $"[JsonProperty(\"{property.OriginalName}\")]"
             : string.Empty,
     });
 }
Ejemplo n.º 11
0
        protected virtual PropertyTemplate AddProperty(ModelTransferObject model, string name, TypeTransferObject type, ClassTemplate classTemplate, IConfiguration configuration, bool canRead = true, bool canWrite = true)
        {
            this.MapType(model.Language, configuration.Language, type);
            PropertyTemplate propertyTemplate = classTemplate.AddProperty(name, type.ToTemplate()).FormatName(configuration);

            propertyTemplate.HasGetter = canRead;
            propertyTemplate.HasSetter = canWrite;
            this.AddUsing(type, classTemplate, configuration);
            return(propertyTemplate);
        }
Ejemplo n.º 12
0
    public void AddTemplate(PropertyTemplate pt)
    {
        if (pt == null)
        {
            throw new ArgumentNullException(nameof(pt));
        }

        ActiveTemplates.Add(pt);
        mfbSelectTemplates.AddTemplate(pt.ID);
    }
Ejemplo n.º 13
0
        public void PropertyDefaultValue()
        {
            PropertyTemplate template = new PropertyTemplate(null, "test", Code.Type("type"));

            template.DefaultValue = Code.String("value");
            PropertyWriter writer = new PropertyWriter();

            writer.Write(template, this.output);
            Assert.AreEqual("public type test { get; set; } = \"value\";", this.output.ToString());
        }
Ejemplo n.º 14
0
        protected override PropertyTemplate AddProperty(ModelTransferObject model, MemberTransferObject member, ClassTemplate classTemplate)
        {
            PropertyTemplate propertyTemplate = base.AddProperty(model, member, classTemplate);

            if (!propertyTemplate.Name.Equals(member.Name, StringComparison.CurrentCultureIgnoreCase))
            {
                propertyTemplate.WithAttribute("JsonProperty", Code.String(member.Name));
                classTemplate.AddUsing("Newtonsoft.Json");
            }
            return(propertyTemplate);
        }
Ejemplo n.º 15
0
        protected override PropertyTemplate AddProperty(ModelTransferObject model, string name, TypeTransferObject type, ClassTemplate classTemplate, IConfiguration configuration, bool canRead = true, bool canWrite = true)
        {
            PropertyTemplate propertyTemplate = base.AddProperty(model, name, type, classTemplate, configuration, canRead, canWrite);

            if (!propertyTemplate.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
            {
                propertyTemplate.WithAttribute("JsonProperty", Code.String(name));
                classTemplate.AddUsing("Newtonsoft.Json");
            }
            return(propertyTemplate);
        }
Ejemplo n.º 16
0
        protected override PropertyTemplate AddProperty(ModelTransferObject model, MemberTransferObject member, ClassTemplate classTemplate)
        {
            IOptions         propertyOptions  = this.Options.Get(member);
            PropertyTemplate propertyTemplate = base.AddProperty(model, member, classTemplate);

            propertyTemplate.Strict = propertyOptions.Strict;
            if (propertyTemplate.DefaultValue == null && propertyOptions.Strict && !propertyTemplate.Type.IsNullable)
            {
                propertyTemplate.DefaultValue = member.Type.Default;
            }
            return(propertyTemplate);
        }
 public Guid AddNewTemplate(PropertyTemplate propertyTemplate)
 {
     using (var context = new InstantStoreDataContext())
     {
         var id = Guid.NewGuid();
         propertyTemplate.Id          = id;
         propertyTemplate.IsPrototype = true;
         context.PropertyTemplates.InsertOnSubmit(propertyTemplate);
         context.SubmitChanges();
         return(id);
     }
 }
Ejemplo n.º 18
0
        public void DefaultPropertyDeclaration_test()
        {
            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            var pg = new PropertyGenerator(property, new PocoSetting());

            Assert.IsTrue(pg.Declaration.Contains("public int CategoryID {get;set;}"));
        }
Ejemplo n.º 19
0
        public List <string> GetAttributes(PropertyTemplate property)
        {
            var att = new List <string>();

            _sharedAttributes.ForEach(x =>
            {
                var a = x.GetAttributes(property);
                if (a.Any())
                {
                    att.AddRange(a);
                }
            });
            return(att);
        }
Ejemplo n.º 20
0
    protected void SegregateProperties(bool fStripDefault = false)
    {
        List <CustomPropertyType> lstRemainingProps = new List <CustomPropertyType>();

        ActiveProperties.Clear();
        ActivePropTypes.Clear();

        PropertyTemplate ptMerged = PropertyTemplate.MergedTemplate(ActiveTemplates);

        // this is cached so we can do it on every call, postback or not
        CustomPropertyType[] rgCptAll = CustomPropertyType.GetCustomPropertyTypes(Page.User.Identity.IsAuthenticated ? Username : string.Empty);

        foreach (CustomPropertyType cpt in rgCptAll)
        {
            // see if this either has a value or is in one of the active templates.
            // if it doesn't have a value but is in a template, give it a value.
            CustomFlightProperty fp = Properties.Find(cfp => cfp.PropTypeID == cpt.PropTypeID);

            // To be included, it must be EITHER
            // a) in the merged set of templates OR
            // b) in the set of properties with a non-default value (fp != null && !fp.IsDefaultValue) OR
            // c) in the set of properties with a default value (fp != null && (!fStripDefault && fp.IsDefaultValue)
            bool fInclude = ptMerged.ContainsProperty(cpt.PropTypeID) || (fp != null && (!fStripDefault || !fp.IsDefaultValue));
            if (fp == null)
            {
                fp = new CustomFlightProperty(cpt);
            }

            if (!fInclude)
            {
                lstRemainingProps.Add(cpt);
            }
            else
            {
                ActiveProperties.Add(fp);
                ActivePropTypes.Add(fp.PropTypeID);
            }
        }

        ActiveProperties.Sort((cfp1, cfp2) => { return(cfp1.PropertyType.SortKey.CompareCurrentCultureIgnoreCase(cfp2.PropertyType.SortKey)); });

        ListItem li = cmbPropsToAdd.Items[0];

        cmbPropsToAdd.Items.Clear();
        cmbPropsToAdd.Items.Add(li);
        cmbPropsToAdd.SelectedValue = string.Empty;    // reset the selection
        cmbPropsToAdd.DataSource    = lstRemainingProps;
        cmbPropsToAdd.DataBind();
    }
Ejemplo n.º 21
0
        public void PascalCasePropertyDeclaration()
        {
            var property = new PropertyTemplate
            {
                PropName = "Category_ID",
                PropType = "int",
                IsKey    = true
            };
            var pg = new PropertyGenerator(property, new PocoSetting
            {
                NameCase = CaseEnum.Pas
            });

            //Debug.WriteLine(pg);
            Assert.IsTrue(pg.Declaration.Contains("public int CategoryID {get;set;}"));
        }
Ejemplo n.º 22
0
        public void Property_has__type_collection_without_prefix_namespac_test()
        {
            // Arrange
            var setting  = new PocoSetting();
            var property = new PropertyTemplate
            {
                PropName       = "Table",
                PropType       = "List<SimpleDataTable>",
                ClassNameSpace = "SP1",
            };
            var expected = "public List<SimpleDataTable> Table {get;set;}";
            // Act
            string sut = new PropertyGenerator(property, setting);

            // Assert
            Assert.IsTrue(sut.Contains(expected));
        }
Ejemplo n.º 23
0
        public virtual void Write(ICodeFragment fragment, IOutputCache output)
        {
            PropertyTemplate template         = (PropertyTemplate)fragment;
            PropertyTemplate previousProperty = output.LastFragments.TakeWhile(x => !(x is ClassTemplate)).OfType <PropertyTemplate>().Skip(1).FirstOrDefault();

            if (previousProperty?.Attributes.Count > 0 || previousProperty != null && template.Attributes.Count > 0)
            {
                output.BreakLine();
            }
            if (template.Comment != null && !string.IsNullOrWhiteSpace(template.Comment.Description))
            {
                output.Add(template.Comment).BreakLine();
            }
            if (template.Attributes.Count > 0)
            {
                output.Add(template.Attributes);
            }
            output.Add(template.Visibility == Visibility.None ? string.Empty : template.Visibility.ToString().ToLower())
            .Add(" ")
            .Add(template.IsVirtual ? "virtual " : string.Empty)
            .Add(template.IsStatic ? "static " : string.Empty)
            .Add(template.Type)
            .Add(" ")
            .Add(template.Name);
            if (template.HasGetter || template.HasSetter)
            {
                output.Add(" { ")
                .Add(template.HasGetter ? "get; " : string.Empty)
                .Add(template.HasSetter ? "set; " : string.Empty)
                .Add("}");
            }
            if (template.DefaultValue != null)
            {
                output.Add(" = ")
                .Add(template.DefaultValue)
                .CloseLine();
            }
            if (template.Expression != null)
            {
                output.Add(" => ")
                .Add(template.Expression)
                .CloseLine();
            }
            output.BreakLineIfNotEmpty();
        }
Ejemplo n.º 24
0
        //Description property is null
        public void IsNullablePropertyDeclaration()
        {
            PropertyTemplate property = new PropertyTemplate
            {
                IsKey      = false,
                IsNullable = true,
                PropName   = "dummy1",
                PropType   = "int"
            };

            PropertyGenerator pg = new PropertyGenerator(property, new PocoSetting
            {
                AddNullableDataType = true
            });

            //Debug.WriteLine(pg);
            Assert.IsTrue(pg.Declaration.Contains("public int? dummy1 {get;set;}"));
        }
Ejemplo n.º 25
0
        public void JsonAttributePropertyDeclaration()
        {
            //public int CategoryID {get;set;} //PrimaryKey not null
            PropertyTemplate property = new PropertyTemplate
            {
                PropName = "CategoryID",
                PropType = "int",
                IsKey    = true
            };
            var pg = new PropertyGenerator(property, new PocoSetting
            {
                AddJsonAttribute = true
            });
            //  Debug.WriteLine(pg);
            var expected = "[JsonProperty(PropertyName = \"CategoryID\")]";

            Assert.IsTrue(pg.ToString().Contains(expected));
        }
        public void PropertyTemplate_with_Required_false_Test()
        {
            // Arrange
            PropertyTemplate p = new PropertyTemplate
            {
                PropName   = "FirstName",
                PropType   = "string",
                IsNullable = true,
                Serial     = 1,
            };

            //Act
            var sut = AttributeFactory.Default.GetAttributes(p, "req");
            var att = string.Join(" ", sut);

            //Assert
            Assert.IsTrue(att.Length == 0);
        }
        public void PropertyTemplate_with_table_Test()
        {
            // Arrange
            PropertyTemplate p = new PropertyTemplate
            {
                PropName = "FirstName",
                PropType = "string",
                //IsNullable = false, //IsNullable is false by default
                IsKey = true,
            };

            //Act
            var sut = AttributeFactory.Default.GetAttributes(p, "tab");
            var att = string.Join(" ", sut);

            //Assert
            Assert.IsTrue(att.Length == 0);
        }
        public void PropertyTemplate_with_key_true_Test()
        {
            // Arrange
            PropertyTemplate p = new PropertyTemplate
            {
                PropName = "FirstName",
                PropType = "string",
                IsKey    = true,
                Serial   = 1,
            };

            //Act
            var sut = AttributeFactory.Default.GetAttributes(p, "key");
            var att = string.Join(" ", sut);

            //Assert
            Assert.IsTrue(att.Contains("[Key"));
        }
Ejemplo n.º 29
0
        public void LazyirtualPropertyDeclaration()
        {
            var property = new PropertyTemplate
            {
                PropName    = "Products",
                PropType    = "List<Product>",
                PropComment = "// not null",
                IsNavigate  = true
            };
            PropertyGenerator pg = new PropertyGenerator(property, new PocoSetting
            {
                AddEager      = false,
                AddNavigation = true
            });

            //   Debug.WriteLine(pg);
            Assert.IsTrue(pg.Declaration.Contains("virtual public List<Product> Products {get;set;}"));
        }
        public void PropertyTemplate_with_setting_key_Test()
        {
            // Arrange
            PropertyTemplate p = new PropertyTemplate
            {
                PropName = "FirstName",
                PropType = "string",
                IsKey    = true,
            };

            //Act
            var sut = AttributeFactory.Default
                      .Init()
                      .GetAllAttributes(p);
            var att = string.Join(" ", sut);

            //Assert
            Assert.IsTrue(att.Length == 0);
        }
Ejemplo n.º 31
0
 public static int Update(Zippy.Data.IDalProvider db, PropertyTemplate entity)
 {
     return db.Update(entity);
 }
Ejemplo n.º 32
0
 /// <summary>
 /// 获取 [属性模板 的 模板] 的 [扩展属性模板] 集合
 /// </summary>
 public static List<ExtProperty> GetTemplateID_ExtPropertys(Zippy.Data.IDalProvider db, PropertyTemplate entity)
 {
     if (entity.TemplateID.HasValue)
            return db.Take<ExtProperty>("TemplateID=@TemplateID", db.CreateParameter("TemplateID", entity.TemplateID));
     return new List<ExtProperty>();
 }
Ejemplo n.º 33
0
 public static int Insert(Zippy.Data.IDalProvider db, PropertyTemplate entity)
 {
     int rtn = db.Insert(entity);
     return rtn;
 }
Ejemplo n.º 34
0
 /// <summary>
 /// 获取 [属性模板 的 属性模板] 的 [产品] 集合
 /// </summary>
 public static List<Z01Product> GetPropertyTemplate_Z01Products(Zippy.Data.IDalProvider db, PropertyTemplate entity)
 {
     if (entity.TemplateID.HasValue)
            return db.Take<Z01Product>("PropertyTemplate=@PropertyTemplate", db.CreateParameter("PropertyTemplate", entity.TemplateID));
     return new List<Z01Product>();
 }