Пример #1
0
        public void Delete_ContentReference_CallsCoreDelete()
        {
            var contentLink = Factory.GetPageReference();

            _fixture.ServiceLocationMock.CoreIndexerMock.Invocations.Clear();

            _indexer.Delete(contentLink);

            _fixture.ServiceLocationMock.CoreIndexerMock.Verify(
                m => m.Delete(contentLink.ID.ToString(), It.IsAny <string>(), It.IsAny <Type>(), It.IsAny <string>()),
                Times.Once());
        }
Пример #2
0
 public static Task <bool> DeleteAsync(T data, bool immediately = true)
 {
     if (!Support)
     {
         return(Task.FromResult(false));
     }
     return(Queue(() => Indexer.Delete(data, immediately)));
 }
Пример #3
0
        public static Task <bool> DeleteAsync(Expression <Func <Selector <T>, Selector <T> > > expression, bool immediately = true)
        {
            if (!Support)
            {
                return(Task.FromResult(false));
            }
            var tenant = CoreContext.TenantManager.GetCurrentTenant().TenantId;

            return(Queue(() => Indexer.Delete(expression, tenant, immediately)));
        }
Пример #4
0
        public Task <bool> DeleteAsync(T data, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return(Task.FromResult(false));
            }
            return(Queue(() => Indexer.Delete(data, immediately)));
        }
Пример #5
0
        public Task <bool> DeleteAsync(Expression <Func <Selector <T>, Selector <T> > > expression, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return(Task.FromResult(false));
            }
            var tenant = TenantManager.GetCurrentTenant().TenantId;

            return(Queue(() => Indexer.Delete(expression, tenant, immediately)));
        }
Пример #6
0
 public static void Delete(T data, bool immediately = true)
 {
     if (!Support)
     {
         return;
     }
     try
     {
         Indexer.Delete(data, immediately);
     }
     catch (Exception e)
     {
         Logger.Error("Delete", e);
     }
 }
Пример #7
0
        public static void Delete(Expression <Func <Selector <T>, Selector <T> > > expression, bool immediately = true)
        {
            if (!Support)
            {
                return;
            }
            var tenant = CoreContext.TenantManager.GetCurrentTenant().TenantId;

            try
            {
                Indexer.Delete(expression, tenant, immediately);
            }
            catch (Exception e)
            {
                Logger.Error("Index", e);
            }
        }
Пример #8
0
        public void Delete(T data, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }

            try
            {
                Indexer.Delete(data, immediately);
            }
            catch (Exception e)
            {
                Logger.Error("Delete", e);
            }
        }
Пример #9
0
        public void Delete(Expression <Func <Selector <T>, Selector <T> > > expression, bool immediately = true)
        {
            var t = ServiceProvider.GetService <T>();

            if (!FactoryIndexerHelper.Support(t))
            {
                return;
            }

            var tenant = TenantManager.GetCurrentTenant().TenantId;

            try
            {
                Indexer.Delete(expression, tenant, immediately);
            }
            catch (Exception e)
            {
                Logger.Error("Index", e);
            }
        }
Пример #10
0
        public static void Sync(CancellationToken ct)
        {
            bool taken = false;

            using (var scope = PuckCache.ServiceProvider.CreateScope())
            {
                var contentService = scope.ServiceProvider.GetService <I_Content_Service>();
                var searcher       = scope.ServiceProvider.GetService <I_Content_Searcher>();
                var repo           = scope.ServiceProvider.GetService <I_Puck_Repository>();
                var config         = scope.ServiceProvider.GetService <IConfiguration>();
                try
                {
                    Monitor.TryEnter(lck, lock_wait, ref taken);
                    if (!taken)
                    {
                        return;
                    }
                    var serverName = ApiHelper.ServerName();
                    var meta       = repo.GetPuckMeta().Where(x => x.Name == DBNames.SyncId && x.Key == serverName).FirstOrDefault();
                    if (meta == null)
                    {
                        return;
                    }
                    var syncId       = int.Parse(meta.Value);
                    var instructions = repo.GetPuckInstruction().Where(x => x.Id > syncId && x.ServerName != serverName).ToList();
                    if (instructions.Count == 0)
                    {
                        return;
                    }
                    //dosync
                    var hasPublishInstruction = false;
                    var instructionTotal      = 0;
                    instructions.ForEach(x => instructionTotal += x.Count);
                    if (instructionTotal > PuckCache.MaxSyncInstructions)
                    {
                        //todo, update settings and republish entire site
                        if (!PuckCache.IsRepublishingEntireSite)
                        {
                            PuckCache.IsRepublishingEntireSite = true;
                            var republishTask = contentService.RePublishEntireSite2();
                            republishTask.GetAwaiter().GetResult();
                        }
                        StateHelper.UpdateTaskMappings();
                        StateHelper.UpdateRedirectMappings();
                        StateHelper.UpdatePathLocaleMappings();
                        StateHelper.UpdateDomainMappings();
                        StateHelper.UpdateCacheMappings();
                        StateHelper.UpdateCrops();
                    }
                    else
                    {
                        foreach (var instruction in instructions)
                        {
                            if (instruction.InstructionKey == InstructionKeys.SetSearcher)
                            {
                                searcher.SetSearcher();
                            }
                            if (instruction.InstructionKey == InstructionKeys.Delete)
                            {
                                hasPublishInstruction = true;
                                if (Indexer.CanWrite)
                                {
                                    var qh = new QueryHelper <BaseModel>(prependTypeTerm: false);
                                    qh.SetQuery(instruction.InstructionDetail);
                                    var models = qh.GetAll(limit: int.MaxValue);
                                    Indexer.Delete(models);
                                }
                                else
                                {
                                    searcher.SetSearcher();
                                }
                            }
                            if (instruction.InstructionKey == InstructionKeys.RepublishSite)
                            {
                                if (!PuckCache.IsRepublishingEntireSite)
                                {
                                    PuckCache.IsRepublishingEntireSite = true;
                                    var republishTask = contentService.RePublishEntireSite2();
                                    republishTask.GetAwaiter().GetResult();
                                }
                            }
                            else if (instruction.InstructionKey == InstructionKeys.Publish)
                            {
                                hasPublishInstruction = true;
                                var toIndex = new List <BaseModel>();
                                //instruction detail holds comma separated list of ids and variants in format id:variant,id:variant
                                var idList = instruction.InstructionDetail.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                if (Indexer.CanWrite)
                                {
                                    foreach (var idAndVariant in idList)
                                    {
                                        var idAndVariantArr = idAndVariant.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                                        var id      = Guid.Parse(idAndVariantArr[0]);
                                        var variant = idAndVariantArr[1];
                                        var publishedOrCurrentRevision = repo.PublishedOrCurrentRevision(id, variant);
                                        if (publishedOrCurrentRevision != null)
                                        {
                                            var model = publishedOrCurrentRevision.ToBaseModel();
                                            toIndex.Add(model);
                                        }
                                    }
                                    Indexer.Index(toIndex);
                                }
                                else
                                {
                                    searcher.SetSearcher();
                                }
                            }
                            else if (instruction.InstructionKey == InstructionKeys.UpdateCrops)
                            {
                                StateHelper.UpdateCrops();
                            }
                            else if (instruction.InstructionKey == InstructionKeys.UpdateCacheMappings)
                            {
                                StateHelper.UpdateCacheMappings();
                            }
                            else if (instruction.InstructionKey == InstructionKeys.UpdateDomainMappings)
                            {
                                StateHelper.UpdateDomainMappings();
                            }
                            else if (instruction.InstructionKey == InstructionKeys.UpdatePathLocales)
                            {
                                StateHelper.UpdatePathLocaleMappings();
                            }
                            else if (instruction.InstructionKey == InstructionKeys.UpdateRedirects)
                            {
                                StateHelper.UpdateRedirectMappings();
                            }
                            else if (instruction.InstructionKey == InstructionKeys.UpdateTaskMappings)
                            {
                                StateHelper.UpdateTaskMappings();
                            }
                        }
                        if (hasPublishInstruction)
                        {
                            if (((config.GetValue <bool?>("UseAzureDirectory") ?? false) || (config.GetValue <bool?>("UseSyncDirectory") ?? false)) &&
                                config.GetValue <bool>("IsEditServer"))
                            {
                                var newInstruction = new PuckInstruction();
                                newInstruction.InstructionKey = InstructionKeys.SetSearcher;
                                newInstruction.Count          = 1;
                                newInstruction.ServerName     = ApiHelper.ServerName();
                                repo.AddPuckInstruction(newInstruction);
                                repo.SaveChanges();
                            }
                        }
                    }
                    //update syncId
                    //var maxInstructionId = instructions.Max(x => x.Id);
                    var maxInstructionIdOrDefault = repo.GetPuckInstruction().Max(x => (int?)x.Id);
                    var maxInstructionId          = maxInstructionIdOrDefault.HasValue ? maxInstructionIdOrDefault.Value : 0;
                    meta.Value = maxInstructionId.ToString();
                    repo.SaveChanges();
                    OnAfterSync(null, new AfterSyncEventArgs {
                        Instructions = instructions
                    });
                }
                catch (Exception ex)
                {
                    PuckCache.PuckLog.Log(ex);
                }
                finally
                {
                    if (taken)
                    {
                        Monitor.Exit(lck);
                    }
                    PuckCache.IsSyncQueued = false;
                }
            }
        }