コード例 #1
0
        public static ExecResult <bool> DiagramElementsReport(string location)
        {
            ExecResult <Boolean> result = new ExecResult <bool>();

            try
            {
                // Получаем диаграмму
                EA.Diagram reportDiagram = null;

                switch (location)
                {
                case "Diagram":
                    reportDiagram = EARepository.GetCurrentDiagram();
                    break;

                case "MainMenu":
                case "TreeView":
                    if (EARepository.GetTreeSelectedItemType() != EA.ObjectType.otDiagram)
                    {
                        throw new Exception("Не выбрана диаграмма в ProjectExplorer");
                    }

                    reportDiagram = EARepository.GetTreeSelectedObject();
                    break;
                }

                // Проверяем, что это диаграмма - библиотечная
                EA.Package diagramPackage = EARepository.GetPackageByID(reportDiagram.PackageID);
                EA.Package libPackage     = LibraryHelper.GetLibraryRootFromPackage(diagramPackage);
                if (libPackage == null)
                {
                    throw new Exception("Диаграмма не в библиотеке");
                }

                // Устанавливаем текущую библиотеку
                if (Context.CurrentLibrary.PackageID != libPackage.PackageID)
                {
                    Context.CurrentLibrary = libPackage;
                }

                // Устанавливаем текущую диаграмму
                Context.CurrentDiagram = reportDiagram;

                // запрашиваем параметры показа
                ExecResult <List <ComponentLevel> > displayLevelsResult = FSelectComponentLevels.Execute(new List <ComponentLevel>()
                {
                    ComponentLevel.Node, ComponentLevel.Device, ComponentLevel.ExecutionEnv, ComponentLevel.Component
                });
                if (displayLevelsResult.code != 0)
                {
                    return(result);
                }


                // Подготавливаем имя RDLC - файла отчёта
                string fullReportName = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Reports", "LibDiagram.rdlc");
                if (!File.Exists(fullReportName))
                {
                    throw new Exception("файл отчёта " + fullReportName + "не найден");
                }

                // Подготавливаем источники данных для отчёта
                List <ReportDataSource> reportDataSources = new List <ReportDataSource>();

                List <ElementData> elementDataList = EAHelper.GetCurDiagramElementData().Values.ToList <ElementData>();
                foreach (var elementData in elementDataList) // Дообогащаем информацию об элементах данными узла размещения
                {
                    int?rootDeployNodeID = LibraryHelper.GetDeployComponentNode(elementData._ElementID);
                    if (rootDeployNodeID != null)
                    {
                        elementData.RootDeployNodeID = rootDeployNodeID;
                    }
                }

                ReportDataSource reportDataSource = new ReportDataSource("DS_ElementData", elementDataList);
                reportDataSources.Add(reportDataSource);

                List <ConnectorData> connectorDataList = EAHelper.GetCurDiagramConnectors();
                ReportDataSource     reportDataSource1 = new ReportDataSource("DS_ConnectorData", connectorDataList);
                reportDataSources.Add(reportDataSource1);


                // Подготавливаем параметры отчёта
                List <ReportParameter> reportParameters = new List <ReportParameter>();
                // Картинка диаграммы
                string SavedDiagramImagePath = DiagramExporter.ExportPNG(reportDiagram);
                //string base64Image = Convert.ToBase64String(File.ReadAllBytes(SavedDiagramImagePath));
                reportParameters.Add(new ReportParameter("paramDiagramImage", "file:///" + SavedDiagramImagePath));
                reportParameters.Add(new ReportParameter("paramComponentLevels", string.Join(",", displayLevelsResult.value.Select(cl => ((int)cl).ToString()))));


                // запускаем форму
                ExecResult <bool> fReportResult = FReport.Execute(fullReportName, reportDataSources, reportParameters);
                if (fReportResult.code != 0)
                {
                    throw new Exception(fReportResult.message);
                }
            }
            catch (Exception ex)
            {
                result.setException(ex);
            }

            return(result);
        }
コード例 #2
0
        ///
        /// Called when user makes a selection in the menu.
        /// This is your main exit point to the rest of your Add-in
        ///
        /// <param name="Repository" />the repository
        /// <param name="Location" />the location of the menu
        /// <param name="MenuName" />the name of the menu
        /// <param name="ItemName" />the name of the selected menu item
        public void EA_MenuClick(EA.Repository repository, string location, string menuName, string itemName)
        {
            switch (itemName)
            {
            // ------ DESIGN --------------------------------------------------------------

            case menuPutLibElementOnDiagram:
                var putLibElementResult = Context.Designer.PutElementOnDiagram();
                OutExecResult(putLibElementResult);
                break;

            case menuPutContourContour:
                var putContourContourResult = Context.Designer.PutContourContourOnDiagram(location);
                OutExecResult(putContourContourResult);
                break;

            case menuPutParentDHierarchyOnDiagram:
                var putDeploymentHierarchyResult = Context.Designer.PutParentHierarchyOnDiagram();
                OutExecResult(putDeploymentHierarchyResult);
                break;

            case menuPutChildrenDHierarchyOnDiagram:
                var putPutCDHResult = Context.Designer.PutChildrenDHierarchyOnDiagram();
                OutExecResult(putPutCDHResult);
                break;

            case menuPutChildrenDeployHierarchy:
                var putChildrenDeployHierarchyResult = Context.Designer.PutChildrenDeployHierarchy(location);
                OutExecResult(putChildrenDeployHierarchyResult);
                break;

            case menuSetElementTags:
                var setElementTagsResult = Context.Designer.SetElementTags(location);
                OutExecResult(setElementTagsResult);
                break;



            // ------ DESIGN LINKS --------------------------------------------------------------
            case menuCreateLink:
                var createCommunicationResult = Context.LinkDesigner.CreateLink();
                OutExecResult(createCommunicationResult);
                break;

            case menuManageLinks:
                var ManageLinksResult = Context.LinkDesigner.ManageLinks();
                OutExecResult(ManageLinksResult);
                break;


            case menuManageLinkVisibility:
                var ManageLinkVisibilityResult = Context.LinkDesigner.ManageLinkVisibility();
                OutExecResult(ManageLinkVisibilityResult);
                break;


            case menuSetConnectorTags:
                var setConnectorTagsResult = Context.LinkDesigner.SetConnectorTags(location);
                OutExecResult(setConnectorTagsResult);
                break;

            case menuSetSimilarLinksTags:
                var setSimilarLinksTags = Context.LinkDesigner.SetSimilarLinksTags(location);
                OutExecResult(setSimilarLinksTags);
                break;

            // ------ UTILS --------------------------------------------------------------
            case menuSetCurrentDiagram:
                Context.CurrentDiagram = Context.EARepository.GetCurrentDiagram();
                Logger.Out("Установлена текущая диаграмма = " + Context.CurrentDiagram.Name);
                break;

            case menuSetCurrentLibrary:
                var setCurrentLibraryResult = LibraryHelper.SetCurrentLibrary(location);
                OutExecResult(setCurrentLibraryResult);
                break;

            case menuSetDPLibratyTag:
                var setDPLibratyTagResult = EATVHelper.SetDPLibratyTag(location);
                OutExecResult(setDPLibratyTagResult);
                break;


            case menuReloadConnectorData:
                Context.ConnectorData = null;
                Logger.Out("Сброшены данные коннекторов");
                break;

            case menuDoOnConnectActions:
                Addin_OnConnectActions();
                break;

            case menuRunSQLQuery:
                var fRunSQLQueryResult = FRunSQLQuery.Execute();
                OutExecResult(fRunSQLQueryResult);
                break;

            // --------- REPORTS ------------------------------------------------------------
            case menuDiagramElementsReport:
                var fDiagramElementsReportResult = ReportsHelper.DiagramElementsReport(location);
                OutExecResult(fDiagramElementsReportResult);
                break;



            // ------ EXPORT --------------------------------------------------------------
            case menuExportDiagram:
                var exportResult = DiagramExporter.Export(location);
                break;


            // ------ TEST --------------------------------------------------------------
            case menuTest1:
                var test1Result = Test1();
                OutExecResult(test1Result);
                break;

            case menuTest2:
                var test2Result = Test2();
                OutExecResult(test2Result);
                break;

            case menuTest3:
                var test3Result = Test3();
                OutExecResult(test3Result);
                break;
            }
        }