Beispiel #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++;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Populate
        /// </summary>
        /// <param name="query"></param>
        public void Populate(string query, int pageNo)
        {
            this.Query = query;
            if (string.IsNullOrEmpty(query))
            {
                return;
            }

            string indexPath = HttpContext.Current.Server.MapPath("~/LuceneIndex/");
            var    result    = SiteSearchService.Search(query, indexPath);

            //Implement Paging
            this.SearchParam = new SearchAttributes();
            this.SearchParam.RecordsPerPage   = 10;
            this.SearchParam.TotalRecordCount = result.Count;
            SearchParam.TotalPages            = (int)Math.Ceiling((double)SearchParam.TotalRecordCount / SearchParam.RecordsPerPage);
            SearchParam.CurrentPageNumber     = pageNo;

            this.SearchResult = result.Skip((SearchParam.CurrentPageNumber - 1) * SearchParam.RecordsPerPage)
                                .Take(SearchParam.RecordsPerPage).ToList();
        }
Beispiel #3
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;
        }