Advertisement
Guest User

Untitled

a guest
Feb 5th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1.     // Irgendeine abstrakte Basis, die nebenbei auch die Webheader Collection als statische Variable hält
  2.     public abstract class CoBRAService
  3.     {
  4.         public CoBRAService(string username, string password, string webserviceRootUrl)
  5.         {
  6.             Username = username;
  7.             Password = password;
  8.             BaseService = new CoBRABaseService();
  9.             DmsService = new CoBRADmsService();
  10.             WebserviceRootUrl = webserviceRootUrl;
  11.             SetWebserviceRootUrl(WebserviceRootUrl);
  12.         }
  13.  
  14.         // STATISCHE VARIABLE IN EINER ABSTRAKTEN KLASSE MÖGLICH?
  15.         public static WebHeaderCollection webHeaderCollection = new WebHeaderCollection();
  16.  
  17.         public CoBRABaseService BaseService { get; private set; }
  18.  
  19.         public dmsService DmsService { get; private set; }
  20.  
  21.         public string WebserviceRootUrl { get; private set; }
  22.  
  23.         public string Username { get; set; }
  24.  
  25.         public string Password { get; set; }
  26.  
  27.         public bool Login()
  28.         {
  29.             try
  30.             {
  31.                 CoBRA_BASE.ResultVoid loginResult = BaseService.loginUser(Username, Password);
  32.                 double? loginErrorCode = loginResult.errorCode;
  33.                 return loginErrorCode == 0;
  34.             }
  35.             catch (Exception e)
  36.             {
  37.                 Console.WriteLine(e);
  38.                 return false;
  39.             }
  40.         }
  41.  
  42.         protected bool CheckSession(int errorCode)
  43.         {
  44.             bool activeSession = errorCode == 0;
  45.  
  46.             if (!activeSession)
  47.             {
  48.                 BaseService.SetSessionExpired();
  49.                 activeSession = Login();
  50.                 if (activeSession)
  51.                 {
  52.                     BaseService.SetSessionActive();
  53.                 }
  54.             }
  55.  
  56.             return activeSession;
  57.         }
  58.  
  59.         public bool SetWebserviceRootUrl(string rootUrl)
  60.         {
  61.             bool validRootUrl = false;
  62.  
  63.             try
  64.             {
  65.                 WebserviceRootUrl = rootUrl;
  66.                 BaseService.Url = $"{WebserviceRootUrl}/svc/cobra.cfc?wsdl";
  67.                 DmsService.Url = $"{WebserviceRootUrl}/svc/dms.cfc?wsdl";
  68.                 validRootUrl = true;
  69.             }
  70.             catch (Exception e)
  71.             {
  72.                 Console.WriteLine(e);
  73.             }
  74.  
  75.             return validRootUrl;
  76.         }
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement