Exemplo n.º 1
0
 public static string UpdateArticleURlInArticleContent(string content, string toReplace, string replaceWith)
 {
     DataConfigurationRepository dataConfigurationRepository = new
                      DataConfigurationRepository(HttpContext.Current.Application["KBDataPath"].ToString(), HttpContext.Current.Application["KBInstallPath"].ToString());
     var newContent = content.Replace(toReplace, replaceWith);
     newContent = newContent.Replace("|' target=_parent>", "' target=_parent>");
     return newContent.Replace(dataConfigurationRepository.AdminURL, dataConfigurationRepository.PS5URL);
 }
Exemplo n.º 2
0
        public static ArticlePartialViewModel CreateArticlePartialViewModel(ArticleItem articleItem, ArticleModule articleModule,
            ArrayList categoryNamesList, ArrayList attributeNamesList, PortalType portalType,
            Dictionary<string, string> resources, int clientId, int portalId, string adminURL)
        {
            ArticlePartialViewModel articlePartialViewModel = new ArticlePartialViewModel();
            DataConfigurationRepository dataConfigurationRepository = new
                            DataConfigurationRepository(HttpContext.Current.Application["KBDataPath"].ToString(), HttpContext.Current.Application["KBInstallPath"].ToString());
            articlePartialViewModel.Resources = resources;
            articlePartialViewModel.ArticleItem = articleItem;
            articlePartialViewModel.clientId = clientId;
            articlePartialViewModel.portalId = portalId;
            if (articleModule != null)
            {
                articlePartialViewModel.ArticleConfiguration = articleModule;
            }
            else
            {
                //---- set defaults ------

            }
            List<BreadcrumbViewModel> categories = new List<BreadcrumbViewModel>();
            foreach (List<string> names in categoryNamesList)
            {
                BreadcrumbViewModel itemList = new BreadcrumbViewModel();
                itemList.NavigationList = new List<SelectListItem>();
                foreach (string name in names)
                {
                    itemList.NavigationList.Add(new SelectListItem() { Text = name, Value = string.Empty, Selected = false });
                }
                categories.Add(itemList);
            }
            articlePartialViewModel.Categories = categories;
            articlePartialViewModel.Attributes = new List<BreadcrumbViewModel>();
            List<BreadcrumbViewModel> attr = new List<BreadcrumbViewModel>();
            foreach (List<string> names in attributeNamesList)
            {
                BreadcrumbViewModel itemList = new BreadcrumbViewModel();
                itemList.NavigationList = new List<SelectListItem>();
                foreach (string name in names)
                {
                    itemList.NavigationList.Add(new SelectListItem() { Text = name, Value = string.Empty, Selected = false });
                }
                attr.Add(itemList);
            }
            articlePartialViewModel.Attributes = attr;
            articlePartialViewModel.ImageLinks = new List<ImageLinkViewModel>();
            ImageLinkViewModel imageLinkViewModel;

            //check Favorite is enabled
            if (articlePartialViewModel.ArticleConfiguration.articleControlsProperties.ArticleFavoriteDisplay)
            {
                imageLinkViewModel = new ImageLinkViewModel() { Icon = (articlePartialViewModel.ArticleItem.Favorite == true &&
                    (portalType != PortalType.Open && portalType != PortalType.Registration)) ?
                    @Utilities.GetImageUrl(clientId, portalId, "favoriteactive.png") : @Utilities.GetImageUrl(clientId, portalId, "favorite.png"),
                                                                Link = "/Article/FavoriteArticle/" + clientId + "/" + portalId,
                                                                Title = Utilities.GetResourceText(resources, "CONTROLS_FAVORITELABEL"),
                                                                ToggleIcon = (articlePartialViewModel.ArticleItem.Favorite == true ||
                                                                portalType == PortalType.Open || portalType == PortalType.Registration) ?
                                                                @Utilities.GetImageUrl(clientId, portalId, "favorite.png") :
                                                                @Utilities.GetImageUrl(clientId, portalId, "favoriteactive.png")
                };
                imageLinkViewModel.Id = "favorites";
                articlePartialViewModel.ImageLinks.Add(imageLinkViewModel);
            }

            //check Subscription is enabled
            if (articlePartialViewModel.ArticleConfiguration.articleControlsProperties.ArticleSubscribeDisplay)
            {
                imageLinkViewModel = new ImageLinkViewModel() { Icon = @Utilities.GetImageUrl(clientId, portalId, "subscribe.png"),
                    Link = "", Title = Utilities.GetResourceText(resources, "CONTROLS_SUBSCRIBELABEL"),
                    ToggleIcon = @Utilities.GetImageUrl(clientId, portalId, "subscribe_selected.png") };
                // imageLinkViewModel = new ImageLinkViewModel() { Icon = (articlesViewModel.ArticlePartialViewModel.ArticleItem.SubscriptionStatus == true && (_portal.PortalType != PortalType.Open && _portal.PortalType != PortalType.Registration)) ? @Utilities.GetImageUrl(clientId, portalId, "subscribe_select.png") : @Utilities.GetImageUrl(clientId, portalId, "subscribe.png"), Link = "/Article/ToggleArticleSubscription/" + clientId + "/" + portalId, Title = Utilities.GetResourceText(resources, "CONTROLS_SUBSCRIBELABEL"), ToggleIcon = (articlesViewModel.ArticlePartialViewModel.ArticleItem.SubscriptionStatus == true || _portal.PortalType == PortalType.Open || _portal.PortalType == PortalType.Registration) ? @Utilities.GetImageUrl(clientId, portalId, "subscribe.png") : @Utilities.GetImageUrl(clientId, portalId, "subscribe.png") };
                //imageLinkViewModel = new ImageLinkViewModel() { Icon = @Utilities.GetImageUrl(clientId, portalId, "subscribe.png"), Link = "", Title = Utilities.GetResourceText(resources,"CONTROLS_SUBSCRIBELABEL"), ToggleIcon = @Utilities.GetImageUrl(clientId, portalId, "subscribe.png") };
                imageLinkViewModel.Id = "subscribe";
                articlePartialViewModel.ImageLinks.Add(imageLinkViewModel);
            }
            //Check share is enabled
            if (articlePartialViewModel.ArticleConfiguration.articleControlsProperties.ArticleShareDisplay)
            {
                imageLinkViewModel = new ImageLinkViewModel() { Icon = @Utilities.GetImageUrl(clientId, portalId, "share.png"),
                    Link = "", Title = Utilities.GetResourceText(resources, "CONTROLS_SHARELABEL"),
                    ToggleIcon = @Utilities.GetImageUrl(clientId, portalId, "share_selected.png") };
                imageLinkViewModel.Id = "share";
                articlePartialViewModel.ImageLinks.Add(imageLinkViewModel);
            }
            if (articlePartialViewModel.ArticleConfiguration.articleControlsProperties.ArticleEditDisplay)
            {
                imageLinkViewModel = new ImageLinkViewModel() { Icon = @Utilities.GetImageUrl(clientId, portalId, "edit.png"),
                                                                Link = adminURL + "/index.aspx?aid=",
                                                                Title = Utilities.GetResourceText(resources, "CONTROLS_EDITLABEL"),
                    ToggleIcon = @Utilities.GetImageUrl(clientId, portalId, "edit.png") };
                imageLinkViewModel.Id = "edit";
                articlePartialViewModel.ImageLinks.Add(imageLinkViewModel);
            }
            articlePartialViewModel.Attachments = articleItem.Attachments;
            return articlePartialViewModel;
        }
Exemplo n.º 3
0
        public static void LogPortalVisit(int userid, int portalId, int clientId, int newlog, string url)
        {
            string ipv4Address = "";

            var connectionStrings = new SqlNativeConnectionStrings(HttpContext.Current.Application["KBInstallPath"].ToString());
            var datRepo = new DataConfigurationRepository(HttpContext.Current.Application["KBDataPath"].ToString(), HttpContext.Current.Application["KBInstallPath"].ToString());
            SqlServerPortalLogRepository portalLogRep = new SqlServerPortalLogRepository(connectionStrings, datRepo);
            if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                ipv4Address = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(new char[] { ',' }).FirstOrDefault();
            }
            if (ipv4Address == "")
            {
                ipv4Address = HttpContext.Current.Request.UserHostAddress;
            }
            portalLogRep.PortalVisitAsync(portalId, clientId, userid, HttpContext.Current.Session.SessionID, ipv4Address, newlog, url);
        }
Exemplo n.º 4
0
        public static void UpdateLogoff(this HttpSessionStateBase session, int portalId, int clientId)
        {
            User user = (User)session["UserSession_" + portalId.ToString()];
            int userid = user.UserId;
            string ipv4Address = "";
            var connectionStrings = new SqlNativeConnectionStrings(HttpContext.Current.Application["KBInstallPath"].ToString());
            var datRepo = new DataConfigurationRepository(HttpContext.Current.Application["KBDataPath"].ToString(), HttpContext.Current.Application["KBInstallPath"].ToString());
            SqlServerPortalLogRepository portalLogRep = new SqlServerPortalLogRepository(connectionStrings, datRepo);
            if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                ipv4Address = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(new char[] { ',' }).FirstOrDefault();
            }
            if (ipv4Address == "")
            {
                ipv4Address = HttpContext.Current.Request.UserHostAddress;
            }

            portalLogRep.Logoff(portalId, clientId, userid, HttpContext.Current.Session.SessionID, ipv4Address);
        }
Exemplo n.º 5
0
        private void InitializeAutofac()
        {
            try
            {
                // See https://code.google.com/p/autofac/wiki/WebApiIntegration for details.

                var builder = new ContainerBuilder();

                RegistryKey clientkey = Registry.LocalMachine;
                if (System.Environment.Is64BitOperatingSystem && System.Environment.Is64BitProcess)
                {
                    //logger.Warn("Detected a 64 bit system with 64 bit processes.  This configuration is not supported.");
                }
                else if (!System.Environment.Is64BitOperatingSystem)
                {
                    //logger.Warn("Detected a 32 bit system. This configuration is not supported.");
                }

                RegistryKey rootKey = clientkey.OpenSubKey(@"SOFTWARE\KnowledgeBase.Net\", true);
                string installPath = string.Empty;
                if (rootKey.GetValueNames().Contains("Program Files"))
                {
                    installPath = rootKey.GetValue("Program Files").ToString();
                }

                Application["KBInstallPath"] = installPath;

                string dataPath = string.Empty;
                if (rootKey.GetValueNames().Contains("Data Files"))
                {
                    dataPath = rootKey.GetValue("Data Files").ToString();
                }

                Application["KBDataPath"] = dataPath;

                IPortalRepository portalRep = new XmlPortalRepository(dataPath);
                Application.Add("PortalManager", new PortalManager(portalRep));
                PortalResource portalResourceRep = new PortalResource(dataPath);
                Application.Add("PortalResource", new PortalResourceManager(portalResourceRep));

                // Add your registrations
                var connectionStrings = new SqlNativeConnectionStrings(installPath);
                // data repository
                var datRepo = new DataConfigurationRepository(dataPath, installPath);

                builder.RegisterControllers(Assembly.GetExecutingAssembly());

                // Ideally we'd register all SqlServer*Respository types in one call.
                // But I'm not sure how to do it yet.
                //builder
                //    .RegisterAssemblyTypes(typeof(SqlServerUserRepository).Assembly)
                //    .Where(t => t.Name.StartsWith("SqlServer"))
                //    .Where(t => t.Name.EndsWith("Repository"))
                //    .As(t => t)
                //    .WithParameter("connectionStrings", connectionStrings);

                //builder
                //   .RegisterType<SqlNativeConnectionStrings>()
                //   .As<IConnectionStrings>()
                //   .WithParameter("stringsFilePath", "c:\\test");

                builder
                    .RegisterType<SqlServerArticleRepository>()
                    .As<IArticleRepository>()
                    .WithParameter(
                        (paramInfo, componentContext) => paramInfo.ParameterType == typeof(SqlNativeConnectionStrings),
                        (paramInfo, componentContext) => connectionStrings)
                    .WithParameter((paramInfo, componentContext) => paramInfo.ParameterType == typeof(DataConfigurationRepository),
                        (paramInfo, componentContext) => datRepo);
                builder
                    .RegisterType<SqlServerCategoryRepository>()
                    .As<ICategoryRepository>()
                    .WithParameter(
                        (paramInfo, componentContext) => paramInfo.ParameterType == typeof(SqlNativeConnectionStrings),
                        (paramInfo, componentContext) => connectionStrings)
                    .WithParameter((paramInfo, componentContext) => paramInfo.ParameterType == typeof(DataConfigurationRepository),
                        (paramInfo, componentContext) => datRepo);

                builder
                    .RegisterType<SqlServerSolutionFinderRepository>()
                    .As<ISolutionFinderRepository>()
                    .WithParameter(
                        (paramInfo, componentContext) => paramInfo.ParameterType == typeof(SqlNativeConnectionStrings),
                        (paramInfo, componentContext) => connectionStrings)
                    .WithParameter((paramInfo, componentContext) => paramInfo.ParameterType == typeof(DataConfigurationRepository),
                        (paramInfo, componentContext) => datRepo);

                builder.RegisterType<SearchRepository>()
                    .As<ISearchesRepository>()
                   .WithParameter(
                        (paramInfo, componentContext) => paramInfo.ParameterType == typeof(SqlNativeConnectionStrings),
                        (paramInfo, componentContext) => connectionStrings)
                    .WithParameter((paramInfo, componentContext) => paramInfo.ParameterType == typeof(DataConfigurationRepository),
                        (paramInfo, componentContext) => datRepo);

                builder
                    .RegisterType<SqlServerUserRepository>()
                    .As<IUserRepository>()
                    .WithParameter(
                        (paramInfo, componentContext) => paramInfo.ParameterType == typeof(SqlNativeConnectionStrings),
                        (paramInfo, componentContext) => connectionStrings)
                    .WithParameter((paramInfo, componentContext) => paramInfo.ParameterType == typeof(DataConfigurationRepository),
                        (paramInfo, componentContext) => datRepo);

                builder
                   .RegisterType<TokenRepository>()
                   .As<ITokenRepository>()
                   .WithParameter(
                       (paramInfo, componentContext) => paramInfo.ParameterType == typeof(SqlNativeConnectionStrings),
                       (paramInfo, componentContext) => connectionStrings)
                   .WithParameter((paramInfo, componentContext) => paramInfo.ParameterType == typeof(DataConfigurationRepository),
                       (paramInfo, componentContext) => datRepo);

                 builder
                   .RegisterType<ActiveDirectoryRepository>()
                   .As<IActiveDirectoryRepository>()
                   .WithParameter(
                       (paramInfo, componentContext) => paramInfo.ParameterType == typeof(SqlNativeConnectionStrings),
                       (paramInfo, componentContext) => connectionStrings)
                   .WithParameter((paramInfo, componentContext) => paramInfo.ParameterType == typeof(DataConfigurationRepository),
                       (paramInfo, componentContext) => datRepo);

                builder
                   .RegisterType<SqlServerAdminRepository>()
                   .As<IAdminRepository>()
                   .WithParameter(
                       (paramInfo, componentContext) => paramInfo.ParameterType == typeof(SqlNativeConnectionStrings),
                       (paramInfo, componentContext) => connectionStrings)
                   .WithParameter((paramInfo, componentContext) => paramInfo.ParameterType == typeof(DataConfigurationRepository),
                       (paramInfo, componentContext) => datRepo);

                builder
                    .RegisterType<ArticleManager>()
                    .WithParameter(
                        (paramInfo, componentContext) => paramInfo.ParameterType == typeof(IArticleRepository),
                        (paramInfo, componentContext) => componentContext.Resolve<IArticleRepository>());
                builder
                   .RegisterType<SolutionFinderManager>()
                   .WithParameter(
                       (paramInfo, componentContext) => paramInfo.ParameterType == typeof(ISolutionFinderRepository),
                       (paramInfo, componentContext) => componentContext.Resolve<ISolutionFinderRepository>());

                builder
                    .RegisterType<UsersManager>()
                    .WithParameter(
                        (paramInfo, componentContext) => paramInfo.ParameterType == typeof(IUserRepository),
                        (paramInfo, componentContext) => componentContext.Resolve<IUserRepository>());

                builder
                   .RegisterType<SearchesManager>()
                   .WithParameter(
                       (paramInfo, componentContext) => paramInfo.ParameterType == typeof(ISearchesRepository),
                       (paramInfo, componentContext) => componentContext.Resolve<ISearchesRepository>());

                builder
                   .RegisterType<CategoryManager>()
                   .WithParameter(
                       (paramInfo, componentContext) => paramInfo.ParameterType == typeof(ICategoryRepository),
                       (paramInfo, componentContext) => componentContext.Resolve<ICategoryRepository>());

                builder
                   .RegisterType<AdminManager>()
                   .WithParameter(
                       (paramInfo, componentContext) => paramInfo.ParameterType == typeof(IAdminRepository),
                       (paramInfo, componentContext) => componentContext.Resolve<IAdminRepository>());

                builder
                  .RegisterType<TokenManager>()
                  .WithParameter(
                      (paramInfo, componentContext) => paramInfo.ParameterType == typeof(ITokenRepository),
                      (paramInfo, componentContext) => componentContext.Resolve<ITokenRepository>());

                builder
                 .RegisterType<ActiveDirectoryManager>()
                 .WithParameter(
                     (paramInfo, componentContext) => paramInfo.ParameterType == typeof(IActiveDirectoryRepository),
                     (paramInfo, componentContext) => componentContext.Resolve<IActiveDirectoryRepository>());

                // We don't need to map UsersManager's ctor parameter; Autofac does that for us.
                //builder.RegisterType<UsersManager>();

                // Registers HTTP context abstraction classes including <see cref="HttpContextBase"/> and
                // <see cref="HttpSessionStateBase"/> for use by components that live in the HTTP request lifetime.
                // I'm not sure if we need it or not.
                builder.RegisterModule(new AutofacWebTypesModule());

                var container = builder.Build();
                container.ActivateGlimpse();

                // Set the dependency resolver for Web API.
                //var webApiResolver = new AutofacWebApiDependencyResolver(container);
                //GlobalConfiguration.Configuration.DependencyResolver = webApiResolver;

                // Set the dependency resolver for MVC.
                var mvcResolver = new AutofacDependencyResolver(container);
                DependencyResolver.SetResolver(mvcResolver);
            }
            catch (Exception ex)
            {
                throw ex;
                // todo
            }
        }