Bugfix: UriMappingService supports grandparent WI

Topics: CAB & Smart Client Software Factory
Aug 16, 2005 at 10:39 PM
originally posted by: kirchsth

Translate(Uri uriToTranslate) checks only entries of the parent WorkItem no entries of (great) grandparents.
e.g.
GrandParentWI with "uie://TfmsMainMenu/Task"
ParentWI without an entry
WI with "uie://TfmsMainMenu/Task/Add"
UriMappingService("uie://TfmsMainMenu/Task/Add") returns "uie://TfmsMainMenu/Task/Add.xxxxxxx"
not "uie://TfmsMainMenu/Task.yyyyy/Add.xxxxxxx"

the #else section contains the bugfix
====

public Uri Translate(Uri uriToTranslate)
{
if (translatedUris.ContainsKey(uriToTranslate))
{
return translatedUrisuriToTranslate;
}

string mappedUri = null;
WorkItem parent = WorkItem.GetParent();
Uri stripped = new Uri(this.StripLastItem(uriToTranslate).AbsoluteUri.TrimEnd('/'));
string mappedItem = this.GetLastUriItem(uriToTranslate) + "." + WorkItem.Name;
#if !ParentBugfix
if (parent == null)
{
if (!translatedUris.ContainsKey(uriToTranslate))
{
if (translatedUris.ContainsKey(stripped))
{
mappedUri = FixUri(translatedUrisstripped.AbsoluteUri) + mappedItem;
}
if (mappedUri == null)
{
mappedUri = FixUri(stripped.AbsoluteUri) + mappedItem;
}

translatedUrisuriToTranslate = new Uri(mappedUri);
}
return translatedUrisuriToTranslate;
}

UriMappingService parentMapper = parent.GetService<UriMappingService>();


if (parentMapper.translatedUris.ContainsKey(stripped))
{
mappedUri = FixUri(parentMapper.translatedUrisstripped.AbsoluteUri) + mappedItem;
}
else if (translatedUris.ContainsKey(stripped))
{
mappedUri = FixUri(translatedUrisstripped.AbsoluteUri) + mappedItem;
}

if (mappedUri == null)
{
mappedUri = FixUri(stripped.AbsoluteUri) + mappedItem;
}
Uri mapped = new Uri(mappedUri);
translatedUrisuriToTranslate = mapped;
return mapped;
#else
while (mappedUri == null && parent != null)
{
UriMappingService parentMapper = parent.GetService<UriMappingService>();
if (parentMapper.translatedUris.ContainsKey(stripped))
{
mappedUri = FixUri(parentMapper.translatedUrisstripped.AbsoluteUri) + mappedItem;
}
else
{
parent=parent.GetParent();
}
}
if (mappedUri == null)
{
if (translatedUris.ContainsKey(stripped))
{
mappedUri = FixUri(translatedUrisstripped.AbsoluteUri) + mappedItem;
}
else
{
mappedUri = FixUri(stripped.AbsoluteUri) + mappedItem;
}
}
Uri mapped = new Uri(mappedUri);
translatedUrisuriToTranslate = mapped;
return mapped;
#endif
}