Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            // Check for a SolrConnection
            string solrString = System.Configuration.ConfigurationManager.AppSettings["SolrServer"];

            if (!string.IsNullOrEmpty(solrString))
            {
                SolrService.Init(solrString);
            }
            else
            {
                Console.Error.WriteLine("Could not initialize connection to the Solr server. Please verify that your SolrServer app property is correct.");
                return;
            }

            if (args.Length > 0)
            {
                Database.SetInitializer <CatfishDbContext>(null);
                using (CatfishDbContext Db = new CatfishDbContext())
                {
                    if (args[0] == "import")
                    {
                        import(Db);
                    }
                    else if (args[0] == "export")
                    {
                        export(Db);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TestEscapeQueryString()
        {
            string inputString = "\"query:Test*\"*";
            string testString  = "\\\"query\\:Test*\\\"*";
            string result      = SolrService.EscapeQueryString(inputString);

            Assert.AreEqual(testString, result);
        }
Exemplo n.º 3
0
        public void CanInitializeSolr()
        {
            string connectionString = System.Configuration.ConfigurationManager.AppSettings["SolrServer"];

            SolrService.Init(connectionString);

            Assert.IsTrue(SolrService.IsInitialized);
            Assert.IsNotNull(SolrService.SolrOperations);
        }
Exemplo n.º 4
0
        public IActionResult Insert([FromBody] SolrBook book)
        {
            var dbBook = new Book();

            book.SaveToModel(Context, dbBook);
            Context.Books.Add(dbBook);
            Context.SaveChanges();
            SolrService.IndexBook(dbBook);
            return(Ok(SolrBook.FromBook(dbBook)));
        }
Exemplo n.º 5
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            if (e.Args.Contains("GenerateIndex"))
            {
                SolrService.Init(this);
                //SolrService solrSrv = new SolrService(new ApplicationDbContext());
                //solrSrv.GenerateSolrIndexTemplate(Console.Out, new Type[] { typeof(MainForm) }, true);
            }
        }
Exemplo n.º 6
0
 public IActionResult Search(string searchTerm = "", int page = 0, int pageSize = 10, string filter = "")
 {
     try
     {
         var response = SolrService.Query(searchTerm, page, pageSize, filter);
         return(Ok(response));
     }
     catch (Exception)
     {
         return(BadRequest(new { message = "The search service is not available" }));
     }
 }
Exemplo n.º 7
0
        public JsonResult CommitEmployee(EmployeeModel model)
        {
            bool result;

            if (model.Id == null)
            {
                //new record
                model.Id = Guid.NewGuid().ToString();
            }
            result = new SolrService().SaveData(_solr, model);
            return(Json(result));
        }
Exemplo n.º 8
0
        public override object GetContent(object model)
        {
            if (Fields.Count > 0)
            {
                //For testing -- go to the page that use this region and add ?entity=[entityId]
                HttpContext context = HttpContext.Current;
                SolrService solrSrv = new SolrService();


                //grab the columnHeaders
                foreach (var field in Fields)
                {
                    // field = CheckDisplayOption(field);
                    CFEntityTypeAttributeMapping map = entityTypeService.GetEntityTypeAttributeMappingById(field.Id);

                    if (!typeof(Catfish.Core.Models.Forms.OptionsField).IsAssignableFrom(field.GetType()))
                    {
                        if (field.SelectedDisplayOption.Equals(eDisplayOption.DropDownList))//(field.IsDropdown)
                        {
                            string fId = "value_" + map.MetadataSet.Guid.Replace('-', '_') + "_" + map.Field.Guid.Replace('-', '_') + "_en_ss";


                            string result   = SolrService.GetPartialMatichingText(fId, "", 100);
                            var    response = Newtonsoft.Json.JsonConvert.DeserializeObject <SolrResponse>(result);

                            if (response.facet_counts.facet_fields.Count > 0)
                            {
                                foreach (var f in response.facet_counts.GetFacetsForField(fId))
                                {
                                    field.ListFields.Add(new SelectListItem {
                                        Text = f.Item1, Value = f.Item1
                                    });
                                }
                            }
                        }
                        else if (field.SelectedDisplayOption.Equals(eDisplayOption.Slider))
                        {
                            string fId = "value_" + map.MetadataSet.Guid.Replace('-', '_') + "_" + map.Field.Guid.Replace('-', '_') + "_is";

                            IDictionary <string, SolrNet.StatsResult> statsResult = solrSrv.GetStats(fId, "*:*");

                            field.Min = statsResult[fId].Min;
                            field.Max = statsResult[fId].Max;
                        }
                    }

                    Mappings.Add(map);
                }
            }

            return(base.GetContent(model));
        }
Exemplo n.º 9
0
        public IActionResult Delete(Guid id)
        {
            var book = Context.Books.SingleOrDefault(m => m.Id == id);

            if (book == null)
            {
                return(NotFound(new { message = $"Book with id {id} was not found" }));
            }
            Context.Books.Remove(book);
            Context.SaveChanges();
            SolrService.DeleteBook(id);
            return(Ok());
        }
Exemplo n.º 10
0
 public void TestFailedServiceInitialization()
 {
     try
     {
         SolrService.Init(null);
         Assert.Fail("Initialization passed with no connection string.");
     }
     catch (InvalidOperationException e)
     {
         // Failed to initialize. This passes the test.
         Assert.IsTrue(true);
     }
 }
Exemplo n.º 11
0
        public IActionResult Update([FromBody] SolrBook book)
        {
            var dbBook = Context.Books.SingleOrDefault(m => m.Id == book.id);

            if (dbBook == null)
            {
                return(NotFound(new { message = $"Book with id {book.id} was not found" }));
            }
            book.SaveToModel(Context, dbBook);
            Context.Books.Update(dbBook);
            Context.SaveChanges();
            SolrService.IndexBook(dbBook);
            return(Ok(SolrBook.FromBook(dbBook)));
        }
Exemplo n.º 12
0
 public void TestFailedServiceInitialization()
 {
     try
     {
         SolrService.Init((string)null);
         Assert.Fail("Initialization passed with no connection string.");
     }
     catch (InvalidOperationException ex)
     {
         // Failed to initialize. This passes the test.
         Console.WriteLine("Exception : {0}", ex.Message);
         Assert.IsTrue(true);
     }
 }
Exemplo n.º 13
0
        public ViewResult SaveEmployee(string id = null)
        {
            EmployeeModel emp;

            if (id != null)
            {
                emp = new SolrService().GetEmployeeDetail(_solr, id);
            }
            else
            {
                emp = new EmployeeModel();
            }
            return(View("SaveEmployee", emp));
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            MainForm.Update();

            if (MainForm.Id > 0)
            {
                Db.Entry(MainForm).State = System.Data.Entity.EntityState.Modified;
            }
            else
            {
                Db.MainForms.Add(MainForm);
            }

            Db.SaveChanges();
            SolrService.RequestSolrUpdate();
        }
Exemplo n.º 15
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //Metadata provider
            ModelMetadataProviders.Current = new Catfish.Areas.Manager.Helpers.ModelMetadataProvider();

            //Custom model binders
            System.Web.Mvc.ModelBinders.Binders.Add(typeof(FormField), new XmlModelBinder());
            System.Web.Mvc.ModelBinders.Binders.Add(typeof(OptionsField), new XmlModelBinder());
            // ModelBinders.Binders.Add(typeof(DateTime), new DateModelBinder());

            //Additional CSS and Javascripts
            Hooks.Head.Render += (ui, str, page, post) =>
            {
                // Do something
                str.Append("<script src=\"/Scripts/jquery-2.1.1.min.js\" type=\"text/javascript\" ></script>");
                str.Append("<script src=\"/Scripts/jquery-ui.min.js\" type=\"text/javascript\" ></script>");
                str.Append("<script src=\"/Scripts/bootstrap.min.js\" type=\"text/javascript\" ></script>");
                str.Append("<link type=\"text/css\" rel=\"stylesheet\" href=\"/content/jquery-ui.min.css\" />");
                str.Append("<link type=\"text/css\" rel=\"stylesheet\" href=\"/content/bootstrap.min.css\" />");
                str.Append("<link type=\"text/css\" rel=\"stylesheet\" href=\"/content/Custom.css\" />");
            };

            //Adding manager menu items
            AddManagerMenus();

            //Multilingual menu
            Hooks.Menu.RenderItemLink = ViewHelper.MultilingualMenuRenderer;

            // Setup Validation Attributes
            FormFieldValidationAttribute.CurrentLanguageCodes = () => new string[] { ViewHelper.GetActiveLanguage().TwoLetterISOLanguageName };

            // Check for a SolrConnection
            string solrString = System.Configuration.ConfigurationManager.AppSettings["SolrServer"];

            if (!string.IsNullOrEmpty(solrString))
            {
                SolrService.Init(solrString);
            }
        }
Exemplo n.º 16
0
        public void DataPumpTest()
        {
            var documents = new[]
            {
                new Brand()
                {
                    id       = "B2009/67185",
                    brand    = "plast textil şekil",
                    attorney = "YUSUF ÖZDAMAR YÖA MAKRO PATENT MARKA VE FİKRİ HAKL",
                    holders  = "PLAST-TEXTIL SL",
                    classes  = "22"
                },

                new Brand()
                {
                    id       = "B2014/6752",
                    brand    = "thomson",
                    attorney = "GÜLÇİN GÖKÜŞ DERİŞ PATENT VE MARKA A. Ş.",
                    holders  = "TECHNICOLOR",
                    classes  = "7, 9, 11"
                },

                new Brand()
                {
                    id       = "B2004/44966",
                    brand    = "imza",
                    attorney = "DESTEK PATENT A. Ş.",
                    holders  = "TAŞKINIRMAK GİYİM SAN. VE TİC. A. Ş.",
                    classes  = "3, 5, 24, 25, 27, 35"
                }
            };

            var solr = new SolrService("192.168.99.26");

            var coll = solr.GetCollection("Brands");

            coll.DataPump(documents, CancellationToken.None)
            .Wait();


            coll.DeleteSingle("B2004/44966");

            coll.CommitAndOptimize();
        }
Exemplo n.º 17
0
        public override object GetContent(object model)
        {
            HttpContext context = HttpContext.Current;

            if (string.IsNullOrEmpty(SearchResultTemplate))
            {
                SearchResultTemplate = "SearchResult";
            }

            if (context != null)
            {
                string query = context.Request.QueryString[SimpleSearch.QUERY_PARAM];
                Page         = ParseInt(context.Request.QueryString[SearchResults.PAGE_PARAM], 1, 1);
                TotalPerPage = ParseInt(context.Request.QueryString[SearchResults.PERPAGE_PARAM], 10, 1);

                if (!string.IsNullOrEmpty(query))
                {
                    query = string.Format("*{0}*", SolrService.EscapeQueryString(query.Trim()));
                    CatfishDbContext db = new CatfishDbContext();
                    EntityService    es = new EntityService(db);

                    var results = es.GetEntitiesTextSearch(query, new string[] { ViewHelper.GetActiveLanguage().TwoLetterISOLanguageName });
                    Total      = results.Count();
                    TotalPages = (int)Math.Ceiling((float)Total / (float)TotalPerPage);

                    if (Page < 1)
                    {
                        Page = 1;
                    }
                    else if (Page > TotalPages)
                    {
                        Page = TotalPages + 1;
                    }

                    int startValue = (Page - 1) * TotalPerPage;

                    Results = results.OrderBy(m => m.Id).Skip(startValue).Take(TotalPerPage).ToArray();
                }
            }

            return(base.GetContent(model));
        }
Exemplo n.º 18
0
        public void Initialize(MockConnection solrConnection)
        {
            //if (SolrService.IsInitialized)
            //{
            //    //TODO: Inject the new connection into this current solr thread.
            //}
            //else
            //{
            //    SolrService.ForceInit(solrConnection);
            //}

            SolrService.ForceInit(solrConnection);

            try
            {
                Catfish.Tests.Migrations.Configuration config = new Catfish.Tests.Migrations.Configuration();
                var migrator = new DbMigrator(config);

                foreach (string migName in migrator.GetLocalMigrations())
                {
                    Type        migration = config.MigrationsAssembly.GetType(string.Format("{0}.{1}", config.MigrationsNamespace, migName.Substring(16)));
                    DbMigration m         = (DbMigration)Activator.CreateInstance(migration);
                    m.Up();

                    var prop = m.GetType().GetProperty("Operations", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    if (prop != null)
                    {
                        IEnumerable <MigrationOperation> operations = prop.GetValue(m) as IEnumerable <MigrationOperation>;
                        var generator  = config.GetSqlGenerator("System.Data.SQLite");
                        var statements = generator.Generate(operations, "2008");
                        foreach (MigrationStatement item in statements)
                        {
                            Db.Database.ExecuteSqlCommand(item.Sql);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 19
0
        public CatfishDbContext(System.Data.Common.DbConnection connection, bool contextOwnsConnection) : base(connection, contextOwnsConnection)
        {
            //if (SolrService.IsInitialized)
            //{
            //    solr = ServiceLocator.Current.GetInstance<ISolrOperations<Dictionary<string, object>>>();
            //}
            string solrString = System.Configuration.ConfigurationManager.AppSettings["SolrServer"];

            if (!string.IsNullOrEmpty(solrString))
            {
                SolrService.Init(solrString);
            }

            var sqlTimeout = ConfigurationManager.AppSettings["SqlConnectionTimeoutSeconds"];

            if (!string.IsNullOrEmpty(sqlTimeout))
            {
                ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = int.Parse(sqlTimeout);
            }
        }
Exemplo n.º 20
0
        public ActionResult AutoCompleteField(string fieldId, string partialText, int rows = 10)
        {
            string jsonResult = SolrService.GetPartialMatichingText(fieldId, partialText, rows);

            return(this.Content(jsonResult, "application/json"));
        }
Exemplo n.º 21
0
        public JsonResult DeleteEmployee(string id)
        {
            var result = new SolrService().DeleteData(_solr, id);

            return(Json(result));
        }
Exemplo n.º 22
0
        public void TestSuccessServiceInitialization()
        {
            string connectionString = System.Configuration.ConfigurationManager.AppSettings["SolrServer"];

            SolrService.Init(connectionString);
        }
Exemplo n.º 23
0
        void Application_Start(object sender, EventArgs e)
        {
            // Load Plugins
            LoadPlugins();
            ControllerBuilder.Current.SetControllerFactory(typeof(PluginControllerFactory));
            ViewEngines.Engines.Add(PluginContext.Current.ViewEngine);

            // Code that runs on application startup
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            RegisterPluginRoutes();

            //Metadata provider
            ModelMetadataProviders.Current = new Catfish.Areas.Manager.Helpers.ModelMetadataProvider();

            //Custom model binders
            System.Web.Mvc.ModelBinders.Binders.Add(typeof(FormField), new XmlModelBinder());
            System.Web.Mvc.ModelBinders.Binders.Add(typeof(OptionsField), new XmlModelBinder());
            // ModelBinders.Binders.Add(typeof(DateTime), new DateModelBinder());

            //Additional CSS and Javascripts
            Hooks.Head.Render += (ui, str, page, post) =>
            {
                // Do something
                str.Append("<script src=\"/Scripts/jquery-2.1.1.min.js\" type=\"text/javascript\" ></script>");
                str.Append("<script src=\"/Scripts/jquery-ui.min.js\" type=\"text/javascript\" ></script>");
                str.Append("<script src=\"/Scripts/bootstrap.min.js\" type=\"text/javascript\" ></script>");
                str.Append("<script src=\"/Scripts/catfish-global.js\" type=\"text/javascript\" ></script>");
                str.Append("<script src=\"/Scripts/solrQueryParser.js\" type=\"text/javascript\" ></script>");
                str.Append("<link type=\"text/css\" rel=\"stylesheet\" href=\"/content/jquery-ui.min.css\" />");
                str.Append("<link type=\"text/css\" rel=\"stylesheet\" href=\"/content/bootstrap.min.css\" />");
                str.Append("<link type=\"text/css\" rel=\"stylesheet\" href=\"/content/Custom.css\" />");
            };

            //Adding manager menu items
            AddManagerMenus();

            //Multilingual menu
            Hooks.Menu.RenderItemLink = ViewHelper.MultilingualMenuRenderer;
            //register multiple languange for the site --May 17 2018
            foreach (string lang in ConfigHelper.LanguagesCodes)
            {
                Piranha.WebPages.WebPiranha.RegisterCulture(lang, new System.Globalization.CultureInfo(lang));
            }


            // Setup Validation Attributes
            FormFieldValidationAttribute.CurrentLanguageCodes = () => new string[] { ViewHelper.GetActiveLanguage().TwoLetterISOLanguageName };

            // Check for a SolrConnection
            string solrString = System.Configuration.ConfigurationManager.AppSettings["SolrServer"];

            if (!string.IsNullOrEmpty(solrString))
            {
                SolrService.Init(solrString);
            }

            CFXmlModel.InitializeExternally = (CFXmlModel model) =>
            {
                if (HttpContext.Current.User != null) // If we are just loading a model, this may be null.
                {
                    string guid = HttpContext.Current.User.Identity.Name;
                    model.CreatedByGuid = guid;

                    // This is done to avoid a massive performance hit when loading models from the database
                    var ctx = Catfish.Contexts.UserContext.GetContextForUser(guid);

                    if (ctx != null && ctx.User != null)
                    {
                        model.CreatedByName = ctx.User.Firstname + " " + ctx.User.Surname;
                    }
                }
            };

            AddPublicUserListIfDoesNotExist();


            // Initialize Plugins
            InitializePlugins();
        }
Exemplo n.º 24
0
        public IActionResult Index()
        {
            var result = new SolrService().SolrSearchData(_solr, null);

            return(View(result));
        }
        private void InitializeSolr()
        {
            string solrString = System.Configuration.ConfigurationManager.AppSettings["SolrServer"];

            SolrService.ForceInit(solrString);
        }
Exemplo n.º 26
0
        public PartialViewResult SearchEmployee(string search)
        {
            var result = new SolrService().SolrSearchData(_solr, search);

            return(PartialView("~/Views/Partial/_SearchEmployeePartial.cshtml", result));
        }