public void Export(ExportSettings settings, IOrganizationService service, ConnectionDetail detail, BackgroundWorker worker = null)
        {
            List <int> lcids;

            if (settings.LanguageToExport != -1)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Loading environment base language...");
                }
                var baseLanguageCode = service.RetrieveMultiple(new QueryExpression("organization")
                {
                    ColumnSet = new ColumnSet("languagecode")
                }).Entities.First().GetAttributeValue <int>("languagecode");

                lcids = new List <int> {
                    baseLanguageCode, settings.LanguageToExport
                }.Distinct().ToList();
            }
            else
            {
                // Loading available languages
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Loading provisioned languages...");
                }
                var lcidRequest  = new RetrieveProvisionedLanguagesRequest();
                var lcidResponse = (RetrieveProvisionedLanguagesResponse)service.Execute(lcidRequest);
                lcids = lcidResponse.RetrieveProvisionedLanguages.Select(lcid => lcid).ToList();
            }

            // Loading entities
            var emds = new List <EntityMetadata>();

            if (worker != null && worker.WorkerReportsProgress)
            {
                worker.ReportProgress(0, "Loading selected entities...");
            }
            foreach (string entityLogicalName in settings.Entities)
            {
                var filters = EntityFilters.Default;
                if (settings.ExportEntities)
                {
                    filters = filters | EntityFilters.Entity;
                }
                if (settings.ExportCustomizedRelationships)
                {
                    filters = filters | EntityFilters.Relationships;
                }
                if (settings.ExportAttributes || settings.ExportOptionSet || settings.ExportBooleans)
                {
                    filters = filters | EntityFilters.Attributes;
                }

                var request = new RetrieveEntityRequest {
                    LogicalName = entityLogicalName, EntityFilters = filters
                };
                var response = (RetrieveEntityResponse)service.Execute(request);
                emds.Add(response.EntityMetadata);
            }

            var file = new ExcelPackage();

            file.File = new FileInfo(settings.FilePath);

            if (settings.ExportEntities && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting entities translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Entities");
                var et    = new EntityTranslation();
                et.Export(emds, lcids, sheet, settings);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportAttributes && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting attributes translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Attributes");
                var at    = new AttributeTranslation();
                at.Export(emds, lcids, sheet, settings);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportCustomizedRelationships && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting relationships with custom labels translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Relationships");
                var rt    = new RelationshipTranslation();
                rt.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);

                var sheetNn = file.Workbook.Worksheets.Add("RelationshipsNN");
                var rtNn    = new RelationshipNnTranslation();
                rtNn.Export(emds, lcids, sheetNn);
                StyleMutator.FontDefaults(sheetNn);
            }

            if (settings.ExportGlobalOptionSet)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting global optionsets translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Global OptionSets");
                var ot    = new GlobalOptionSetTranslation();
                ot.Export(lcids, sheet, service, settings);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportOptionSet && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting optionset translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("OptionSets");
                var ot    = new OptionSetTranslation();
                ot.Export(emds, lcids, sheet, settings);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportBooleans && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting booleans translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Booleans");

                var bt = new BooleanTranslation();
                bt.Export(emds, lcids, sheet, settings);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportViews && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting views translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Views");
                var vt    = new ViewTranslation();
                vt.Export(emds, lcids, sheet, service, settings);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportCharts && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting Charts translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Charts");
                var vt    = new VisualizationTranslation();
                vt.Export(emds, lcids, sheet, service, settings);
                StyleMutator.FontDefaults(sheet);
            }

            if ((settings.ExportForms || settings.ExportFormTabs || settings.ExportFormSections || settings.ExportFormFields) && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting forms translations...");
                }

                var ft = new FormTranslation();

                ft.Export(emds, lcids, file.Workbook, service,
                          new FormExportOption
                {
                    ExportForms        = settings.ExportForms,
                    ExportFormTabs     = settings.ExportFormTabs,
                    ExportFormSections = settings.ExportFormSections,
                    ExportFormFields   = settings.ExportFormFields
                }, settings);
            }

            if (settings.ExportSiteMap)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting SiteMap custom labels translations...");
                }

                var st = new SiteMapTranslation();

                st.Export(lcids, file.Workbook, service, settings, detail);
            }

            if (settings.ExportDashboards)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting Dashboards custom labels translations...");
                }

                var st = new DashboardTranslation();

                st.Export(lcids, file.Workbook, service, settings);
            }

            file.Save();
        }
Example #2
0
        public void Export(ExportSettings settings, IOrganizationService service, BackgroundWorker worker = null)
        {
            // Loading available languages
            if (worker != null && worker.WorkerReportsProgress)
            {
                worker.ReportProgress(0, "Loading provisioned languages...");
            }
            var lcidRequest  = new RetrieveProvisionedLanguagesRequest();
            var lcidResponse = (RetrieveProvisionedLanguagesResponse)service.Execute(lcidRequest);
            var lcids        = lcidResponse.RetrieveProvisionedLanguages.Select(lcid => lcid).ToList();

            // Loading entities
            var emds = new List <EntityMetadata>();

            if (worker != null && worker.WorkerReportsProgress)
            {
                worker.ReportProgress(0, "Loading selected entities...");
            }
            foreach (string entityLogicalName in settings.Entities)
            {
                var filters = EntityFilters.Default;
                if (settings.ExportEntities)
                {
                    filters = filters | EntityFilters.Entity;
                }
                if (settings.ExportCustomizedRelationships)
                {
                    filters = filters | EntityFilters.Relationships;
                }
                if (settings.ExportAttributes || settings.ExportOptionSet || settings.ExportBooleans)
                {
                    filters = filters | EntityFilters.Attributes;
                }

                var request = new RetrieveEntityRequest {
                    LogicalName = entityLogicalName, EntityFilters = filters
                };
                var response = (RetrieveEntityResponse)service.Execute(request);
                emds.Add(response.EntityMetadata);
            }

            var file = new ExcelPackage();

            file.File = new FileInfo(settings.FilePath);

            if (settings.ExportEntities && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting entities translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Entities");
                var et    = new EntityTranslation();
                et.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportAttributes && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting attributes translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Attributes");
                var at    = new AttributeTranslation();
                at.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportCustomizedRelationships && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting relationships with custom labels translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Relationships");
                var rt    = new RelationshipTranslation();
                rt.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);

                var sheetNn = file.Workbook.Worksheets.Add("RelationshipsNN");
                var rtNn    = new RelationshipNnTranslation();
                rtNn.Export(emds, lcids, sheetNn);
                StyleMutator.FontDefaults(sheetNn);
            }

            if (settings.ExportGlobalOptionSet)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting global optionsets translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Global OptionSets");
                var ot    = new GlobalOptionSetTranslation();
                ot.Export(lcids, sheet, service);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportOptionSet && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting optionset translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("OptionSets");
                var ot    = new OptionSetTranslation();
                ot.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportBooleans && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting booleans translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Booleans");

                var bt = new BooleanTranslation();
                bt.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportViews && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting views translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Views");
                var vt    = new ViewTranslation();
                vt.Export(emds, lcids, sheet, service);
                StyleMutator.FontDefaults(sheet);
            }

            if (settings.ExportCharts && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting Charts translations...");
                }

                var sheet = file.Workbook.Worksheets.Add("Charts");
                var vt    = new VisualizationTranslation();
                vt.Export(emds, lcids, sheet, service);
                StyleMutator.FontDefaults(sheet);
            }

            if ((settings.ExportForms || settings.ExportFormTabs || settings.ExportFormSections || settings.ExportFormFields) && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting forms translations...");
                }

                var ft = new FormTranslation();

                ft.Export(emds, lcids, file.Workbook, service,
                          new FormExportOption
                {
                    ExportForms        = settings.ExportForms,
                    ExportFormTabs     = settings.ExportFormTabs,
                    ExportFormSections = settings.ExportFormSections,
                    ExportFormFields   = settings.ExportFormFields
                });
            }

            if (settings.ExportSiteMap)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting SiteMap custom labels translations...");
                }

                var st = new SiteMapTranslation();

                st.Export(lcids, file.Workbook, service);
            }

            if (settings.ExportDashboards)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting Dashboards custom labels translations...");
                }

                var st = new DashboardTranslation();

                st.Export(lcids, file.Workbook, service);
            }

            file.Save();

            if (DialogResult.Yes == MessageBox.Show("Do you want to open generated document?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Process.Start(settings.FilePath);
            }
        }
Example #3
0
        public void Export(ExportSettings settings, IOrganizationService service, BackgroundWorker worker = null)
        {
            // Loading available languages
            if (worker != null && worker.WorkerReportsProgress)
            {
                worker.ReportProgress(0, "Loading provisioned languages...");
            }
            var lcidRequest  = new RetrieveProvisionedLanguagesRequest();
            var lcidResponse = (RetrieveProvisionedLanguagesResponse)service.Execute(lcidRequest);
            var lcids        = lcidResponse.RetrieveProvisionedLanguages.Select(lcid => lcid).ToList();

            // Loading entities
            var emds = new List <EntityMetadata>();

            if (worker != null && worker.WorkerReportsProgress)
            {
                worker.ReportProgress(0, "Loading selected entities...");
            }
            foreach (string entityLogicalName in settings.Entities)
            {
                var request = new RetrieveEntityRequest {
                    LogicalName = entityLogicalName, EntityFilters = EntityFilters.Attributes
                };
                var response = (RetrieveEntityResponse)service.Execute(request);
                emds.Add(response.EntityMetadata);
            }
#if NO_GEMBOX
            var file = new ExcelPackage(new FileInfo(settings.FilePath));
#else
            var file = new ExcelFile();
#endif
            if (settings.ExportEntities && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting entities translations...");
                }

#if NO_GEMBOX
                var sheet = file.Workbook.Worksheets.Add("Entities");
                var et    = new EntityTranslation();
                et.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);
#else
                var sheet = file.Worksheets.Add("Entities");
                var et    = new EntityTranslation();
                et.Export(emds, lcids, sheet);
#endif
            }

            if (settings.ExportAttributes && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting attributes translations...");
                }
#if NO_GEMBOX
                var sheet = file.Workbook.Worksheets.Add("Attributes");
                var at    = new AttributeTranslation();
                at.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);
#else
                var sheet = file.Worksheets.Add("Attributes");
                var at    = new AttributeTranslation();
                at.Export(emds, lcids, sheet);
#endif
            }

            if (settings.ExportGlobalOptionSet)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting global optionsets translations...");
                }
#if NO_GEMBOX
                var sheet = file.Workbook.Worksheets.Add("Global OptionSets");
                var ot    = new GlobalOptionSetTranslation();
                ot.Export(lcids, sheet, service);
                StyleMutator.FontDefaults(sheet);
#else
                var sheet = file.Worksheets.Add("Global OptionSets");
                var ot    = new GlobalOptionSetTranslation();
                ot.Export(lcids, sheet, service);
#endif
            }

            if (settings.ExportOptionSet && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting optionset translations...");
                }

#if NO_GEMBOX
                var sheet = file.Workbook.Worksheets.Add("OptionSets");
                var ot    = new OptionSetTranslation();
                ot.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);
#else
                var sheet = file.Worksheets.Add("OptionSets");
                var ot    = new OptionSetTranslation();
                ot.Export(emds, lcids, sheet);
#endif
            }

            if (settings.ExportBooleans && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting booleans translations...");
                }

#if NO_GEMBOX
                var sheet = file.Workbook.Worksheets.Add("Booleans");

                var bt = new BooleanTranslation();
                bt.Export(emds, lcids, sheet);
                StyleMutator.FontDefaults(sheet);
#else
                var sheet = file.Worksheets.Add("Booleans");

                var bt = new BooleanTranslation();
                bt.Export(emds, lcids, sheet);
#endif
            }

            if (settings.ExportViews && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting views translations...");
                }

#if NO_GEMBOX
                var sheet = file.Workbook.Worksheets.Add("Views");
                var vt    = new ViewTranslation();
                vt.Export(emds, lcids, sheet, service);
                StyleMutator.FontDefaults(sheet);
#else
                var sheet = file.Worksheets.Add("Views");
                var vt    = new ViewTranslation();
                vt.Export(emds, lcids, sheet, service);
#endif
            }

            if ((settings.ExportForms || settings.ExportFormTabs || settings.ExportFormSections || settings.ExportFormFields) && emds.Count > 0)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting forms translations...");
                }

                var ft = new FormTranslation();
#if NO_GEMBOX
                ft.Export(emds, lcids, file.Workbook, service,
#else
                ft.Export(emds, lcids, file, service,
#endif
                          new FormExportOption
                {
                    ExportForms        = settings.ExportForms,
                    ExportFormTabs     = settings.ExportFormTabs,
                    ExportFormSections = settings.ExportFormSections,
                    ExportFormFields   = settings.ExportFormFields
                });
            }

            if (settings.ExportSiteMap)
            {
                if (worker != null && worker.WorkerReportsProgress)
                {
                    worker.ReportProgress(0, "Exporting SiteMap custom labels translations...");
                }

                var st = new SiteMapTranslation();

#if NO_GEMBOX
                st.Export(lcids, file.Workbook, service);
#else
                st.Export(lcids, file, service);
#endif
            }

#if NO_GEMBOX
            file.Save();
#else
            file.Save(settings.FilePath, SaveOptions.XlsxDefault);
#endif
        }