Beispiel #1
0
        private void getMergeTMlist()
        {
            LanguageHelper.Initialize();

            TMListResponse[] TMlist = RAPI_Session.generateTMlist();
            Dictionary <string[], ClientTMs> TMGroups       = new Dictionary <string[], ClientTMs>();
            Dictionary <string[], ClientTMs> sortedTMGroups = new Dictionary <string[], ClientTMs>();

            Program.mainWindow.updateProgress(25);

            foreach (TMListResponse tm in TMlist)
            {
                if (tm.Client.Length > 0 && (client == "***All***" || tm.Client == client))
                {
                    string[] newid   = new string[] { tm.Client, tm.SourceLangCode, tm.TargetLangCode };
                    string[] existID = null;

                    foreach (string[] id in TMGroups.Keys)
                    {
                        if (tm.Client == TMGroups[id].client && tm.SourceLangCode == TMGroups[id].sLang && tm.TargetLangCode == TMGroups[id].tLang)
                        {
                            existID = id;
                        }
                    }

                    if (existID == null)
                    {
                        ClientTMs newGroup = new ClientTMs(newid);
                        TMGroups.Add(newid, newGroup);
                        TMGroups[newid].TMlist.Add(tm);
                    }
                    else
                    {
                        TMGroups[existID].TMlist.Add(tm);
                    }
                }
            }

            Program.mainWindow.updateProgress(50);

            IOrderedEnumerable <KeyValuePair <string[], ClientTMs> > linqGroups = from clientTMgroup in TMGroups
                                                                                  orderby clientTMgroup.Key[0], clientTMgroup.Key[1], clientTMgroup.Key[2] ascending
            select clientTMgroup;


            Worksheet ws;
            Workbook  wb = new Workbook();
            string    wsName = "TM list";

            if (wb.Worksheets.Count == 0)
            {
                ws = wb.Worksheets.Add(wsName);
            }
            else
            {
                ws      = wb.Worksheets[0];
                ws.Name = wsName;
            }

            WriteHeader(ref ws);

            int rowCount = 0;

            Program.mainWindow.updateProgress(75);

            foreach (KeyValuePair <string[], ClientTMs> kvp in linqGroups)
            {
                sortedTMGroups.Add(kvp.Key, kvp.Value);
            }

            foreach (string[] id in sortedTMGroups.Keys)
            {
                if (sortedTMGroups[id].TMlist.Count > 0)
                {
                    rowCount++;
                    Cell c = ws.Cells[rowCount, 0];
                    c.Value = sortedTMGroups[id].client + " (" + sortedTMGroups[id].sLang + " > " + sortedTMGroups[id].tLang + ")";
                    Helper.AddFontColor(c, Color.Purple);

                    rowCount++;

                    sortedTMGroups[id].findMasterTM();

                    TMListResponse tm = sortedTMGroups[id].getMasterTM();
                    WriteTM(tm, ref ws, rowCount);
                    FormatLine(tm, rowCount, ref ws);

                    rowCount++;

                    TMListResponse[] resultList = sortedTMGroups[id].getOtherTM();
                    foreach (TMListResponse tmn in resultList)
                    {
                        WriteTM(tmn, ref ws, rowCount);
                        FormatLine(tmn, rowCount, ref ws);
                        rowCount++;
                    }
                }
            }

            Helper.autoFitColumns(ref ws);
            wb.Save(exportFile);
            Program.mainWindow.updateProgress(100);
        }