I'm writing a custom build task and and would like to access the value of this property programmatically. It is possible? I've looked at all of the members of the Task class and didn't see anything that looked like it would allow me to get the value.
If the custom task can't run without a property, the best practice is to make that property a required input:
[Required]
public string OutDir { get; set; }
Set by:
<MyTask ... OutDir="$(OutDir)" />
Related
I created a custom field and trying to add the warehouse selector to it.I try to read from the customization guide and tried it but,the selector does not show up in the custom field.
This is the code I tried.
#region UsrCustomSite
[PXDBInt]
[PXUIField(DisplayName="Warehouse", Visibility = PXUIVisibility.SelectorVisible)]
[PXSelector(typeof(Search<IN.INSite.siteCD>),typeof(IN.INSite.descr),DescriptionField =(typeof(IN.INSite.siteCD)),SubstituteKey =(typeof(IN.INSite.siteCD)),DirtyRead =true)]
public virtual int? UsrCustomSite { get; set; }
public abstract class usrCustomSite : PX.Data.BQL.BqlInt.Field { }
#endregion
Am I missing something here?
I would try changing
[PXSelector(typeof(Search<IN.INSite.siteCD>)
to
[PXSelector(typeof(Search<IN.INSite.siteID>)
You are storing an int so you want the id, the substitute Key setting will make it so that the UI will show the CD.
In ASP.NET MVC application I have a model named CarSearchCriteria:
public class CarSearchCriteria{
public int CarMake {get;set;} // This is selected from a dropdownlist
public int YearOfFirstReg {get;set;}
public string ModelVariant {get;set}
}
I have two views - one for editing and the other one for viewing. In the editing view for the CarMake property I can do the following. I know I could have used DropDownListFor but didn't want to mess with SelectList for the time being:
<select name="CarMake">
<option value="1">BMW</option>
<option value="2">Mercedes</option>
<option value="3">Toyota</option>
</select>
So the model binding mechanism will easily bind the selected value to the appropriate model property. But what about the reading mode. I can't show 1s or 2s. I need to show BMW, Mercedes and so on. My question is what is the preferred way, do I have to have a property name that holds the actual textual information, something like CarMakeText?
You could have both the identifier (which you currently have) as well as the Make object itself. The latter would never need to be accessed when building the model, but can be accessed when reading the model. A lazy-loaded read-only property often works well for that. Something like this:
public int CarMakeID { get; set; }
public Make CarMake
{
get
{
if (CarMakeID == default(int))
return null;
// fetch the Make from data and return it
}
}
Naturally, this depends a lot on what a Make actually is and where you get it. If there's just some in-memory list somewhere then that should work fine. If fetching an instance of a Make is a little more of an operation (say, fetching from a database) then maybe some in-object caching would be in order in case you need to access it more than once:
public int CarMakeID { get; set; }
private Make _carMake;
public Make CarMake
{
get
{
if (CarMakeID == default(int))
return null;
if (_carMake == null)
// fetch the Make from data and save it to _carMake
return _carMake;
}
}
David's solution is just fine but for some reason I find my own solution to better fit my needs and besides that I find it more elegant. So basically what I do is I create a class that holds the textual descriptions of all the properties that keep just ID. For example, I have the following model:
public class EmployeeModel{
public int EmployeeID {get;set;}
public string FullName {get;set}
*public int DepartmentID {get;set}
*public int SpecialityID {get;set;}
public int Age {get;set;}
}
The properties marked with asterisk are the properties that keep ids of possible many predefined options and when showing we're supposed to show the actual descriptions, not the number representations. So for this purpose, we create a separate class:
public class EmployeeTextValues{
public string DepartmentName {get;set;}
public string SpecialityName {get;set;}
}
And then I just add this class as a property to my model:
public EmployeeTextValues TextValues {get;set;}
After that, it's quite easy to access it from anywhere, including Razor.
P.S. I'm sure that a lot of people will tend to do the following before initializing this property:
Employee emp=new Employee;
emp.Age=25;
emp.TextValues.DepartmentName="Engineering";// Don't do this
If you try to access or set Textvalues.Someproperty you'll get Object reference not set to an instance of an object. So do not forget to set TextValues first to some initialized object. Just a kind reminder, that's all.
this is the method definition:
public static bool TryValidateObject(
Object instance,
ValidationContext validationContext,
ICollection<ValidationResult> validationResults,
bool validateAllProperties
)
what i am confused is the validateAllProperties parameter, I understand when it is true-validate all properties.
What about when it is false, not validate all properties, but which property will be validated?
See here for a good answer:
http://connect.microsoft.com/VisualStudio/feedback/details/605635/missleading-parametername-validateallproperties-in-validator-try-validate-componentemodel-dataannotations
It seems that when validateAllProperties is set to false that only the RequiredAttribute is validated.
When the property is false the Validator should validate each of the properties on the object that have a ValidationAttribute applied to them. This can include any of these attributes: CustomValidationAttribute, DataTypeAttribute, RangeAttribute, RegularExpressionAttribute, RequiredAttribute, and StringLengthAttribute, along with any other attributes that derive from ValidationAttribute.
See the MSDN library on the TryValidateObject method for more information.
In the following example, Foo should be validated, while Bar should not.
public class Example
{
[Required(ErrorMessage = "Foo is a required property.")]
public object Foo { get; set; }
public object Bar { get; set; }
}
I also don't fully understand it but after struggling with Unit Testing custom validators written by me I noticed one interresting thing.
When I launched my tests without this parameter (so by default it was false), my custom validators were omitted! if I set it to true, they were taken into account in my tests and now I can happily continue TDD. Hope this helps you a bit.
Arjen is right, only the Required attribute is validated when the validateAllProperties parameter is false.
I wrote a post about OData validation using DataAnnotations and I found the same issue.
http://blog.jorgef.net/2011/01/odata-dataannotations.html
I made a custom task in my TFS build to examine my project's GlobalAssemblyInfo.cs file in order to extract an attribute (AssemblyInformationalVersion to be exact) in order to use its value in naming a zip file that I make with the build.
<UsingTask TaskName="GetAssemblyInformationalVersion.GetAssemblyInformationalVersionTask"
AssemblyFile="$(MSBuildExtensionsPath)\GetAssemblyInformationalVersion.dll" />
The .cs file for my DLL has these two properties:
[Required]
public String InfoFile { get; set; }
public String InfoVersion { get; set; }
Here is my call to my task:
<GetAssemblyInformationalVersionTask InfoFile="$(Path to file)\GlobalAssemblyInfo.cs" />
My intention is to pass in the assembly info file through the property InfoFile so that I can find what I want (which my C# code does) and set it to the property InfoVersion for me to reference in TFS by running it as a task. In principle, I would use the property InfoVersion to use in naming my zip file. For example,
"Package.$(some form of reference to InfoVersion).zip"
However, I have not been able to find a way to actually accomplish this.
My question is: How can I invoke the get part of my property in my task? It seems like it should be easy, since I have not found anything written about this sort of thing online, but any help will be much appreciated.
Your custom task, GetAssemblyInformationVersionTask, will need to have a property on it of type ITaskItem that is decorated with the [Output] attribute.
public class GetAssemblyInformationVersionTask
{
[Output]
public ITaskItem Version { get; set; }
public override bool Execute()
{
// code to set Version
return true;
}
}
Then you will be able to use it like so:
<GetAssemblyInformationVersionTask InfoFile="$(Path to file)\GlobalAssemblyInfo.cs">
<Output TaskParameter="Version" ItemName="AssemblyVersion" />
</GetAssemblyInformationVersionTask>
AssemblyVersion will be the item variable that will contain the value of the Version property of your task.
If you've not seen it, MSDN Best Practices for Reliable Builds, Part 2 touches on the subject of output parameters. I'll see if I can't find better examples online.
Thomas Ardal has another good sample of [Output] in a custom task here.
HTH,
Z
I have a class
public class Item
{
public string A { get; set; }
public Control B { get; set; }
}
I'm using MVVM with Silverlight. I have a custom view that is inherited from a standard view. Custom view has public property public ICollection MyItems { get; set; } which should store items described above.
In xaml of my view I have
xxxx.MyItems>
Item A="someText" B="_existingButton" />
Item A="someText2" B="_existingButton2" />
/xxxx.MyItems>
Initialize() method of View fails when trying to assign value for B.
How can I assign a reference to existing element for a custom collection item?
I don't exactly understand what you are trying to achieve, but to help you arrive at a solution, I recommend that you attempt your task in the code behind file first (i.e. in the .xaml.cs) file.
By doing this, you will be given much more informative help from the compiler and intellisense.
Once you've achieved what you wanted in the code behind, then try and implement it in the xaml file.