Example #1
0
        public TabularTranslatedItem(string table, IModelComponent obj, TabularTranslatedItemProperty property, TabularTranslatedItem caption, SSAS.TabularTranslationsAnnotation annotations)
        {
            _Table    = table;
            _object   = obj;
            _Property = property;

            TranslationCollection translations;
            string sCaption;
            string sDescription;
            string sDisplayFolder = null;

            if (obj is DimensionAttribute)
            {
                _ObjectType = TabularTranslatedItemType.Column;
                DimensionAttribute typedobj = (DimensionAttribute)obj;
                translations   = typedobj.Translations;
                sDisplayFolder = typedobj.AttributeHierarchyDisplayFolder;
                sCaption       = typedobj.Name;
                sDescription   = typedobj.Description;
            }
            else if (obj is Hierarchy)
            {
                _ObjectType = TabularTranslatedItemType.Hierarchy;
                Hierarchy typedobj = (Hierarchy)obj;
                translations   = typedobj.Translations;
                sDisplayFolder = typedobj.DisplayFolder;
                sCaption       = typedobj.Name;
                sDescription   = typedobj.Description;
            }
            else if (obj is Level)
            {
                _ObjectType = TabularTranslatedItemType.Level;
                Level typedobj = (Level)obj;
                translations = typedobj.Translations;
                sCaption     = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is CalculationProperty)
            {
                _ObjectType = TabularTranslatedItemType.Measure;
                CalculationProperty typedobj = (CalculationProperty)obj;
                translations   = typedobj.Translations;
                sDisplayFolder = typedobj.DisplayFolder;
                sCaption       = typedobj.CalculationReference;
                sDescription   = typedobj.Description;

                if (sCaption.StartsWith("[") && sCaption.EndsWith("]"))
                {
                    sCaption = sCaption.Substring(1, sCaption.Length - 2);
                }
            }
            else if (obj is Database)
            {
                _ObjectType = TabularTranslatedItemType.Database;
                Database typedobj = (Database)obj;
                translations = typedobj.Translations;
                sCaption     = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Cube)
            {
                _ObjectType = TabularTranslatedItemType.Cube;
                Cube typedobj = (Cube)obj;
                translations = typedobj.Translations;
                sCaption     = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Perspective)
            {
                _ObjectType = TabularTranslatedItemType.Perspective;
                Perspective typedobj = (Perspective)obj;
                translations = typedobj.Translations;
                sCaption     = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Dimension)
            {
                _ObjectType = TabularTranslatedItemType.Table;
                Dimension typedobj = (Dimension)obj;
                translations = typedobj.Translations;
                sCaption     = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Microsoft.AnalysisServices.Action)
            {
                _ObjectType = TabularTranslatedItemType.Action;
                Microsoft.AnalysisServices.Action typedobj = (Microsoft.AnalysisServices.Action)obj;
                translations = typedobj.Translations;
                sCaption     = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else
            {
                throw new Exception("Unexpected object type: " + obj.GetType().Name);
            }

            _ObjectName = sCaption;

            if (property == TabularTranslatedItemProperty.Caption)
            {
                _DefaultLanguage = sCaption;

                SSAS.TabularTranslationObjectAnnotation annotation = annotations.Find(obj);
                if (annotation != null && translations.Count == 0)
                {
                    foreach (SSAS.TabularTranslationAnnotation tranAnnotation in annotation.TabularTranslations)
                    {
                        Translation t = new Translation(tranAnnotation.Language);
                        if (obj is DimensionAttribute)
                        {
                            t = new AttributeTranslation(tranAnnotation.Language);
                        }
                        t.Caption       = tranAnnotation.Caption;
                        t.Description   = tranAnnotation.Description;
                        t.DisplayFolder = tranAnnotation.DisplayFolder;
                        translations.Add(t);
                    }
                    _restoredTranslations = true;
                }
            }
            else if (property == TabularTranslatedItemProperty.Description)
            {
                _DefaultLanguage = sDescription;
            }
            else if (property == TabularTranslatedItemProperty.DisplayFolder)
            {
                _DefaultLanguage = sDisplayFolder;
            }

            Languages = new Core.DirtyMonitoredDictionary <int, string>();
            foreach (Translation t in translations)
            {
                if (property == TabularTranslatedItemProperty.Caption)
                {
                    Languages.Add(t.Language, t.Caption);
                }
                else if (property == TabularTranslatedItemProperty.Description)
                {
                    Languages.Add(t.Language, t.Description);
                }
                else if (property == TabularTranslatedItemProperty.DisplayFolder)
                {
                    Languages.Add(t.Language, t.DisplayFolder);
                }
            }

            if (caption != null)
            {
                caption.DependentProperties.Add(this);
            }
        }
Example #2
0
        private void SaveInternal(TranslationCollection translations, Dictionary <int, string> DisplayFolderLanguages, Dictionary <int, string> DescriptionLanguages, SSAS.TabularTranslationObjectAnnotation annotation)
        {
            List <int> listAllLanguages = new List <int>(Languages.Keys);

            foreach (int iLang in DisplayFolderLanguages.Keys)
            {
                if (!listAllLanguages.Contains(iLang))
                {
                    listAllLanguages.Add(iLang);
                }
            }
            foreach (int iLang in DescriptionLanguages.Keys)
            {
                if (!listAllLanguages.Contains(iLang))
                {
                    listAllLanguages.Add(iLang);
                }
            }

            List <SSAS.TabularTranslationAnnotation> listAnnotations = new List <TabularTranslationAnnotation>();

            translations.Clear();
            foreach (int iLang in listAllLanguages)
            {
                Translation t = new Translation(iLang);
                if (translations is AttributeTranslationCollection)
                {
                    t = new AttributeTranslation(iLang);
                }
                if (DisplayFolderLanguages.ContainsKey(iLang))
                {
                    t.DisplayFolder = DisplayFolderLanguages[iLang];
                }
                if (DescriptionLanguages.ContainsKey(iLang))
                {
                    t.Description = DescriptionLanguages[iLang];
                }

                if (Languages.ContainsKey(iLang) && !string.IsNullOrEmpty(Languages[iLang]))
                {
                    t.Caption = Languages[iLang];
                }
                else if (!string.IsNullOrEmpty(t.DisplayFolder) || !string.IsNullOrEmpty(t.Description))
                {
                    t.Caption = this.DefaultLanguage; //this works around a problem where if they translate the display folder or the description but not the caption, then the caption ends up blank
                }
                if (!string.IsNullOrEmpty(t.Caption) || !string.IsNullOrEmpty(t.Description) || !string.IsNullOrEmpty(t.DisplayFolder))
                {
                    translations.Add(t);
                    SSAS.TabularTranslationAnnotation tranAnnotation = new TabularTranslationAnnotation();
                    tranAnnotation.Caption       = t.Caption;
                    tranAnnotation.Description   = t.Description;
                    tranAnnotation.DisplayFolder = t.DisplayFolder;
                    tranAnnotation.Language      = t.Language;
                    listAnnotations.Add(tranAnnotation);
                }
            }

            if (annotation != null)
            {
                annotation.TabularTranslations = listAnnotations.ToArray();
            }
        }
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 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 #4
0
        public void Import(string filePath, IOrganizationService service, BackgroundWorker worker = null)
        {
            var stream = File.OpenRead(filePath);
            var file   = new ExcelPackage(stream);

            var emds = new List <EntityMetadata>();

            var  forms               = new List <Entity>();
            var  ft                  = new FormTranslation();
            var  st                  = new SiteMapTranslation();
            var  db                  = new DashboardTranslation();
            bool hasFormContent      = false;
            bool hasDashboardContent = false;
            bool hasSiteMapContent   = false;

            foreach (var sheet in file.Workbook.Worksheets)
            {
                switch (sheet.Name)
                {
                case "Entities":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing entities translations...");
                    }

                    var et = new EntityTranslation();
                    et.Import(sheet, emds, service);
                    break;

                case "Attributes":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing attributes translations...");
                    }

                    var at = new AttributeTranslation();
                    at.Import(sheet, emds, service);
                    break;

                case "Relationships":
                {
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing Relationships with custom label translations...");
                    }

                    var rt = new RelationshipTranslation();
                    rt.Import(sheet, emds, service);
                    break;
                }

                case "RelationshipsNN":
                {
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing NN Relationships with custom label translations...");
                    }

                    var rtNn = new RelationshipNnTranslation();
                    rtNn.Import(sheet, emds, service);
                    break;
                }

                case "Global OptionSets":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing global optionsets translations...");
                    }

                    var got = new GlobalOptionSetTranslation();
                    got.Import(sheet, service);
                    break;

                case "OptionSets":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing optionsets translations...");
                    }

                    var ot = new OptionSetTranslation();
                    ot.Import(sheet, service);
                    break;

                case "Booleans":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing booleans translations...");
                    }

                    var bt = new BooleanTranslation();
                    bt.Import(sheet, service);
                    break;

                case "Views":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing views translations...");
                    }

                    var vt = new ViewTranslation();
                    vt.Import(sheet, service);
                    break;

                case "Charts":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing charts translations...");
                    }

                    var vt2 = new VisualizationTranslation();
                    vt2.Import(sheet, service);
                    break;

                case "Forms":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing forms translations...");
                    }

                    ft.ImportFormName(sheet, service);
                    break;

                case "Forms Tabs":
                    ft.PrepareFormTabs(sheet, service, forms);
                    hasFormContent = true;
                    break;

                case "Forms Sections":
                    ft.PrepareFormSections(sheet, service, forms);
                    hasFormContent = true;
                    break;

                case "Forms Fields":
                    ft.PrepareFormLabels(sheet, service, forms);
                    hasFormContent = true;
                    break;

                case "Dashboards":
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing dashboard translations...");
                    }

                    db.ImportFormName(sheet, service);
                    break;

                case "Dashboards Tabs":
                    db.PrepareFormTabs(sheet, service, forms);
                    hasDashboardContent = true;
                    break;

                case "Dashboards Sections":
                    db.PrepareFormSections(sheet, service, forms);
                    hasDashboardContent = true;
                    break;

                case "Dashboards Fields":
                    db.PrepareFormLabels(sheet, service, forms);
                    hasDashboardContent = true;
                    break;

                case "SiteMap Areas":
                    st.PrepareAreas(sheet, service);
                    hasSiteMapContent = true;
                    break;

                case "SiteMap Groups":
                    st.PrepareGroups(sheet, service);
                    hasSiteMapContent = true;
                    break;

                case "SiteMap SubAreas":
                    st.PrepareSubAreas(sheet, service);
                    hasSiteMapContent = true;
                    break;
                }

                if (hasFormContent)
                {
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing form content translations...");
                    }

                    ft.ImportFormsContent(service, forms);
                }

                if (hasDashboardContent)
                {
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing dashboard content translations...");
                    }

                    db.ImportFormsContent(service, forms);
                }

                if (hasSiteMapContent)
                {
                    if (worker != null && worker.WorkerReportsProgress)
                    {
                        worker.ReportProgress(0, "Importing SiteMap translations...");
                    }

                    st.Import(service);
                }
            }

            if (worker != null && worker.WorkerReportsProgress)
            {
                worker.ReportProgress(0, "Publishing customizations...");
            }

            var paxRequest = new PublishAllXmlRequest();

            service.Execute(paxRequest);
        }
Example #5
0
 public async Task <int> Insert(AttributeTranslation attributeTranslation)
 {
     _ttributeTranslationRepository.Create(attributeTranslation);
     return(await Context.SaveChangesAsync());
 }
Example #6
0
 public async Task <int> Update(AttributeTranslation attributeTranslation)
 {
     return(await Context.SaveChangesAsync());
 }
        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 #8
0
        public void Import(string filePath, IOrganizationService service, BackgroundWorker worker = null)
        {
            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var file = new ExcelPackage(stream);

                var emds = new List <EntityMetadata>();

                var  forms               = new List <Entity>();
                var  ft                  = new FormTranslation();
                var  st                  = new SiteMapTranslation();
                var  db                  = new DashboardTranslation();
                bool hasFormContent      = false;
                bool hasDashboardContent = false;
                bool hasSiteMapContent   = false;

                var count = file.Workbook.Worksheets.Count(x =>
                                                           !x.Name.StartsWith("Forms ") && !x.Name.StartsWith("Dashboards ") &&
                                                           !x.Name.StartsWith("SiteMap "));

                var hasFormElts      = file.Workbook.Worksheets.Any(x => x.Name.StartsWith("Forms "));
                var hasDashboardElts = file.Workbook.Worksheets.Any(x => x.Name.StartsWith("Dashboards "));
                var hasSiteMapElts   = file.Workbook.Worksheets.Any(x => x.Name.StartsWith("SiteMap "));

                if (hasFormElts)
                {
                    count++;
                }

                if (hasDashboardElts)
                {
                    count++;
                }

                if (hasSiteMapElts)
                {
                    count++;
                }

                int overallProgress = 0;
                foreach (var sheet in file.Workbook.Worksheets)
                {
                    try
                    {
                        switch (sheet.Name)
                        {
                        case "Entities":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing entities translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            var et = new EntityTranslation();
                            et.Result += Engine_OnResult;
                            et.Import(sheet, emds, service, worker);

                            break;

                        case "Attributes":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing attributes translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            var at = new AttributeTranslation();
                            at.Result += Engine_OnResult;
                            at.Import(sheet, emds, service, worker);
                            break;

                        case "Relationships":
                        {
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                                {
                                    Message = "Importing Relationships with custom label translations...",
                                    Item    = 1,
                                    Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                                });

                            var rt = new RelationshipTranslation();
                            rt.Result += Engine_OnResult;
                            rt.Import(sheet, emds, service, worker);
                            break;
                        }

                        case "RelationshipsNN":
                        {
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                                {
                                    Message = "Importing NN Relationships with custom label translations...",
                                    Item    = 1,
                                    Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                                });

                            var rtNn = new RelationshipNnTranslation();
                            rtNn.Result += Engine_OnResult;
                            rtNn.Import(sheet, emds, service, worker);
                            break;
                        }

                        case "Global OptionSets":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing global optionsets translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            var got = new GlobalOptionSetTranslation();
                            got.Result += Engine_OnResult;
                            got.Import(sheet, service, worker);
                            break;

                        case "OptionSets":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing optionsets translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            var ot = new OptionSetTranslation();
                            ot.Result += Engine_OnResult;
                            ot.Import(sheet, service, worker);
                            break;

                        case "Booleans":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing booleans translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            var bt = new BooleanTranslation();
                            bt.Result += Engine_OnResult;
                            bt.Import(sheet, service, worker);
                            break;

                        case "Views":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing views translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            var vt = new ViewTranslation();
                            vt.Result += Engine_OnResult;
                            vt.Import(sheet, service, worker);
                            break;

                        case "Charts":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing charts translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            var vt2 = new VisualizationTranslation();
                            vt2.Result += Engine_OnResult;
                            vt2.Import(sheet, service, worker);
                            break;

                        case "Forms":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing forms translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            ft.ImportFormName(sheet, service, worker);
                            break;

                        case "Forms Tabs":
                            ft.PrepareFormTabs(sheet, service, forms);
                            hasFormContent = true;
                            break;

                        case "Forms Sections":
                            ft.PrepareFormSections(sheet, service, forms);
                            hasFormContent = true;
                            break;

                        case "Forms Fields":
                            ft.PrepareFormLabels(sheet, service, forms);
                            hasFormContent = true;
                            break;

                        case "Dashboards":
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing dashboard translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            db.ImportFormName(sheet, service, worker);
                            break;

                        case "Dashboards Tabs":
                            db.PrepareFormTabs(sheet, service, forms);
                            hasDashboardContent = true;
                            break;

                        case "Dashboards Sections":
                            db.PrepareFormSections(sheet, service, forms);
                            hasDashboardContent = true;
                            break;

                        case "Dashboards Fields":
                            db.PrepareFormLabels(sheet, service, forms);
                            hasDashboardContent = true;
                            break;

                        case "SiteMap Areas":
                            st.PrepareAreas(sheet, service);
                            hasSiteMapContent = true;
                            break;

                        case "SiteMap Groups":
                            st.PrepareGroups(sheet, service);
                            hasSiteMapContent = true;
                            break;

                        case "SiteMap SubAreas":
                            st.PrepareSubAreas(sheet, service);
                            hasSiteMapContent = true;
                            break;
                        }

                        if (hasFormContent)
                        {
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing form content translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            ft.ImportFormsContent(service, forms, worker);
                        }

                        if (hasDashboardContent)
                        {
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing dashboard content translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            db.ImportFormsContent(service, forms, worker);
                        }

                        if (hasSiteMapContent)
                        {
                            worker.ReportProgressIfPossible(0, new ProgressInfo
                            {
                                Message = "Importing SiteMap translations...",
                                Item    = 1,
                                Overall = overallProgress == 0 ? 1 : overallProgress * 100 / count
                            });

                            st.Import(service);
                        }
                    }
                    catch (Exception error)
                    {
                        Engine_OnResult(this, new TranslationResultEventArgs
                        {
                            Success   = false,
                            SheetName = sheet.Name,
                            Message   = error.Message
                        });
                    }
                    finally
                    {
                        overallProgress++;
                    }
                }

                worker.ReportProgressIfPossible(0, new ProgressInfo
                {
                    Message = "Publishing customizations...",
                    Item    = 100,
                    Overall = 100
                });

                var paxRequest = new PublishAllXmlRequest();
                service.Execute(paxRequest);

                worker.ReportProgressIfPossible(0, new ProgressInfo
                {
                    Message = "",
                    Item    = 100,
                    Overall = 100
                });
            }
        }
Example #9
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
        }
Example #10
0
        public async Task <ActionResultResponse <string> > Insert(string tenantId, string creatorId, string creatorFullName, string creatorAvatar,
                                                                  AttributeMeta attributeMeta)
        {
            var productAttributeId = Guid.NewGuid().ToString();
            var productAttribute   = new Attribute
            {
                Id = productAttributeId,
                ConcurrencyStamp = productAttributeId,
                IsActive         = attributeMeta.IsActive,
                IsRequire        = attributeMeta.IsRequire,
                IsMultiple       = attributeMeta.IsMultiple,
                IsSelfContent    = attributeMeta.IsSelfContent,
                TenantId         = tenantId,
                CreatorId        = creatorId,
                CreatorFullName  = creatorFullName,
                CreatorAvatar    = creatorAvatar
            };

            var result = await _attributeRepository.Insert(productAttribute);

            if (result <= 0)
            {
                return(new ActionResultResponse <string>(result,
                                                         _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }


            #region insert Translation.
            if (attributeMeta.Translations.Count > 0)
            {
                var resultInsertTranslation = await InsertTranslation();

                if (resultInsertTranslation.Code <= 0)
                {
                    return(resultInsertTranslation);
                }
            }
            #endregion

            return(new ActionResultResponse <string>(1, _warehouseResourceService.GetString("Add new product attribute successful."),
                                                     string.Empty, productAttributeId));

            #region Local functions
            async Task <ActionResultResponse <string> > InsertTranslation()
            {
                var productAttributeTranslations = new List <AttributeTranslation>();

                foreach (var productAttributeTranslation in attributeMeta.Translations)
                {
                    //  Check name exists.
                    var isNameExists = await _attributeTranslationRepository.CheckExists(productAttributeId, tenantId,
                                                                                         productAttributeTranslation.LanguageId, productAttributeTranslation.Name);

                    if (isNameExists)
                    {
                        await RollbackInsert();

                        return(new ActionResultResponse <string>(-1,
                                                                 _warehouseResourceService.GetString("Product attribute name: \"{0}\" already exists.",
                                                                                                     productAttributeTranslation.Name)));
                    }

                    var productAttributeTranslationInsert = new AttributeTranslation
                    {
                        AttributeId = productAttributeId,
                        TenantId    = tenantId,
                        LanguageId  = productAttributeTranslation.LanguageId.Trim(),
                        Name        = productAttributeTranslation.Name.Trim(),
                        Description = productAttributeTranslation.Description?.Trim(),
                        UnsignName  = productAttributeTranslation.Name?.StripVietnameseChars().ToUpper()
                    };

                    productAttributeTranslations.Add(productAttributeTranslationInsert);
                }

                var resultTranslation = await _attributeTranslationRepository.Inserts(productAttributeTranslations);

                if (resultTranslation > 0)
                {
                    return(new ActionResultResponse <string>(resultTranslation,
                                                             _warehouseResourceService.GetString("Add new product attribute translation successful.")));
                }

                await RollbackInsertTranslation();
                await RollbackInsert();

                return(new ActionResultResponse <string>(-2,
                                                         _warehouseResourceService.GetString("Can not insert product attribute translation. Please contact with administrator.")));
            }

            async Task RollbackInsert()
            {
                await _attributeRepository.ForceDelete(productAttributeId);
            }

            async Task RollbackInsertTranslation()
            {
                await _attributeTranslationRepository.ForceDelete(productAttributeId);
            }

            #endregion Local functions
        }
Example #11
0
        public async Task <ActionResultResponse <string> > Update(string tenantId, string lastUpdateUserId, string lastUpdateFullName, string lastUpdateAvatar,
                                                                  string productAttributeId, AttributeMeta attributeMeta)
        {
            var info = await _attributeRepository.GetInfo(productAttributeId);

            if (info == null)
            {
                return(new ActionResultResponse <string>(-1, _warehouseResourceService.GetString("Product attribute does not exists.")));
            }

            if (info.TenantId != tenantId)
            {
                return(new ActionResultResponse <string>(-2,
                                                         _warehouseResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            if (info.ConcurrencyStamp != attributeMeta.ConcurrencyStamp)
            {
                return(new ActionResultResponse <string>(-3,
                                                         _warehouseResourceService.GetString(
                                                             "The product attribute already updated by other people. you are not allowed to edit the product attribute information.")));
            }

            // Todo Not allow update IsSelfContent if used by product.

            // Delete all attribute values when change IsSelfContent property.(IsSelfContent = true : delete )
            if (attributeMeta.IsSelfContent)
            {
                await _attributeValueTranslationRepository.DeleteByProductAttribute(productAttributeId);

                await _attributeValueRepository.DeleteByProductAttribute(productAttributeId);
            }

            info.IsActive           = attributeMeta.IsActive;
            info.IsRequire          = attributeMeta.IsRequire;
            info.IsMultiple         = attributeMeta.IsMultiple;
            info.IsSelfContent      = attributeMeta.IsSelfContent;
            info.ConcurrencyStamp   = Guid.NewGuid().ToString();
            info.LastUpdateTime     = DateTime.Now;
            info.LastUpdateUserId   = lastUpdateUserId;
            info.LastUpdateFullName = lastUpdateFullName;

            await _attributeRepository.Update(info);

            #region translation.
            if (attributeMeta.Translations.Count > 0)
            {
                var resultUpdateTranslation = await UpdateTranslation();

                if (resultUpdateTranslation.Code <= 0)
                {
                    return(resultUpdateTranslation);
                }
            }
            #endregion

            return(new ActionResultResponse <string>(1, _warehouseResourceService.GetString("Update product attribute successful."),
                                                     string.Empty, info.ConcurrencyStamp));

            async Task <ActionResultResponse <string> > UpdateTranslation()
            {
                foreach (var productAttributeTranslation in attributeMeta.Translations)
                {
                    var isNameExists = await _attributeTranslationRepository.CheckExists(info.Id, tenantId,
                                                                                         productAttributeTranslation.LanguageId, productAttributeTranslation.Name);

                    if (isNameExists)
                    {
                        return(new ActionResultResponse <string>(-4, _warehouseResourceService.GetString("Product attribute name: \"{0}\" already exists.")));
                    }

                    var productAttributeTranslationInfo =
                        await _attributeTranslationRepository.GetInfo(info.Id, productAttributeTranslation.LanguageId);

                    if (productAttributeTranslationInfo != null)
                    {
                        productAttributeTranslationInfo.Name        = productAttributeTranslation.Name.Trim();
                        productAttributeTranslationInfo.Description = productAttributeTranslation.Description?.Trim();
                        productAttributeTranslationInfo.UnsignName  = productAttributeTranslation.Name?.StripVietnameseChars().ToUpper();

                        await _attributeTranslationRepository.Update(productAttributeTranslationInfo);
                    }
                    else
                    {
                        var productAttributeTranslationInsert = new AttributeTranslation
                        {
                            AttributeId = productAttributeId,
                            TenantId    = tenantId,
                            LanguageId  = productAttributeTranslation.LanguageId.Trim(),
                            Name        = productAttributeTranslation.Name.Trim(),
                            Description = productAttributeTranslation.Description?.Trim(),
                            UnsignName  = productAttributeTranslation.Name.StripVietnameseChars().ToUpper()
                        };

                        await _attributeTranslationRepository.Insert(productAttributeTranslationInsert);
                    }
                }
                return(new ActionResultResponse <string>(1,
                                                         _warehouseResourceService.GetString("Update product attribute translation successful."), string.Empty, info.ConcurrencyStamp));
            }
        }
Example #12
0
        private void SaveInternal(TranslationCollection translations, Dictionary<int, string> DisplayFolderLanguages, Dictionary<int, string> DescriptionLanguages, SSAS.TabularTranslationObjectAnnotation annotation)
        {
            List<int> listAllLanguages = new List<int>(Languages.Keys);
            foreach (int iLang in DisplayFolderLanguages.Keys)
            {
                if (!listAllLanguages.Contains(iLang))
                    listAllLanguages.Add(iLang);
            }
            foreach (int iLang in DescriptionLanguages.Keys)
            {
                if (!listAllLanguages.Contains(iLang))
                    listAllLanguages.Add(iLang);
            }

            List<SSAS.TabularTranslationAnnotation> listAnnotations = new List<TabularTranslationAnnotation>();
            translations.Clear();
            foreach (int iLang in listAllLanguages)
            {
                Translation t = new Translation(iLang);
                if (translations is AttributeTranslationCollection)
                    t = new AttributeTranslation(iLang);
                if (DisplayFolderLanguages.ContainsKey(iLang))
                    t.DisplayFolder = DisplayFolderLanguages[iLang];
                if (DescriptionLanguages.ContainsKey(iLang))
                    t.Description = DescriptionLanguages[iLang];

                if (Languages.ContainsKey(iLang) && !string.IsNullOrEmpty(Languages[iLang]))
                    t.Caption = Languages[iLang];
                else if (!string.IsNullOrEmpty(t.DisplayFolder) || !string.IsNullOrEmpty(t.Description))
                    t.Caption = this.DefaultLanguage; //this works around a problem where if they translate the display folder or the description but not the caption, then the caption ends up blank
                
                if (!string.IsNullOrEmpty(t.Caption) || !string.IsNullOrEmpty(t.Description) || !string.IsNullOrEmpty(t.DisplayFolder))
                {
                    translations.Add(t);
                    SSAS.TabularTranslationAnnotation tranAnnotation = new TabularTranslationAnnotation();
                    tranAnnotation.Caption = t.Caption;
                    tranAnnotation.Description = t.Description;
                    tranAnnotation.DisplayFolder = t.DisplayFolder;
                    tranAnnotation.Language = t.Language;
                    listAnnotations.Add(tranAnnotation);
                }
            }

            if (annotation != null)
                annotation.TabularTranslations = listAnnotations.ToArray();
        }
Example #13
0
        public TabularTranslatedItem(string table, IModelComponent obj, TabularTranslatedItemProperty property, TabularTranslatedItem caption, SSAS.TabularTranslationsAnnotation annotations)
        {
            _Table = table;
            _object = obj;
            _Property = property;

            TranslationCollection translations;
            string sCaption;
            string sDescription;
            string sDisplayFolder = null;
            if (obj is DimensionAttribute)
            {
                _ObjectType = TabularTranslatedItemType.Column;
                DimensionAttribute typedobj = (DimensionAttribute)obj;
                translations = typedobj.Translations;
                sDisplayFolder = typedobj.AttributeHierarchyDisplayFolder;
                sCaption = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Hierarchy)
            {
                _ObjectType = TabularTranslatedItemType.Hierarchy;
                Hierarchy typedobj = (Hierarchy)obj;
                translations = typedobj.Translations;
                sDisplayFolder = typedobj.DisplayFolder;
                sCaption = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Level)
            {
                _ObjectType = TabularTranslatedItemType.Level;
                Level typedobj = (Level)obj;
                translations = typedobj.Translations;
                sCaption = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is CalculationProperty)
            {
                _ObjectType = TabularTranslatedItemType.Measure;
                CalculationProperty typedobj = (CalculationProperty)obj;
                translations = typedobj.Translations;
                sDisplayFolder = typedobj.DisplayFolder;
                sCaption = typedobj.CalculationReference;
                sDescription = typedobj.Description;

                if (sCaption.StartsWith("[") && sCaption.EndsWith("]"))
                {
                    sCaption = sCaption.Substring(1, sCaption.Length - 2);
                }
            }
            else if (obj is Database)
            {
                _ObjectType = TabularTranslatedItemType.Database;
                Database typedobj = (Database)obj;
                translations = typedobj.Translations;
                sCaption = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Cube)
            {
                _ObjectType = TabularTranslatedItemType.Cube;
                Cube typedobj = (Cube)obj;
                translations = typedobj.Translations;
                sCaption = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Perspective)
            {
                _ObjectType = TabularTranslatedItemType.Perspective;
                Perspective typedobj = (Perspective)obj;
                translations = typedobj.Translations;
                sCaption = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Dimension)
            {
                _ObjectType = TabularTranslatedItemType.Table;
                Dimension typedobj = (Dimension)obj;
                translations = typedobj.Translations;
                sCaption = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else if (obj is Microsoft.AnalysisServices.Action)
            {
                _ObjectType = TabularTranslatedItemType.Action;
                Microsoft.AnalysisServices.Action typedobj = (Microsoft.AnalysisServices.Action)obj;
                translations = typedobj.Translations;
                sCaption = typedobj.Name;
                sDescription = typedobj.Description;
            }
            else
            {
                throw new Exception("Unexpected object type: " + obj.GetType().Name);
            }

            _ObjectName = sCaption;

            if (property == TabularTranslatedItemProperty.Caption)
            {
                _DefaultLanguage = sCaption;

                SSAS.TabularTranslationObjectAnnotation annotation = annotations.Find(obj);
                if (annotation != null && translations.Count == 0)
                {
                    foreach (SSAS.TabularTranslationAnnotation tranAnnotation in annotation.TabularTranslations)
                    {
                        Translation t = new Translation(tranAnnotation.Language);
                        if (obj is DimensionAttribute)
                            t = new AttributeTranslation(tranAnnotation.Language);
                        t.Caption = tranAnnotation.Caption;
                        t.Description = tranAnnotation.Description;
                        t.DisplayFolder = tranAnnotation.DisplayFolder;
                        translations.Add(t);
                    }
                    _restoredTranslations = true;
                }
            
            }
            else if (property == TabularTranslatedItemProperty.Description)
            {
                _DefaultLanguage = sDescription;
            }
            else if (property == TabularTranslatedItemProperty.DisplayFolder)
            {
                _DefaultLanguage = sDisplayFolder;
            }

            Languages = new Core.DirtyMonitoredDictionary<int, string>();
            foreach (Translation t in translations)
            {
                if (property == TabularTranslatedItemProperty.Caption)
                {
                    Languages.Add(t.Language, t.Caption);
                }
                else if (property == TabularTranslatedItemProperty.Description)
                {
                    Languages.Add(t.Language, t.Description);
                }
                else if (property == TabularTranslatedItemProperty.DisplayFolder)
                {
                    Languages.Add(t.Language, t.DisplayFolder);
                }
            }

            if (caption != null)
            {
                caption.DependentProperties.Add(this);
            }
        }