My bot is displaying in Skype, but the 6 and 8 appear as emoji.
This is just a normal FormFlow form:
public class WeightsForm
{
public Weight FromUnitType { get; set; }
public double Amount { get; set; }
public Weight ToUnitType { get; set; }
public static IForm<WeightsForm> BuildForm()
{
return new FormBuilder<WeightsForm>()
.Message("Now you can select weight conversion details.")
.AddRemainingFields()
.Build();
}
}
with Weights based on an enum:
public enum Weight
{
None,
Ton,
Slug,
Pound,
Ounce,
Grain,
Picogram,
Nanogram,
Microgram,
Milligram,
Centigram,
Decigram,
Gram,
Dekagram,
Hectogram,
Kilogram,
Megagram,
Gigagram,
Teragram
}
What is the best way to get this to display, on Skype, without the emoji?
To fix this you need to change the template used for generating the numbers so that Skype does not interpret this as an emoji. If you add this annotation on your class:
[Template(TemplateUsage.EnumSelectOne, ChoiceFormat = "{0}. {1}")]
That would fix the problem for single selections. Alternatively you could change the default template in builder.Configuration.Templates. If you wanted to fix EnumSelectMany you could add that as well.
What version of the SDK are you running? If you are running the latest and unless you have tweaked the choice style you should get buttons on skype by default. (The next release will have more style options as well.)
Related
Consider the following simple model:
public class TestClass {
[MyRequired(ErrorMessage = "Some error message")]
public int TestVariable { get; set; }
}
This will implicitly add the [Required] attribute and the rendered html will contain data-val attributes for both [Required] and [MyRequired].
I found 2 possible solutions:
// Solution #1 (.net 5 only)
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
// Solution #2
services.AddControllers(options => options.SuppressImplicitRequiredAttributeForNonNullableReferenceTypes = true);
Unfortunately the first solution is not available for .net 6 and the second solution doesn't seem to work (propably because int is a value type and not a reference type?)
Finally I was able to solve this by making the TestVariable nullable:
public int? TestVariable { get; set; }
Not sure if this is good practice. Is there any way to disable this behavior globally without making everything nullable?
Can anyone tell me if they have run into any "memory" limitations with Xamarin Forms App for Android?
I recently decided to give Xamarin another go... A few years back I ran into far too many hurdles and went a different route. I hoped things had changed.
I have an empty Xamarin Forms App for Android ONLY at this point (no OSX or UWP support). I created and updated the initial app (4.3 Xamarin Forms). I modified the mainpage.xaml and the mainpage.xaml.cs. Simple 3 row grid... 2 columns... first row, small header image centered columnspan="2"... Second row is also centered, with a CollectionView to "horizontally" scroll some simple small icon/images... Third row of gird is for detail (not yet implemented). So, with this, you can see the application is still quite small and has no real magic going on... Here is the delimma...
I have 8 c# Objects that are a c# Class... I began building the application using a simplified version of the class... Name, and ImageName only for the purpose of testing the 4.3 CollectionView for a navigation UI... After I had the functionality I wanted and it was running and tested for deployment to device, Everything seemed fine... So, I continued and built out the full class objects (13 fields, all strings no real data entered, just empty quotes for value = "". The only fields I have filled in are the original Name and ImageName is code read only... Running the App in the emulator, it now fails on load... and the emulator asks if I would like to close or try and reload...
It seems that my display class, when the class has more than the first few fields filled in causes some sort of overload:
var displaylist = new List<"DisplayClass"> ();
var dc = New DisplayClass({Name = "This Icon"})... add all 8 and things are working...
var dc = new DisplayClass({Name="This Icon", State="MA", Style="", Definition="", ... all others empty string});
--- add all 8 classes with names only and all empty fields... fails to load app...
public class DisplayClass
{
public string Name { get; set; }
public string State { get; set; }
public string Style { get; set; }
public string Definition { get; set; }
public string Days { get; set; }
public string Time { get; set; }
public DateTime StartDate { get; set; }
public string Imageurl { get; set; }
public string Dataurl { get; set; }
public string Retrievalurl { get; set; }
public string LastRetrievalDate { get; set; }
public string LastInfoData { get; set; }
public string Quantity { get; set; }
public string ImageName
{
get { return Name.Replace(" ", string.Empty).ToLower(); }
}
}
I updated the emulator to use 4GB instead of 1GB, but that had no effect. There are no code errors that I can tell, if I remark out the full object classes and implement the stripped out version it works without error... I do not get an error, only a App failed to start dialog from Android...
Can anyone shed light on this?
My bad... I had an un-instantiated datetime in my class... oops... sorry folks!
I just can't figure out how to ask a yes/no question while filling a form with FormFlow. You can't use the Confirm method to fill a bool,
var builtForm = new FormBuilder<BuyingACar>()
.Field(nameof(NewCar))
.Field(nameof(Model))
.Field(nameof(Brand))
.Build();
I need the field "NewCar" to be a prompt with buttons "yes" and "no". I don't want to use an enum since it will send a 0/1 when a button's pressed.
edit: My final goal is to fill a bool field.
It should work perfecly with booleans. It accepts "Yes", "No", "y" and "n" as possible answers. If you use the special Pattern Language {||} you can edit the prompt to include the options.
Here is an example.
public enum Brands
{
Volvo, BMW
}
[Serializable]
public class BuyingACar
{
[Prompt("Would you like to buy a car? {||}")]
public bool NewCar { get; set; }
public Brands? Brand { get; set; }
public static IForm<BuyingACar> BuildForm()
{
return new FormBuilder<BuyingACar>()
.Build();
}
}
And the result:
We have a lot of Dto classes in our project and on various occasions SELECT them using Expressions from the entity framework context. This has the benefit, that EF can parse our request, and build a nice SQL statement out of it.
Unfortunatly, this has led to very big Expressions, because we have no way of combining them.
So if you have a class DtoA with 3 properties, and one of them is of class DtoB with 5 properties, and again one of those is of class DtoC with 10 properties, you would have to write one big selector.
public static Expression<Func<ClassA, DtoA>> ToDto =
from => new DtoA
{
Id = from.Id,
Name = from.Name,
Size = from.Size,
MyB = new DtoB
{
Id = from.MyB.Id,
...
MyCList = from.MyCList.Select(myC => new DtoC
{
Id = myC.Id,
...
}
}
};
Also, they cannot be reused. When you have DtoD, which also has a propertiy of class DtoB, you would have to paste in the desired code of DtoB and DtoC again.
public static Expression<Func<ClassD, DtoD>> ToDto =
from => new DtoD
{
Id = from.Id,
Length = from.Length,
MyB = new DtoB
{
Id = from.MyB.Id,
...
MyCList = from.MyCList.Select(myC => new DtoC
{
Id = myC.Id,
...
}
}
};
So this will escalate pretty fast. Please note that the mentioned code is just an example, but you get the idea.
I would like to define an expression for each class and then combine them as required, as well as EF still be able to parse it and generate the SQL statement so to not lose the performance improvement.
How can i achieve this?
Have you thought about using Automapper ? You can define your Dtos and create a mapping between the original entity and the Dto and/or vice versa, and using the projection, you don't need any select statements as Automapper will do it for you automatically and it will project only the dto's properties into SQL query.
for example, if you have a Person table with the following structure:
public class Person
{
public int Id { get; set; }
public string Title { get; set; }
public string FamilyName { get; set; }
public string GivenName { get; set; }
public string Initial { get; set; }
public string PreferredName { get; set; }
public string FormerTitle { get; set; }
public string FormerFamilyName { get; set; }
public string FormerGivenName { get; set; }
}
and your dto was like this :
public class PersonDto
{
public int Id { get; set; }
public string Title { get; set; }
public string FamilyName { get; set; }
public string GivenName { get; set; }
}
You can create a mapping between Person and PersonDto like this
Mapper.CreateMap<Person, PersonDto>()
and when you query the database using Entity Framework (for example), you can use something like this to get PersonDto columns only:
ctx.People.Where(p=> p.FamilyName.Contains("John"))
.Project()
.To<PersonDto>()
.ToList();
which will return a list of PersonDtos that has a family name contains "John", and if you run a sql profiler for example you will see that only the PersonDto columns were selected.
Automapper also supports hierachy, if your Person for example has an Address linked to it that you want to return AddressDto for it.
I think it worth to have a look and check it, it cleans a lot of the mess that manual mapping requires.
I thought about it a little, and I didn't come up with any "awesome" solution.
Essentially you have two general choices here,
Use placeholder and rewrite expression tree entirely.
Something like this,
public static Expression<Func<ClassA, DtoA>> DtoExpression{
get{
Expression<Func<ClassA, DtoA>> dtoExpression = classA => new DtoA(){
BDto = Magic.Swap(ClassB.DtoExpression),
};
// todo; here you have access to dtoExpression,
// you need to use expression transformers
// in order to find & replace the Magic.Swap(..) call with the
// actual Expression code(NewExpression),
// Rewriting the expression tree is no easy task,
// but EF will be able to understand it this way.
// the code will be quite tricky, but can be solved
// within ~50-100 lines of code, I expect.
// For that, see ExpressionVisitor.
// As ExpressionVisitor detects the usage of Magic.Swap,
// it has to check the actual expression(ClassB.DtoExpression),
// and rebuild it as MemberInitExpression & NewExpression,
// and the bindings have to be mapped to correct places.
return Magic.Rebuild(dtoExpression);
}
The other way is to start using only Expression class(ditching the LINQ). This way you can write the queries from zero, and reusability will be nice, however, things get harder & you lose type safety. Microsoft has nice reference about dynamic expressions. If you structure everything that way, you can reuse a lot of the functionality. Eg, you define NewExpression and then you can later reuse it, if needed.
The third way is to basically use lambda syntax: .Where, .Select etc.. This gives you definitely better "reusability" rate. It doesn't solve your problem 100%, but it can help you to compose queries a bit better. For example: from.MyCList.Select(dtoCSelector)
I'm having trouble with my ASP.NET MVC 3 application. I have 2 propertiesin my model whereby I only want 1 of them required in my view based on whichever one is empty. So for example, if I enter a phone number then email is no longer required and vice versa, but if I leave both empty, then either 1 should be required, below is my model:
[Display(Name = "Contact Phone Number:")]
[MaxLength(150)]
public string ContactPhoneNumber { get; set; }
[Display(Name = "Contact Email Address:")]
[MaxLength(100)]
public string ContactEmailAddress { get; set; }
Would I need to create a custom attribute to validate my model and if so, how would I achieve this?
You can implement IValidatableObject on your class and provide a Validate() method that implements your custom logic. Combine this with custom validation logic on the client if you prefer to ensure that one is supplied. I find this easier than implementing an attribute.
public class ContactModel : IValidatableObject
{
...
public IEnumerable<ValidationResult> Validate( ValidationContext context )
{
if (string.IsNullOrWhitespace( ContactPhoneNumber )
&& string.IsNullOrWhitespace( ContactEmailAddress ))
{
yield return new ValidationResult( "Contact Phone Number or Email Address must be supplied.", new [] { "ContactPhoneNumber", "ContactEmailAddress" } );
}
}
}
To get everything working at client side you'll need to add the following script to your view:
<script type="text/javascript">
$(function() {
$('form').validate();
$('form').rules('add', {
"ContactPhoneNumber": {
depends: function(el) { return !$('#ContactEmailAddress').val(); }
}
});
});
</script>
Annotation-based conditional validation can be defined using ExpressiveAnnotations:
[RequiredIf("ContactPhoneNumber == null",
ErrorMessage = "At least email or phone should be provided.")]
public string ContactEmailAddress { get; set; }
[RequiredIf("ContactEmailAddress == null",
ErrorMessage = "At least email or phone should be provided.")]
public string ContactPhoneNumber { get; set; }
Here is a MSDN blog entry about conditional validations: http://blogs.msdn.com/b/simonince/archive/2011/02/04/conditional-validation-in-asp-net-mvc-3.aspx
I know you already have a solution, but I had a similar situation, so maybe my solution will prove helpful to someone else. I implemented a custom attribute with client-side validation. Here is my blog post: http://hobbscene.com/2011/10/22/conditional-validation/