示例#1
0
            public ExecuteCounterBatchCommand(DocumentDatabase database, CounterBatch counterBatch)
            {
                _database   = database;
                _dictionary = new Dictionary <string, List <CounterOperation> >();
                _replyWithAllNodesValues = counterBatch?.ReplyWithAllNodesValues ?? false;
                _fromEtl       = counterBatch?.FromEtl ?? false;
                CountersDetail = new CountersDetail
                {
                    Counters = new List <CounterDetail>()
                };

                if (counterBatch == null)
                {
                    return;
                }

                foreach (var docOps in counterBatch.Documents)
                {
                    foreach (var operation in docOps.Operations)
                    {
                        HasWrites |= operation.Type != CounterOperationType.Get &&
                                     operation.Type != CounterOperationType.None;
                        Add(docOps.DocumentId, operation);
                    }
                }
            }
示例#2
0
            // used only from smuggler import
            public ExecuteCounterBatchCommand(DocumentDatabase database)
            {
                _database   = database;
                _dictionary = new Dictionary <string, List <CounterOperation> >();

                CountersDetail = new CountersDetail
                {
                    Counters = new List <CounterDetail>()
                };
            }
示例#3
0
        public static CountersDetail GetInternal(DocumentDatabase database, DocumentsOperationContext context, StringValues counters, string docId, bool full)
        {
            var result = new CountersDetail();
            var names  = counters.Count != 0
                ? counters
                : database.DocumentsStorage.CountersStorage.GetCountersForDocument(context, docId);

            foreach (var counter in names)
            {
                GetCounterValue(context, database, docId, counter, full, result);
            }

            return(result);
        }
示例#4
0
        private static void GetCounterValue(DocumentsOperationContext context, DocumentDatabase database, string docId,
                                            string counterName, bool addFullValues, CountersDetail result)
        {
            var  fullValues = addFullValues ? new Dictionary <string, long>() : null;
            long?value      = null;

            foreach (var(cv, val) in database.DocumentsStorage.CountersStorage.GetCounterValues(context,
                                                                                                docId, counterName))
            {
                value = value ?? 0;
                try
                {
                    value = checked (value + val);
                }
                catch (OverflowException e)
                {
                    CounterOverflowException.ThrowFor(docId, counterName, e);
                }

                if (addFullValues)
                {
                    fullValues[cv] = val;
                }
            }

            if (value == null)
            {
                return;
            }

            if (result.Counters == null)
            {
                result.Counters = new List <CounterDetail>();
            }

            result.Counters.Add(new CounterDetail
            {
                DocumentId    = docId,
                CounterName   = counterName,
                TotalValue    = value.Value,
                CounterValues = fullValues
            });
        }
示例#5
0
        //[Authenticate]
        public async Task <PageProfileMold> Get(GetPageProfile request)
        {
            var pageProfileMold = new PageProfileMold {
            };
            var address         = UTF32Encoding.UTF8.GetString(Base64UrlTextEncoder.Decode(request.PageAddress));

            pageProfileMold.Address = address;

            var query = RavenSession.Query <PageProfile>();

            //Выделяем возможные пути
            var pathes = new HashSet <string>();
            var sb     = new StringBuilder();

            for (int i = 0; i < address.Length; i++)
            {
                var c = address[i];
                sb.Append(c);
                if (i > 8)
                {
                    switch (c)
                    {
                    case '/':
                    {
                        pathes.Add(sb.ToString());
                        break;
                    }

                    default:
                        break;
                    }
                }
            }
            pathes.Add(sb.ToString());

            query = query.Where(e => e.Address.In(pathes));

            //Запрашиваем
            var profiles = await query.ToListAsync();

            var perkList = new List <string> {
            };

            foreach (var profile in profiles)
            {
                var            id = RavenSession.Advanced.GetDocumentId(profile);
                CountersDetail operationResult = RavenSession.Advanced.DocumentStore.Operations
                                                 .Send(new GetCountersOperation(id));
                perkList.AddRange(operationResult.Counters.Select(x => $"{nameof(Perk)}/{x.CounterName}"));
            }

            var perks = await RavenSession.LoadAsync <Perk>(perkList);

            pageProfileMold.Perks = new List <PerkInProfileMold>();

            var mapper = new Mapper(new MapperConfiguration(expression =>
            {
                expression.CreateMap <Perk, PerkInProfileMold>();
            }));

            foreach (var perkPair in perks)
            {
                var perk = mapper.Map <Perk, PerkInProfileMold>(perkPair.Value);
                pageProfileMold.Perks.Add(perk);
            }

            return(pageProfileMold);
        }