public void PrintExcel(List <string> dataList, string[] titles, string fileName) { if (dataList != null) { if (dataList.Count > 0) { //verilen başlık sayısına göre excel satır sayısı hesapla int rowCount = dataList.Count() / titles.Length; //Satır sayısı ile başlıkların sayısını çarpımı,doğrulama için int Size = rowCount * titles.Length; //Verilen liste ve dizi elemanları excel sayfasına düzgün yerleşiyor mu diye kontrol et, Örneğin listede 21 eleman varken,titles 4 elemanlı durumu hatalı if (Size.Equals(dataList.Count)) { ExcelPrinter printer = new ExcelPrinter(); //Verilen nesneler örtüşüyorsa, excele yazdıracak metodu çağır printer.Print(dataList, titles, fileName); } else { PrintConsole._INFO("Eksik başlık bilgisi veya liste eleman sayısı istenen sayıda değil."); } } } }
void OK() { foreach (var item in PDFFilesToPrint) { if (item.ToLower().Contains(".pdf") && PDFPrinter != null) { PDFPrinter.Print(item, SelectedPrinter, IsSetDuplex); } else if (ExcelPrinter != null) { ExcelPrinter.Print(item, SelectedPrinter, IsSetDuplex); } } }
static void Main(string[] args) { IPrinter printer = new ConsolePrinter(); IPrinter excelPrinter = new ExcelPrinter( 1, 1, ConfigurationManager.AppSettings["DirectoriesInspectOutputPath"], ConfigurationManager.AppSettings["ExcelTableName"], false); MyLogger logger = new MyLogger(); logger.Configuration(new FileSrc(ConfigurationManager.AppSettings["LogFilePath"]), LevelOfDetalization.info); IRunner structRunner = new StructAndEnumTasksRunner(printer, logger); IRunner exeptionRunner = new ExceptionTaskRunner(printer, logger); IRunner filesRunner = new FilesTasksRunner(printer, logger); IRunner serializationRunner = new SerializationTasksRunner(printer, logger); IRunner reflectionRunner = new ReflectionTasksRunner(printer, logger); IRunner dirInspectRunner = new DirectoriesInspectRunner(excelPrinter, logger); IRunner excelInspectRunner = new ExcelsInspectorRunner(new ExcelPrinter( 1, 1, ConfigurationManager.AppSettings["DirectoriesInspectOutputPath"], "123", false), logger); structRunner.Run(); exeptionRunner.Run(); filesRunner.Run(); serializationRunner.Run(); reflectionRunner.Run(); dirInspectRunner.Run(); excelInspectRunner.Run(); Console.Read(); }
static void MainSub() { //AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolverHelper.AssemblyResolveHandler; //var projectFilePath = NDEPEND_PROJECT_FILE_PATH.ToAbsoluteFilePath(); //Console.WriteLine("*** Load NDepend Project from {" + projectFilePath.ToString() + @"}***"); // 0) Creates a NDependServicesProvider object var ndependServicesProvider = new NDependServicesProvider(); // 1) obtain some VS solution or project file path var visualStudioManager = ndependServicesProvider.VisualStudioManager; ICollection <IAbsoluteFilePath> vsSlnOrProjFilePaths; IntPtr ownerWindowHandle = Process.GetCurrentProcess().MainWindowHandle; // get a non IntPtr.Zero owner Window Handle. If you are in a System.Console try this visualStudioManager.ShowDialogSelectVisualStudioSolutionsOrProjects(ownerWindowHandle, out vsSlnOrProjFilePaths); // Could also use: visualStudioManager.GetMostRecentlyUsedVisualStudioSolutionOrProject() can also be used // 2) obtains assemblies file path to analyze var assembliesFilePath = (from vsSlnOrProjFilePath in vsSlnOrProjFilePaths from assembliesFilePathTmp in visualStudioManager.GetAssembliesFromVisualStudioSolutionOrProject(vsSlnOrProjFilePath) select assembliesFilePathTmp).Distinct().ToArray(); // 3) gets or create a IProject object var projectManager = ndependServicesProvider.ProjectManager; //var path = NDepend.Path.PathHelpers.ToAbsoluteFilePath(@"C:\projetos\estudoipt\dapperdotnet\dapper-dot-net\"); //IProject project = projectManager.CreateBlankProject(assembliesFilePath.FirstOrDefault(), "metricsproject"); IProject project = projectManager.CreateTemporaryProject(assembliesFilePath, TemporaryProjectMode.Temporary); // Or, to get a IProject object, could also use // projectManager.CreateBlankProject() to create a persisten project // and then project.CodeToAnalyze.SetApplicationAssemblies() // and then projectManager.SaveProject(project); o save the project file // // Or, to get an existing IProject object, could also use // projectManager.ShowDialogChooseAnExistingProject(out project) // Or programmatically list most recently used NDepend projects on this machine through // projectManager.GetMostRecentlyUsedProjects() // 4) gets an IAnalysisResult object from the IProject object IAnalysisResult analysisResult = project.RunAnalysis(); // *** This particular method works only with a Build Machine license *** // Or project.RunAnalysisAndBuildReport() // *** This particular method works only with a Build Machine license *** // Or, to get a IAnalysisResult object, first gets a IAnalysisResultRef object, that represents a reference to a persisted IAnalysisResult object // project.TryGetMostRecentAnalysisResultRef() or project.GetAvailableAnalysisResultsRefs() or project.GetAvailableAnalysisResultsRefsGroupedPerMonth() // and then analysisResultRef.Load() // 5) gets a ICodeBase object from the IAnalysisResult object ICodeBase codeBase = analysisResult.CodeBase; // Or eventually a ICompareContext object if you wish to analyze diff // codeBase.CreateCompareContextWithOlder(olderCodeBase) Calculator.ICalculate calc = new Calculator.NumberOfChildren(); var result = calc.Calculate(codeBase); IMetricPrinter m = new ExcelPrinter(); m.Print("NumberOfChildren", result); calc = new Calculator.CouplingBetweenObjectClasses(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("CouplingBetweenObject", result); calc = new Calculator.DepthOfInheritanceTree(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("DepthOfInheritanceTree", result); calc = new Calculator.LackOfCohesionInMethods(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("LackOfCohesionInMethods", result); calc = new Calculator.ResponseForAClass(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("ResponseForAClass", result); calc = new Calculator.WeightedMethodsPerClass(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("WeightedMethodsPerClass", result); // 6) use the code model API to query code and do develop any algorithm you need! // For example here we are looking for complex methods /*var complexMethods = (from m in codeBase.Application.Methods * where m.ILCyclomaticComplexity > 1 * orderby m.ILCyclomaticComplexity descending * select m).ToArray(); * if (complexMethods.Length == 0) { return; } * Console.WriteLine("Press a key to show the " + complexMethods.Length + " most complex methods"); * Console.ReadKey(); * foreach (var m in complexMethods) * { * Console.WriteLine(m.FullName + " has a IL cyclomatic complexity of " + m.ILCyclomaticComplexity); * } * * * // 7) eventually lets the user opens source file declaration * if (complexMethods.First().SourceFileDeclAvailable) * { * var mostComplexMethod = complexMethods.First(); * Console.WriteLine("Press a key to open the source code decl of the most complex method?"); * Console.ReadKey(); * mostComplexMethod.TryOpenSource(); * // Eventually use ExtensionMethodsTooling.TryCompareSourceWith(NDepend.CodeModel.ISourceFileLine,NDepend.CodeModel.ISourceFileLine) * // to compare 2 different versions of a code element * }*/ }
public IGHPrinterDefine GetObj(string Extension) { Extension = Extension.ToLower(); IGHPrinterDefine result; if (this.InstanceList.ContainsKey(Extension)) { result = this.InstanceList[Extension]; } else { string text = Extension; switch (text) { case ".doc": case ".docx": case ".dot": case ".dotx": case ".txt": result = new WordPrinter(); return(result); case ".xls": case ".xlt": case ".xlsx": case ".xltx": result = new ExcelPrinter(); return(result); case ".htm": case ".html": case ".mht": result = new HtmlPrinter(); return(result); case ".ppt": case ".pptx": result = new PowerPointPrinter(); return(result); case ".vsd": case ".vsdx": result = new VisioPrinter(); return(result); case ".mpp": result = new ProjectPrinter(); return(result); //case ".frx": // //result = new FastReportPrinter(); // return result; case ".bmp": case ".jpg": case ".jpeg": case ".png": case ".gif": result = new ImgPrinter(); return(result); } result = null; } return(result); }
private void ImplementDeferredPrinting(string MMECode, string GroupName, string CustomerName, string DeviceType, ReportSelectionPredicate Predicate) { SystemHost.Journal.AppendLog("PrintingServer", LogJournalMessageType.Note, String.Format( "Printing request: ID - {0}, Group - {1}, Customer - {2}, Device - {3}, Predicate - {4}", MMECode, GroupName, CustomerName, DeviceType, Predicate)); var clientsListPath = Settings.Default.ClientsListPath; if (!Path.IsPathRooted(clientsListPath)) { clientsListPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, clientsListPath); } var clientsList = new ClientsEngine(clientsListPath); var record = clientsList.ClientRecords.FirstOrDefault(Arg => Arg.MMECode == MMECode); if (record == null) { SystemHost.Journal.AppendLog("PrintingServer", LogJournalMessageType.Error, String.Format("Equipment ID {0} is not found in the configuration list", MMECode)); return; } var deviceItemsWithParams = new List <DeviceItemWithParams>(); var conditions = new List <ConditionItem>(); var normatives = new List <ParameterNormativeItem>(); try { using (var centralDbClient = new CentralDatabaseServiceClient()) { var devices = centralDbClient.GetDevices(GroupName); deviceItemsWithParams.AddRange(from deviceItem in devices let error = centralDbClient.ReadDeviceErrors(deviceItem.InternalID).FirstOrDefault() let devParams = centralDbClient.ReadDeviceParameters(deviceItem.InternalID) where (error == 0) && (Predicate == ReportSelectionPredicate.QC) || (error != 0) && (Predicate == ReportSelectionPredicate.Rejected) || (Predicate == ReportSelectionPredicate.All) select new DeviceItemWithParams { GeneralInfo = deviceItem, Parameters = devParams, DefectCode = error }); if (deviceItemsWithParams.Count > 0) { conditions = centralDbClient.ReadDeviceConditions(deviceItemsWithParams[0].GeneralInfo.InternalID); normatives = centralDbClient.ReadDeviceNormatives(deviceItemsWithParams[0].GeneralInfo.InternalID); } } } catch (Exception) { #region Local Database try { m_DatabaseClient = new DatabaseCommunicationProxy(DATABASE_SERVER_ENDPOINT_NAME, String.Format(Settings.Default.DatabaseServerAddressTemplate, record.IPAddress)); m_DatabaseClient.Open(); try { var devices = m_DatabaseClient.ReadDevices(GroupName); deviceItemsWithParams.AddRange(from deviceItem in devices let error = m_DatabaseClient.ReadDeviceErrors(deviceItem.InternalID).FirstOrDefault() let devParams = m_DatabaseClient.ReadDeviceParameters(deviceItem.InternalID) where (error == 0) && (Predicate == ReportSelectionPredicate.QC) || (error != 0) && (Predicate == ReportSelectionPredicate.Rejected) || (Predicate == ReportSelectionPredicate.All) select new DeviceItemWithParams { GeneralInfo = deviceItem, Parameters = devParams, DefectCode = error }); if (deviceItemsWithParams.Count > 0) { conditions = m_DatabaseClient.ReadDeviceConditions(deviceItemsWithParams[0].GeneralInfo.InternalID); normatives = m_DatabaseClient.ReadDeviceNormatives(deviceItemsWithParams[0].GeneralInfo.InternalID); } } finally { if (m_DatabaseClient.State != CommunicationState.Faulted) { m_DatabaseClient.Close(); } else { m_DatabaseClient.Abort(); } } } catch (FaultException <FaultData> ex) { SystemHost.Journal.AppendLog("PrintingServer", LogJournalMessageType.Error, String.Format("Error while retrieving information from MME local database: {0}", ex.Message)); return; } catch (Exception ex) { SystemHost.Journal.AppendLog("PrintingServer", LogJournalMessageType.Error, String.Format("Error while retrieving information from MME local database: {0}", ex.Message)); return; } #endregion } try { var templatePath = record.Use2PosTemplate ? Settings.Default.TemplateModDev : Settings.Default.TemplateTabDev; if (!Path.IsPathRooted(templatePath)) { templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, templatePath); } var excelPrinter = new ExcelPrinter { TemplateXlsFilePath = templatePath, Copies = 1, PrinterName = record.PrinterName, SaveToFile = false, SaveXlsFilePath = "" }; excelPrinter.CreateXlsReport(record.Use2PosTemplate, new ReportInfo { CustomerName = CustomerName, GroupName = GroupName, ModuleType = DeviceType, Conditions = conditions, Normatives = normatives }, deviceItemsWithParams, false, false); SystemHost.Journal.AppendLog("PrintingServer", LogJournalMessageType.Info, String.Format("Printing has been succeeded for {0}[{1}] on {2}", MMECode, record.IPAddress, record.PrinterName)); } catch (Exception ex) { SystemHost.Journal.AppendLog("PrintingServer", LogJournalMessageType.Error, String.Format("Error while creating report: {0}", ex.Message)); } }
static void MainSub() { //AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolverHelper.AssemblyResolveHandler; //var projectFilePath = NDEPEND_PROJECT_FILE_PATH.ToAbsoluteFilePath(); //Console.WriteLine("*** Load NDepend Project from {" + projectFilePath.ToString() + @"}***"); // 0) Creates a NDependServicesProvider object var ndependServicesProvider = new NDependServicesProvider(); // 1) obtain some VS solution or project file path var visualStudioManager = ndependServicesProvider.VisualStudioManager; ICollection<IAbsoluteFilePath> vsSlnOrProjFilePaths; IntPtr ownerWindowHandle = Process.GetCurrentProcess().MainWindowHandle; // get a non IntPtr.Zero owner Window Handle. If you are in a System.Console try this visualStudioManager.ShowDialogSelectVisualStudioSolutionsOrProjects(ownerWindowHandle, out vsSlnOrProjFilePaths); // Could also use: visualStudioManager.GetMostRecentlyUsedVisualStudioSolutionOrProject() can also be used // 2) obtains assemblies file path to analyze var assembliesFilePath = (from vsSlnOrProjFilePath in vsSlnOrProjFilePaths from assembliesFilePathTmp in visualStudioManager.GetAssembliesFromVisualStudioSolutionOrProject(vsSlnOrProjFilePath) select assembliesFilePathTmp).Distinct().ToArray(); // 3) gets or create a IProject object var projectManager = ndependServicesProvider.ProjectManager; //var path = NDepend.Path.PathHelpers.ToAbsoluteFilePath(@"C:\projetos\estudoipt\dapperdotnet\dapper-dot-net\"); //IProject project = projectManager.CreateBlankProject(assembliesFilePath.FirstOrDefault(), "metricsproject"); IProject project = projectManager.CreateTemporaryProject(assembliesFilePath, TemporaryProjectMode.Temporary); // Or, to get a IProject object, could also use // projectManager.CreateBlankProject() to create a persisten project // and then project.CodeToAnalyze.SetApplicationAssemblies() // and then projectManager.SaveProject(project); o save the project file // // Or, to get an existing IProject object, could also use // projectManager.ShowDialogChooseAnExistingProject(out project) // Or programmatically list most recently used NDepend projects on this machine through // projectManager.GetMostRecentlyUsedProjects() // 4) gets an IAnalysisResult object from the IProject object IAnalysisResult analysisResult = project.RunAnalysis(); // *** This particular method works only with a Build Machine license *** // Or project.RunAnalysisAndBuildReport() // *** This particular method works only with a Build Machine license *** // Or, to get a IAnalysisResult object, first gets a IAnalysisResultRef object, that represents a reference to a persisted IAnalysisResult object // project.TryGetMostRecentAnalysisResultRef() or project.GetAvailableAnalysisResultsRefs() or project.GetAvailableAnalysisResultsRefsGroupedPerMonth() // and then analysisResultRef.Load() // 5) gets a ICodeBase object from the IAnalysisResult object ICodeBase codeBase = analysisResult.CodeBase; // Or eventually a ICompareContext object if you wish to analyze diff // codeBase.CreateCompareContextWithOlder(olderCodeBase) Calculator.ICalculate calc = new Calculator.NumberOfChildren(); var result = calc.Calculate(codeBase); IMetricPrinter m = new ExcelPrinter(); m.Print("NumberOfChildren",result); calc = new Calculator.CouplingBetweenObjectClasses(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("CouplingBetweenObject", result); calc = new Calculator.DepthOfInheritanceTree(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("DepthOfInheritanceTree", result); calc = new Calculator.LackOfCohesionInMethods(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("LackOfCohesionInMethods", result); calc = new Calculator.ResponseForAClass(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("ResponseForAClass", result); calc = new Calculator.WeightedMethodsPerClass(); result = calc.Calculate(codeBase); m = new ExcelPrinter(); m.Print("WeightedMethodsPerClass", result); // 6) use the code model API to query code and do develop any algorithm you need! // For example here we are looking for complex methods /*var complexMethods = (from m in codeBase.Application.Methods where m.ILCyclomaticComplexity > 1 orderby m.ILCyclomaticComplexity descending select m).ToArray(); if (complexMethods.Length == 0) { return; } Console.WriteLine("Press a key to show the " + complexMethods.Length + " most complex methods"); Console.ReadKey(); foreach (var m in complexMethods) { Console.WriteLine(m.FullName + " has a IL cyclomatic complexity of " + m.ILCyclomaticComplexity); } // 7) eventually lets the user opens source file declaration if (complexMethods.First().SourceFileDeclAvailable) { var mostComplexMethod = complexMethods.First(); Console.WriteLine("Press a key to open the source code decl of the most complex method?"); Console.ReadKey(); mostComplexMethod.TryOpenSource(); // Eventually use ExtensionMethodsTooling.TryCompareSourceWith(NDepend.CodeModel.ISourceFileLine,NDepend.CodeModel.ISourceFileLine) // to compare 2 different versions of a code element }*/ }