i have a little problem and can´t figure out how to resolve it.
I am Validating an XDocument against a schema and i get all the nodes which have error. But the Validation process doesnt go deeper after finding an error.
_document.Validate(_schema, (o, e) =>
{
XElement xEle = null;
if (o is XAttribute)
xEle = (o as XAttribute).Parent;
if (o is XElement)
xEle = o as XElement;
if (xEle == null)
{
Debug.WriteLine(o.ToString());
return;
}
_elemtList.Add(o as XElement);
});
My problem is like following
<Car>
<CarName></CarName>
<CarInteriour>
<CarInteriorColor>Red</CarInteriorColor>
</CarInteriour>
</Car>
Lets say this is valid.
If i Change the following to
<Car>
<CarInteriour>
<CarInteriorColor></CarInteriorColor>
</CarInteriour>
</Car>
Here is the CarName tag missing and the color Red.
I will only get the error for CarName but not color Red.
The validation process seems to skip that structure because it did find an error.
Is there a way to still keep validating even if there was an error ?
Ok i found a solution which works for me and i am giving you an update because it works pretty neat.
What i am doing now is. I use a foreach for every XElement in my _document.Descendants() and i validate every element. This finds every error in the document multiple times.
So what i do is, i check my errorlist if i already did find this error before. My errorlist is a list of my own class errorcontainer which has the found XElement with the Error Message.
This way i only add new errors to the list and show this errors on a dialog. The user now can select an error and i will directly jump to the error in my editor.
ErrorContainer errorContainer = new ErrorContainer(xEle, e.Message);
if (_errors.Any(error => error.xElement.Equals(errorContainer.xElement) && string.CompareOrdinal(error.errorMessage, errorContainer.errorMessage) == 0))
{
return;
}
_errors.Add(errorContainer);
I hope this helps some other people who need help on this issue :)
Related
I noticed an odd issue and I can't seem to find anything to explain it.
on one of my models i add an error output message to alert that a record is not available, but when it outputs, i get no text, just a blank page.
Now the language tags are valid, the only thing i can figure is that the language file isn't meant to be used on a model, if thats the case I don't see that being explained anywhere.
I hope someone can help me get in the right direction on this, if i have to just set it to false and handle the message on the ui, I'll do that, but prefer not to.
Thanks.
EDIT:
here is what a quick code snipplet that should help:
//fetch topic data.
$this->db->select('id, Name, Description, Level');
$this->db->from('groups');
$this->db->where('id', $gid);
$query = $this->db->get();
$GroupData = $query->row();
//see if we have any records to show.
if($query->num_rows() > 0) {
$this->setId($GroupData->id);
$this->setName($GroupData->Name);
$this->setDescription($GroupData->Description);
$this->setLevel($GroupData->Level);
} else {
//no record was found, throw an error.
show_error($this->lang->line('invalidgid').'<hr />File:'.__FILE__.'<br />Line:'.__LINE__, 500, $this->lang->line('error'));
log_message('error', 'invalid GroupID was provided.'); //log error in error log.
}
I feel dumb, but I figured it out, the language file hasn't loaded yet at that point, ARGH!
I will have to go back to the drawing board on this one it looks, any suggestions, please post them.
I am trying to get the selected element in Ckeditor. I.e. if the html is:
This has a link.
I want to retrieve the entire a element when I select the link text.
As I understand it the following code:
editor.getSelection().getSelectedElement()
is supposed to do that. But it is always returning null (no matter how much or how little I select). I have tried various other element types and the result is always the same.
getSelection() by itself is not returning null. I am able to get just the link text with
editor.getSelection().getNative().toString().
I even tried some old code that I found here:
http://cksource.com/forums/viewtopic.php?f=6&t=11997&p=31833
but that resulted in the error Object #<Object> has no method 'getRangeAt'
Does anyone have any suggestions?
I was too troubleshooting the same thing. But got this code working.
Just check if it helps
var element = CKEDITOR.plugins.link.getSelectedLink( editor );
if ( element )
{
if ( element.is( 'a' ) )
{
var urldata = element.getAttribute( 'href' );
this.setValue(urldata);
}
}
LINQ newbie here
I am trying to get a value of a field - using a fieldName variable.
If I do a watch on row[FieldName] I do get a value - but when I do it on the actual code it will not compile.
string fieldName = "awx_name"
List<awx_property> propertyQry =
(
from property in crm.awx_propertyawx_properties
where property.awx_propertyid == new Guid(id)
select property
).ToList();
foreach (awx_property row in propertyQry)
{
//THIS DOES NOT WORK
fieldValue = row[fieldName];
}
Thanks in advance. Alternatives would be welcome as well
You keep us guessing what you are trying to do here... You need to specify the types of the objects, so it's easy for us to understand and help. Anyway, I think you are trying to get an object based on the ID. Since you are getting by Id, my guess would be the return value is a single object.
var propertyObj =( from property in crm.awx_propertyawx_properties
where property.awx_propertyid == new Guid(id)
select property
).SingleOrDefault();
if(propertyObj != null) {
fieldValue = propertyObj.GetType().GetProperty(fieldName).GetValue(propertyObj, null);
}
Of course, you need to add validation to make sure you don't get null or any other error while accessing the property value.
Hope it helps.
What type is fieldValue? What does awx_property look like? This will only work is awx_property is a key/value collection. It its not, you could use reflection instead.
If it is a key/value collection you are probably missing a cast. (row[FieldName].ToString() or something) Also you are missing a semi-colon in the foreach block.
Hi I been searching for my error but I can't find anything that help me. The problem is this. I been working with Subsonic 3, Newtonsoft Json and the linq way of write so I have this easy query:
var found = from client in newclients.All() where client.Period == "sometext" select client;
string periodoJSON = JsonConvert.SerializeObject(periodoFound); //this get "Self referencing loop Exception"
the problem is when I run this script I get the horrible exception "Self referening loop exception" in the JsonConvert line, subsonic have all the objects without any problem but if I do the following.
var found = from client in newclients.All() where client.Period == "sometext" select new client{client.Name, client.LastName, etc};
string periodoJSON = JsonConvert.SerializeObject(periodoFound);
I get the object serialize with a any problem with all the properties. I'm doing the last way because I have to finish my work but is any other way or solution for this problem, if not I will have to write all the properties every time I want to get a full table properties.
hope any can solve my problem o help me in the path for find a solution....
what I have is a really basic query with linq and I try the three values for JsonSerializerSettings and any work, again I'm working with subsonic 3 this not happend either with subsnoic 2 and I can make it work if I specify one by one the properties of the object in the linq query does any have any clue of what is happend, ANY more help would be great!!! If I put the value of Serialize my page get crazy and in a infinity loop state, if I decide for error simple doesn't work and Ignore nothing happen... some more information about this self referencia loop?
var u = usuario.SingleOrDefault(x => x.TipoUsuario == "A" || x.TipoUsuario == "W");
JsonSerializerSettings setting = new JsonSerializerSettings();
setting.ReferenceLoopHandling = ReferenceLoopHandling.Error; //.Serialize .Ignore
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"usuario", "var usuario=" + JsonConvert.SerializeObject(u, Formatting.None, setting) + ";");
Update ------
I code the following
string jsU = JsonConvert.SerializeObject(u,Formatting.None,new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects, ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
and is workign but the only thing wrongs is that in the json object comes all the information about the columns of subsonic 3 and a BIG chunk of text explain it... does any one know how to not SEND this part of the object??
Without knowing more about you object model it is hard to provide a definitive answer, but I would take a look at the ReferenceLoopHandling enum.
You're calling string SerializeObject(object value) on JsonConvert. Try the string SerializeObject(object value, Formatting formatting, JsonSerializerSettings settings) method instead. The JsonSerializerSettings settings parameter lets you set a bunch of things, including the ReferenceLoopHandling ReferenceLoopHandling { get; set; } property.
You can try these values:
public enum ReferenceLoopHandling
{
Error,
Ignore,
Serialize
}
Obviously, Error is the default and that's what you're getting. Perhaps one of the others will help.
Ex 1:
"autor.ComentariosWorkItens.Add(comentarioWorkItem);"
autor.ComentariosWorkItens makes EF4 load all ComentariosWorkItens.
Ex 2:
comentarioWorkItem.Usuario = autor;
Fixup make EF load all ComentariosWorkItens too:
private void FixupUsuario(Usuario previousValue)
{
if (previousValue != null && previousValue.ComentariosWorkItens.Contains(this))
{
previousValue.ComentariosWorkItens.Remove(this);
}
if (Usuario != null)
{
if (!Usuario.ComentariosWorkItens.Contains(this))
{
Usuario.ComentariosWorkItens.Add(this);
}
}
}
How can I prevent this?
1: Turn it around:
comentarioWorkItem.Usario = autor;
2: How is the EF supposed to answer this:
previousValue.ComentariosWorkItens.Contains(this)
... without looking into ComentariosWorkItens?
I sent a email to Julie Lerman. Here her answer:
"I think this is known (and AWFUL) behavior on EF’s part. I’m not sure what to tell you.
You might want to take a look in the MSDN forums to see if anyone from the team has anything to say about it.
And, since I’m in the middle of reviewing my book before it goes to print, I will check to be sure I have a warning about this in there somewhere!"