private void Connect() { ResetUnsetProperties(); if ((!_initializing && !base.DesignMode) && (((!string.IsNullOrEmpty(_userDomain) && !string.IsNullOrEmpty(_userName)) && !string.IsNullOrEmpty(_userPassword)) || ((string.IsNullOrEmpty(_userDomain) && string.IsNullOrEmpty(_userName)) && string.IsNullOrEmpty(_userPassword)))) { if (_v2TaskService != null || _v1TaskScheduler != null) { Dispose(true); } if (_hasV2 && !_forceV1) { _v2TaskService = new TaskSchedulerClass(); if (!string.IsNullOrEmpty(_targetServer)) { if (_targetServer.StartsWith(@"\")) { _targetServer = _targetServer.TrimStart(new char[] { '\\' }); } if (_targetServer.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase)) { _targetServer = null; } } _v2TaskService.Connect(_targetServer, _userName, _userDomain, _userPassword); _targetServer = _v2TaskService.TargetServer; _userName = _v2TaskService.ConnectedUser; _userDomain = _v2TaskService.ConnectedDomain; _maxVer = GetV2Version(); } else { _v1Impersonation = new WindowsImpersonatedIdentity(_userName, _userDomain, _userPassword); var scheduler = new CTaskScheduler(); _v1TaskScheduler = (ITaskScheduler)scheduler; if (!string.IsNullOrEmpty(_targetServer)) { if (!_targetServer.StartsWith(@"\\")) { _targetServer = @"\\" + _targetServer; } } else { _targetServer = null; } _v1TaskScheduler.SetTargetComputer(_targetServer); _targetServer = (string)_v1TaskScheduler.GetTargetComputer(); _maxVer = _v1Ver; } } }
/// <summary> /// Connects this instance of the <see cref="TaskService" /> class to a running Task Scheduler. /// </summary> private void Connect() { ResetUnsetProperties(); if (!initializing && !DesignMode) { if (((!string.IsNullOrEmpty(userDomain) && !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(userPassword)) || (string.IsNullOrEmpty(userDomain) && string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(userPassword)))) { // Clear stuff if already connected if (v2TaskService != null || v1TaskScheduler != null) { Dispose(true); } if (hasV2 && !forceV1) { v2TaskService = new TaskSchedulerClass(); if (!string.IsNullOrEmpty(targetServer)) { // Check to ensure character only server name. (Suggested by bigsan) if (targetServer.StartsWith(@"\")) { targetServer = targetServer.TrimStart('\\'); } // Make sure null is provided for local machine to compensate for a native library oddity (Found by ctrollen) if (targetServer.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase)) { targetServer = null; } } v2TaskService.Connect(targetServer, userName, userDomain, userPassword); targetServer = v2TaskService.TargetServer; userName = v2TaskService.ConnectedUser; userDomain = v2TaskService.ConnectedDomain; maxVer = GetV2Version(); } else { v1Impersonation = new WindowsImpersonatedIdentity(userName, userDomain, userPassword); var csched = new CTaskScheduler(); v1TaskScheduler = (ITaskScheduler)csched; if (!string.IsNullOrEmpty(targetServer)) { // Check to ensure UNC format for server name. (Suggested by bigsan) if (!targetServer.StartsWith(@"\\")) { targetServer = @"\\" + targetServer; } } else { targetServer = null; } v1TaskScheduler.SetTargetComputer(targetServer); targetServer = v1TaskScheduler.GetTargetComputer(); maxVer = v1Ver; } } else { throw new ArgumentException("A username, password, and domain must be provided."); } } }
private void Connect() { ResetUnsetProperties(); if ((!_initializing && !base.DesignMode) && (((!string.IsNullOrEmpty(_userDomain) && !string.IsNullOrEmpty(_userName)) && !string.IsNullOrEmpty(_userPassword)) || ((string.IsNullOrEmpty(_userDomain) && string.IsNullOrEmpty(_userName)) && string.IsNullOrEmpty(_userPassword)))) { if (_v2TaskService != null || _v1TaskScheduler != null) Dispose(true); if (_hasV2 && !_forceV1) { _v2TaskService = new TaskSchedulerClass(); if (!string.IsNullOrEmpty(_targetServer)) { if (_targetServer.StartsWith(@"\")) _targetServer = _targetServer.TrimStart(new char[] { '\\' }); if (_targetServer.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase)) _targetServer = null; } _v2TaskService.Connect(_targetServer, _userName, _userDomain, _userPassword); _targetServer = _v2TaskService.TargetServer; _userName = _v2TaskService.ConnectedUser; _userDomain = _v2TaskService.ConnectedDomain; _maxVer = GetV2Version(); } else { _v1Impersonation = new WindowsImpersonatedIdentity(_userName, _userDomain, _userPassword); var scheduler = new CTaskScheduler(); _v1TaskScheduler = (ITaskScheduler)scheduler; if (!string.IsNullOrEmpty(_targetServer)) { if (!_targetServer.StartsWith(@"\\")) _targetServer = @"\\" + _targetServer; } else _targetServer = null; _v1TaskScheduler.SetTargetComputer(_targetServer); _targetServer = (string)_v1TaskScheduler.GetTargetComputer(); _maxVer = _v1Ver; } } }