示例#1
0
        public void Export(string filePath)
        {
            using (var workbook = new XLWorkbook(XLEventTracking.Disabled))
            {
                IEnumerable <CultureInfo> cultures = null;
                if (Cultures != null)
                {
                    cultures = Cultures.Select(vc => vc.Culture);
                }
                else
                {
                    cultures = Solution.Cultures.Keys;
                }

                IEnumerable <VSProject> projects = Projects;
                if (Projects == null)
                {
                    projects = (IEnumerable <VSProject>)Solution.Projects.Values;
                }

                foreach (var project in projects)
                {
                    var data = GetData(project, cultures);

                    if (IncludeProjectsWithoutTranslations || data.Count() > 0)
                    {
                        AddProject(project, workbook, cultures, data);
                    }
                }

                workbook.SaveAs(filePath);
            }
        }
        private (int totalRecods, ICollection <CultureItem> items) GetData()
        {
            var query = Cultures.Select(x => new CultureItem
            {
                LCID         = x.LCID,
                EnglishName  = x.EnglishName,
                NativeName   = x.NativeName,
                CultureTypes = x.CultureTypes
            });

            //if the search text is not empty, then apply where clause
            if (!string.IsNullOrWhiteSpace(Q))
            {
                var _keyWords = Q.Split(new[] { ' ', ',', ':' }, StringSplitOptions.RemoveEmptyEntries).Distinct();

                //null check is not required in our case for this sample,
                //added just for demonstration in case the search will be done in nullable database fields
                query = query.Where(x => _keyWords.Any(kw =>
                                                       (x.EnglishName != null && x.EnglishName.Contains(kw, StringComparison.OrdinalIgnoreCase)) ||
                                                       (x.NativeName != null && x.NativeName.Contains(kw, StringComparison.OrdinalIgnoreCase))));
            }

            //if search filter for culture type is specified, then add where clause
            if (CT != CultureTypes.AllCultures)
            {
                query = query.Where(x => x.CultureTypes.HasFlag(CT));
            }

            //count records that returns after the search
            var t = query.Count();

            var i = query

                    //make sure to order items before paging
                    .OrderBy(x => x.EnglishName)

                    //skip items before current page
                    .Skip((P - 1) * S)

                    //take only 10 (page size) items
                    .Take(S)
                    .ToList();

            return(t, i);
        }
        /// <summary>
        /// Gets the list of all events that belongs to the tournament schedule
        /// </summary>
        /// <returns>A <see cref="Task{T}"/> representing the asynchronous operation</returns>
        public async Task <IEnumerable <ICompetition> > GetScheduleAsync()
        {
            IEnumerable <Tuple <URN, URN> > sportEventIds;

            if (ExceptionStrategy == ExceptionHandlingStrategy.THROW)
            {
                var tasks = Cultures.Select(s => _sportEventCache.GetEventIdsAsync(Id, s)).ToList();
                await Task.WhenAll(tasks).ConfigureAwait(false);

                sportEventIds = tasks.First().Result;
            }
            else
            {
                var tasks = Cultures.Select(s => new Func <URN, CultureInfo, Task <IEnumerable <Tuple <URN, URN> > > >(_sportEventCache.GetEventIdsAsync).SafeInvokeAsync(Id, s, ExecutionLog, GetFetchErrorMessage("Schedule"))).ToList();
                await Task.WhenAll(tasks).ConfigureAwait(false);

                sportEventIds = tasks.First().Result;
            }

            return(sportEventIds?.Select(i => _sportEntityFactory.BuildSportEvent <ICompetition>(i.Item1, i.Item2 ?? SportId, Cultures, ExceptionStrategy)).ToList());
        }
        /// <summary>
        /// Constructs and returns a <see cref="T:System.String" /> containing compacted representation of the current instance
        /// </summary>
        /// <returns>A <see cref="T:System.String" /> containing compacted representation of the current instance.</returns>
        protected override string PrintC()
        {
            var result = $"{PrintI()}, Cultures=[{string.Join(", ", Cultures.Select(c => c.TwoLetterISOLanguageName))}]"; //, Status={((SportEventStatus)Status).PrintC()}";

            return(result);
        }
        /// <summary>
        /// Constructs and returns a <see cref="T:System.String" /> containing compacted representation of the current instance
        /// </summary>
        /// <returns>A <see cref="T:System.String" /> containing compacted representation of the current instance.</returns>
        protected override string PrintC()
        {
            var result = $"{PrintI()}, Cultures=[{string.Join(", ", Cultures.Select(c => c.TwoLetterISOLanguageName))}]";

            return(result);
        }
示例#6
0
 public IEnumerator <string> GetEnumerator()
 {
     return(Cultures.Select(c => this[c]).GetEnumerator());
 }