private SearchStatus getSearchStatus(string entitySchemaName)
        {
            SearchStatus responce = new SearchStatus();
            var          esq      = new EntitySchemaQuery(UserConnection.EntitySchemaManager,
                                                          "GlobalDuplicateSearchState");
            var processedColumn = esq.AddColumn("ProcessedCount");
            var totalColumn     = esq.AddColumn("TotalCount");
            var dateColumn      = esq.AddColumn("SearchStatusChangedOn");
            var codeColumn      = esq.AddColumn("SearchStatus.Code");

            esq.Filters.Add(esq.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                           "SchemaToSearchName", entitySchemaName));
            var entities = esq.GetEntityCollection(UserConnection);

            if (entities.Count > 0)
            {
                var processedColumnSchema = entities[0].Schema.Columns.GetByName(processedColumn.Name);
                int processed             = entities[0].GetTypedColumnValue <int>(processedColumnSchema.ColumnValueName);
                var totalColumnSchema     = entities[0].Schema.Columns.GetByName(totalColumn.Name);
                int total = entities[0].GetTypedColumnValue <int>(totalColumnSchema.ColumnValueName);
                responce.Percent = (total > 0)? Math.Round((decimal)((processed * 100) / total), 2) : 0m;
                var dateColumnSchema = entities[0].Schema.Columns.GetByName(dateColumn.Name);
                responce.ChangeOn = entities[0].GetTypedColumnValue <DateTime>(dateColumnSchema.ColumnValueName);
                var codeColumnSchema = entities[0].Schema.Columns.GetByName(codeColumn.Name);
                responce.Code = entities[0].GetTypedColumnValue <string>(codeColumnSchema.ColumnValueName);
            }
            return(responce);
        }
        private SearchStatus searchStart(string entitySchemaName)
        {
            searchUpdate(entitySchemaName, "Finished");
            string jobProcessName = string.Format("StartGlobal{0}DuplicatesSearch", entitySchemaName);

            AppScheduler.ScheduleImmediateProcessJob("DuplicatesSearchJob", "DuplicatesSearchGroup",
                                                     jobProcessName, UserConnection.Workspace.Name, UserConnection.CurrentUser.Name);
            SearchStatus responce = new SearchStatus();

            responce.ChangeOn = DateTime.Now;
            responce.Code     = "InProgress";
            responce.Percent  = 0;
            return(responce);
        }
        private SearchStatus ScheduleSearch(string entitySchemaName, TimeSchedule timeSchedule)
        {
            searchUpdate(entitySchemaName, "Finished");
            string jobProcessName = string.Format("StartGlobal{0}DuplicatesSearch", entitySchemaName);

            AppScheduler.RemoveJob(entitySchemaName + "DuplicatesSearchJob", "DuplicatesSearchGroup");
            IJobDetail job = AppScheduler.CreateProcessJob(entitySchemaName + "DuplicatesSearchJob",
                                                           "DuplicatesSearchGroup",
                                                           jobProcessName,
                                                           UserConnection.Workspace.Name,
                                                           UserConnection.CurrentUser.Name);
            ICronTrigger trigger = new CronTriggerImpl(entitySchemaName + "DuplicatesSearchJob", "DuplicatesSearchGroup",
                                                       string.Format("0 {0} {1} ? * {2}", timeSchedule.Minutes, timeSchedule.Hours, timeSchedule.SelectedDays));

            trigger.TimeZone = TimeZoneInfo.Utc;
            AppScheduler.Instance.ScheduleJob(job, trigger);
            SearchStatus responce = new SearchStatus();

            responce.ChangeOn = DateTime.Now;
            responce.Code     = "InProgress";
            responce.Percent  = 0;
            return(responce);
        }