public static void RequestLock(ConnectionManagerBase connectionManager, string objectPath) { if (connectionManager == null) { throw new ArgumentNullException("connectionManager"); } if (string.IsNullOrEmpty(objectPath)) { return; } DateTime dateTime = DateTime.Now.AddSeconds(ReadObjectLockTimeout()); Dictionary <string, object> methodParameters = new Dictionary <string, object> { ["ObjectRelPath"] = objectPath, ["RequestTransfer"] = true }; while (DateTime.Now < dateTime) { IResultObject resultObject; try { resultObject = connectionManager.ExecuteMethod("SMS_ObjectLock", "RequestLock", methodParameters); } catch (SmsQueryException ex) { ExceptionUtilities.TraceException(ex); Thread.Sleep(1000); continue; } if (resultObject == null) { Thread.Sleep(1000); } else { using (resultObject) { if (resultObject["RequestState"].ObjectValue != null) { if (resultObject["RequestState"].IntegerValue == 10 || resultObject["RequestState"].IntegerValue == 11) { break; } if (resultObject["RequestState"].IntegerValue == 12) { break; } } } Thread.Sleep(1000); } } }
public static void ReleaseLock(ConnectionManagerBase connectionManager, string objectPath) { if (connectionManager == null) { throw new ArgumentNullException("connectionManager"); } if (string.IsNullOrEmpty(objectPath)) { return; } Dictionary <string, object> methodParameters = new Dictionary <string, object>(); methodParameters["ObjectRelPath"] = objectPath; connectionManager.ExecuteMethod("SMS_ObjectLock", "ReleaseLock", methodParameters); }
internal bool CreateObjectFromInfFile(ConnectionManagerBase connectionManager) { Dictionary <string, object> methodParameters = new Dictionary <string, object> { { "DriverPath", Path.GetDirectoryName(InfLocation) }, { "INFFile", Path.GetFileName(InfLocation) } }; IResultObject driverObject = null; try { log.Debug("CreateFromINF: " + InfLocation); using (IResultObject resultObject = connectionManager.ExecuteMethod("SMS_Driver", "CreateFromINF", methodParameters)) { log.Debug("CreateInstance: " + InfLocation); driverObject = connectionManager.CreateInstance(resultObject["Driver"].ObjectValue); } } catch (SmsQueryException ex) { // error 183 = driver exist, check if source content is ok. if (ex.ExtendStatusErrorCode == 183) { if (ex.InnerException is ManagementException managementException) { try { // update content source path if it dose not exist string query = string.Format("SELECT * FROM SMS_Driver WHERE CI_UniqueID='{0}'", managementException.ErrorInformation["ObjectInfo"].ToString()); driverObject = Utility.GetFirstWMIInstance(connectionManager, query); if (!Directory.Exists(driverObject["ContentSourcePath"].StringValue)) { log.Debug("UpdateContentSourcePath: " + driverObject["LocalizedDisplayName"].StringValue); driverObject["ContentSourcePath"].StringValue = Path.GetDirectoryName(InfLocation); } } catch (SmsQueryException ex1) { ManagementException mgmtException = ex.InnerException as ManagementException; Exception = new SystemException(mgmtException.ErrorInformation["Description"].ToString()); log.Error(string.Format("ContentSourcePath: {0}, {1}, {2}", InfLocation, ex1.GetType().Name, Exception.Message)); return(false); } } else { return(false); } } else if (ex.ExtendStatusErrorCode == 13L) { Exception = new SystemException("Invalid inf file."); log.Error(string.Format("InvalidInf: {0}", InfLocation)); return(false); } else { ManagementException mgmtException = ex.InnerException as ManagementException; Exception = new SystemException(mgmtException.ErrorInformation["Description"].ToString()); log.Error(string.Format("Error: {0}", Exception.Message)); return(false); } } if (driverObject == null) { log.Debug("NoObject: " + InfLocation); return(false); } driverObject["IsEnabled"].BooleanValue = true; try { driverObject.Put(); driverObject.Get(); } catch (SmsQueryException ex) { ManagementException mgmtException = ex.InnerException as ManagementException; Exception = new SystemException(mgmtException.ErrorInformation["Description"].ToString()); log.Error(string.Format("PutDriverObject: {0}, {1}, {2}", InfLocation, ex.GetType().Name, Exception.Message)); return(false); } Object = driverObject; return(true); }