//[ValidateAntiForgeryToken] public HttpResponseMessage InstallPackage(string packageUrl) { Log.Add("install package:" + packageUrl); var zoneId = Env.ZoneMapper.GetZoneId(ActiveModule.PortalID); var appId = new DnnMapAppToInstance(Log).GetAppIdFromInstance(new DnnInstanceInfo(ActiveModule), zoneId); bool success; // Install package // var messages = new List<ExportImportMessage>(); var helper = new ImportExportEnvironment(Log); try { // Increase script timeout to prevent timeouts HttpContext.Current.Server.ScriptTimeout = 300; success = new ZipImport(helper, zoneId, appId, PortalSettings.UserInfo.IsSuperUser, Log) .ImportZipFromUrl(packageUrl, ActiveModule.DesktopModule.ModuleName == "2sxc-app"); } catch (Exception ex) { Exceptions.LogException(ex); throw new Exception("An error occurred while installing the app: " + ex.Message, ex); } Log.Add("install completed with success:" + success); return(Request.CreateResponse(success ? HttpStatusCode.OK : HttpStatusCode.InternalServerError, new { success, helper.Messages })); }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { if (!HandleRequestWithThisController(request)) { return(PreviousSelector.SelectController(request)); } var routeData = request.GetRouteData(); var controllerTypeName = routeData.Values[RouteParts.ControllerKey] + "Controller"; // Handle the app-api queries try { var appFolder = Route.AppPathOrNull(routeData); if (appFolder == null) { var sexy = Helpers.GetSxcOfApiRequest(request); appFolder = sexy.App.Folder; } // new for 2sxc 9.34 #1651 var edition = ""; if (routeData.Values.ContainsKey(RouteParts.EditionKey)) { edition = routeData.Values[RouteParts.EditionKey].ToString(); } if (!string.IsNullOrEmpty(edition)) { edition += "/"; } var controllerFolder = Path.Combine(DnnMapAppToInstance.AppBasePath(), appFolder, edition + "api/"); var controllerPath = Path.Combine(controllerFolder + controllerTypeName + ".cs"); // note: this may look like something you could optimize/cache the result, but that's a bad idea // because when the file changes, the type-object will be different, so please don't optimize :) if (File.Exists(HostingEnvironment.MapPath(controllerPath))) { var assembly = BuildManager.GetCompiledAssembly(controllerPath); var type = assembly.GetType(controllerTypeName, true, true); // try to fix path resolution request.Properties.Add(CodeCompiler.SharedCodeRootPathKeyInCache, controllerFolder); return(new HttpControllerDescriptor(_config, controllerTypeName, type)); } } catch (Exception e) { var exception = new Exception("2sxc Api Controller Finder: Error while selecting / compiling a controller for the request. Pls check the event-log and the code. See the inner exception for more details.", e); DotNetNuke.Services.Exceptions.Exceptions.LogException(exception); throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message, e)); } throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.NotFound, "2sxc Api Controller Finder: Controller " + controllerTypeName + " not found in app.")); }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { if (!HandleRequestWithThisController(request)) { return(PreviousSelector.SelectController(request)); } var routeData = request.GetRouteData(); var controllerTypeName = routeData.Values["controller"] + "Controller"; // Handle the app-api queries try { var appFolder = routeData.Values["apppath"]?.ToString(); if (appFolder == null) { var sexy = Helpers.GetSxcOfApiRequest(request, false); appFolder = sexy.App.Folder; } var controllerPath = Path.Combine(DnnMapAppToInstance.AppBasePath(), appFolder, "api/" + controllerTypeName + ".cs"); if (File.Exists(HostingEnvironment.MapPath(controllerPath))) { var assembly = BuildManager.GetCompiledAssembly(controllerPath); var type = assembly.GetType(controllerTypeName, true, true); return(new HttpControllerDescriptor(_config, controllerTypeName, type)); } } catch (Exception e) { var exception = new Exception("2sxc Api Controller Finder: Error while selecting / compiling a controller for the request. Pls check the event-log and the code. See the inner exception for more details.", e); DotNetNuke.Services.Exceptions.Exceptions.LogException(exception); throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message, e)); } throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.NotFound, "2sxc Api Controller Finder: Controller " + controllerTypeName + " not found in app.")); }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { // Log this lookup and add to history for insights var log = new Log("Sxc.Http", null, request?.RequestUri?.AbsoluteUri); AddToInsightsHistory(request?.RequestUri?.AbsoluteUri, log); var wrapLog = log.Call <HttpControllerDescriptor>(); if (!HandleRequestWithThisController(request)) { return(wrapLog("upstream", PreviousSelector.SelectController(request))); } var routeData = request.GetRouteData(); var controllerTypeName = routeData.Values[RouteParts.ControllerKey] + "Controller"; // Handle the app-api queries try { var appFolder = Route.AppPathOrNull(routeData); if (appFolder == null) { log.Add("no folder found in url, will auto-detect"); var sexy = Helpers.GetCmsBlock(request, false, log); appFolder = sexy.App.Folder; } log.Add($"App Folder: {appFolder}"); // new for 2sxc 9.34 #1651 var edition = ""; if (routeData.Values.ContainsKey(RouteParts.EditionKey)) { edition = routeData.Values[RouteParts.EditionKey].ToString(); } if (!string.IsNullOrEmpty(edition)) { edition += "/"; } log.Add($"Edition: {edition}"); var controllerFolder = Path.Combine(DnnMapAppToInstance.AppBasePath(), appFolder, edition + "api/"); controllerFolder = controllerFolder.Replace("\\", @"/"); log.Add($"Controller Folder: {controllerFolder}"); var controllerPath = Path.Combine(controllerFolder + controllerTypeName + ".cs"); log.Add($"Controller Path: {controllerPath}"); // note: this may look like something you could optimize/cache the result, but that's a bad idea // because when the file changes, the type-object will be different, so please don't optimize :) if (File.Exists(HostingEnvironment.MapPath(controllerPath))) { var assembly = BuildManager.GetCompiledAssembly(controllerPath); var type = assembly.GetType(controllerTypeName, true, true); // help with path resolution for compilers running inside the created controller request?.Properties.Add(CodeCompiler.SharedCodeRootPathKeyInCache, controllerFolder); var descriptor = new HttpControllerDescriptor(_config, type.Name, type); return(wrapLog("ok", descriptor)); } log.Add("path not found"); } catch (Exception e) { var apiErrPrefix = "2sxc Api Controller Finder: " + "Error selecting / compiling an API controller. " + "Check event-log, code and inner exception. "; var helpText = ErrorHelp.HelpText(e); var exception = new Exception(apiErrPrefix + helpText, e); DotNetNuke.Services.Exceptions.Exceptions.LogException(exception); wrapLog("error", null); throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message, e)); } wrapLog("error", null); throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.NotFound, "2sxc Api Controller Finder: Controller " + controllerTypeName + " not found in app.")); }
public string TargetPath(string folder) { var appPath = Path.Combine(DnnMapAppToInstance.AppBasePath(), folder); return(HttpContext.Current.Server.MapPath(appPath)); }
/// <summary> /// Get search info for each dnn module containing 2sxc data /// </summary> /// <returns></returns> public IList <SearchDocument> GetModifiedSearchDocuments(IInstanceInfo instance, DateTime beginDate) { var searchDocuments = new List <SearchDocument>(); var dnnModule = (instance as EnvironmentInstance <ModuleInfo>)?.Original; // always log with method, to ensure errors are cought Log.Add($"start search for mod#{dnnModule?.ModuleID}"); if (dnnModule == null) { return(searchDocuments); } var isContentModule = dnnModule.DesktopModule.ModuleName == "2sxc"; // New Context because PortalSettings.Current is null var zoneId = new DnnEnvironment(Log).ZoneMapper.GetZoneId(dnnModule.OwnerPortalID); int?appId; // = new ZoneRuntime(zoneId, Log).DefaultAppId; if (!isContentModule) { appId = new DnnMapAppToInstance().GetAppIdFromInstance(instance, zoneId); if (!appId.HasValue) { return(searchDocuments); } } // must find tenant through module, as the PortalSettings.Current is null in search mode var tenant = new DnnTenant(new PortalSettings(dnnModule.OwnerPortalID)); var mcb = new ModuleContentBlock(instance, Log, tenant); var sexy = mcb.SxcInstance; var language = dnnModule.CultureCode; var contentGroup = sexy.App.ContentGroupManager.GetInstanceContentGroup(dnnModule.ModuleID, dnnModule.TabID); var template = contentGroup.Template; // This list will hold all EAV entities to be indexed var dataSource = sexy.Data; if (template == null) { return(searchDocuments); } var engine = EngineFactory.CreateEngine(template); engine.Init(template, sexy.App, new DnnInstanceInfo(dnnModule), dataSource, InstancePurposes.IndexingForSearch, sexy, Log); // see if data customization inside the cshtml works try { engine.CustomizeData(); } catch (Exception e) // Catch errors here, because of references to Request etc. { Exceptions.LogException(new SearchIndexException(dnnModule, e)); } var searchInfoDictionary = new Dictionary <string, List <ISearchInfo> >(); // Get DNN SearchDocuments from 2Sexy SearchInfos foreach (var stream in dataSource.Out.Where(p => p.Key != AppConstants.Presentation && p.Key != AppConstants.ListPresentation)) { var entities = stream.Value.List; var searchInfoList = searchInfoDictionary[stream.Key] = new List <ISearchInfo>(); searchInfoList.AddRange(entities.Select(entity => { var searchInfo = new SearchInfo { Entity = entity, Url = "", Description = "", Body = GetJoinedAttributes(entity, language), Title = entity.Title?[language]?.ToString() ?? "(no title)", ModifiedTimeUtc = (entity.Modified == DateTime.MinValue ? DateTime.Now.Date.AddHours(DateTime.Now.Hour) : entity.Modified).ToUniversalTime(), UniqueKey = "2sxc-" + dnnModule.ModuleID + "-" + (entity.EntityGuid != new Guid() ? entity.EntityGuid.ToString() : (stream.Key + "-" + entity.EntityId)), IsActive = true, TabId = dnnModule.TabID, PortalId = dnnModule.PortalID }; // Take the newest value (from ContentGroupItem and Entity) if (entity is IHasEditingData typed) { var contentGroupItemModifiedUtc = typed.ContentGroupItemModified.ToUniversalTime(); searchInfo.ModifiedTimeUtc = searchInfo.ModifiedTimeUtc > contentGroupItemModifiedUtc ? searchInfo.ModifiedTimeUtc : contentGroupItemModifiedUtc; } return(searchInfo); })); } // check if the cshtml has search customizations try { engine.CustomizeSearch(searchInfoDictionary, new DnnInstanceInfo(dnnModule), beginDate); } catch (Exception e) { Exceptions.LogException(new SearchIndexException(dnnModule, e)); } // reduce load by only keeping recently modified ites foreach (var searchInfoList in searchInfoDictionary) { // Filter by Date - take only SearchDocuments that changed since beginDate var searchDocumentsToAdd = searchInfoList.Value.Where(p => p.ModifiedTimeUtc >= beginDate.ToUniversalTime()).Select(p => (SearchDocument)p); searchDocuments.AddRange(searchDocumentsToAdd); } return(searchDocuments); }