Exemplo n.º 1
0
        public static ActionResult PatchWebsite(Session session)
        {
            try
            {
                Action patch_2_0 = () =>
                {
                    var webInstallationInfo    = WebInstallationInfo.CreateFromFeature(session, "PM");
                    var webInstallationOptions = GetWebInstallationOptions(session);
                    var configFilePath         = webInstallationInfo.GetWebConfigFilePath(webInstallationOptions["PM"]);
                    var dic = new Dictionary <string, string>();
                    dic["multipleSiteBindingsEnabled"] = "true";
                    CprBroker.Installers.Installation.AddSectionNode("serviceHostingEnvironment", dic, configFilePath, "system.serviceModel");
                };

                var infos = new Dictionary <string, WebPatchInfo[]>();
                infos["PM"] = new WebPatchInfo[] {
                    new WebPatchInfo()
                    {
                        Version = new Version(2, 0), PatchAction = patch_2_0
                    }
                };

                return(WebsiteCustomAction.PatchWebsite(session, infos));
            }
            catch (Exception ex)
            {
                session.ShowErrorMessage(ex);
                throw ex;
            }
        }
        public static void PatchWebsite_1_3_0(Session session)
        {
            var types = new Type[]
            {
                typeof(CprBroker.Providers.CPRDirect.CPRDirectClientDataProvider),
                typeof(CprBroker.Providers.CPRDirect.CPRDirectExtractDataProvider)
            };
            var webInstallationInfo = WebInstallationInfo.CreateFromFeature(session, "CPR");
            var configFilePath      = webInstallationInfo.GetWebConfigFilePath(EventBrokerCustomActions.PathConstants.CprBrokerWebsiteDirectoryRelativePath);

            // Add new node(s) for data providers
            CprBroker.Installers.Installation.AddKnownDataProviderTypes(types, configFilePath);
        }
        private static void PatchWebsite_2_2_2(Session session)
        {
            var types = new Type[]
            {
                typeof(CprBroker.Engine.Events.DataChangeEventManager),
                typeof(CprBroker.Providers.Local.Search.LocalSearchDataProvider)
            };
            var webInstallationInfo = WebInstallationInfo.CreateFromFeature(session, "CPR");
            var configFilePath      = webInstallationInfo.GetWebConfigFilePath(EventBrokerCustomActions.PathConstants.CprBrokerWebsiteDirectoryRelativePath);


            // Remove node for data provider: DataChangeEventManager under Engine.dll
            CprBroker.Installers.Installation.RemoveSectionNode(configFilePath, "dataProviders/knownTypes/add[contains(@type, 'DataChangeEventManager') and contains(@type, 'Engine')]");

            // Add new node(s) for data providers
            CprBroker.Installers.Installation.AddKnownDataProviderTypes(types, configFilePath);
        }
        private static void PatchWebsite_2_1_1(Session session)
        {
            // This patch adds /PersonMasterService12 to the address of existing person master data providers for versions prior to 2.1.1
            try
            {
                // Load connection string and encryption keys
                var webInstallationInfo = WebInstallationInfo.CreateFromFeature(session, "CPR");
                var configFilePath      = webInstallationInfo.GetWebConfigFilePath(EventBrokerCustomActions.PathConstants.CprBrokerWebsiteDirectoryRelativePath);
                var config = CprBroker.Installers.Installation.OpenConfigFile(configFilePath);
                DataProvider.EncryptionAlgorithm = DataProviderKeysSection.GetFromConfig(config);
                var connectionString = config.ConnectionStrings.ConnectionStrings["CprBroker.Config.Properties.Settings.CprBrokerConnectionString"].ConnectionString;

                using (var dataContext = new CprBroker.Data.DataProviders.DataProvidersDataContext(connectionString))
                {
                    var providers = dataContext.DataProviders.ToArray();
                    providers = providers
                                .Where(dp =>
                    {
                        var type = Type.GetType(dp.TypeName, false, true);
                        return
                        (type != null &&
                         string.Equals(type.Name, typeof(CprBroker.Providers.PersonMaster.PersonMasterDataProvider).Name));
                    }
                                       ).ToArray();

                    foreach (var prov in providers)
                    {
                        var adr = prov["Address"];
                        if (!string.IsNullOrEmpty(adr))
                        {
                            if (!adr.EndsWith("/PersonMasterService12", StringComparison.InvariantCultureIgnoreCase))
                            {
                                prov["Address"] += "/PersonMasterService12";
                            }
                        }
                    }
                    dataContext.SubmitChanges();
                }
            }
            finally
            {
                // Unload encryption keys
                DataProvider.EncryptionAlgorithm = null;
            }
        }
        public static ActionResult SetCprBrokerUrl(Session session)
        {
            try
            {
                WebInstallationInfo cprBrokerWebInstallationInfo = WebInstallationInfo.CreateFromFeature(session, "CPR");

                var urls = cprBrokerWebInstallationInfo.CalculateWebUrls();
                Func <string, string> urlFunc = u => string.Format("{0}Services/Events.asmx", u);
                var bestUrl = urlFunc(urls[0]);

                for (int i = 0; i < urls.Length; i++)
                {
                    string url    = urlFunc(urls[i]);
                    var    client = new System.Net.WebClient();
                    try
                    {
                        client.DownloadData(url);
                        bestUrl = url;
                        break;
                    }
                    catch (Exception ex)
                    {
                        object o = ex;
                    }
                }

                Installation.SetApplicationSettingInConfigFile(
                    GetServiceExeConfigFullFileName(session),
                    typeof(CprBroker.Config.Properties.Settings),
                    "EventsServiceUrl",
                    bestUrl
                    );
                return(ActionResult.Success);
            }
            catch (Exception ex)
            {
                session.ShowErrorMessage(ex);
                throw ex;
            }
        }
        public static ActionResult CloneDataProviderSectionsToBackendService(Session session)
        {
            try
            {
                try { StopService(ServiceName); }
                catch { }
                WebInstallationInfo cprBrokerWebInstallationInfo = WebInstallationInfo.CreateFromFeature(session, "CPR");
                var sourcePath = cprBrokerWebInstallationInfo.GetWebConfigFilePath(PathConstants.CprBrokerWebsiteDirectoryRelativePath);
                var targetPath = GetServiceExeConfigFullFileName(session);

                // TODO: Shall we also clone connection strings?
                Installation.CopyConfigNode("//configuration", "configSections", sourcePath, targetPath, Installation.MergeOption.Overwrite);
                Installation.CopyConfigNode("//configuration", "dataProvidersGroup", sourcePath, targetPath, Installation.MergeOption.Overwrite);

                try { StartService(ServiceName); }
                catch { }
                return(ActionResult.Success);
            }
            catch (Exception ex)
            {
                session.ShowErrorMessage(ex);
                throw ex;
            }
        }