Example #1
0
        /// <summary>
        /// Rebuild Index
        /// </summary>
        private void RebuildIndex(List <Record_Language> recordLanguages, string indexPath)
        {
            var  defaultLanguageID     = AppSettingsUtility.GetGuid(AppSettingsKeys.DefaultLanguageID);
            Guid descriptionVariableID = new Guid(AppSettingsUtility.GetString(AppSettingsKeys.DescriptionVariableID));

            foreach (var recordLanguage in recordLanguages)
            {
                SiteSearchItem siteSearchItem = new SiteSearchItem();

                siteSearchItem.ID    = recordLanguage.ID.ToString();
                siteSearchItem.Title = recordLanguage.Name;
                var descriptionVariable = recordLanguage.Record.Variables.Where(r => r.VariableID == descriptionVariableID && r.LanguageID == defaultLanguageID).FirstOrDefault();

                if (descriptionVariable != null)
                {
                    siteSearchItem.Description = descriptionVariable.Value;
                }

                siteSearchItem.URL       = new RecordData().GetRecordUrl(recordLanguage.ID, recordLanguage.Name);
                siteSearchItem.IsDeleted = recordLanguage.Record.IsDeleted || !recordLanguage.Record.IsActive;

                SiteSearchService.SaveToIndex(siteSearchItem, indexPath);

                recordProcessed++;
            }
        }
Example #2
0
        /// <summary>
        /// Page Load Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToString(Session["LoginValidate"]) != "1")
            {
                //Request.Abort();
                Response.Redirect("/Support/AdminLogin.aspx?auth=BuildIndex.aspx");
            }
            if (Request.QueryString["action"] != null)
            {
                string action = Request.QueryString["action"].ToString();
                if (action == "RebuildIndexAsync")
                {
                    RebuildIndexAsync();
                }
                else
                {
                    string res = GetProgress();
                    Response.Clear();
                    Response.Write(res);
                    Response.End();
                }

                return;
            }


            recordProcessed        = 0;
            ltRecordProcessed.Text = recordProcessed.ToString();

            ltTotalRecords.Text = RecordService.GetRecords(AppSettingsUtility.GetGuid(AppSettingsKeys.DefaultLanguageID)).Count.ToString();
        }
Example #3
0
        /// <summary>
        /// Rebuild Index
        /// </summary>
        public void RebuildIndexAsync()
        {
            var    defaultLanguageID = AppSettingsUtility.GetGuid(AppSettingsKeys.DefaultLanguageID);
            var    recordLanguages   = RecordService.GetRecords(defaultLanguageID);
            string indexPath         = HttpContext.Current.Server.MapPath("~/LuceneIndex/");

            Task.Run(() => RebuildIndex(recordLanguages, indexPath));
        }
Example #4
0
        /// <summary>
        /// Get Document Link
        /// </summary>
        /// <param name="documentID"></param>
        /// <returns></returns>
        public static string GetRecordLink(Guid recordID)
        {
            var recLink    = new Record_Variable();
            var recl       = "";
            var recordLink = AppSettingsUtility.GetGuid(AppSettingsKeys.RecordLink);

            using (var context = new TSMContext())
            {
                recLink = context.Record_Variables.Where(d => d.RecordID == recordID && d.VariableID == recordLink).FirstOrDefault();
            }
            if (recLink != null)
            {
                recl = recLink.Value.ToString();
            }
            return(recl);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToString(Session["LoginValidate"]) != "1")
            {
                //Request.Abort();
                Response.Redirect("/Support/AdminLogin.aspx?auth=RebuildDownloadXML.aspx");
            }
            if (Request.QueryString["action"] != null)
            {
                string res = GetProgress();
                Response.Clear();
                Response.Write(res);
                Response.End();

                return;
            }

            lblTotalRecords.Text = RecordService.GetRecords(AppSettingsUtility.GetGuid(AppSettingsKeys.DefaultLanguageID)).Count.ToString();
            if ((recordProcessed == 0) || (recordProcessed == recordTotal))
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "disableButton",
                                                    "$('#btnRebuildDownloadCache').prop('disabled', false); $('#loaderImg').hide();", true);
                ScriptManager.RegisterStartupScript(this, GetType(), "disableSuccess",
                                                    "$('#dvSuccess').hide();", true);
                ScriptManager.RegisterStartupScript(this, GetType(), "disableFailure",
                                                    "$('#dvFailure').hide();", true);
                recordProcessed = 0;
                lblTotalRecordsProcessed.Text    = recordProcessed.ToString();
                lblTotalRecordsNotProcessed.Text = recordNotProcessed.ToString();
                recordTotal = Convert.ToInt32(lblTotalRecords.Text);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "disableButton",
                                                    "$('#btnRebuildDownloadCache').prop('disabled', true); $('#loaderImg').show();", true);
                ScriptManager.RegisterStartupScript(this, GetType(), "disableSuccess",
                                                    "$('#dvSuccess').hide();", true);
                ScriptManager.RegisterStartupScript(this, GetType(), "disableFailure",
                                                    "$('#dvFailure').hide();", true);
            }
        }
Example #6
0
        /// <summary>
        /// Save Records
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            bool isSuccess = false;

            try
            {

                var record = new Record();

                //For add
                if (this.ID == Guid.Empty)
                {
                    record.ID = Guid.NewGuid();
                    record.CreatedBy = TSMContext.CurrentUser.ID;
                    record.CreatedDate = DateTime.UtcNow;
                }
                else // for update
                {
                    record = RecordService.GetRecord(this.ID);
                    record.LastModifiedBy = TSMContext.CurrentUser.ID;
                    record.LastModifiedDate = DateTime.UtcNow;
                }

                record.IsActive = this.IsActive;
                record.IsPublic = this.IsPublic;
                record.IsDeleted = false;

                //Record Language
                record.Record_Languages = new List<Record_Language>();
                record.Record_Languages.Add(new Record_Language
                {
                    ID = record.ID,
                    LanguageID = this.LanguageID,
                    Name = this.Name.Trim()
                });


                //for Documents
                List<Guid> deletedFiles = new List<Guid>();
                List<Document> newDocuments = new List<Document>();
                if (!string.IsNullOrEmpty(this.Documents))
                {
                    List<string> files = this.Documents.Split('|').ToList();
                    if (record.Documents == null)
                    {
                        record.Documents = new List<Document>();
                    }

                    //Add new files
                    foreach (string file in files)
                    {
                        if (!record.Documents.Any(d => d.Path == file))
                        {
                            var document = new Document
                            {
                                ID = Guid.NewGuid(),
                                RecordID = record.ID,
                                Size = 0,
                                Type = GetDocumentType(file),
                                Path = file
                            };
                            newDocuments.Add(document);
                        }
                    }

                    //Delete deleted files
                    foreach (var document in record.Documents)
                    {
                        if (!files.Any(f => f == document.Path))
                        {
                            deletedFiles.Add(document.ID);
                        }
                    }
                    record.Documents.RemoveAll(d => deletedFiles.Any(df => df == d.ID));

                }

                //for record variables
                record.Variables = new List<Record_Variable>();
                foreach (var recordVariable in this.RecordVariables)
                {
                    string value = string.Empty;
                    if (recordVariable.Type == VariableType.SingleChoice || recordVariable.Type == VariableType.Text || recordVariable.Type == VariableType.DateTime)
                    {
                        if (!string.IsNullOrEmpty(recordVariable.StringValue))
                        {
                            value = recordVariable.StringValue.Trim();
                        }
                    }
                    else if (recordVariable.Type == VariableType.Boolean)
                    {
                        value = recordVariable.BoolValue ? "true" : "false";
                    }
                    else if (recordVariable.Type == VariableType.MultipleChoice)
                    {
                        if (recordVariable.SelectedChoices.Count > 0)
                        {
                            foreach (string selectedChoice in recordVariable.SelectedChoices)
                            {
                                value += selectedChoice + "|";
                            }
                            value = value.TrimEnd('|');
                        }
                    }

                    if (!string.IsNullOrEmpty(value))
                    {
                        record.Variables.Add(new Record_Variable
                        {
                            ID = Guid.NewGuid(),
                            RecordID = record.ID,
                            VariableID = recordVariable.VariableID,
                            LanguageID = this.LanguageID,
                            Value = value.Trim()
                        });
                    }

                }

                //Save to service
                record.Documents = newDocuments;
                record.Countries = new List<Country>();
                record.Regions = new List<Region>();
                record.Sectors = new List<Sector>();
                record = RecordService.Save(record, this.LanguageID, deletedFiles, SelectedCountries, SelectedRegions, SelectedSectors, newDocuments);

                //update xml for record
                UpdateXML(record);

                this.ID = record.ID;
                isSuccess = true;

                //Lucene Search
                TSM.Entity.ComplexType.SiteSearchItem siteSearchItem = new Entity.ComplexType.SiteSearchItem();
                Guid descriptionVariableID = new Guid(AppSettingsUtility.GetString(AppSettingsKeys.DescriptionVariableID));
                RecordData recordData = new RecordData();

                //SiteSearch Item Values
                siteSearchItem.ID = record.ID.ToString();
                siteSearchItem.Title = this.Name.Trim();
                siteSearchItem.Description = record.Variables.Where(r => r.VariableID == descriptionVariableID && r.LanguageID == this.LanguageID).FirstOrDefault().Value.ToString();

                //For URL we need to use Eng Language Only
                Guid engLanguageID = AppSettingsUtility.GetGuid(AppSettingsKeys.DefaultLanguageID);
                string enTitle = record.Record_Languages.Where(rl => rl.LanguageID == engLanguageID).FirstOrDefault().Name;

                string url = recordData.GetRecordUrl(record.ID, enTitle);
                siteSearchItem.URL = url;

                siteSearchItem.IsDeleted = record.IsDeleted || !record.IsActive;

                string path = HostingEnvironment.ApplicationPhysicalPath + "LuceneIndex";//path to LuceneIndex folder
                SiteSearchService.SaveToIndexAsync(siteSearchItem, path);
            }
            catch (Exception ex)
            {
                ErrorLog.WriteLog("ManageRecordModel", "Save", ex, string.Empty);
            }

            return isSuccess;
        }
Example #7
0
        /// <summary>
        /// Populate
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Populate(Guid id, string urlPath)
        {
            bool isExists   = false;
            var  languageID = TSMContext.CurrentSiteLanguageID;

            this.ThematicFocus = new List <string>();
            this.DesignProcess = new List <string>();

            try
            {
                this.RecordLanguage = RecordService.GetRecordLanguage(id, languageID);

                if (this.RecordLanguage != null)
                {
                    isExists = true;

                    this.Name = RecordLanguage.Name;
                    this.ID   = id.ToString();

                    //Document Type
                    var documentType = RecordLanguage.Record.Variables.Where(v => v.VariableID == AppSettingsUtility.GetGuid(AppSettingsKeys.DocumentTypeVariableID) &&
                                                                             v.LanguageID == languageID).FirstOrDefault();
                    if (documentType != null)
                    {
                        this.DocumentType = documentType.Value;
                    }

                    //Description
                    var description = RecordLanguage.Record.Variables.Where(v => v.VariableID == AppSettingsUtility.GetGuid(AppSettingsKeys.DescriptionVariableID) &&
                                                                            v.LanguageID == languageID).FirstOrDefault();

                    if (description != null)
                    {
                        this.Description = description.Value;
                    }

                    this.Region    = GetRegionName(RecordLanguage, languageID);
                    this.Countries = GetCountryNames(RecordLanguage, languageID);

                    // Year
                    var year = RecordLanguage.Record.Variables.Where(v => v.VariableID == AppSettingsUtility.GetGuid(AppSettingsKeys.YearVariableID) &&
                                                                     v.LanguageID == languageID).FirstOrDefault();

                    if (year != null)
                    {
                        this.Year = year.Value;
                    }

                    //last updated
                    var lastUpdated = RecordLanguage.Record.Variables.Where(v => v.VariableID == AppSettingsUtility.GetGuid(AppSettingsKeys.LastUpdatedVariableID) &&
                                                                            v.LanguageID == languageID).FirstOrDefault();

                    if (lastUpdated != null)
                    {
                        this.LastUpdated = GetLastUpdatedValue(lastUpdated.Value);
                    }

                    //Implementation Period
                    var startYear = RecordLanguage.Record.Variables.Where(v => v.VariableID == AppSettingsUtility.GetGuid(AppSettingsKeys.StartYearVariableID) &&
                                                                          v.LanguageID == languageID).FirstOrDefault();
                    var endYear = RecordLanguage.Record.Variables.Where(v => v.VariableID == AppSettingsUtility.GetGuid(AppSettingsKeys.EndYearVariableID) &&
                                                                        v.LanguageID == languageID).FirstOrDefault();

                    if (startYear != null)
                    {
                        this.ImplementationPeriod = startYear.Value;
                    }

                    if (endYear != null)
                    {
                        this.ImplementationPeriod += "/" + endYear.Value;
                    }

                    var variableLanguages = VariableService.GetVariables(languageID);

                    //Thematic focus
                    var thematicVariables = variableLanguages.Where(vl => vl.Variable.VariableCategory == VariableCategory.ThematicFocus &&
                                                                    CompareVariableValue(RecordLanguage.Record.Variables, vl, "true")).ToList();

                    foreach (var variableLanguage in thematicVariables)
                    {
                        this.ThematicFocus.Add(variableLanguage.DisplayName);
                    }
                    this.ThematicFocus = this.ThematicFocus.OrderBy(tf => tf).ToList();

                    //design process focus
                    var designProcessVariables = variableLanguages.Where(vl => vl.Variable.VariableCategory == VariableCategory.DesignProcess &&
                                                                         CompareVariableValue(RecordLanguage.Record.Variables, vl, "true")).ToList();

                    foreach (var variableLanguage in designProcessVariables)
                    {
                        this.DesignProcess.Add(variableLanguage.DisplayName);
                    }
                    this.DesignProcess = this.DesignProcess.OrderBy(dp => dp).ToList();

                    //Populate Sectors
                    var         sectorLanguages = PrioritySectorService.GetSectors(languageID);
                    var         tsmSectors      = SectorService.GetTSMSectors(languageID);
                    List <Guid> sectorIds       = this.RecordLanguage.Record.Sectors.Select(s => s.ID).ToList();
                    this.ServiceSectors = PopulateSectors(sectorIds, sectorLanguages, tsmSectors, SectorType.Service);
                    this.ProductSectors = PopulateSectors(sectorIds, sectorLanguages, tsmSectors, SectorType.Product);

                    //Populate Files
                    this.Files = new List <Document>();
                    if (RecordLanguage.Record.Documents != null)
                    {
                        this.Files = RecordLanguage.Record.Documents;
                    }

                    //Get Public
                    var isPub = RecordLanguage.Record.Variables.Where(v => v.VariableID == AppSettingsUtility.GetGuid(AppSettingsKeys.isDownload) &&
                                                                      v.LanguageID == languageID).FirstOrDefault();

                    if (isPub != null)
                    {
                        if (isPub.Value == "true")
                        {
                            this.isPublic = "ITCdownload";
                        }
                        else
                        {
                            this.isPublic = "Regulardownload";
                        }
                    }
                    else
                    {
                        this.isPublic = "Regulardownload";
                    }



                    //Link Record
                    var linkRecord = RecordLanguage.Record.Variables.Where(v => v.VariableID == AppSettingsUtility.GetGuid(AppSettingsKeys.RecordLink) &&
                                                                           v.LanguageID == languageID).FirstOrDefault();

                    if (linkRecord != null)
                    {
                        this.recordLink = linkRecord.Value;
                    }

                    this.ZipFilePath   = "";
                    this.LoginStat     = "";
                    this.urlPathForDoc = urlPath.ToString();
                }
            }
            catch (Exception ex)
            {
                ErrorLog.WriteLog("DocumentDetailModel", "Populate", ex, "");
            }

            return(isExists);
        }
Example #8
0
        /// <summary>
        /// Get Filter Records
        /// </summary>
        /// <param name="regions"></param>
        /// <param name="countries"></param>
        /// <param name="internationalSectors"></param>
        /// <param name="documentTypes"></param>
        /// <param name="trueFalseVariables"></param>
        /// <param name="year"></param>
        /// <param name="implementationStart"></param>
        /// <param name="implementationEnd"></param>
        /// <param name="authority"></param>
        /// <param name="lastUpdateStart"></param>
        /// <param name="lastUpdateEnd"></param>
        /// <returns></returns>
        public static List <Guid> GetFilterRecordIds(List <Guid> regions, List <Guid> countries, List <Guid> internationalSectors, List <string> documentTypes,
                                                     List <Guid> trueFalseVariables, int?year, int?implementationStart, int?implementationEnd, string authority,
                                                     DateTime?lastUpdateStart, DateTime?lastUpdateEnd, Guid languageID)
        {
            List <Record> records   = GetRecords();
            List <Guid>   sectors   = new List <Guid>();
            List <Guid>   recordIDs = new List <Guid>();

            if (internationalSectors != null && internationalSectors.Count > 0)
            {
                using (var context = new TSMContext())
                {
                    var query = context.Sectors.Where(s => s.International_NomenclatureID != null &&
                                                      internationalSectors.Contains(s.International_NomenclatureID.Value)).Select(s => s.ID);
                    sectors = query.ToList();
                }
            }


            //Region Checking
            if (regions != null && regions.Count > 0)
            {
                records = (from r in records
                           where r.Regions.Any(region => regions.Any(sr => sr == region.ID))
                           select r).ToList();
            }

            //Country Checking
            if (countries != null && countries.Count > 0 && records != null)
            {
                records = (from r in records
                           where r.Countries.Any(c => countries.Any(sc => sc == c.ID))
                           select r).ToList();
            }

            //Sector Checking
            if (sectors != null && sectors.Count > 0 && records != null)
            {
                records = (from r in records
                           where r.Sectors.Any(c => sectors.Any(sc => sc == c.ID))
                           select r).ToList();
            }

            //Document Type Checking
            var documentTypeVariableID = AppSettingsUtility.GetGuid(AppSettingsKeys.DocumentTypeVariableID);

            if (documentTypes != null && documentTypes.Count > 0 && records != null)
            {
                records = (from r in records
                           where CheckVariableValue(r.Variables, documentTypeVariableID, documentTypes)
                           select r).ToList();
            }

            //True/False variable checking
            if (trueFalseVariables != null && trueFalseVariables.Count > 0 && records != null)
            {
                foreach (var variableID in trueFalseVariables)
                {
                    if (records != null)
                    {
                        records = (from r in records
                                   where CheckVariableValue(r.Variables, variableID, "true")
                                   select r).ToList();
                    }
                }
            }

            //Year checking
            var yearVariableID = AppSettingsUtility.GetGuid(AppSettingsKeys.YearVariableID);

            if (year != null)
            {
                if (records != null)
                {
                    records = (from r in records
                               where CheckVariableValue(r.Variables, yearVariableID, year.Value.ToString())
                               select r).ToList();
                }
            }

            //Implementation Year checking
            var startYearVariableID = AppSettingsUtility.GetGuid(AppSettingsKeys.StartYearVariableID);
            var endYearVariableID   = AppSettingsUtility.GetGuid(AppSettingsKeys.EndYearVariableID);

            if (implementationStart.HasValue && implementationEnd.HasValue)
            {
                if (records != null)
                {
                    records = (from r in records
                               where CheckVariableValue(r.Variables, startYearVariableID, endYearVariableID, implementationStart.Value, implementationEnd.Value)
                               select r).ToList();
                }
            }

            //Last Updated Checking
            var lastUpdatedVariableID = AppSettingsUtility.GetGuid(AppSettingsKeys.LastUpdatedVariableID);

            if (lastUpdateStart.HasValue && lastUpdateEnd.HasValue)
            {
                if (records != null)
                {
                    records = (from r in records
                               where CheckVariableValue(r.Variables, lastUpdatedVariableID, lastUpdateStart.Value, lastUpdateEnd.Value)
                               select r).ToList();
                }
            }

            //Authority Checking
            var AuthorityVariableID = AppSettingsUtility.GetGuid(AppSettingsKeys.AuthorityVariableID);

            if (!string.IsNullOrEmpty(authority))
            {
                if (records != null)
                {
                    records = (from r in records
                               where CheckVariableValue(r.Variables, AuthorityVariableID, authority.ToString())
                               select r).ToList();
                }
            }

            if (records != null && records.Count > 0)
            {
                recordIDs = records.Select(r => r.ID).ToList();
            }

            return(recordIDs);
        }