1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
|
//
// System.Runtime.Remoting.RemotingConfiguration.cs
//
// Author: Jaime Anguiano Olarra (jaime@gnome.org)
// Lluis Sanchez Gual (lluis@ideary.com)
//
// (C) 2002, Jaime Anguiano Olarra
//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Lifetime;
using Mono.Xml;
namespace System.Runtime.Remoting
{
[System.Runtime.InteropServices.ComVisible (true)]
public static class RemotingConfiguration
{
static string applicationID = null;
static string applicationName = null;
// static string configFile = "";
// static SmallXmlParser parser = null;
static string processGuid = null;
static bool defaultConfigRead = false;
static bool defaultDelayedConfigRead = false;
static CustomErrorsModes _errorMode = CustomErrorsModes.RemoteOnly;
static Hashtable wellKnownClientEntries = new Hashtable();
static Hashtable activatedClientEntries = new Hashtable();
static Hashtable wellKnownServiceEntries = new Hashtable();
static Hashtable activatedServiceEntries = new Hashtable();
static Hashtable channelTemplates = new Hashtable ();
static Hashtable clientProviderTemplates = new Hashtable ();
static Hashtable serverProviderTemplates = new Hashtable ();
// public properties
// At this time the ID will be the application name
public static string ApplicationId
{
get
{
applicationID = ApplicationName;
return applicationID;
}
}
public static string ApplicationName
{
get { return applicationName; }
set { applicationName = value; }
}
public static CustomErrorsModes CustomErrorsMode
{
get { return _errorMode; }
set { _errorMode = value; }
}
public static string ProcessId
{
get {
if (processGuid == null)
processGuid = AppDomain.GetProcessGuid ();
return processGuid;
}
}
// public methods
[MonoTODO ("ensureSecurity support has not been implemented")]
public static void Configure (string filename, bool ensureSecurity)
{
lock (channelTemplates) {
if (!defaultConfigRead) {
var bundled = Environment.GetBundledMachineConfig ();
if (bundled != null)
ReadConfigString (bundled);
if (File.Exists (Environment.GetMachineConfigPath ()))
ReadConfigFile (Environment.GetMachineConfigPath ());
defaultConfigRead = true;
}
if (filename != null)
ReadConfigFile (filename);
}
}
[Obsolete ("Use Configure(String,Boolean)")]
public static void Configure (string filename)
{
Configure (filename, false);
}
private static void ReadConfigString (string filename)
{
try
{
SmallXmlParser parser = new SmallXmlParser ();
using (TextReader rreader = new StringReader (filename)) {
ConfigHandler handler = new ConfigHandler (false);
parser.Parse (rreader, handler);
}
}
catch (Exception ex)
{
throw new RemotingException ("Configuration string could not be loaded: " + ex.Message, ex);
}
}
private static void ReadConfigFile (string filename)
{
try
{
SmallXmlParser parser = new SmallXmlParser ();
using (TextReader rreader = new StreamReader (filename)) {
ConfigHandler handler = new ConfigHandler (false);
parser.Parse (rreader, handler);
}
}
catch (Exception ex)
{
throw new RemotingException ("Configuration file '" + filename + "' could not be loaded: " + ex.Message, ex);
}
}
internal static void LoadDefaultDelayedChannels ()
{
lock (channelTemplates)
{
if (defaultDelayedConfigRead || defaultConfigRead) return;
SmallXmlParser parser = new SmallXmlParser ();
using (TextReader rreader = new StreamReader (Environment.GetMachineConfigPath ())) {
ConfigHandler handler = new ConfigHandler (true);
parser.Parse (rreader, handler);
}
defaultDelayedConfigRead = true;
}
}
public static ActivatedClientTypeEntry[] GetRegisteredActivatedClientTypes ()
{
lock (channelTemplates)
{
ActivatedClientTypeEntry[] entries = new ActivatedClientTypeEntry[activatedClientEntries.Count];
activatedClientEntries.Values.CopyTo (entries,0);
return entries;
}
}
public static ActivatedServiceTypeEntry[] GetRegisteredActivatedServiceTypes ()
{
lock (channelTemplates)
{
ActivatedServiceTypeEntry[] entries = new ActivatedServiceTypeEntry[activatedServiceEntries.Count];
activatedServiceEntries.Values.CopyTo (entries,0);
return entries;
}
}
public static WellKnownClientTypeEntry[] GetRegisteredWellKnownClientTypes ()
{
lock (channelTemplates)
{
WellKnownClientTypeEntry[] entries = new WellKnownClientTypeEntry[wellKnownClientEntries.Count];
wellKnownClientEntries.Values.CopyTo (entries,0);
return entries;
}
}
public static WellKnownServiceTypeEntry[] GetRegisteredWellKnownServiceTypes ()
{
lock (channelTemplates)
{
WellKnownServiceTypeEntry[] entries = new WellKnownServiceTypeEntry[wellKnownServiceEntries.Count];
wellKnownServiceEntries.Values.CopyTo (entries,0);
return entries;
}
}
public static bool IsActivationAllowed (Type svrType)
{
lock (channelTemplates)
{
return activatedServiceEntries.ContainsKey (svrType);
}
}
public static ActivatedClientTypeEntry IsRemotelyActivatedClientType (Type svrType)
{
lock (channelTemplates)
{
return activatedClientEntries [svrType] as ActivatedClientTypeEntry;
}
}
public static ActivatedClientTypeEntry IsRemotelyActivatedClientType (string typeName, string assemblyName)
{
return IsRemotelyActivatedClientType (Assembly.Load(assemblyName).GetType (typeName));
}
public static WellKnownClientTypeEntry IsWellKnownClientType (Type svrType)
{
lock (channelTemplates)
{
return wellKnownClientEntries [svrType] as WellKnownClientTypeEntry;
}
}
public static WellKnownClientTypeEntry IsWellKnownClientType (string typeName, string assemblyName)
{
return IsWellKnownClientType (Assembly.Load(assemblyName).GetType (typeName));
}
public static void RegisterActivatedClientType (ActivatedClientTypeEntry entry)
{
lock (channelTemplates)
{
if (wellKnownClientEntries.ContainsKey (entry.ObjectType) || activatedClientEntries.ContainsKey (entry.ObjectType))
throw new RemotingException ("Attempt to redirect activation of type '" + entry.ObjectType.FullName + "' which is already redirected.");
activatedClientEntries[entry.ObjectType] = entry;
ActivationServices.EnableProxyActivation (entry.ObjectType, true);
}
}
public static void RegisterActivatedClientType (Type type, string appUrl)
{
if (type == null) throw new ArgumentNullException ("type");
if (appUrl == null) throw new ArgumentNullException ("appUrl");
RegisterActivatedClientType (new ActivatedClientTypeEntry (type, appUrl));
}
public static void RegisterActivatedServiceType (ActivatedServiceTypeEntry entry)
{
lock (channelTemplates)
{
activatedServiceEntries.Add (entry.ObjectType, entry);
}
}
public static void RegisterActivatedServiceType (Type type)
{
RegisterActivatedServiceType (new ActivatedServiceTypeEntry (type));
}
public static void RegisterWellKnownClientType (Type type, string objectUrl)
{
if (type == null) throw new ArgumentNullException ("type");
if (objectUrl == null) throw new ArgumentNullException ("objectUrl");
RegisterWellKnownClientType (new WellKnownClientTypeEntry (type, objectUrl));
}
public static void RegisterWellKnownClientType (WellKnownClientTypeEntry entry)
{
lock (channelTemplates)
{
if (wellKnownClientEntries.ContainsKey (entry.ObjectType) || activatedClientEntries.ContainsKey (entry.ObjectType))
throw new RemotingException ("Attempt to redirect activation of type '" + entry.ObjectType.FullName + "' which is already redirected.");
wellKnownClientEntries[entry.ObjectType] = entry;
ActivationServices.EnableProxyActivation (entry.ObjectType, true);
}
}
public static void RegisterWellKnownServiceType (Type type, string objectUri, WellKnownObjectMode mode)
{
RegisterWellKnownServiceType (new WellKnownServiceTypeEntry (type, objectUri, mode));
}
public static void RegisterWellKnownServiceType (WellKnownServiceTypeEntry entry)
{
lock (channelTemplates)
{
wellKnownServiceEntries [entry.ObjectUri] = entry;
RemotingServices.CreateWellKnownServerIdentity (entry.ObjectType, entry.ObjectUri, entry.Mode);
}
}
internal static void RegisterChannelTemplate (ChannelData channel)
{
channelTemplates [channel.Id] = channel;
}
internal static void RegisterClientProviderTemplate (ProviderData prov)
{
clientProviderTemplates [prov.Id] = prov;
}
internal static void RegisterServerProviderTemplate (ProviderData prov)
{
serverProviderTemplates [prov.Id] = prov;
}
internal static void RegisterChannels (ArrayList channels, bool onlyDelayed)
{
foreach (ChannelData channel in channels)
{
if (onlyDelayed && channel.DelayLoadAsClientChannel != "true")
continue;
if (defaultDelayedConfigRead && channel.DelayLoadAsClientChannel == "true")
continue;
if (channel.Ref != null)
{
ChannelData template = (ChannelData) channelTemplates [channel.Ref];
if (template == null) throw new RemotingException ("Channel template '" + channel.Ref + "' not found");
channel.CopyFrom (template);
}
foreach (ProviderData prov in channel.ServerProviders)
{
if (prov.Ref != null)
{
ProviderData template = (ProviderData) serverProviderTemplates [prov.Ref];
if (template == null) throw new RemotingException ("Provider template '" + prov.Ref + "' not found");
prov.CopyFrom (template);
}
}
foreach (ProviderData prov in channel.ClientProviders)
{
if (prov.Ref != null)
{
ProviderData template = (ProviderData) clientProviderTemplates [prov.Ref];
if (template == null) throw new RemotingException ("Provider template '" + prov.Ref + "' not found");
prov.CopyFrom (template);
}
}
ChannelServices.RegisterChannelConfig (channel);
}
}
internal static void RegisterTypes (ArrayList types)
{
foreach (TypeEntry type in types)
{
if (type is ActivatedClientTypeEntry)
RegisterActivatedClientType ((ActivatedClientTypeEntry)type);
else if (type is ActivatedServiceTypeEntry)
RegisterActivatedServiceType ((ActivatedServiceTypeEntry)type);
else if (type is WellKnownClientTypeEntry)
RegisterWellKnownClientType ((WellKnownClientTypeEntry)type);
else if (type is WellKnownServiceTypeEntry)
RegisterWellKnownServiceType ((WellKnownServiceTypeEntry)type);
}
}
public static bool CustomErrorsEnabled (bool isLocalRequest)
{
if (_errorMode == CustomErrorsModes.Off) return false;
if (_errorMode == CustomErrorsModes.On) return true;
return !isLocalRequest;
}
internal static void SetCustomErrorsMode (string mode)
{
if (mode == null)
throw new RemotingException ("mode attribute is required");
// the mode is case insensitive
string m = mode.ToLower ();
if (m != "on" && m != "off" && m != "remoteonly")
throw new RemotingException ("Invalid custom error mode: " + mode);
_errorMode = (CustomErrorsModes) Enum.Parse(typeof(CustomErrorsModes), m, true);
}
}
/***************************************************************
* Internal classes used by RemotingConfiguration.Configure () *
***************************************************************/
internal class ConfigHandler : SmallXmlParser.IContentHandler
{
ArrayList typeEntries = new ArrayList ();
ArrayList channelInstances = new ArrayList ();
ChannelData currentChannel = null;
Stack currentProviderData = null;
string currentClientUrl = null;
string appName;
string currentXmlPath = "";
bool onlyDelayedChannels;
public ConfigHandler (bool onlyDelayedChannels)
{
this.onlyDelayedChannels = onlyDelayedChannels;
}
void ValidatePath (string element, params string[] paths)
{
foreach (string path in paths)
if (CheckPath (path)) return;
throw new RemotingException ("Element " + element + " not allowed in this context");
}
bool CheckPath (string path)
{
CompareInfo ci = CultureInfo.InvariantCulture.CompareInfo;
if (ci.IsPrefix (path, "/", CompareOptions.Ordinal))
return path == currentXmlPath;
else
return ci.IsSuffix (currentXmlPath, path, CompareOptions.Ordinal);
}
public void OnStartParsing (SmallXmlParser parser) {}
public void OnProcessingInstruction (string name, string text) {}
public void OnIgnorableWhitespace (string s) {}
public void OnStartElement (string name, SmallXmlParser.IAttrList attrs)
{
try
{
if (currentXmlPath.StartsWith ("/configuration/system.runtime.remoting"))
ParseElement (name, attrs);
currentXmlPath += "/" + name;
}
catch (Exception ex)
{
throw new RemotingException ("Error in element " + name + ": " + ex.Message, ex);
}
}
public void ParseElement (string name, SmallXmlParser.IAttrList attrs)
{
if (currentProviderData != null)
{
ReadCustomProviderData (name, attrs);
return;
}
switch (name)
{
case "application":
ValidatePath (name, "system.runtime.remoting");
if (attrs.Names.Length > 0)
appName = attrs.Values[0];
break;
case "lifetime":
ValidatePath (name, "application");
ReadLifetine (attrs);
break;
case "channels":
ValidatePath (name, "system.runtime.remoting", "application");
break;
case "channel":
ValidatePath (name, "channels");
if (currentXmlPath.IndexOf ("application") != -1)
ReadChannel (attrs, false);
else
ReadChannel (attrs, true);
break;
case "serverProviders":
ValidatePath (name, "channelSinkProviders", "channel");
break;
case "clientProviders":
ValidatePath (name, "channelSinkProviders", "channel");
break;
case "provider":
case "formatter":
ProviderData prov;
if (CheckPath ("application/channels/channel/serverProviders") ||
CheckPath ("channels/channel/serverProviders"))
{
prov = ReadProvider (name, attrs, false);
currentChannel.ServerProviders.Add (prov);
}
else if (CheckPath ("application/channels/channel/clientProviders") ||
CheckPath ("channels/channel/clientProviders"))
{
prov = ReadProvider (name, attrs, false);
currentChannel.ClientProviders.Add (prov);
}
else if (CheckPath ("channelSinkProviders/serverProviders"))
{
prov = ReadProvider (name, attrs, true);
RemotingConfiguration.RegisterServerProviderTemplate (prov);
}
else if (CheckPath ("channelSinkProviders/clientProviders"))
{
prov = ReadProvider (name, attrs, true);
RemotingConfiguration.RegisterClientProviderTemplate (prov);
}
else
ValidatePath (name);
break;
case "client":
ValidatePath (name, "application");
currentClientUrl = attrs.GetValue ("url");
break;
case "service":
ValidatePath (name, "application");
break;
case "wellknown":
ValidatePath (name, "client", "service");
if (CheckPath ("client"))
ReadClientWellKnown (attrs);
else
ReadServiceWellKnown (attrs);
break;
case "activated":
ValidatePath (name, "client", "service");
if (CheckPath ("client"))
ReadClientActivated (attrs);
else
ReadServiceActivated (attrs);
break;
case "soapInterop":
ValidatePath (name, "application");
break;
case "interopXmlType":
ValidatePath (name, "soapInterop");
ReadInteropXml (attrs, false);
break;
case "interopXmlElement":
ValidatePath (name, "soapInterop");
ReadInteropXml (attrs, false);
break;
case "preLoad":
ValidatePath (name, "soapInterop");
ReadPreload (attrs);
break;
case "debug":
ValidatePath (name, "system.runtime.remoting");
break;
case "channelSinkProviders":
ValidatePath (name, "system.runtime.remoting");
break;
case "customErrors":
ValidatePath (name, "system.runtime.remoting");
RemotingConfiguration.SetCustomErrorsMode (attrs.GetValue ("mode"));
break;
default:
throw new RemotingException ("Element '" + name + "' is not valid in system.remoting.configuration section");
}
}
public void OnEndElement (string name)
{
if (currentProviderData != null)
{
currentProviderData.Pop ();
if (currentProviderData.Count == 0)
currentProviderData = null;
}
currentXmlPath = currentXmlPath.Substring (0, currentXmlPath.Length - name.Length - 1);
}
void ReadCustomProviderData (string name, SmallXmlParser.IAttrList attrs)
{
SinkProviderData parent = (SinkProviderData) currentProviderData.Peek ();
SinkProviderData data = new SinkProviderData (name);
for (int i=0; i < attrs.Names.Length; ++i)
data.Properties [attrs.Names[i]] = attrs.GetValue (i);
parent.Children.Add (data);
currentProviderData.Push (data);
}
void ReadLifetine (SmallXmlParser.IAttrList attrs)
{
for (int i=0; i < attrs.Names.Length; ++i) {
switch (attrs.Names[i]) {
case "leaseTime":
LifetimeServices.LeaseTime = ParseTime (attrs.GetValue(i));
break;
case "sponsorshipTimeout":
LifetimeServices.SponsorshipTimeout = ParseTime (attrs.GetValue(i));
break;
case "renewOnCallTime":
LifetimeServices.RenewOnCallTime = ParseTime (attrs.GetValue(i));
break;
case "leaseManagerPollTime":
LifetimeServices.LeaseManagerPollTime = ParseTime (attrs.GetValue(i));
break;
default:
throw new RemotingException ("Invalid attribute: " + attrs.Names[i]);
}
}
}
TimeSpan ParseTime (string s)
{
if (s == "" || s == null) throw new RemotingException ("Invalid time value");
int i = s.IndexOfAny (new char[] { 'D','H','M','S' });
string unit;
if (i == -1)
unit = "S";
else {
unit = s.Substring (i);
s = s.Substring (0,i);
}
double val;
try {
val = double.Parse (s);
}
catch {
throw new RemotingException ("Invalid time value: " + s);
}
if (unit == "D") return TimeSpan.FromDays (val);
if (unit == "H") return TimeSpan.FromHours (val);
if (unit == "M") return TimeSpan.FromMinutes (val);
if (unit == "S") return TimeSpan.FromSeconds (val);
if (unit == "MS") return TimeSpan.FromMilliseconds (val);
throw new RemotingException ("Invalid time unit: " + unit);
}
void ReadChannel (SmallXmlParser.IAttrList attrs, bool isTemplate)
{
ChannelData channel = new ChannelData ();
for (int i=0; i < attrs.Names.Length; ++i)
{
string at = attrs.Names[i];
string val = attrs.Values[i];
if (at == "ref" && !isTemplate)
channel.Ref = val;
else if (at == "delayLoadAsClientChannel")
channel.DelayLoadAsClientChannel = val;
else if (at == "id" && isTemplate)
channel.Id = val;
else if (at == "type")
channel.Type = val;
else
channel.CustomProperties.Add (at, val);
}
if (isTemplate)
{
if (channel.Id == null) throw new RemotingException ("id attribute is required");
if (channel.Type == null) throw new RemotingException ("id attribute is required");
RemotingConfiguration.RegisterChannelTemplate (channel);
}
else
channelInstances.Add (channel);
currentChannel = channel;
}
ProviderData ReadProvider (string name, SmallXmlParser.IAttrList attrs, bool isTemplate)
{
ProviderData prov = (name == "provider") ? new ProviderData () : new FormatterData ();
SinkProviderData data = new SinkProviderData ("root");
prov.CustomData = data.Children;
currentProviderData = new Stack ();
currentProviderData.Push (data);
for (int i=0; i < attrs.Names.Length; ++i)
{
string at = attrs.Names[i];
string val = attrs.Values[i];
if (at == "id" && isTemplate)
prov.Id = val;
else if (at == "type")
prov.Type = val;
else if (at == "ref" && !isTemplate)
prov.Ref = val;
else
prov.CustomProperties.Add (at, val);
}
if (prov.Id == null && isTemplate) throw new RemotingException ("id attribute is required");
return prov;
}
void ReadClientActivated (SmallXmlParser.IAttrList attrs)
{
string type = GetNotNull (attrs, "type");
string assm = ExtractAssembly (ref type);
if (currentClientUrl == null || currentClientUrl == "")
throw new RemotingException ("url attribute is required in client element when it contains activated entries");
typeEntries.Add (new ActivatedClientTypeEntry (type, assm, currentClientUrl));
}
void ReadServiceActivated (SmallXmlParser.IAttrList attrs)
{
string type = GetNotNull (attrs, "type");
string assm = ExtractAssembly (ref type);
typeEntries.Add (new ActivatedServiceTypeEntry (type, assm));
}
void ReadClientWellKnown (SmallXmlParser.IAttrList attrs)
{
string url = GetNotNull (attrs, "url");
string type = GetNotNull (attrs, "type");
string assm = ExtractAssembly (ref type);
typeEntries.Add (new WellKnownClientTypeEntry (type, assm, url));
}
void ReadServiceWellKnown (SmallXmlParser.IAttrList attrs)
{
string objectUri = GetNotNull (attrs, "objectUri");
string smode = GetNotNull (attrs, "mode");
string type = GetNotNull (attrs, "type");
string assm = ExtractAssembly (ref type);
WellKnownObjectMode mode;
if (smode == "SingleCall") mode = WellKnownObjectMode.SingleCall;
else if (smode == "Singleton") mode = WellKnownObjectMode.Singleton;
else throw new RemotingException ("wellknown object mode '" + smode + "' is invalid");
typeEntries.Add (new WellKnownServiceTypeEntry (type, assm, objectUri, mode));
}
void ReadInteropXml (SmallXmlParser.IAttrList attrs, bool isElement)
{
Type t = Type.GetType (GetNotNull (attrs, "clr"));
string[] xmlName = GetNotNull (attrs, "xml").Split (',');
string localName = xmlName [0].Trim ();
string ns = xmlName.Length > 0 ? xmlName[1].Trim() : null;
if (isElement) SoapServices.RegisterInteropXmlElement (localName, ns, t);
else SoapServices.RegisterInteropXmlType (localName, ns, t);
}
void ReadPreload (SmallXmlParser.IAttrList attrs)
{
string type = attrs.GetValue ("type");
string assm = attrs.GetValue ("assembly");
if (type != null && assm != null)
throw new RemotingException ("Type and assembly attributes cannot be specified together");
if (type != null)
SoapServices.PreLoad (Type.GetType (type));
else if (assm != null)
SoapServices.PreLoad (Assembly.Load (assm));
else
throw new RemotingException ("Either type or assembly attributes must be specified");
}
string GetNotNull (SmallXmlParser.IAttrList attrs, string name)
{
string value = attrs.GetValue (name);
if (value == null || value == "")
throw new RemotingException (name + " attribute is required");
return value;
}
string ExtractAssembly (ref string type)
{
int i = type.IndexOf (',');
if (i == -1) return "";
string asm = type.Substring (i+1).Trim();
type = type.Substring (0, i).Trim();
return asm;
}
public void OnChars (string ch) {}
public void OnEndParsing (SmallXmlParser parser)
{
RemotingConfiguration.RegisterChannels (channelInstances, onlyDelayedChannels);
if (appName != null) RemotingConfiguration.ApplicationName = appName;
if (!onlyDelayedChannels)
RemotingConfiguration.RegisterTypes (typeEntries);
}
}
/*******************************************************************
* Internal data structures used by ConfigHandler, to store *
* machine.config's remoting related data. *
* If having them implemented this way, makes configuration too *
* slow, we can use string arrays. *
*******************************************************************/
internal class ChannelData {
internal string Ref;
internal string Type;
internal string Id;
internal string DelayLoadAsClientChannel;
ArrayList _serverProviders = new ArrayList ();
ArrayList _clientProviders = new ArrayList ();
Hashtable _customProperties = new Hashtable ();
internal ArrayList ServerProviders {
get {
if (_serverProviders == null) _serverProviders = new ArrayList ();
return _serverProviders;
}
}
public ArrayList ClientProviders {
get {
if (_clientProviders == null) _clientProviders = new ArrayList ();
return _clientProviders;
}
}
public Hashtable CustomProperties {
get {
if (_customProperties == null) _customProperties = new Hashtable ();
return _customProperties;
}
}
public void CopyFrom (ChannelData other)
{
if (Ref == null) Ref = other.Ref;
if (Id == null) Id = other.Id;
if (Type == null) Type = other.Type;
if (DelayLoadAsClientChannel == null) DelayLoadAsClientChannel = other.DelayLoadAsClientChannel;
if (other._customProperties != null)
{
foreach (DictionaryEntry entry in other._customProperties)
if (!CustomProperties.ContainsKey (entry.Key))
CustomProperties [entry.Key] = entry.Value;
}
if (_serverProviders == null && other._serverProviders != null)
{
foreach (ProviderData prov in other._serverProviders)
{
ProviderData np = new ProviderData();
np.CopyFrom (prov);
ServerProviders.Add (np);
}
}
if (_clientProviders == null && other._clientProviders != null)
{
foreach (ProviderData prov in other._clientProviders)
{
ProviderData np = new ProviderData();
np.CopyFrom (prov);
ClientProviders.Add (np);
}
}
}
}
internal class ProviderData {
internal string Ref;
internal string Type;
internal string Id;
internal Hashtable CustomProperties = new Hashtable ();
internal IList CustomData;
public void CopyFrom (ProviderData other)
{
if (Ref == null) Ref = other.Ref;
if (Id == null) Id = other.Id;
if (Type == null) Type = other.Type;
foreach (DictionaryEntry entry in other.CustomProperties)
if (!CustomProperties.ContainsKey (entry.Key))
CustomProperties [entry.Key] = entry.Value;
if (other.CustomData != null)
{
if (CustomData == null) CustomData = new ArrayList ();
foreach (SinkProviderData data in other.CustomData)
CustomData.Add (data);
}
}
}
internal class FormatterData: ProviderData {
}
}
|