private void CreateApplication() { if (this.CheckApplicationExists()) { return; } this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Creating Application: {0}", this.ApplicationName)); COMAdminCatalogCollection appCollection = GetApplications(); COMAdminCatalogObject app = (COMAdminCatalogObject)appCollection.Add(); app.set_Value("Name", this.ApplicationName); if (!string.IsNullOrEmpty(this.Identity)) { app.set_Value("Identity", this.Identity); app.set_Value("Password", this.UserPassword ?? string.Empty); } app.set_Value("Activation", this.activation.ToString()); app.set_Value("ApplicationAccessChecksEnabled", this.EnforceAccessChecks); appCollection.SaveChanges(); }
static void Main(string[] args) { COMAdminCatalog catalog = new COMAdminCatalog(); COMAdminCatalogCollection applications = catalog.GetCollection("Applications"); applications.Populate(); for (int i = 0; i < applications.Count; i++) { COMAdminCatalogObject application = applications.Item[i]; Console.WriteLine(application.Name); Console.WriteLine(application.Value["Identity"]); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
static private void performccreatecomappop(appoptions apopts) { try { bool bins = ((apopts & appoptions.install) != 0); bool bunins = ((apopts & appoptions.uninstall) != 0); bool bstart = ((apopts & appoptions.start) != 0); bool bstop = ((apopts & appoptions.stop) != 0); COMAdminCatalog catalog = new COMAdminCatalog(); COMAdminCatalogCollection applications = catalog.GetCollection("Applications") as COMAdminCatalogCollection; applications.Populate(); if (bins || bunins || bstart || bstop || breg) { for (int i = 0; i < applications.Count; ++i) { COMAdminCatalogObject app = applications.get_Item(i) as COMAdminCatalogObject; if (app.Name.ToString() == appname) { if (bstart) { catalog.StartApplication(appname); return; } catalog.ShutdownApplication(appname); if (bins || bunins) { applications.Remove(i); applications.SaveChanges(); } break; } } if (bins) { applications.Populate(); COMAdminCatalogObject application = applications.Add() as COMAdminCatalogObject; application.Value["ID"] = Guid.NewGuid().ToString("B"); application.Value["Name"] = appname; application.Value["RunForever"] = brunforever; applications.SaveChanges(); if (System.Environment.OSVersion.Version.Major > 5) { COMAdminCatalogCollection roles = (COMAdminCatalogCollection)applications.GetCollection("Roles", application.Key); roles.Populate(); COMAdminCatalogObject role = roles.Add() as COMAdminCatalogObject; role.Value["Name"] = "DefaultRole"; roles.SaveChanges(); COMAdminCatalogCollection users = (COMAdminCatalogCollection)roles.GetCollection("UsersInRole", role.Key); users.Populate(); COMAdminCatalogObject user = users.Add() as COMAdminCatalogObject; user.Value["User"] = "******"; users.SaveChanges(); } applications.SaveChanges(); } } if (breg || bunreg) { if (data.Count == 0) { if (filename == "") { ShowSyntax(); } List <KeyValuePair <string, string> > progclsidlst = new List <KeyValuePair <string, string> >(); if (filename.ToLower().IndexOf(".wsc") != -1) { progclsidlst = CodeGenHelper.GetclsidsfromWSC(filename); } else { progclsidlst = CodeGenHelper.GetclsidsfromAssembly(filename); if (progclsidlst.Count == 0) { progclsidlst = CodeGenHelper.GetclsidsfromTLB(filename); } } foreach (var kv in progclsidlst) { data.Add(kv.Key); } } foreach (string d in data) { if (breg) { catalog.ImportComponent(appname, d); } } } else if (bgac || bungac) { if (bgac) { catalog.InstallComponent(appname, filename, "", ""); } } applications.SaveChanges(); } catch { } }
private void ExtractComponentProperties(StringBuilder result, ICOMAdminCatalog catalog, COMAdminCatalogObject application) { ICatalogCollection appCatalog = (ICatalogCollection)catalog.GetCollection(COMConstants.APPLICATIONS_CATALOG_NAME); appCatalog.Populate(); foreach (COMAdminCatalogObject app in appCatalog) { if (app.Key.Equals(application.Key)) { ICatalogCollection componentCatalog = (ICatalogCollection)appCatalog.GetCollection(COMConstants.COMPONENTS_CATALOG_NAME, app.Key); componentCatalog.Populate(); foreach (COMAdminCatalogObject comp in componentCatalog) { foreach (ComponentProperties property in componentsProperties) { try { object propertyValue = comp.get_Value(property.Name); if (propertyValue.GetType() != property.Type) { TypeConverter converter = TypeDescriptor.GetConverter(property.Type); if (converter is EnumConverter) { foreach (int value in Enum.GetValues(property.Type)) { if (value == (int)propertyValue) { propertyValue = Enum.ToObject(property.Type, (int)propertyValue); } } } else { propertyValue = converter.ConvertFrom(propertyValue); } } if (!propertyValue.Equals(property.DefaultValue)) { result.AppendFormat("\t<component-property component-name=\"{0}\" property-name=\"{1}\" value=\"{2}\" />", comp.Name, property.Name, propertyValue); result.AppendLine(); } } catch { } } } } } }
private static void ExtractInstallComponent(StringBuilder result, ICOMAdminCatalog catalog, COMAdminCatalogObject application) { ICatalogCollection appCatalog = (ICatalogCollection)catalog.GetCollection(COMConstants.APPLICATIONS_CATALOG_NAME); appCatalog.Populate(); foreach (COMAdminCatalogObject app in appCatalog) { if (app.Key.Equals(application.Key)) { List<string> dlls = new List<string>(); ICatalogCollection componentCatalog = (ICatalogCollection)appCatalog.GetCollection(COMConstants.COMPONENTS_CATALOG_NAME, app.Key); componentCatalog.Populate(); foreach (COMAdminCatalogObject comp in componentCatalog) { string dll = (string)comp.get_Value(@"DLL"); if (!dlls.Contains(dll)) { dlls.Add(dll); } } dlls.Sort(); foreach (string dllFile in dlls) { if (!dllFile.Equals(@"mscoree.dll", StringComparison.InvariantCultureIgnoreCase)) { result.AppendFormat("\t<install-component file=\"{0}\" />", dllFile); } else { result.Append("\t<install-component file=\"INSERT .NET DLL FILE HERE\" net=\"true\" />"); } result.AppendLine(); } } } }
private static void ExtractApplicationRoles(StringBuilder result, ICOMAdminCatalog catalog, COMAdminCatalogObject application) { ICatalogCollection appCatalog = (ICatalogCollection)catalog.GetCollection(COMConstants.APPLICATIONS_CATALOG_NAME); appCatalog.Populate(); foreach (COMAdminCatalogObject app in appCatalog) { if (app.Key.Equals(application.Key)) { ICatalogCollection rolesCatalog = (ICatalogCollection)appCatalog.GetCollection(COMConstants.ROLES_CATALOG_NAME, app.Key); rolesCatalog.Populate(); foreach (COMAdminCatalogObject role in rolesCatalog) { result.AppendFormat("\t<role name=\"{0}\">", role.get_Value(@"Name")); result.AppendLine(); ICatalogCollection usersInRolesCatalog = (ICatalogCollection)rolesCatalog.GetCollection(COMConstants.USERS_IN_ROLES_CATALOG_NAME, role.Key); usersInRolesCatalog.Populate(); foreach (COMAdminCatalogObject user in usersInRolesCatalog) { result.AppendFormat("\t\t<user name=\"{0}\" />", user.get_Value(@"User")); result.AppendLine(); } result.Append("\t</role>"); result.AppendLine(); } } } }
public string DumpApplication(ICOMAdminCatalog catalog, COMAdminCatalogObject application) { StringBuilder result = new StringBuilder(); result.AppendFormat("<com-create-application name=\"{0}\">", application.Name); result.AppendLine(); ExtractApplicationProperties(result, catalog, application); ExtractApplicationRoles(result, catalog, application); ExtractInstallComponent(result, catalog, application); ExtractComponentProperties(result, catalog, application); result.AppendLine("</com-create-application>"); return result.ToString(); }