public QueryResult <int> ExecuteQuery(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            var result = Retrier.Retry(SearchServiceClient.RetryCount, SearchServiceClient.RetryWaitMilliseconds, typeof(CommunicationException),
                                       () => SearchServiceClient.Instance.ExecuteQuery(query, GetQueryContext(query, context)));

            return(new QueryResult <int>(result.Hits, result.TotalCount));
        }
示例#2
0
        private static bool ReindexBinaryProperties(int versionId, DateTime timeLimit)
        {
            using (new SystemAccount())
            {
                var node = Node.LoadNodeByVersionId(versionId);
                if (node == null)
                {
                    return(true);
                }

                if (node.VersionModificationDate > timeLimit)
                {
                    Tracer.Write($"SKIP V#{node.VersionId} {node.Version} N#{node.Id} {node.Path}");
                    return(true);
                }

                try
                {
                    Retrier.Retry(3, 2000, typeof(Exception), () =>
                    {
                        var indx = SearchManager.LoadIndexDocumentByVersionId(versionId);
                        DataBackingStore.SaveIndexDocument(node, indx);
                    });
                    Tracer.Write($"Save V#{node.VersionId} {node.Version} N#{node.Id} {node.Path}");
                    return(true);
                }
                catch (Exception e)
                {
                    Tracer.WriteError("Error after 3 attempts: {0}", e);
                    return(false);
                }
            }
        }
        private static bool LoadEmptyPreviewFoldersBlock(string path, int blockSize, out List <NodeInfo> buffer)
        {
            var block = new List <NodeInfo>();

            Retrier.Retry(3, 1000, typeof(Exception), () => { block = LoadEmptyPreviewFoldersBlockInternal(path, blockSize); });

            buffer = block;

            return(block.Any());
        }
        private static bool LoadPreviewImagesBlock(string path, int maxIndex, int minimumNodeId, int blockSize, out List <NodeInfo> buffer)
        {
            var block = new List <NodeInfo>();

            Retrier.Retry(3, 1000, typeof(Exception), () => { block = LoadPreviewImagesBlockInternal(path, maxIndex, minimumNodeId, blockSize); });

            buffer = block;

            return(block.Any());
        }
        public QueryResult <string> ExecuteQueryAndProject(SnQuery query, IPermissionFilter filter, IQueryContext context)
        {
            var projection = query.Projection ?? IndexFieldName.NodeId;
            var converter  = !(context.GetPerFieldIndexingInfo(projection).IndexFieldHandler is IIndexValueConverter indexFieldHandler)
                ? DefaultConverter
                : indexFieldHandler.GetBack;

            var result = Retrier.Retry(SearchServiceClient.RetryCount, SearchServiceClient.RetryWaitMilliseconds, typeof(CommunicationException),
                                       () => SearchServiceClient.Instance.ExecuteQueryAndProject(query, GetQueryContext(query, context)));

            return(new QueryResult <string>(result.Hits.Select(h => converter(h)?.ToString()), result.TotalCount));
        }
        private static async Task DeleteContentFromDb(int nodeId)
        {
            await Retrier.RetryAsync(3, 3000, () => DeleteContentFromDbInternalAsync(nodeId), (counter, exc) =>
            {
                if (exc == null)
                {
                    return(true);
                }

                Trace.WriteError($"Content {nodeId} could not be deleted. {exc.Message}");
                return(false);
            });
        }
示例#7
0
        internal static void UndoContentChanges(string path, params string[] typeNameArray)
        {
            if (typeNameArray == null || typeNameArray.Length == 0)
            {
                typeNameArray = new[] { typeof(GenericContent).Name }
            }
            ;
            if (string.IsNullOrEmpty(path))
            {
                path = "/Root";
            }

            var error = false;

            using (new SystemAccount())
            {
                Parallel.ForEach(ContentQuery
                                 .Query(SafeQueries.LockedContentByPath, QuerySettings.AdminSettings, typeNameArray, path).Nodes
                                 .Where(n => n is GenericContent).Cast <GenericContent>(),
                                 new ParallelOptions {
                    MaxDegreeOfParallelism = 10
                },
                                 gc =>
                {
                    Logger.LogMessage($"UNDO changes: {gc.Path}");

                    try
                    {
                        Retrier.Retry(3, 1000, typeof(Exception), () =>
                        {
                            var tgc = Node.Load <GenericContent>(gc.Id);
                            tgc.UndoCheckOut();
                        });
                    }
                    catch (Exception ex)
                    {
                        error   = true;
                        var msg = $"Error during undo changes of {gc.Path} (v: {gc.Version}): {ex.Message}";
                        SnLog.WriteException(ex, msg);
                        Logger.LogException(ex, msg);
                        SnTrace.ContentOperation.WriteError(msg + " " + ex.StackTrace);
                    }
                });
            }

            if (error)
            {
                throw new InvalidOperationException("One or more errors occurred during UndoChanges, please check the log.");
            }
        }
    }