Пример #1
0
        protected void Application_Start()
        {
#if DEBUG
            DyntaxaLogger.WriteMessage("Web application started");
#endif
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);

            RegisterRoutes(RouteTable.Routes);
            // MK 2015-10-12 County map isn't used?
            //String path = Server.MapPath("~/Images/Maps/Sverigekarta med län.shp");
            //CountyOccurrenceMap.InitializeMap(path);

            Configuration.SetInstallationType();
            CoreData.CountryManager     = new CountryManagerMultiThreadCache();
            CoreData.LocaleManager      = new LocaleManagerMultiThreadCache();
            CoreData.ReferenceManager   = new ReferenceManagerMultiThreadCache();
            CoreData.TaxonManager       = new TaxonManagerMultiThreadCache();
            CoreData.UserManager        = new UserManagerMultiThreadCache();
            CoreData.SpeciesFactManager = new SpeciesFactManagerMultiThreadCache();

            UserDataSource.SetDataSource();
            TaxonDataSource.SetDataSource();
            PesiNameDataSource.SetDataSource();
            TaxonAttributeDataSource.SetDataSource();
            ReferenceDataSource.SetDataSource();
            AnalysisDataSource.SetDataSource();

            CoreData.UserManager.LoginApplicationUser();
            CoreData.UserManager.LoginApplicationTransactionUser();
            ScheduledTasksManager.AddTasks();
        }
 public static bool SetCurrentUserRoleToTaxonRevisionEditor(this IUserContext user, int revisionId)
 {
     try
     {
         ITaxonRevision taxonRevision = CoreData.TaxonManager.GetTaxonRevision(user, revisionId);
         return(AuthorizationManager.SetUserRoleToTaxonRevisionEditor(user, taxonRevision.Guid));
     }
     catch (Exception ex)
     {
         DyntaxaLogger.WriteException(ex);
         return(false);
     }
 }
Пример #3
0
        /// <summary>
        /// Handles the Error event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception exception     = Server.GetLastError();
            var       httpException = exception as HttpException;

            Response.Clear();
            Server.ClearError();
            var routeData = new RouteData();

            routeData.Values["controller"] = "Errors";
            routeData.Values["action"]     = "General";
            routeData.Values["exception"]  = exception;
            Response.StatusCode            = 500;
            if (httpException != null)
            {
                Response.StatusCode = httpException.GetHttpCode();
                switch (Response.StatusCode)
                {
                case 400:
                    routeData.Values["action"] = "Http400";
                    break;

                case 403:
                    routeData.Values["action"] = "Http403";
                    break;

                case 404:
                    routeData.Values["action"] = "Http404";
                    break;

                case 500:
                    routeData.Values["action"] = "Http500";
                    break;
                }
            }
            // Avoid IIS7 getting in the middle
            Response.TrySkipIisCustomErrors = true;
            IController errorsController = new ErrorsController();
            var         wrapper          = new HttpContextWrapper(Context);
            var         rc = new RequestContext(wrapper, routeData);

            // Log to file (Debug Level) when http statuscode 500 (Internal Server Error)
            if (Response.StatusCode == 500)
            {
                DyntaxaLogger.WriteDebugException(exception);
            }
            errorsController.Execute(rc);
        }
Пример #4
0
        /// <summary>
        /// Updates the cache by getting all relations and all taxa from Taxon service
        /// and create a TaxonRelationTree.
        /// This method is thread safe.
        /// </summary>
        /// <param name="userContext">The user context.</param>
        public static void UpdateCache(IUserContext userContext)
        {
            lock (LockingTarget)
            {
                Debug.WriteLine("Start update Cache {0}", DateTime.Now);
                ITaxonSearchCriteria taxonSearchCriteria = new TaxonSearchCriteria();
                var allTaxa = CoreData.TaxonManager.GetTaxa(userContext, taxonSearchCriteria);

                TaxonRelationSearchCriteria searchCriteria = new TaxonRelationSearchCriteria();
                TaxonRelationList           allRelations   = CoreData.TaxonManager.GetTaxonRelations(userContext, searchCriteria);
                TaxonRelationList       = allRelations;
                CachedTaxonRelationTree = TaxonRelationsTreeManager.CreateTaxonRelationsTree(
                    userContext,
                    allRelations,
                    allTaxa);
                CacheLastUpdatedTime = DateTime.Now;
                Debug.WriteLine("End update Cache {0}", DateTime.Now);
                DyntaxaLogger.WriteMessage("DyntaxaTree updated {0}", DateTime.Now);
            }
        }
        public ActionResult Settings(MatchSettingsViewModel model)
        {
            CreateMatchSelectLists(model);

            if (ModelState.IsValid)
            {
                var manager = new DyntaxaMatchManager(GetCurrentUser());
                List <DyntaxaMatchItem> items;

                if (model.MatchToType == MatchTaxonToType.TaxonId)
                {
                    model.LabelForProvidedText = Resources.DyntaxaResource.MatchOptionsOutputProvidedTaxonIdLabel;
                }

                bool fileFound = false;
                if (Request.Files.Count > 0)
                {
                    foreach (string file in Request.Files)
                    {
                        HttpPostedFileBase hpf = this.Request.Files[file];
                        if (hpf == null || hpf.ContentLength == 0)
                        {
                            continue;
                        }
                        fileFound = true;

                        string fileExtension = Path.GetExtension(hpf.FileName);
                        if (fileExtension == ".xls" || fileExtension == ".xlsx")
                        {
                            string fileName = GetFileName(fileExtension);
                            hpf.SaveAs(fileName);
                            DyntaxaLogger.WriteMessage("Match->Settings saved uploaded file: " + fileName);
                            model.FileName = fileName;
                            items          = manager.GetMatches(fileName, model);

                            try
                            {
                                if (System.IO.File.Exists(fileName))
                                {
                                    System.IO.File.Delete(fileName);
                                    DyntaxaLogger.WriteMessage("Match->Settings deleted uploaded file: " + fileName);
                                }
                            }
                            catch
                            {
                                DyntaxaLogger.WriteMessage("Match->Settings exception when trying to delete: " + fileName);
                            }

                            if (items.IsNotEmpty())
                            {
                                Session["MatchOptions"] = model;
                                Session["MatchItems"]   = items;
                                return(RedirectToAction("MatchItems"));
                            }
                            else
                            {
                                //TODO: Error. File has no valid content or is not a valid excel file.
                            }
                        }
                        else
                        {
                            ViewData.ModelState.AddModelError("FileName", Resources.DyntaxaResource.MatchOptionsFileExtensionError);
                        }
                    }
                }

                if (!fileFound)
                {
                    if (model.ClipBoard.IsNotEmpty())
                    {
                        items = manager.GetDyntaxaMatchItemsFromText(model.ClipBoard, model);
                        if (items.IsNotEmpty())
                        {
                            Session["MatchOptions"] = model;
                            Session["MatchItems"]   = items;
                            return(RedirectToAction("MatchItems"));
                        }
                        else
                        {
                            //TODO: Error. File has no valid content or is not a valid excel file.
                        }
                    }
                    else
                    {
                        //TODO: Handle error when data is missing
                    }
                }
            }

            return(View(model));
        }
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.IsChildAction || Request.IsAjaxRequest() || Session == null)
            {
                return;
            }

            IUserContext user = GetCurrentUser();

            string masterName;

            if (Request.QueryString["mode"] != null)
            {
                if (Request.QueryString["mode"].ToLower() == "full")
                {
                    masterName            = "Site";
                    Session["masterpage"] = masterName;
                }
                else if (Request.QueryString["mode"].ToLower() == "mini")
                {
                    masterName            = "Rest";
                    Session["masterpage"] = masterName;
                }
            }

            if (Session["masterpage"] != null && (string)Session["masterpage"] == "Rest")
            {
                ViewBag.MiniMode = true;
            }
            else
            {
                ViewBag.MiniMode = false;
            }

            // set language
            if (Request.QueryString["lang"] != null)
            {
                ILocale locale;

                locale = CoreData.LocaleManager.GetUsedLocales(GetCurrentUser()).Get(Request.QueryString["lang"]);
                if (locale.IsNotNull())
                {
                    SetLanguage(locale.ISOCode);
                    if (user.IsAuthenticated())
                    {
                        user.Locale = locale;
                    }
                }
            }

            // Removed from code 2012-02-28 (agoh) only set revision from Revision Controller - start editing
            // set revisionId
            //string strRevisionId = (filterContext.RouteData.Values["revisionId"] ??
            //                    filterContext.RequestContext.HttpContext.Request.QueryString["revisionId"] ??
            //                    filterContext.RequestContext.HttpContext.Request.Form["revisionId"]) as string;
            //int revisionId;
            //if (int.TryParse(strRevisionId, out revisionId))
            //{
            //    Session["RevisionId"] = revisionId;
            //}

            // Set LogOn information
            ViewBag.IsLoggedIn = user.IsAuthenticated();
            ViewBag.UserName   = user.User.UserName;

            // Set Taxon and Revision information
            ViewBag.TaxonId     = this.TaxonIdentifier.Id;
            ViewBag.RevisionId  = this.RevisionId;
            ViewBag.RootTaxonId = this.RootTaxonId;

            if (this.RevisionId.HasValue && user.CurrentRole == null)
            {
                user.SetCurrentUserRoleToTaxonRevisionEditor(this.RevisionId.Value);
            }

#if DEBUG
            ViewBag.Debug = true;
#else
            ViewBag.Debug = false;
#endif

            ActionDescriptor actionDescriptor = filterContext.ActionDescriptor;
            string           actionName       = actionDescriptor.ActionName;
            string           controllerName   = actionDescriptor.ControllerDescriptor.ControllerName;
            ViewBag.CookieName = string.Format("{0}{1}", controllerName, actionName);

            // Log history event
            if (actionName != "TaxonQualitySummaryChart")
            {
                var logEventHistoryItem = new LogEventHistoryItem();
                logEventHistoryItem.Action     = actionName;
                logEventHistoryItem.Controller = controllerName;
                logEventHistoryItem.TaxonId    = this.TaxonIdentifier.Id;
                logEventHistoryItem.RevisionId = this.RevisionId;
                logEventHistoryItem.Form       = Request.Form != null?Request.Form.PrettyPrint() : "-";

                logEventHistoryItem.HttpAction = Request.HttpMethod;
                logEventHistoryItem.Url        = DyntaxaLogger.GetUrl();
                logEventHistoryItem.Date       = DateTime.Now;
                logEventHistoryItem.UserName   = user.User != null ? user.User.UserName : "******";
                logEventHistoryItem.UserRole   = user.CurrentRole != null ? user.CurrentRole.Identifier : "-";
                logEventHistoryItem.Referrer   = Request.UrlReferrer != null ? Request.UrlReferrer.OriginalString : "-";
                var logEventHistory = Session["LogEventHistory"] as LogEventHistory;
                if (logEventHistory == null)
                {
                    logEventHistory            = new LogEventHistory();
                    Session["LogEventHistory"] = logEventHistory;
                }
                logEventHistory.HistoryItems.Add(logEventHistoryItem);
                if (logEventHistory.HistoryItems.Count > 10)
                {
                    logEventHistory.HistoryItems.RemoveAt(0);
                }
            }

            base.OnActionExecuting(filterContext);
        }
Пример #7
0
        /// <summary>
        /// Method that generate a list of taxon items with the most basic set of parameters.
        /// </summary>
        /// <returns>Export taxon items.</returns>
        private List <ExportTaxonItem> GetExportTaxonItems()
        {
            Boolean                hasOutputTaxonNames;
            ExportTaxonItem        exportTaxonItem;
            Int32                  index;
            ITaxon                 taxon;
            List <ExportTaxonItem> exportTaxonList;
            List <TaxonNameList>   allTaxonNames = null;

            ArtDatabanken.Data.SpeciesFact speciesFact;
            Stopwatch         stopwatch;
            TaxonCategoryList outputTaxonCategories;
            TaxonList         filteredTaxa;

            stopwatch = new Stopwatch();
            stopwatch.Start();

            exportTaxonList       = new List <ExportTaxonItem>();
            hasOutputTaxonNames   = HasOutputTaxonNames();
            filteredTaxa          = _options.GetFilteredTaxa(this._userContext);
            outputTaxonCategories = _options.GetOutputTaxonCategories();
            if (filteredTaxa.IsNotEmpty())
            {
                if (hasOutputTaxonNames)
                {
                    allTaxonNames = CoreData.TaxonManager.GetTaxonNames(_userContext, filteredTaxa);
                }

                for (index = 0; index < filteredTaxa.Count; index++)
                {
                    taxon           = filteredTaxa[index];
                    exportTaxonItem = new ExportTaxonItem(
                        taxon,
                        _options.GetTaxonTreeNode(taxon),
                        outputTaxonCategories);

                    // Add swedish history information.
                    if (_options.OutputSwedishHistory)
                    {
                        speciesFact = _options.GetSpeciesFact(this._userContext, ArtDatabanken.Data.FactorId.SwedishHistory, exportTaxonItem.Taxon);
                        if (speciesFact.IsNotNull() &&
                            speciesFact.MainField.IsNotNull() &&
                            speciesFact.MainField.EnumValue.IsNotNull())
                        {
                            exportTaxonItem.SwedishHistory = speciesFact.MainField.EnumValue.OriginalLabel;
                        }
                    }

                    // Add swedish occurrence information.
                    if (_options.OutputSwedishOccurrence)
                    {
                        speciesFact = _options.GetSpeciesFact(this._userContext, ArtDatabanken.Data.FactorId.SwedishOccurrence, exportTaxonItem.Taxon);
                        if (speciesFact.IsNotNull() &&
                            speciesFact.MainField.IsNotNull() &&
                            speciesFact.MainField.EnumValue.IsNotNull())
                        {
                            exportTaxonItem.SwedishOccurrence = speciesFact.MainField.EnumValue.OriginalLabel;
                        }
                    }

                    // Add taxon name information.
                    if (hasOutputTaxonNames)
                    {
                        exportTaxonItem.TaxonNames = allTaxonNames[index];
                    }

                    // Synonyms
                    if (_options.OutputSynonyms)
                    {
                        exportTaxonItem.Synonyms = GetSynonyms(taxon);
                    }

                    // Synonyms
                    if (_options.OutputProParteSynonyms)
                    {
                        exportTaxonItem.ProParteSynonyms = GetProParteSynonyms(taxon);
                    }

                    // Synonyms
                    if (_options.OutputMisappliedNames)
                    {
                        exportTaxonItem.MisappliedNames = GetMisappliedNames(taxon);
                    }

                    // Synonyms excl. auktor
                    //if (_options.OutputExcludeAuctor)
                    //{
                    //    //exportTaxonItem.MisappliedNames = GetMisappliedNames(taxon);
                    //}

                    exportTaxonList.Add(exportTaxonItem);
                }
            }

            stopwatch.Stop();
            DyntaxaLogger.WriteMessage("Export: Get all data to populate Excel file: {0:N0} milliseconds", stopwatch.ElapsedMilliseconds);

            return(exportTaxonList);
        }