private void MakeReplacements(RichTextBox richTextBox, string xaml)
{
if (richTextBox == null || string.IsNullOrEmpty(xaml))
return;
string url = Url;
if (string.IsNullOrEmpty(url) && DesignerProperties.GetIsInDesignMode(this))
url = "http://myServer.com/rest/services/myService"; // Use design Url
if (!string.IsNullOrEmpty(url))
{
string resourceName = GetResourceName(url);
IdentityManager.ServerInfo serverInfo = IdentityManager.Current.FindServerInfo(url);
string server = serverInfo == null ? Regex.Match(url, "http.?//[^/]*").ToString() : serverInfo.ServerUrl;
xaml = xaml.Replace("$RESOURCENAME", XamlEncode(resourceName));
xaml = xaml.Replace("$URL", XamlEncode(url));
xaml = xaml.Replace("$SERVER", XamlEncode(server));
}
#if !SILVERLIGHT
xaml = xaml.Replace("$AUTHENTICATIONTYPE", _authenticationType.ToString());
#endif
xaml = xaml.Replace("$ERRORMESSAGE", XamlEncode(ErrorMessage));
string previousError = null;
string referer = null;
string proxyUrl = null;
if (GenerateTokenOptions != null)
{
previousError = GenerateTokenOptions.PreviousError.ToString();
referer = GenerateTokenOptions.Referer;
proxyUrl = GenerateTokenOptions.ProxyUrl;
}
xaml = xaml.Replace("$PREVIOUSERROR", XamlEncode(previousError));
xaml = xaml.Replace("$SERVER", XamlEncode(referer));
xaml = xaml.Replace("$PROXYURL", XamlEncode(proxyUrl));
#if SILVERLIGHT
richTextBox.Xaml = xaml;
#else
StringReader stringReader = new StringReader(xaml);
XmlReader xmlReader = XmlReader.Create(stringReader);
richTextBox.Document = XamlReader.Load(xmlReader) as FlowDocument;
#endif
}