Beispiel #1
0
        public void AddNewKey(ResourceEntity entity, string key)
        {
            Contract.Requires(entity != null);
            Contract.Requires(!string.IsNullOrEmpty(key));

            if (!entity.CanEdit(null))
            {
                return;
            }

            var entry = entity.Add(key);

            if (entry == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(_snapshot))
            {
                _resourceEntities.LoadSnapshot(_snapshot);
            }

            _selectedTableEntries.Clear();
            _selectedTableEntries.Add(entry);
        }
Beispiel #2
0
        public static ICollection <EntryChange> ImportTable([NotNull] this ResourceEntity entity, [NotNull][ItemNotNull] ICollection <string> fixedColumnHeaders, [NotNull][ItemNotNull] IList <IList <string> > table)
        {
            if (!table.Any())
            {
                return(Array.Empty <EntryChange>());
            }

            table = table.NormalizeTable();

            var headerColumns = GetHeaderColumns(table, fixedColumnHeaders);

            var fixedColumnHeadersCount = fixedColumnHeaders.Count;
            var dataColumnCount         = headerColumns.Count - fixedColumnHeadersCount;

            var dataColumnHeaders = headerColumns
                                    .Skip(fixedColumnHeadersCount)
                                    .Take(dataColumnCount)
                                    .ToArray();

            dataColumnCount = dataColumnHeaders.Length;

            if (dataColumnHeaders.Distinct().Count() != dataColumnHeaders.Count())
            {
                throw new ImportException(Resources.ImportDuplicateLanguageError);
            }

            var mappings = table.Skip(1)
                           .Select(columns => new { Key = columns[0], TextColumns = columns.Skip(fixedColumnHeadersCount).Take(dataColumnCount).ToArray() })
                           .Where(mapping => !string.IsNullOrEmpty(mapping.Key))
                           .SelectMany(mapping => mapping.TextColumns.Select((column, index) =>
                                                                             new
            {
                mapping.Key,
                Entry      = entity.Entries.SingleOrDefault(e => e.Key == mapping.Key) ?? entity.Add(mapping.Key),
                Text       = column,
                Culture    = dataColumnHeaders[index].ExtractCulture(),
                ColumnKind = dataColumnHeaders[index].GetColumnKind()
            }))
                           .Where(mapping => mapping.Entry != null)
                           .Select(mapping => new EntryChange(mapping.Entry, mapping.Text, mapping.Culture, mapping.ColumnKind, mapping.Entry.GetEntryData(mapping.Culture, mapping.ColumnKind)))
                           .ToArray();

            var changes = mappings
                          .Where(mapping => (mapping.OriginalText != mapping.Text) && !string.IsNullOrEmpty(mapping.Text))
                          .ToArray();

            VerifyCultures(entity, changes.Select(c => c.Culture).Distinct());

            return(changes);
        }
Beispiel #3
0
        public static ICollection <EntryChange> ImportTable(this ResourceEntity entity, ICollection <string> fixedColumnHeaders, IList <IList <string> > table)
        {
            Contract.Requires(entity != null);
            Contract.Requires(fixedColumnHeaders != null);
            Contract.Requires(table != null);
            Contract.Ensures(Contract.Result <ICollection <EntryChange> >() != null);

            if (!table.Any())
            {
                return(new EntryChange[0]);
            }

            var headerColumns = GetHeaderColumns(table, fixedColumnHeaders);

            var fixedColumnHeadersCount = fixedColumnHeaders.Count;
            var dataColumnCount         = headerColumns.Count - fixedColumnHeadersCount;

            var dataColumnHeaders = headerColumns
                                    .Skip(fixedColumnHeadersCount)
                                    .Take(dataColumnCount)
                                    .ToArray();

            dataColumnCount = dataColumnHeaders.Length;

            VerifyCultures(entity, dataColumnHeaders);

            var mappings = table.Skip(1)
                           .Select(columns => new { Key = columns[0], TextColumns = columns.Skip(fixedColumnHeadersCount).Take(dataColumnCount).ToArray() })
                           .Where(mapping => !string.IsNullOrEmpty(mapping.Key))
                           .SelectMany(mapping => mapping.TextColumns.Select((column, index) =>
                                                                             new
            {
                mapping.Key,
                Entry      = entity.Entries.SingleOrDefault(e => e.Key == mapping.Key) ?? entity.Add(mapping.Key),
                Text       = column,
                Culture    = dataColumnHeaders[index].ExtractCulture(),
                ColumnKind = dataColumnHeaders[index].GetColumnKind()
            }))
                           .Where(mapping => mapping.Entry != null)
                           .Select(mapping => new EntryChange(mapping.Entry, mapping.Text, mapping.Culture, mapping.ColumnKind, mapping.Entry.GetEntryData(mapping.Culture, mapping.ColumnKind)))
                           .ToArray();

            var changes = mappings
                          .Where(mapping => (mapping.OriginalText != mapping.Text) && !string.IsNullOrEmpty(mapping.Text))
                          .ToArray();

            return(changes);
        }