17 using System.Collections.Generic;
18 using System.Diagnostics;
22 using System.Reflection;
23 using System.Security.Principal;
24 using System.ServiceModel;
26 using System.Text.RegularExpressions;
29 using System.Xml.Linq;
30 using erminas.SmartAPI.CMS.Project;
31 using erminas.SmartAPI.CMS.ServerManagement;
32 using erminas.SmartAPI.Exceptions;
33 using erminas.SmartAPI.RedDotCmsXmlServer;
34 using erminas.SmartAPI.Utils;
35 using erminas.SmartAPI.Utils.CachedCollections;
38 namespace erminas.SmartAPI.CMS
42 private readonly DateTime _lastActionDate;
43 private readonly DateTime _loginDate;
44 private readonly Guid _loginGuid;
45 private readonly
string _moduleName;
46 private readonly
string _projectName;
48 public RunningSessionInfo(Guid loginGuid,
string projectName,
string moduleName, DateTime loginDate,
49 DateTime lastActionDate)
51 _loginGuid = loginGuid;
52 _projectName = projectName;
53 _moduleName = moduleName;
54 _loginDate = loginDate;
55 _lastActionDate = lastActionDate;
60 _projectName = element.GetAttributeValue(
"projectname");
61 _moduleName = element.GetAttributeValue(
"moduledescription");
62 _loginDate = element.GetOADate(
"logindate").GetValueOrDefault();
63 _lastActionDate = element.GetOADate(
"lastactiondate").GetValueOrDefault();
64 element.TryGetGuid(out _loginGuid);
67 public DateTime LastActionDate
69 get {
return _lastActionDate; }
72 public DateTime LoginDate
74 get {
return _loginDate; }
79 get {
return _loginGuid; }
82 public string ModuleName
84 get {
return _moduleName; }
87 public string ProjectName
89 get {
return _projectName; }
96 IndexedCachedList<string, IDialogLocale> DialogLocales {
get; }
98 XmlDocument ExecuteRQL(
string query, RQL.IODataFormat format);
105 XmlDocument ExecuteRQL(
string query);
113 XmlDocument ExecuteRQLInProjectContext(
string query, Guid projectGuid);
115 XmlDocument ExecuteRQLInProjectContextAndEmbeddedInProjectElement(
string query, Guid projectGuid);
123 string ExecuteRQLRaw(
string query, RQL.IODataFormat ioDataFormat);
133 string GetTextContent(Guid projectGuid,
ILanguageVariant lang, Guid elementGuid,
string typeString);
138 IIndexedCachedList<int, ISystemLocale> Locales {
get; }
140 Guid LogonGuid {
get; }
146 void SelectProject(Guid projectGuid);
153 void SelectProject(
IProject project);
160 void SendMailFromCurrentUserAccount(
EMail mail);
161 void SendMailFromSystemAccount(
EMail mail);
170 Version ServerVersion {
get; }
172 string SessionKey {
get; }
185 Guid SetTextContent(Guid projectGuid,
ILanguageVariant languageVariant, Guid textElementGuid,
string typeString,
200 void WaitForAsyncProcess(TimeSpan maxWait, Predicate<IAsynchronousProcess> processPredicate);
209 void WaitForAsyncProcess(TimeSpan maxWait, TimeSpan retry, Predicate<IAsynchronousProcess> processPredicate);
212 public static class RQL
217 public enum IODataFormat
227 SessionKeyAndLogonGuid,
232 SessionKeyInProjectElement,
246 public const string SESSIONKEY_PLACEHOLDER =
"#__SESSION_KEY__#";
253 internal class Session : ISession
258 ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) =>
true;
261 private const string RQL_IODATA =
"<IODATA>{0}</IODATA>";
262 private const string RQL_IODATA_LOGONGUID =
@"<IODATA loginguid=""{0}"">{1}</IODATA>";
263 private const string RQL_IODATA_SESSIONKEY =
@"<IODATA sessionkey=""{1}"" loginguid=""{0}"">{2}</IODATA>";
264 private const string RQL_IODATA_SESSIONKEY_ONLY =
@"<IODATA sessionkey=""{0}"" loginguid="""">{1}</IODATA>";
266 private const string RQL_IODATA_PROJECT_SESSIONKEY =
267 @"<IODATA loginguid=""{0}""><PROJECT sessionkey=""{1}"">{2}</PROJECT></IODATA>";
269 private const string RQL_LOGIN =
270 @"<ADMINISTRATION action=""login"" name=""{0}"" password=""{1}""></ADMINISTRATION>";
272 private const string RQL_LOGIN_FORCE =
273 @"<ADMINISTRATION action=""login"" name=""{0}"" password=""{1}"" loginguid=""{2}""/>";
275 private const string RQL_SELECT_PROJECT =
276 @"<ADMINISTRATION action=""validate"" guid=""{0}"" useragent=""script""><PROJECT guid=""{1}""/></ADMINISTRATION>";
278 private const string RQL_IODATA_FORMATTED_TEXT =
279 @"<IODATA loginguid=""{0}"" sessionkey=""{1}"" format=""1"">{2}</IODATA>";
281 private static readonly Regex VERSION_REGEXP =
283 "(Management Server.* |CMS Version )\\d+(\\.\\d+)* Build (\\d+\\.\\d+\\.\\d+\\.\\d+)");
285 private static readonly ILog LOG = LogManager.GetLogger(
"Session");
287 private string _loginGuidStr;
288 private string _sessionKeyStr;
292 ServerManager =
new ServerManager(
this);
293 Locales =
new IndexedCachedList<int, ISystemLocale>(GetLocales, x => x.LCID,
Caching.Enabled);
294 DialogLocales =
new IndexedCachedList<string, IDialogLocale>(GetDialogLocales, x => x.LanguageAbbreviation,
300 Func<IEnumerable<RunningSessionInfo>, RunningSessionInfo> sessionReplacementSelector) : this()
303 Login(sessionReplacementSelector);
309 public Session(
ServerLogin login, Guid loginGuid,
string sessionKey, Guid projectGuid) : this()
312 _loginGuidStr = loginGuid.ToRQLString();
313 _sessionKeyStr = sessionKey;
316 XmlElement sessionInfo = GetUserSessionInfoElement();
317 SelectedProjectGuid = sessionInfo.GetGuid(
"projectguid");
318 SelectProject(projectGuid);
327 public IRDList<IAsynchronousProcess> AsynchronousProcesses {
get {
return ServerManager.AsynchronousProcesses; } }
329 public IUser CurrentUser
331 get {
return ServerManager.Users.Current; }
334 public IndexedCachedList<string, IDialogLocale> DialogLocales {
get;
private set; }
339 public void Dispose()
346 LogonGuid =
default(Guid);
356 public XmlDocument ExecuteRQL(
string query, RQL.IODataFormat format)
358 string result = ExecuteRQLRaw(query, format);
359 return ParseRQLResult(
this, result);
362 public XmlDocument ExecuteRQL(
string query)
364 string result = ExecuteRQLRaw(query, RQL.IODataFormat.LogonGuidOnly);
367 var xmlDoc =
new XmlDocument();
368 xmlDoc.LoadXml(result);
370 }
catch (Exception e)
376 public XmlDocument ExecuteRQLInProjectContext(
string query, Guid projectGuid)
378 SelectProject(projectGuid);
379 string result = ExecuteRQLRaw(query, RQL.IODataFormat.SessionKeyAndLogonGuid);
380 return ParseRQLResult(
this, result);
383 public XmlDocument ExecuteRQLInProjectContextAndEmbeddedInProjectElement(
string query, Guid projectGuid)
385 SelectProject(projectGuid);
386 string result = ExecuteRQLRaw(query, RQL.IODataFormat.SessionKeyInProjectElement);
387 return ParseRQLResult(
this, result);
390 public string ExecuteRQLRaw(
string query, RQL.IODataFormat ioDataFormat)
392 string tmpQuery = query.Replace(RQL.SESSIONKEY_PLACEHOLDER,
"#" + _sessionKeyStr);
394 switch (ioDataFormat)
396 case RQL.IODataFormat.SessionKeyAndLogonGuid:
397 rqlQuery =
string.Format(RQL_IODATA_SESSIONKEY, _loginGuidStr, _sessionKeyStr, tmpQuery);
399 case RQL.IODataFormat.LogonGuidOnly:
400 rqlQuery =
string.Format(RQL_IODATA_LOGONGUID, _loginGuidStr, tmpQuery);
402 case RQL.IODataFormat.Plain:
403 rqlQuery =
string.Format(RQL_IODATA, tmpQuery);
405 case RQL.IODataFormat.SessionKeyInProjectElement:
406 rqlQuery =
string.Format(RQL_IODATA_PROJECT_SESSIONKEY, _loginGuidStr, _sessionKeyStr, tmpQuery);
408 case RQL.IODataFormat.FormattedText:
409 rqlQuery =
string.Format(RQL_IODATA_FORMATTED_TEXT, _loginGuidStr, _sessionKeyStr, tmpQuery);
412 case RQL.IODataFormat.SessionKeyOnly:
413 rqlQuery =
string.Format(RQL_IODATA_SESSIONKEY_ONLY, _sessionKeyStr, tmpQuery);
416 throw new ArgumentException(String.Format(
"Unknown RQL.IODataFormat: {0}", ioDataFormat));
418 return SendRQLToServer(rqlQuery);
429 public string GetTextContent(Guid projectGuid,
ILanguageVariant lang, Guid elementGuid,
string typeString)
431 const string LOAD_TEXT_CONTENT =
432 @"<IODATA loginguid=""{0}"" format=""1"" sessionkey=""{1}""><PROJECT><TEXT action=""load"" guid=""{2}"" texttype=""{3}""/></PROJECT></IODATA>";
433 SelectProject(projectGuid);
436 SendRQLToServer(
string.Format(LOAD_TEXT_CONTENT, _loginGuidStr, _sessionKeyStr,
437 elementGuid.ToRQLString(), typeString));
443 public IIndexedCachedList<int, ISystemLocale> Locales {
get;
private set; }
445 public Guid LogonGuid
447 get {
return Guid.Parse(_loginGuidStr); }
448 private set { _loginGuidStr = value.ToRQLString(); }
455 public void SelectProject(Guid projectGuid)
457 if (SelectedProjectGuid.Equals(projectGuid))
467 string.Format(RQL_SELECT_PROJECT, _loginGuidStr, projectGuid.ToRQLString().ToUpperInvariant()),
468 RQL.IODataFormat.LogonGuidOnly);
475 var xmlDoc =
new XmlDocument();
476 xmlDoc.LoadXml(result);
477 XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName(
"SERVER");
478 if (xmlNodes.Count > 0)
480 SessionKey = ((XmlElement) xmlNodes[0]).GetAttributeValue(
"key");
481 SelectedProjectGuid = projectGuid;
486 String.Format(
"Couldn't select project {0}", projectGuid.ToRQLString()),
495 public void SelectProject(
IProject project)
497 SelectProject(project.
Guid);
507 return ServerManager.
Users.Current.ModuleAssignment.IsServerManager
508 ? ServerManager.Projects.FirstOrDefault(x => x.Guid == SelectedProjectGuid)
509 : ServerManager.Projects.ForCurrentUser.FirstOrDefault(x => x.Guid == SelectedProjectGuid);
511 set { SelectProject(value); }
514 public Guid SelectedProjectGuid {
get;
private set; }
516 public void SendMailFromCurrentUserAccount(
EMail mail)
518 SendEmail(ServerManager.Users.Current.EMail, mail);
521 public void SendMailFromSystemAccount(
EMail mail)
524 string fromAddress = server.
From;
526 SendEmail(fromAddress, mail);
536 public Version ServerVersion {
get;
private set; }
538 public string SessionKey
542 if (_sessionKeyStr == null)
546 return _sessionKeyStr;
548 private set { _sessionKeyStr = value; }
560 public Guid SetTextContent(Guid projectGuid,
ILanguageVariant languageVariant, Guid textElementGuid,
561 string typeString,
string content)
563 const string SAVE_TEXT_CONTENT =
564 @"<IODATA loginguid=""{0}"" format=""1"" sessionkey=""{1}""><PROJECT><TEXT action=""save"" guid=""{2}"" texttype=""{3}"" >{4}</TEXT></PROJECT></IODATA>";
565 SelectProject(projectGuid);
568 SendRQLToServer(
string.Format(SAVE_TEXT_CONTENT, _loginGuidStr, _sessionKeyStr,
569 textElementGuid == Guid.Empty ?
"" : textElementGuid.ToRQLString(),
570 typeString, HttpUtility.HtmlEncode(content)));
573 string resultGuidStr = XElement.Load(
new StringReader(rqlResult)).Value.Trim();
576 if (
string.IsNullOrEmpty(resultGuidStr))
578 return textElementGuid;
582 if (!Guid.TryParse(resultGuidStr, out newGuid) ||
583 (textElementGuid != Guid.Empty && textElementGuid != newGuid))
590 public ISystemLocale StandardLocale
592 get {
return Locales.First(locale => locale.IsStandardLanguage); }
605 public void WaitForAsyncProcess(TimeSpan maxWait, Predicate<IAsynchronousProcess> processPredicate)
607 var retryEverySecond =
new TimeSpan(0, 0, 1);
608 WaitForAsyncProcess(maxWait, retryEverySecond, processPredicate);
618 public void WaitForAsyncProcess(TimeSpan maxWait, TimeSpan retry,
619 Predicate<IAsynchronousProcess> processPredicate)
621 Predicate<IRDList<IAsynchronousProcess>> pred = list => list.Any(process => processPredicate(process));
625 DateTime start = DateTime.Now;
626 var retryEvery50ms =
new TimeSpan(0, 0, 0, 0, 50);
627 AsynchronousProcesses.WaitFor(pred, maxWait, retryEvery50ms);
629 TimeSpan timeLeft = maxWait - (DateTime.Now - start);
630 timeLeft = timeLeft.TotalMilliseconds > 0 ? timeLeft :
new TimeSpan(0, 0, 0);
632 AsynchronousProcesses.WaitFor(list => !pred(list), timeLeft, retry);
635 internal XmlElement GetUserSessionInfoElement()
638 const string SESSION_INFO =
@"<PROJECT sessionkey=""{0}""><USER action=""sessioninfo""/></PROJECT>";
639 string reply = ExecuteRQLRaw(SESSION_INFO.RQLFormat(_sessionKeyStr), RQL.IODataFormat.Plain);
641 var doc =
new XmlDocument();
643 return (XmlElement) doc.SelectSingleNode(
"/IODATA/USER");
646 internal void LoginToServerManager()
648 const string LOGIN_TO_SERVER_MANAGER =
649 @"<ADMINISTRATION><MODULE action=""login"" userguid=""{0}"" projectguid=""{1}"" id=""servermanager"" /></ADMINISTRATION>";
650 ExecuteRQL(LOGIN_TO_SERVER_MANAGER.RQLFormat(ServerManager.Users.Current, SelectedProjectGuid));
651 SelectedProjectGuid = Guid.Empty;
654 internal static XmlDocument ParseRQLResult(ISession session,
string result)
656 var xmlDoc =
new XmlDocument();
658 if (!result.Trim().Any())
665 xmlDoc.LoadXml(result);
667 }
catch (Exception e)
669 throw new SmartAPIException(session.ServerLogin,
"Illegal response from server", e);
673 private static string CheckAlreadyLoggedIn(XmlElement xmlElement)
675 return xmlElement.GetAttributeValue(
"loginguid") ??
"";
678 private void CheckLoginResponse(XmlDocument xmlDoc,
679 Func<IEnumerable<RunningSessionInfo>, RunningSessionInfo>
680 sesssionReplacementSelector)
682 XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName(
"LOGIN");
684 if (xmlNodes.Count > 0)
696 private string CmsServerConnectionUrl {
get;
set; }
698 private static string ExtractMessagesWithInnerExceptions(Exception e)
700 Exception curException = e;
701 var builder =
new StringBuilder();
702 string linePrefix =
"";
703 while (curException != null)
705 builder.Append(linePrefix);
706 builder.Append(curException.Message);
707 builder.Append(
"\n");
708 curException = curException.InnerException;
712 return builder.ToString();
715 private List<IDialogLocale> GetDialogLocales()
717 const string LOAD_DIALOG_LANGUAGES =
@"<DIALOG action=""listlanguages"" orderby=""2""/>";
718 string resultStr = ExecuteRQLRaw(LOAD_DIALOG_LANGUAGES, RQL.IODataFormat.LogonGuidOnly);
719 XmlDocument xmlDoc = ParseRQLResult(
this, resultStr);
721 return (from XmlElement curElement in xmlDoc.GetElementsByTagName(
"LIST")
722 select (IDialogLocale) new DialogLocale(this, curElement)).ToList();
727 LOG.InfoFormat(
"User login will be forced. Old login guid was: {0}", oldLoginGuid.ToRQLString());
729 string rql =
string.Format(RQL_IODATA, RQL_LOGIN_FORCE.RQLFormat(pa.Username, pa.Password, oldLoginGuid));
730 string debugRQLOutput =
string.Format(RQL_IODATA,
731 RQL_LOGIN_FORCE.RQLFormat(pa.Username,
"*****", oldLoginGuid));
732 string result = SendRQLToServer(rql, debugRQLOutput);
733 var xmlDoc =
new XmlDocument();
734 xmlDoc.LoadXml(result);
735 XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName(
"LOGIN");
736 return (XmlElement) (xmlNodes.Count > 0 ? xmlNodes[0] : null);
739 private List<ISystemLocale> GetLocales()
741 const string LOAD_LOCALES =
@"<LANGUAGE action=""list""/>";
742 XmlDocument xmlDoc = ExecuteRQL(LOAD_LOCALES);
743 var languages = xmlDoc.GetElementsByTagName(
"LANGUAGES")[0] as XmlElement;
744 if (languages == null)
750 (from XmlElement item in languages.GetElementsByTagName(
"LIST")
751 select (ISystemLocale) new SystemLocale(this, item)).ToList();
754 private XmlDocument GetLoginResponse()
757 string rql =
string.Format(RQL_IODATA,
758 string.Format(RQL_LOGIN, HttpUtility.HtmlEncode(authData.
Username),
759 HttpUtility.HtmlEncode(authData.
Password)));
762 string debugOutputRQL =
string.Format(RQL_IODATA,
763 string.Format(RQL_LOGIN, HttpUtility.HtmlEncode(authData.
Username),
765 var xmlDoc =
new XmlDocument();
768 string result = SendRQLToServer(rql, debugOutputRQL);
769 xmlDoc.LoadXml(result);
781 private Version GetServerVersion(
string baseURL)
783 string versionURI = baseURL +
"ioVersionInfo.asp";
786 using (var client =
new WebClient())
790 var c =
new CredentialCache();
792 client.Credentials = c;
795 client.Headers.Add(
"Referer", baseURL);
797 string responseText = client.DownloadString(versionURI);
798 Match match = VERSION_REGEXP.Match(responseText);
799 if (match.Groups.Count != 4)
802 "Could not retrieve version info of RedDot server at " +
803 baseURL +
"\n" + responseText);
806 return new Version(match.Groups[3].Value);
811 }
catch (WebException e)
814 "Could not retrieve version info of RedDot server at " + baseURL +
815 "\n" + e.Message, e);
816 }
catch (Exception e)
819 "Could not retrieve version info of RedDot server at " + baseURL +
820 "\n" + e.Message, e);
824 private void InitConnection()
827 if (!baseURL.EndsWith(
"/"))
832 CmsServerConnectionUrl = baseURL +
833 (ServerVersion.Major < 11
834 ?
"webservice/RDCMSXMLServer.WSDL"
835 :
"WebService/RQLWebService.svc");
838 private static bool IsProjectUnavailbaleException(Exception e)
842 "The project you have selected is no longer available. Please select a different project via the Main Menu.");
845 private void LoadSelectedProject(XmlDocument xmlDoc)
847 var lastModule = (XmlElement) xmlDoc.SelectSingleNode(
"/IODATA/USER/LASTMODULES/MODULE[@last='1']");
848 if (lastModule == null)
853 string projectStr = lastModule.GetAttributeValue(
"project");
854 if (!
string.IsNullOrEmpty(projectStr))
858 SelectProject(Guid.Parse(projectStr));
861 if (IsProjectUnavailbaleException(e) ||
862 (e.InnerException != null && IsProjectUnavailbaleException(e.InnerException)))
864 SelectedProjectGuid = Guid.Empty;
874 private void Login(Func<IEnumerable<RunningSessionInfo>, RunningSessionInfo> sessionReplacementSelector)
878 XmlDocument xmlDoc = GetLoginResponse();
880 CheckLoginResponse(xmlDoc, sessionReplacementSelector);
885 private void Logout(Guid logonGuid)
887 const string RQL_LOGOUT =
@"<ADMINISTRATION><LOGOUT guid=""{0}""/></ADMINISTRATION>";
888 ExecuteRQLRaw(
string.Format(RQL_LOGOUT, logonGuid.ToRQLString()), RQL.IODataFormat.LogonGuidOnly);
891 private void ParseLoginResponse(XmlNodeList xmlNodes,
PasswordAuthentication authData, XmlDocument xmlDoc,
892 Func<IEnumerable<RunningSessionInfo>, RunningSessionInfo>
893 sessionReplacementSelector)
896 var xmlNode = (XmlElement) xmlNodes[0];
897 string oldLoginGuid = CheckAlreadyLoggedIn(xmlNode);
898 if (oldLoginGuid !=
"")
900 RunningSessionInfo sessionToReplace;
901 if (sessionReplacementSelector == null ||
902 !TryGetSessionInfo(xmlDoc, sessionReplacementSelector, out sessionToReplace))
905 "User is already logged in and no open session was selected to get replaced");
907 xmlNode = GetForceLoginXmlNode(authData, sessionToReplace.LoginGuid);
911 "Could not force login.");
916 string loginGuid = xmlNode.GetAttributeValue(
"guid");
917 if (
string.IsNullOrEmpty(loginGuid))
922 LogonGuid = Guid.Parse(loginGuid);
923 SessionKey = LogonGuid.ToRQLString();
924 LoadSelectedProject(xmlNode.OwnerDocument);
925 var loginNode = (XmlElement) xmlNodes[0];
926 string userGuidStr = loginNode.GetAttributeValue(
"userguid");
927 if (
string.IsNullOrEmpty(userGuidStr))
929 XmlNodeList userNodes = xmlDoc.GetElementsByTagName(
"USER");
930 if (userNodes.Count != 1)
933 "Could not login; Invalid user data");
935 var xmlElement = ((XmlElement) userNodes[0]);
936 ((Users)ServerManager.Users).Current =
new User(
this, xmlElement.GetGuid()) { Name = xmlElement.GetAttributeValue(
"name") };
940 ((Users)ServerManager.Users).Current =
new User(
this, Guid.Parse(loginNode.GetAttributeValue(
"userguid")));
944 private void SendEmail(
string fromAddress,
EMail mail)
947 const string SEND_EMAIL =
948 @"<ADMINISTRATION action=""sendmail"" to=""{0}"" subject=""{1}"" from=""{3}"" plaintext=""1"">{2}</ADMINISTRATION>";
960 private string SendRQLToServer(
string rqlQuery,
string debugRQLQuery = null)
964 LOG.DebugFormat(
"Sending RQL [{0}]: {1}",
ServerLogin.
Name, debugRQLQuery ?? rqlQuery);
967 object resultInfo =
"";
968 var binding =
new BasicHttpBinding();
973 binding.Security.Mode = BasicHttpSecurityMode.Transport;
975 binding.ReaderQuotas.MaxStringContentLength = 2097152*10;
976 binding.ReaderQuotas.MaxArrayLength = 2097152*10;
977 binding.MaxReceivedMessageSize = 2097152*10;
978 binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
979 binding.SendTimeout = TimeSpan.FromMinutes(10);
983 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
984 binding.Security.Mode = isUsingHttps ? BasicHttpSecurityMode.TransportWithMessageCredential : BasicHttpSecurityMode.TransportCredentialOnly;
987 var add =
new EndpointAddress(CmsServerConnectionUrl);
996 client.ClientCredentials.Windows.AllowedImpersonationLevel =
997 TokenImpersonationLevel.Impersonation;
1003 string result = client.Execute(rqlQuery, ref error, ref resultInfo);
1004 string errorStr = (error ??
"").ToString();
1005 if (!
string.IsNullOrEmpty(errorStr))
1008 if (exception.ErrorCode ==
ErrorCode.NoRight || exception.ErrorCode ==
ErrorCode.RDError110)
1016 }
catch (Exception e)
1018 string msg = ExtractMessagesWithInnerExceptions(e);
1020 LOG.Debug(e.StackTrace);
1023 }
catch (EndpointNotFoundException e)
1025 LOG.ErrorFormat(
"Server not found: {0}", CmsServerConnectionUrl);
1027 string.Format(
@"Server ""{0}"" not found", CmsServerConnectionUrl),
1032 private static bool TryGetSessionInfo(XmlDocument xmlDoc,
1033 Func<IEnumerable<RunningSessionInfo>, RunningSessionInfo>
1034 sessionReplacementSelector, out RunningSessionInfo sessionToReplace)
1036 if (sessionReplacementSelector == null)
1038 sessionToReplace = null;
1043 sessionReplacementSelector(from XmlElement curLogin in xmlDoc.GetElementsByTagName(
"LOGIN") where curLogin.TryGetGuid(out loginGuid)
1044 select
new RunningSessionInfo(curLogin));
1046 return sessionToReplace != null;
1062 internal static class VersionVerifier
1064 internal static void EnsureVersion(ISession session)
1066 var stack =
new StackTrace();
1068 StackFrame stackFrame = stack.GetFrames()[1];
1070 MethodBase methodBase = stackFrame.GetMethod();
1071 MemberInfo info = methodBase;
1072 if (methodBase.IsSpecialName && (methodBase.Name.StartsWith(
"get_") || methodBase.Name.StartsWith(
"set_")))
1075 info = methodBase.DeclaringType.GetProperty(methodBase.Name.Substring(4),
1078 BindingFlags.DeclaredOnly | BindingFlags.Public |
1079 BindingFlags.Instance | BindingFlags.NonPublic);
1082 object[] lessThanAttributes = info.GetCustomAttributes(typeof (VersionIsLessThan),
false);
1083 object[] greaterOrEqualAttributes = info.GetCustomAttributes(typeof (VersionIsGreaterThanOrEqual),
false);
1084 if (lessThanAttributes.Count() != 1 && greaterOrEqualAttributes.Count() != 1)
1089 if (lessThanAttributes.Any())
1091 lessThanAttributes.Cast<VersionIsLessThan>()
1093 .Validate(session.ServerLogin, session.ServerVersion, info.Name);
1096 if (greaterOrEqualAttributes.Any())
1098 greaterOrEqualAttributes.Cast<VersionIsGreaterThanOrEqual>()
1100 .Validate(session.ServerLogin, session.ServerVersion, info.Name);