public void ConfigureServices(IServiceCollection services) { services.AddSwagger(); services.AddProjectIdentity(Configuration); services.AddCqrs(); services.AddDbConnectors(); services.AddAutoMapper(typeof(Startup)); services.AddMediatR(typeof(Startup)); services.AddValidatorsFromAssembly(typeof(Startup).Assembly); services.AddRepositories(); services.AddEventSourcing(Configuration); services.AddHateoas(); services.AddControllers(); ConnectionManagerBase .SetConnectionString(Configuration.GetConnectionString("DefaultConnection")); }
internal bool CheckIfExists(ConnectionManagerBase connectionManager) { // would be good if we could check based on architecture here, but there is no column that supports that in SMS_Driver without digging into the xml // we could maybe hack in the description field and append architecture string query = string.Format("SELECT * FROM SMS_Driver WHERE LocalizedDisplayName='{0}' AND DriverVersion='{1}' AND DriverINFFile='{2}'", Model, Version, Path.GetFileName(InfLocation)); IResultObject driverObject = Utility.GetFirstWMIInstance(connectionManager, query); if (driverObject != null) { if (!Directory.Exists(driverObject["ContentSourcePath"].StringValue)) { log.Debug("UpdateContentSourcePath: " + driverObject["LocalizedDisplayName"].StringValue); try { driverObject["ContentSourcePath"].StringValue = Path.GetDirectoryName(InfLocation); 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); } return(false); }
public Vendor(BackgroundWorker worker, ConnectionManagerBase connection, string directory) { connectionManager = connection; backgroundWorker = worker; SourceLocation = directory; Name = new DirectoryInfo(directory).Name; }
public static IEnumerable <IResultObject> SearchWMI(ConnectionManagerBase connectionManager, string query) { using (IResultObject resultObjects = connectionManager.QueryProcessor.ExecuteQuery(query)) { foreach (IResultObject resultObject in resultObjects) { yield return(resultObject); } } }
/// <summary> /// Get database connection for the show. /// </summary> /// <param name="showCode">The Show Code to get connection for</param> /// <param name="useCached">False will always reload show connection, true will use previously cached connection</param> /// <returns>Connection string for a show</returns> public static string GetConnectionString(string showCode, bool useCached) { ConnectionManagerBase MgrBase = new ConnectionManagerBase(GetRegEntConnectionString()); if (!useCached) { return(MgrBase.GetConnectionStringFromDatabase(showCode)); } return(MgrBase.GetConnectionString(showCode)); }
/// <summary> /// Get database connection. /// </summary> public static string GetConnectionString(string serverName, string databaseName) { if (_UseWindowsAuthentication) { return(ConnectionManagerBase.GetWinAuthConnectionString(serverName, databaseName)); } else { return(ConnectionManagerBase.GetGenericConnectionString(serverName, databaseName)); } }
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 string GetEnvironmentMasterConnectionString() { string ConnString = ""; DataTable dt = ConnectionManagerBase.ServerTable; DataRow[] Rows = dt.Select("ServerTypeCode = '" + CRMConfig.EnvironmentMode + "' AND IsEnvironmentMaster = 1"); if (Rows.Length == 1) { ConnString = ConnectionManagerBase.GetGenericConnectionString(Rows[0]["ServerName"].ToString(), EnterpriseDatabaseName); } return(ConnString); }
public void ConfigureServices(IServiceCollection services) { services.AddSettings(Configuration); services.AddDbContext(Configuration.GetConnectionString("DefaultConnection")); services.AddDbConnectors(); services.AddRepositories(); services.AddMapper(); services.AddSwagger(); services.AddJwtIdentity(Configuration.GetSection(nameof(JwtConfiguration))); services.AddLogging(logBuilder => logBuilder.AddSerilog(dispose: true)); services.AddMarten(Configuration); services.AddCqrs(); services.AddMediatR(); services.AddExcelWorkbook(); services.AddGenerators(); services.AddDatabaseLogger(); services.AddHttpContextAccessor(); services.AddFileLoaderServices(); services.AddNotificationManager(); services.AddMvc(options => { options.ModelBinderProviders.Insert(0, new OptionModelBinderProvider()); options.Filters.Add <ModelStateFilter>(); options.Filters.Add( new AsyncExceptionFilter( services.BuildServiceProvider().GetRequiredService <IAsyncLogger>())); options.RespectBrowserAcceptHeader = true; }) .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <RegisterValidator>()) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); ConnectionManagerBase.SetConnectionString(Configuration.GetConnectionString("DefaultConnection")); }
public LegacyPackage(ConnectionManagerBase connection, string name, string source, string target) { connectionManager = connection; Name = name; Source = source; Target = target; GetVersionFromFile(); Hash = Utility.CreateHashForFolder(Source); Import = !File.Exists(Path.Combine(Source, Hash + ".hash")) || CheckVersion(); }
public IEnumerable <IResultObject> GetCollectionMembership(ConnectionManagerBase ConnectionManager, int resourceID) { string query = string.Format("SELECT SMS_Collection.* FROM SMS_FullCollectionMembership, SMS_Collection where ResourceID = '{0}' and SMS_FullCollectionMembership.CollectionID = SMS_Collection.CollectionID", resourceID); using (IResultObject resultObject = ConnectionManager.QueryProcessor.ExecuteQuery(query)) { foreach (IResultObject resultObject1 in resultObject) { yield return(resultObject1); } } }
public static IResultObject GetFirstWMIInstance(ConnectionManagerBase connectionManager, string query) { IResultObject resultObject = null; using (IResultObject resultObjects = connectionManager.QueryProcessor.ExecuteQuery(query)) { foreach (IResultObject resultObject1 in resultObjects) { resultObject = resultObject1; } } return(resultObject); }
public static List <IResultObject> SearchWMIToList(ConnectionManagerBase connectionManager, string query) { List <IResultObject> list = new List <IResultObject>(); using (IResultObject resultObjects = connectionManager.QueryProcessor.ExecuteQuery(query)) { foreach (IResultObject resultObject in resultObjects) { list.Add(resultObject); } } return(list); }
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); }
public static int?CreateFolder(ConnectionManagerBase connectionManager, string folderName, int objectType) { IResultObject instance = connectionManager.CreateInstance("SMS_ObjectContainerNode"); instance["Name"].StringValue = folderName; instance["ObjectType"].IntegerValue = objectType; instance["ParentContainerNodeID"].IntegerValue = 0; instance.Put(); instance.Get(); if (instance == null) { return(new int?()); } return(new int?(instance["ContainerNodeID"].IntegerValue)); }
public DriverPackage(ConnectionManagerBase connection, string name, string source, string target) { connectionManager = connection; Name = name; Source = source; Target = target; GetVersionFromFile(); Hash = Utility.CreateHashForFolder(Source); Import = !File.Exists(Path.Combine(Source, Hash + ".hash")) || CheckVersion(); string[] infFiles = Directory.GetFiles(Source, "*.inf", SearchOption.AllDirectories); Infs = infFiles.Where(x => Path.GetFileName(x) != "autorun.inf").ToArray(); }
public CollevalStatisticsDialog(ActionDescription action, ScopeNode scopeNode) { InitializeComponent(); Title = action.DisplayName; Updater.CheckUpdates(); connectionManager = Microsoft.ConfigurationManagement.AdminConsole.UtilityClass.ConnectionManagerFromScope(scopeNode, "WQL"); progressBar.Style = ProgressBarStyle.Marquee; listViewListCollections.UpdateColumnWidth(columnHeaderName); listViewListCollections.Items.Clear(); listViewListCollections.IsLoading = true; }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> public void ConfigureServices(IServiceCollection services) { services.AddSettings(Configuration); services.AddMemoryCache(); services.AddResponseCaching(); services.AddDbContext(Configuration.GetConnectionString("DefaultConnection")); services.AddDbConnectors(); services.AddTransient <DatabaseSeeder>(); services.AddAutoMapper(typeof(Startup)); services.AddMediatR(typeof(Startup)); services.AddSwagger(); services.AddCqrs(); services.AddEventSourcing(Configuration); services.AddHateoas(); services.AddRepositories(); services.AddRabbitMqService(Configuration); services .AddMvc(options => { options.Filters.Add <ExceptionFilter>(); }) .AddFluentValidation(fv => { fv.RegisterValidatorsFromAssemblyContaining <BeginPersonalityTestValidator>(); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); ConnectionManagerBase .SetConnectionString(Configuration.GetConnectionString("DefaultConnection")); }
private static void ProcessProvisioningMode(ScopeNode scopeNode, ActionDescription action, IResultObject selectedResultObjects, bool mode) { if (selectedResultObjects.ObjectClass == "SMS_Collection") { ConnectionManagerBase connectionManagerInstance = (scopeNode as ConsoleParentNode).RootConnectionNode.GetConnectionManagerInstance("WQL"); try { string query = string.Format("SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='{0}'", selectedResultObjects["CollectionID"].StringValue); using (IResultObject resultObject = connectionManagerInstance.QueryProcessor.ExecuteQuery(query)) { using (ProvisioningModeDialog provisioningMode = new ProvisioningModeDialog(resultObject, action, mode)) { provisioningMode.ShowDialog(SnapIn.Console); return; } } } catch (SmsQueryException ex) { ExceptionUtilities.TraceException(ex); SccmExceptionDialog.ShowDialog(SnapIn.Console, ex); return; } } if (selectedResultObjects.Count == 1) { foreach (IResultObject resultObject in selectedResultObjects) { ThreadPool.QueueUserWorkItem(arg => { ProcessProvisioningMode(resultObject, mode); }); } } else { using (ProvisioningModeDialog provisioningMode = new ProvisioningModeDialog(selectedResultObjects, action, mode)) { provisioningMode.ShowDialog(SnapIn.Console); return; } } }
/// <summary> /// add services to the container. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMemoryCache(); services.AddResponseCaching(); services.AddDbConnectors(); services.AddAutoMapper(typeof(Startup)); services.AddMediatR(Assembly.GetExecutingAssembly()); services.AddSwagger(); services.AddCqrs(); services.AddEventSourcing(Configuration); services.AddHateoas(); services.AddRepositories(); services .AddMvc(options => { options.Filters.Add <ExceptionFilter>(); }) .AddFluentValidation(fv => { fv.RegisterValidatorsFromAssemblyContaining <SaveUserAnswersValidator>(); }) .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); ConnectionManagerBase .SetConnectionString(Configuration.GetConnectionString("DefaultConnection")); }
public static bool AddObjectToFolder(ConnectionManagerBase connectionManager, string folderName, string objectId, int objectType) { try { IResultObject resultObject1; try { string query = string.Format("SELECT * FROM SMS_ObjectContainerNode WHERE Name LIKE '{0}' AND ObjectType={1}", WqlEscapeString(folderName), objectType); resultObject1 = connectionManager.QueryProcessor.ExecuteQuery(query); } catch (SmsQueryException ex) { ExceptionUtilities.TraceException(ex); throw; } IResultObject resultObject2 = null; int? nullable = new int?(); foreach (IResultObject resultObject3 in resultObject1) { if (resultObject3["ObjectType"].IntegerValue == objectType && resultObject3["ParentContainerNodeID"].IntegerValue == 0) { resultObject2 = resultObject3; break; } } if (resultObject2 == null) { try { nullable = CreateFolder(connectionManager, folderName, objectType); } catch (Exception ex) { ExceptionUtilities.TraceException(ex); return(false); } } else { nullable = new int?(resultObject2["ContainerNodeID"].IntegerValue); } IResultObject resultObject4 = null; string query2 = string.Format("Select * From SMS_ObjectContainerItem Where InstanceKey='{0}'", objectId); IResultObject resultObject5 = connectionManager.QueryProcessor.ExecuteQuery(query2); if (resultObject5 != null) { IEnumerator enumerator = resultObject5.GetEnumerator(); if (enumerator.MoveNext()) { resultObject4 = (IResultObject)enumerator.Current; } if (resultObject4 != null) { if (resultObject4["MemberID"] == null) { resultObject4 = null; } } } if (resultObject4 == null) { resultObject4 = connectionManager.CreateInstance("SMS_ObjectContainerItem"); } if (resultObject4 == null) { return(false); } resultObject4["InstanceKey"].StringValue = objectId; resultObject4["ObjectType"].IntegerValue = objectType; resultObject4["ContainerNodeID"].IntegerValue = nullable.Value; resultObject4.Put(); resultObject4.Get(); return(true); } catch (Exception ex) { ExceptionUtilities.TraceException(ex); return(false); } }
public QuickDeployment(ConnectionManagerBase connectionManager, IResultObject collectionObject) : this() { this.connectionManager = connectionManager; Collection = collectionObject; Match match = Regex.Match(collectionObject["Name"].StringValue, @"(?<=\[)([ANSIR]*)\s?(.*)(?=\])"); IsPhased = match.Success ? true : false; if (match.Groups[1].Success) { string key = match.Groups[1].Value; if (Regex.IsMatch(key, @"[A]")) { IsRequired = false; } if (Regex.IsMatch(key, @"[N]")) { UserUIExperience = true; NotifyUser = false; } if (Regex.IsMatch(key, @"[I]")) { OverrideServiceWindows = true; } if (Regex.IsMatch(key, @"[R]")) { RebootOutsideOfServiceWindows = true; } if (Regex.IsMatch(key, @"[S]")) { SuppressReboot = 3; } } if (match.Groups[2].Success) { string[] values = match.Groups[2].Value.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); if (0 < values.Length && Regex.IsMatch(values[0], @"(\+[0-9]+)")) { StartTime = StartTime.AddDays(Convert.ToDouble(values[0].TrimStart('+'))); DeadLineTime = DeadLineTime.AddDays(Convert.ToDouble(values[0].TrimStart('+'))); } if (1 < values.Length && Regex.IsMatch(values[1], @"(([01]\d|2[0-3]):?[0-5]\d)")) { string[] time = values[1].Split(':'); StartTime = StartTime.ChangeTime(Convert.ToInt16(time[0]), Convert.ToInt16(time[1]), 0, 0); DeadLineTime = DeadLineTime.ChangeTime(Convert.ToInt16(time[0]), Convert.ToInt16(time[1]), 0, 0); } if (2 < values.Length && Regex.IsMatch(values[2], @"(\+[0-9]+)")) { DeadLineTime = DeadLineTime.AddDays(Convert.ToDouble(values[2].TrimStart('+'))); } if (3 < values.Length && Regex.IsMatch(values[3], @"(([01]\d|2[0-3]):?[0-5]\d)")) { string[] time = values[3].Split(':'); DeadLineTime = DeadLineTime.ChangeTime(Convert.ToInt16(time[0]), Convert.ToInt16(time[1]), 0, 0); } } }
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); }