I am using Castle Validators on my model. I have an EmailAddress property defined like so:
[ValidateEmail]
public string EmailAddress { get; set; }
The problem is that the regex (?) that the ValidateEmail attribute uses is incorrect. For instance, if I put in an email address like foo#foo.com, it validates correctly, but if I put in an address like foo+1#foo.com, it says it is not valid.
I realize that I can just use the ValidateRegExp attribute with my own regex, but if possible, I'd prefer to use what's already built in to the system.
So is there some way to "fix" the ValidateEmail attribute?
Please get the latest build from the build server, this was fixed a couple of weeks ago.
Given that the Castle project is open-source, grab the source and fix it yourself. Then submit the patch back to the project.
The project maintainers will appreciate it (normally; YMMV) and the project gets stronger.
Related
I have two dlls that are dllA and dllB.
I have same object in both the dlls mentioned as below.
class OrderObect
{
public string firstName {get;set;}
public string lastName {get;set;}
}
I am sending the List from dllA to dllB.
I am getting one exception that is Cannot convert list of dllA.OrderObject to list of dllB.OrderObject.
So how to solve that, Thank you :)
Why duplicating those classes? Whatever, if properties name are the same, you could use reflection and loop through properties to copy values from one to other.
Look to this post to know how to achieve this : here
As Creep says if the properties are the same in both then you can use reflection. A slightly easier way if to use something like express mapper to do the mapping for you
I am looking for something very simple. It can use the Selenium IDE recording tool, but it does not allow me to pick what kind of locators I get.
I want to use:
driver.findElement(By.className(str))
to locate things. All I need is something which watches which UI elements on a web page get clicked and writes out the class attributes of those tags.
If I use the Selenium IDE recording (and export to the right type of thing), I get:
#Test
public void testNav() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.name("3.1.1.5.1.1")).clear();
driver.findElement(By.name("3.1.1.5.1.1")).sendKeys("dan");
driver.findElement(By.name("3.1.1.5.1.5")).click();
driver.findElement(By.linkText("Products")).click();
driver.findElement(By.linkText("Categories")).click();
driver.findElement(By.linkText("Create a Category")).click();
driver.findElement(By.linkText("Cancel")).click();
driver.findElement(By.linkText("Products")).click();
driver.findElement(By.cssSelector("a.DisplayAdminProductsLink")).click();
driver.findElement(By.linkText("Product1")).click();
There are problems with this. First, it is not give me any By.className() calls. Why? Those first 3 calls will not help me. The framework I am using puts arbitrary things into the name. How can I get it to see the class attribute?
There actually are unique words in the class attribute of all of the above tags. I design my apps so that this is so. Yet it will not use them.
Earlier I asked:
Why is it doing a "driver.findElement().click()"? This is fragile and does not
end up working.
What I need is:
elt = driver.waitFor(By.className("c")); elt.click();
This will work reproducibly.....
I am considering to be removed from the question, as the findElement() code does work. You need to set a general time-out on the driver. It is not very obvious that this can be done, but it can.
So, continuing on....
I can go to the "Options" and change the order of the "Locator Builders" in eclipse. I can put "css" at the top. Then I get:
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.1\"]")).clear();
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.1\"]")).sendKeys("dan");
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.5\"]")).click();
The tags are like:
<input class="form-control LoginUsernameField" ... />
But it does not see the class attribute.... Or I can do this manually.
Selenium looks for a unique identifier to identify elements in a webpage. classNames are a very less desired option for this purpose as they are generally not unique. Ids and names on the other hand are generally unique. This might be the reason why Selenium IDE is not selecting classNames and going for other identifiers.
Selenium IDE records user actions. You would have clicked on the element for Selenium IDE to identify it and that is why you are getting driver.findElement().click().
If you want to wait for element to wait you can try implicit wait.
When you want to use driver.findElement(By.className(str)), are you sure that there is one and only one element in the webpage that is associated with a className? If that is the case you can modify the webdriver code manually to use className.
Is there a way I could use the SOQL language to move files from Private to Public library?
I've tried editing the ContentDocument object and changing the ParentId (which obviously doesn't work as ParentId seems to be read-only).
I also attempted to change the PublishStatus, however that seems to be pointless too as there's no way of determining which library will it then belong too. I tried looking into Salesforce documentation, however I can't find a way of connecting the ContentDocument/ContentVersion with a library object (except for the PublishStatus, however as mentioned before that does provide a way to link the Content with Library).
Any help will be greatly appreciated!
Ok, finally got it. For the anyone with similar problem, the solution is (once you know it) very obvious: you can create a link between a library and a content document using ContentWorkspaceDoc, which requires ContentDocumentId (id of the document) and ContentWorkspaceId (id of the library).
I have this idea to try to use a custom IMPORT attribute to new up a class based on a condition. For example, if I have:
[Import("Position_32")] this should exist if I'm running a 32bit OS, and then:
[Import("Position_64")] if Im running a 64 bit OS. Is there any way to make the type name for the attribute dynamic based on a condition?
Conceptually it could look like this:
[Import(((IsWIN64()) ? "Position_64" : "Position_32"))] This doesn't work because the type name needs to be a constant.
I want to make the newing up of the proper position class as transparent as possible. I mean I did a factory based method using funcs to get my desired effect but I'd love to use MEF for this. Ideas?
THanks much,
David
You could use ExportMetadataAttribute like so:
[Import("Position")]
[ExportMetadata("Platform", "32bit")]
public YourType ...
Then, when you go to import, use:
[ImportMany]
public Lazy<YourType,IDictionary<string,object>>[] Positions { get; set; }
You can then check the Dictionary for the appropriate metadata, and use that specific platform, at runtime.
In addition, you can make a custom interface for strongly typed metadata (instead of strings). For details, see Exports and Metadata.
I haven't found any reason for the existence of a few of the App Engine classes. There's a PhoneNumber, a Link, a PostalAddress, a GeoPt, a Rating, etc. Why are these given special treatment? They don't seem to have any smarts - e.g. geo searching. I know Link has more space than a String property, but the rest?
See:
http://code.google.com/appengine/docs/java/datastore/dataclasses.html
Those types are 'semantic' types. They're present in the Java API for parity with the Python API. In the Python API, they define special behaviour with regards to the .to_xml() method - for example, a PhoneNumberProperty serializes like this:
<property name="foo" type="gd:phonenumber"><gd:phoneNumber>12345-678</gd:phoneNumber></property>
I think they're mostly just there to cover common cases and save developers time. If a lot of apps use a phone number field, why require each developer to have to write them? A developer can still write their own if they need/want to.
Not sure about java, but in python the following model/code (tested on dev server) will throw BadValueError, with the message "Invalid URL: stackoverflow.com"
class foo(db.model):
link = db.LinkProperty()
bar = foo()
bar.link = 'stackoverflow.com'
While:
bar.link = 'http://stackoverflow.com'
Works fine.
I haven't tested, but the other properties may or may not also do validation.
Basically using this types in your models allows to add indirect meta data to your code. This may be useful if you are working with any kind of universal renderer for your model classes or if you are performing validation of user input on your models.
For example if you are using PhoneNumber type for a field named userNumber you reflection based renderer may understand that it should automatically assign corresponding validator to text field which will represent it.
Regards,
Pavel.