示例#1
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------
        protected bool AddTag(string tagName, out string errorMessage)
        {
            bool success = false;

            errorMessage = "";

            string tagTN = WebDocProcessing.dbTNWebDocTag;

            try {
                //___ Check it is not shit
                if (tagName == null || tagName == "" || tagName.Trim() == "")
                {
                    errorMessage = "No new tag was provided - please try again.";
                }
                else
                {
                    // clean it up a bit
                    tagName = tagName.Trim();
                    tagName = tagName.Replace("  ", " ");
                    tagName = tagName.Replace("  ", " ");
                    tagName = tagName.Replace("  ", " ");
                    tagName = tagName.Replace("  ", " ");
                    tagName = tagName.Replace("  ", " ");
                    tagName = tagName.Replace("  ", " ");
                    tagName = tagName.Replace("  ", " ");

                    //_____ See if it exists already
                    bool alreadyExists = false;
                    foreach (WebDocTag wdt in KeyInfo.Tags)
                    {
                        if (wdt.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase) == true)
                        {
                            alreadyExists = true;
                            break;
                        }
                    }

                    if (alreadyExists == true)
                    {
                        errorMessage = "The tag name '" + tagName + "' already exists!  Please check the name and try again.";
                    }
                    else
                    {
                        // OK here lets setup the processing obj
                        WebDocProcessing wdp = new WebDocProcessing(MGLSessionInterface.Instance().Config);

                        //_____ So now then lets try to insert it ...
                        success = wdp.InsertWebDocTag(tagName);

                        //_____ Lastly, if added then we need to reset the global organisation variables ....
                        if (success == false)
                        {
                            errorMessage = "Could not insert the new tag name '" + tagName + "'.  This should not normally happen - please inform a website administrator and provide them with a screenshot.";
                        }
                        else
                        {
                            int b4Count = KeyInfo.Tags.Count;

                            // then lastly - if this is successful - we need to refresh the global list of tags ...
                            lock (KeyInfo.Tags) {
                                KeyInfo.Tags = wdp.GetAllWebDocTags();
                            }

                            // Success is that the number of tags increments by one
                            success = ((b4Count + 1) == KeyInfo.Tags.Count);
                            if (success == false)
                            {
                                errorMessage = "Could not update the website global variables after adding new tag '" + tagName
                                               + "'. This should not normally happen - please inform a website administrator and provide them with a screenshot.";
                            }
                            else
                            {
                                errorMessage = "The new tag '" + tagName + "' has been added successfully.";
                                //TBTag.Value = tagName;
                                TBTag.Value    = "";
                                DoDelete.Value = "";
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                ctlInfoSplash.SetupInfoSplash(false, "General error trying to add the tag.  Please try again.", false);
                Logger.LogError(7, "Error adding a new tag: " + ex.ToString());
            }


            return(success);
        }
示例#2
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------
        protected bool DeleteTag(int tagID, out string errorMessage)
        {
            bool success = false;

            errorMessage = "";

            try {
                //___ Check it is not shit
                if (tagID <= 0)
                {
                    errorMessage = "No tag was selected.  Please try again.";
                }
                else
                {
                    string tagName = "";
                    foreach (WebDocTag wdt in KeyInfo.Tags)
                    {
                        if (wdt.ID == tagID)
                        {
                            tagName = wdt.Name;
                            break;
                        }
                    }

                    // OK here lets setup the processing obj
                    WebDocProcessing wdp = new WebDocProcessing(MGLSessionInterface.Instance().Config);

                    //_____ So now then lets try to delete it ... and all the associated XRefs ...
                    success = wdp.DeleteWebDocTag(tagID);

                    //_____ Lastly, if added then we need to reset the global organisation variables ....
                    if (success == false)
                    {
                        errorMessage = "Could not delete the tag with ID " + tagID + ".  This should not normally happen - please inform a website administrator and provide them with a screenshot.";
                    }
                    else
                    {
                        int b4Count = KeyInfo.Tags.Count;

                        // then lastly - if this is successful - we need to refresh the global list of tags ...
                        lock (KeyInfo.Tags) {
                            KeyInfo.Tags = wdp.GetAllWebDocTags();
                        }

                        // Success is that the number of tags increments by one
                        success = ((b4Count - 1) == KeyInfo.Tags.Count);
                        if (success == false)
                        {
                            errorMessage = "Could not update the website global variables after deleting the tag with ID " + tagID
                                           + ". This should not normally happen - please inform a website administrator and provide them with a screenshot.";
                        }
                        else
                        {
                            errorMessage   = "The tag '" + tagName + "' and all corresponding cross-references have been successfully deleted.";
                            TBTag.Value    = "";
                            DoDelete.Value = "";
                        }
                    }
                }
            } catch (Exception ex) {
                ctlInfoSplash.SetupInfoSplash(false, "General error trying to delete the organisation.  Please try again.", false);
                Logger.LogError(7, "Error deleting the organisation: " + ex.ToString());
            }

            return(success);
        }
示例#3
0
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------
        private void LoadAppDefaults()
        {
            TimeSpan t1 = new TimeSpan(DateTime.Now.Ticks);

            //_____1_____ Set the Application Defaults
            {
                MGLApplicationInterface.Instance().ApplicationName      = WebConfigurationManager.AppSettings["ApplicationName"];
                MGLApplicationInterface.Instance().ApplicationShortName = WebConfigurationManager.AppSettings["ApplicationShortName"];
                MGLApplicationInterface.Instance().ApplicationURL       = WebConfigurationManager.AppSettings["ApplicationURL"];
                // Note that this is reset internally, but good to leave the ref here as a reminder that this deepest darkest code exists ...
                Authorisation.ApplicationName = MGLApplicationInterface.Instance().ApplicationName;

                double tempDouble = 0;
                double.TryParse(WebConfigurationManager.AppSettings["ApplicationVersion"], out tempDouble);
                KeyInfoExtended.SoftwareVersion = tempDouble;

                // 16-Mar-2016 - set the PersistentViewState subdirectory
                PagePersistViewStateToFileSystem.AppendSiteShortNameToFolderName(MGLApplicationInterface.Instance().ApplicationShortName);

                // 18-Mar-2016 - Get the JS Version ...
                MGLApplicationInterface.Instance().JSVersion = WebConfigurationManager.AppSettings["JSVersion"];


                // 22-Mar-2016 - extract the static resource settings.  These are used in HTMLUtilities.BuildStaticResourcesHTML to generate the resource references for static libraries like scripts and styles
                // Firstly, are the resources stored locally or pulled accross from another domain?
                MGLApplicationInterface.Instance().StaticResourcePath = WebConfigurationManager.AppSettings["StaticResourcePath"];
                // Secondly, is the Javascript in these resources minified
                bool tempBool = false;
                bool.TryParse(WebConfigurationManager.AppSettings["StaticJavascriptMinified"], out tempBool);
                MGLApplicationInterface.Instance().StaticJavascriptIsMinified = tempBool;


                // 29-Mar-2016 - explicitly turn on or off the removal of leading and trailing whitespace during the page rendering (this saves about 25% of the download size)
                bool.TryParse(WebConfigurationManager.AppSettings["RemoveWhitespaceFromAllPages"], out tempBool);
                MGLApplicationInterface.Instance().RemoveWhitespaceFromAllPages = tempBool;
            }

            //_____2_____ Start the Logging Activities
            Logger.StartLog(MGLApplicationInterface.Instance().ApplicationShortName, "c:/logs", false, true, true);


            //_____3a_____ Load the Configuration Information
            MglWebConfigurationInfo mwci = MglWebConfigurationInfo.GetConfig();
            MglWebConfigurationInfoParamsCollection mwcipc = mwci.ConfigInfoList;

            ConfigurationInfo ci = new ConfigurationInfo();
            bool success         = ci.LoadConfigurationInfoFromWebConfig();

            // 30-Sep-2015 - Get the username and password from the XML config file ...
            {
                SecureString key  = null;
                SecureString auth = null;
                if (MGLXMLReader.GetInfo(MGLApplicationInterface.Instance().ApplicationShortName, "DatabaseLogin", out key, out auth) == true)
                {
                    DatabaseConnectionInfo dbConInfo = ci.DbConInfo;
                    dbConInfo.USER     = key;
                    dbConInfo.PASSWORD = auth;
                    ci.DbConInfo       = dbConInfo;
                }
            }
            // 30-Sep-2015 - Get the SSL Certificate and Password from the XML config file ...
            {
                SecureString key  = null;
                SecureString auth = null;
                if (MGLXMLReader.GetInfo(MGLApplicationInterface.Instance().ApplicationShortName, "DatabaseCertificate", out key, out auth) == true)
                {
                    DatabaseConnectionInfo dbConInfo = ci.DbConInfo;
                    dbConInfo.SSLCertificatePath     = key;
                    dbConInfo.SSLCertificatePassword = auth;
                    ci.DbConInfo = dbConInfo;
                }
            }

            MGL.Web.WebUtilities.MGLApplicationInterface.Instance().ConfigDefault = ci;
            // Test the database connection string ....
            DatabaseWrapper dbInfo = new DatabaseWrapper(ci);

            dbInfo.Connect();

            //_____ 1-Dec-2015 - Get the GeoLocation database XML config file settings ...
            {
                // The clone method works, we just need to be aware that really robust passwords with special characters don't work fantastically with the mySQL connector
                ConfigurationInfo      ciGeoLocation = ci.Clone();
                DatabaseConnectionInfo dbConInfo     = ciGeoLocation.DbConInfo;

                SecureString key  = null;
                SecureString auth = null;
                if (MGLXMLReader.GetInfo(MGLApplicationInterface.Instance().ApplicationShortName, "DatabaseLoginGeoLocation", out key, out auth) == true)
                {
                    dbConInfo.USER     = key;
                    dbConInfo.PASSWORD = auth;
                    dbConInfo.NAME     = "DataNirvana_GeoLocation";
                }

                ciGeoLocation.DbConInfo = dbConInfo;
                MGLApplicationInterface.Instance().GeoLocationConfig = ciGeoLocation;
            }


            //_____3b_____ Set up the physical application path ONCE ....
            if (MGLApplicationInterface.Instance().ConfigDefault != null &&
                MGLApplicationInterface.Instance().PhysicalPathToApplicationRoot == null)
            {
                // 14-Oct-2013 - Changed this to use app domain - that seems to be a better usage of the process and it also means that we can put it in the global.asax
                string physicalPath = AppDomain.CurrentDomain.BaseDirectory.ToString();
                physicalPath = physicalPath.Replace("\\", "/");

                MGLApplicationInterface.Instance().PhysicalPathToApplicationRoot = physicalPath;
            }


            //_____4a_____ Setup the default email settings ...
            SetupDefaultEmail();

            //_____4b_____ Setup the default cryptography stuff ...
            // The temporary application encryption key (e.g. for the search tables ...)
            {
                MGLApplicationInterface.Instance().EncryptionAppKey = MGLEncryption.GenerateKey();
            }

            // 5-Jul-15 - Set the MGLEncryption Key from the web config ...
            {
                SecureString key  = null;
                SecureString auth = null;
                if (MGLXMLReader.GetInfo(MGLApplicationInterface.Instance().ApplicationShortName, "EncryptKeyDefault", out key, out auth) == true)
                {
                    MGLEncryption.SetCryptKey = key;
                }
            }


            //_____5a_____ Application Specific Setup - Setup all the countries, application variables for Organisations, Indicators and Sectors
            DataNirvanaWebProcessing wpHA = new DataNirvanaWebProcessing(MGLApplicationInterface.Instance().ConfigDefault);

            // Uncomment when the database is setup ....
            //            success = success & wp.SetAllIndicators();
            //            success = success & wp.SetAllSectors();
            success = success & wpHA.SetAllOrganisations(true);
            //            success = success & wp.SetAllActivityStates();
            //            success = success & wp.SetAllCountries();
            //            success = success & wp.SetSpatialReferenceDefault();

            WebDocProcessing wdp = new WebDocProcessing(MGLApplicationInterface.Instance().ConfigDefault);

            KeyInfo.Tags = wdp.GetAllWebDocTags();


            //_____5b_____ Application Specific Setup - Set the ProGres Application key ...

            // 5-Jul-15 - Set the ProgresTokens (Public and Private)
            //{
            //    SecureString key = null;
            //    SecureString auth = null;
            //    if (MGLXMLReader.GetInfo(MGLApplicationInterface.Instance().ApplicationShortName, "EncryptKeyProGresPrivate", out key, out auth) == true) {
            //        PNAApplicationInterface.Instance().ProGresEncryptionTokenPrivate = key;
            //    }
            //}
            //{
            //    SecureString key = null;
            //    SecureString auth = null;
            //    if (MGLXMLReader.GetInfo(MGLApplicationInterface.Instance().ApplicationShortName, "EncryptKeyProGresPublic", out key, out auth) == true) {
            //        PNAApplicationInterface.Instance().ProGresEncryptionTokenPublic = key;
            //    }
            //}


            //_____5c_____ Application Specific Setup -  Setup all the lookup lists
            //PNACaseWebProcessing pnaCaseWP = new PNACaseWebProcessing(MGLApplicationInterface.Instance().ConfigDefault);

            bool tempSuccess = false;

            // ListOfPNACaseStatuses
            //PNAApplicationInterface.Instance().ListOfPNACaseStatuses = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfPNACaseStatuses, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfPNAIndividualStatuses
            //PNAApplicationInterface.Instance().ListOfPNAIndividualStatuses = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfPNAIndividualStatuses, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfPNAPriorities - added -15-Dec-2015
            //PNAApplicationInterface.Instance().ListOfPNAPriorities = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfPNAPriorities, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfUNHCROffices
            //PNAApplicationInterface.Instance().ListOfUNHCROffices = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfUNHCROffices, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfAlreadyRegistered
            //PNAApplicationInterface.Instance().ListOfAlreadyRegistered = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfAlreadyRegistered, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfTravelledBefore
            //PNAApplicationInterface.Instance().ListOfTravelledBefore = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfTravelledBefore, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfHasPoRCard
            //PNAApplicationInterface.Instance().ListOfHasPoRCard = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfHasPoRCard, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfReligion
            //PNAApplicationInterface.Instance().ListOfReligion = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfReligion, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfLanguage
            //PNAApplicationInterface.Instance().ListOfLanguage = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfLanguage, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfEthnicity
            //PNAApplicationInterface.Instance().ListOfEthnicity = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfEthnicity, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfDocumentaryProof
            //PNAApplicationInterface.Instance().ListOfDocumentaryProof = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfDocumentaryProof, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfCountries
            //PNAApplicationInterface.Instance().ListOfCountries = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfCountries, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfCoACountries - a rather shortened affair ...
            //PNAApplicationInterface.Instance().ListOfCoACountries = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfCoACountries, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfNationalities
            //PNAApplicationInterface.Instance().ListOfNationalities = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfNationalities, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfYesNo
            //PNAApplicationInterface.Instance().ListYesNo = pnaCaseWP.SetupListGeneric(KeyInfo.ListYesNo, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfSex
            //PNAApplicationInterface.Instance().ListOfSex = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfSex, out tempSuccess, true);
            success = success & tempSuccess;

            // ListOfMaritalStatusesPNA
            //PNAApplicationInterface.Instance().ListMaritalStatus = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfMaritalStatusesPNA, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfRelationshipToHoH
            //PNAApplicationInterface.Instance().ListOfRelationshipToHoH = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfRelationshipToHoH, out tempSuccess, true);
            success = success & tempSuccess;

            // ListOfEducationLevels
            //PNAApplicationInterface.Instance().ListOfEducationLevels = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfEducationLevels, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfEducationDegreeTypes
            //PNAApplicationInterface.Instance().ListOfEducationDegreeTypes = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfEducationQualificationTypes, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfOccupations
            //PNAApplicationInterface.Instance().ListOfOccupations = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfOccupations, out tempSuccess, true);
            success = success & tempSuccess;

            // ListOfWillingToReturn
            //PNAApplicationInterface.Instance().ListOfWillingToReturn = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfWillingToReturn, out tempSuccess, true);
            success = success & tempSuccess;

            // ListOfAddressLocationTypes
            //PNAApplicationInterface.Instance().ListOfAddressLocationTypes = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfAddressLocationTypes, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfAddressTypes
            //PNAApplicationInterface.Instance().ListOfAddressTypes = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfAddressTypes, out tempSuccess, true);
            success = success & tempSuccess;

            // ListOfPNAReferralRecommendations - added 16-Dec-2015
            //PNAApplicationInterface.Instance().ListOfPNAReferralRecommendations = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfPNAReferralRecommendations, out tempSuccess, true);
            success = success & tempSuccess;
            // ListOfPNANonReferralReasons - added 16-Dec-2015
            //PNAApplicationInterface.Instance().ListOfPNANonReferralReasons = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfPNANonReferralReasons, out tempSuccess, true);
            success = success & tempSuccess;



            //_____ Set up the Geographies
            // For the PNA tool, we cannot use the lists of geographies that EVERYONE ELSE IN THE ENTIRE WORLD USES, so we need to use the old ones from ProGres to be consistent
            // In this ancient list from ProGres, FATA and KP are equivalent to NWFP!!!!

            // CoO Province
            //PNAApplicationInterface.Instance().ListOfCoOProvinces = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfCoOProvinces, out tempSuccess, true);
            success = success & tempSuccess;
            // CoO District
            //PNAApplicationInterface.Instance().ListOfCoODistricts = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfCoODistricts, out tempSuccess, true);
            success = success & tempSuccess;
            // CoA Province
            //PNAApplicationInterface.Instance().ListOfCoAProvinces = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfCoAProvinces, out tempSuccess, true);
            success = success & tempSuccess;
            // CoA District
            //PNAApplicationInterface.Instance().ListOfCoADistricts = pnaCaseWP.SetupListGeneric(KeyInfo.ListOfCoADistricts, out tempSuccess, true);
            success = success & tempSuccess;



            //_____6_____ Configure the Security ...
            MGL.Security.SecuritySetup.Configure(true, MGLApplicationInterface.Instance().ApplicationName, MGLApplicationInterface.Instance().ApplicationURL, ci.Clone());
            // 25-Jan-2015 - also store the list of Users in the KeyInfo static class so that they are accessible to other threads that cannot access application variables
            // Also wipe the passwords from the objects as these are irrelevant (and weak security) ....
            // note that wiping the passwords in this way (essentially by the linked "by reference" objects" means that the passwords are wiped from both the online repositories ...
            KeyInfo.AllUsers = new Dictionary <int, MGUser>();
            foreach (int key in MGLApplicationSecurityInterface.Instance().Users.Keys)
            {
                MGUser u;
                MGLApplicationSecurityInterface.Instance().Users.TryGetValue(key, out u);
                u.Password = null;
                KeyInfo.AllUsers.Add(key, u);
            }
            // now reset the original application interface with the users without passwords ...
            MGLApplicationSecurityInterface.Instance().Users = KeyInfo.AllUsers;



            //_____7_____ Application Specific Setup -

            // Make the default root an absolute path so that if links are called in e.g. Ajax pages then they will work ...
            HTMLUtilities.DefaultPath        = ((MGLApplicationSecurityInterface.Instance().AppLoginConfig.UseHTTPS) ? "https://" : "http://") + ci.WebProjectPath();
            HTMLUtilities.ImageRootDirectory = "Images/";

            // 23-Dec-2015 - allows applications to use the https independently in a specific session, even if it is turned off in the global applications settings (sourced from the web.config)
            MGLApplicationInterface.Instance().UseHttpsSessionsIndependently = true;


            //_____8_____ Log the application start in the db ....

            // Check whether the connection to the db is using SSL
            DatabaseWrapper dbInfo2 = new DatabaseWrapper(ci);
            string          sslCipher, sslStartDate, sslEndDate, sslProtocol;
            bool            isSSLConn = dbInfo2.IsSSLConnection(out sslCipher, out sslStartDate, out sslEndDate, out sslProtocol);

            // Calculate how long the start up took
            TimeSpan t2   = new TimeSpan(DateTime.Now.Ticks);
            TimeSpan diff = t2.Subtract(t1);

            // build the "url" with all the params ...
            string logURL = "Application_Start?AppIsSSL=" + MGLApplicationSecurityInterface.Instance().AppLoginConfig.UseHTTPS
                            + "&DBIsSSL=" + isSSLConn + "&Protocol=" + sslProtocol + "&SSLCipher=" + sslCipher
                            + "&SSLStart=" + sslStartDate + "&SSLEnd=" + sslEndDate;

            // 14-Jan-2016 - Get the IP Address
            // 31-Jan-2016 - But this doesn't work unfortunately in the context of the applcation start - produces an error "Request not available in this context"
            string srcIPAddress = "0.0.0.0";

            // Log the application start using a special user ID
            LoggerDB.LogPageRequestInDatabase(ci, MGLApplicationInterface.Instance().ApplicationName,
                                              "Application_Start", "Application_Start", logURL,
                                              DateTime.Now, diff.TotalMilliseconds, 1010101, srcIPAddress);

            // And send an email with that the application has started ...
            //            MGLSecureEmailer.SendEmail("*****@*****.**", "Eddie", "Application Started - " + MGLApplicationInterface.Instance().ApplicationName,
            //                "Application " + MGLApplicationInterface.Instance().ApplicationName + " started at " + DateTime.Now.ToString(),
            //                "", null, null, null, null, 0, true);
        }