Exemplo n.º 1
0
        void LoadDashboard(string path, string folderPath, string folderName, bool editable, bool isPersonal)
        {
            try
            {
                var dashboard = _dashboards.FirstOrDefault(i => i.Path == path);
                if (dashboard == null || dashboard.LastModification != File.GetLastWriteTime(path))
                {
                    if (dashboard != null)
                    {
                        _dashboards.Remove(dashboard);
                    }
                    dashboard = Dashboard.LoadFromFile(path);
                    _dashboards.Add(dashboard);
                }
                dashboard.IsPersonal = isPersonal;
                dashboard.Editable   = editable;
                dashboard.Folder     = folderPath;

                dashboard.DisplayName = Security.Repository.TranslateDashboardName(path.Replace(Security.Repository.DashboardPublicFolder, ""), dashboard.Name);
                var repositoryPath = path.Replace(Security.Repository.DashboardPublicFolder, "");

                if (dashboard.IsPersonal)
                {
                    dashboard.FullName = string.Format("{0} ({1})", dashboard.DisplayName, Security.Repository.TranslateWeb("Personal"));
                }
                else if (!string.IsNullOrEmpty(folderName))
                {
                    dashboard.FullName = string.Format("{0} ({1})", dashboard.DisplayName, Security.Repository.TranslateDashboardFolder(Path.GetDirectoryName(repositoryPath), folderName));
                }
                else
                {
                    dashboard.FullName = dashboard.DisplayName;
                }
                dashboard.ReinitGroupOrders();
                //Init items and translate labels
                foreach (var item in dashboard.Items)
                {
                    var widget = DashboardWidgetsPool.Widgets.ContainsKey(item.WidgetGUID) ? DashboardWidgetsPool.Widgets[item.WidgetGUID] : null;
                    if (widget == null)
                    {
                        continue;
                    }
                    if (!string.IsNullOrEmpty(item.Name) && item.Name != widget.Name)
                    {
                        item.DisplayName = Security.Repository.TranslateDashboardItemName(repositoryPath, item.Name);
                    }
                    else
                    {
                        var instance = widget.ReportPath.Replace(Security.Repository.ReportsFolder, "\\");
                        item.DisplayName = Security.Repository.TranslateWidgetName(instance, widget.Name);
                    }
                    item.SetWidget(widget);

                    if (!string.IsNullOrEmpty(item.GroupName))
                    {
                        item.DisplayGroupName = Security.Repository.TranslateDashboardItemGroupName(repositoryPath, item.GroupName);
                    }
                }
                //Remove lost widgets...
                dashboard.Items.RemoveAll(i => i.Widget == null);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }