コード例 #1
0
        void GeneratePushRequests(int sheetId, StringTableCollection collection, IList <SheetColumn> columnMapping, List <Request> requestsToSend, ITaskReporter reporter)
        {
            // Prepare the column requests.
            // We use a request per column as its possible that some columns in the sheet will be preserved and we don't want to write over them.
            reporter?.ReportProgress("Generating column headers", 0);
            var columnSheetRequests = new List <PushColumnSheetRequest>(columnMapping.Count);

            foreach (var col in columnMapping)
            {
                var colRequest = new PushColumnSheetRequest(sheetId, col);

                columnSheetRequests.Add(colRequest);
                colRequest.Column.PushBegin(collection);
                colRequest.Column.PushHeader(collection, out var header, out var note);
                colRequest.AddHeader(header, note);
            }

            var stringTables = collection.StringTables;
            var tableEntries = new StringTableEntry[stringTables.Count];

            reporter?.ReportProgress("Generating push data", 0.1f);
            foreach (var keyEntry in collection.SharedData.Entries)
            {
                // Collect the table entry data.
                for (int i = 0; i < stringTables.Count; ++i)
                {
                    tableEntries[i] = stringTables[i].GetEntry(keyEntry.Id);
                }

                // Now process each sheet column so they can update their requests.
                foreach (var colReq in columnSheetRequests)
                {
                    if (tableEntries[0].SharedEntry.Metadata.HasMetadata <ExcludeEntryFromExport>())
                    {
                        continue;
                    }

                    colReq.Column.PushCellData(keyEntry, tableEntries, out var value, out var note);
                    colReq.AddRow(value, note);
                }
            }

            foreach (var col in columnSheetRequests)
            {
                col.Column.PushEnd();
                requestsToSend.AddRange(col.Requests);
            }
        }
コード例 #2
0
        void GeneratePushRequests(int sheetId, StringTableCollection collection, IList <SheetColumn> columnMapping, List <Request> requestsToSend, ITaskReporter reporter)
        {
            // Prepare the tables - Sort the keys and table entries
            reporter?.ReportProgress("Sorting entries", 0.2f);
            var sortedKeyEntries   = collection.SharedData.Entries.OrderBy(e => e.Id);
            var sortedTableEntries = new List <IOrderedEnumerable <StringTableEntry> >();

            foreach (var table in collection.StringTables)
            {
                if (table != null)
                {
                    var s = table.Values.OrderBy(e => e.KeyId);
                    sortedTableEntries.Add(s);
                }
            }

            // Extract all the data so we can generate a request to send
            // We go through each Key, extract the table entries for that key if they exists and then pass this to each column.
            var currentTableRowIterator = sortedTableEntries.Select(o =>
            {
                var itr = o.GetEnumerator();
                itr.MoveNext();
                return(itr);
            }).ToArray();

            // Prepare the column requests.
            // We use a request per column as its possible that some columns in the sheet will be preserved and we don't want to write over them.
            reporter?.ReportProgress("Generating column headers", 0.25f);
            var columnSheetRequests = new List <PushColumnSheetRequest>(columnMapping.Count);

            foreach (var col in columnMapping)
            {
                var colRequest = new PushColumnSheetRequest(sheetId, col);

                columnSheetRequests.Add(colRequest);
                colRequest.Column.PushBegin(collection);
                colRequest.Column.PushHeader(collection, out var header, out var note);
                colRequest.AddHeader(header, note);
            }

            // Populate the requests from the string tables
            var currentTableRow = new StringTableEntry[sortedTableEntries.Count];

            foreach (var keyRow in sortedKeyEntries)
            {
                // Extract the string table entries for this row
                for (int i = 0; i < currentTableRow.Length; ++i)
                {
                    var tableRowItr = currentTableRowIterator[i];
                    if (tableRowItr.Current?.KeyId == keyRow.Id)
                    {
                        currentTableRow[i] = tableRowItr.Current;
                        tableRowItr.MoveNext();
                    }
                    else
                    {
                        currentTableRow[i] = null;
                    }
                }

                // Now process each sheet column so they can update their requests.
                foreach (var colReq in columnSheetRequests)
                {
                    colReq.Column.PushCellData(keyRow, currentTableRow, out var value, out var note);
                    colReq.AddRow(value, note);
                }
            }

            foreach (var col in columnSheetRequests)
            {
                col.Column.PushEnd();
                requestsToSend.AddRange(col.Requests);
            }
        }