Advertisement
Guest User

Untitled

a guest
Jul 31st, 2014
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.52 KB | None | 0 0
  1. // Open the SISS catalog on the server
  2. Catalog catalog = integrationServices.Catalogs[catalogName];
  3. if (catalog == null)
  4. {
  5. Console.WriteLine("Unable to open the SSIS catalog : " + catalogName
  6. + ", it does not exist on the server");
  7. return (int)ExitCode.Failure;
  8. }
  9.  
  10. // Open the folder in the catalog
  11. CatalogFolder folder = catalog.Folders[folderName];
  12. if (folder == null)
  13. {
  14. Console.WriteLine("Unable to open the folder : " + folderName
  15. + ", it does not exist on the server");
  16. return (int)ExitCode.Failure;
  17. }
  18.  
  19. // Open the project in the folder
  20. ProjectInfo projectInfo = folder.Projects[projectName];
  21. if (projectInfo == null)
  22. {
  23. Console.WriteLine("Unable to open the project : " + projectName
  24. + ", it does not exist on the server");
  25. return (int)ExitCode.Failure;
  26. }
  27.  
  28. // Check if the package exists
  29. if (!projectInfo.Packages.Contains(packageName))
  30. {
  31. Console.WriteLine("Unable to open the package : " + packageName
  32. + ", it does not exist on the server");
  33. return (int)ExitCode.Failure;
  34. }
  35.  
  36. private T Extract(string itemType, string itemName, Func<T> itemExtractor) where T : class
  37. {
  38. var res = itemExtractor();
  39. if (res == null)
  40. {
  41. Console.WriteLine("Unable to open the {0}: {1}", itemType, itemName);
  42. return null;
  43. }
  44. return res;
  45. }
  46.  
  47. Catalog catalog = Extract("catalog", catalogName, () => integrationServices.Catalogs[catalogName]);
  48. if (catalog == null) return (int)ExitCode.Failure;
  49. CatalogFolder folder = Extract("folder", folderName, () => catalog.Folders[folderName]);
  50. if (folder == null) return (int)ExitCode.Failure;
  51. ProjectInfo projectInfo = Extract("project", projectName, () => folder.Projects[projectName]);
  52. if (projectInfo == null) return (int)ExitCode.Failure;
  53. string package = Extract("package", packageName, () => projectInfo.Packages.Contains(packageName) ? packageName : null);
  54. if (package == null) return (int)ExitCode.Failure;
  55.  
  56. private T Extract(string itemType, string itemName, Func<T> itemExtractor) where T : class
  57. {
  58. var res = itemExtractor();
  59. if (res == null)
  60. {
  61. throw new ItemNotFoundException(string.Format("Unable to open the {0}: {1}", itemType, itemName));
  62. }
  63. return res;
  64. }
  65.  
  66. try
  67. {
  68. Catalog catalog = Extract("catalog", catalogName, () => integrationServices.Catalogs[catalogName]);
  69. CatalogFolder folder = Extract("folder", folderName, () => catalog.Folders[folderName]);
  70. ProjectInfo projectInfo = Extract("project", projectName, () => folder.Projects[projectName]);
  71. string package = Extract("package", packageName, () => projectInfo.Packages.Contains(packageName) ? packageName : null);
  72. }
  73. catch (ItemNotFoundException ex)
  74. {
  75. Console.WriteLine(ex.Message);
  76. return (int)ExitCode.Failure;
  77. }
  78.  
  79. private class CatalogException : Exception
  80. {
  81. public CatalogException(string catalogName) :
  82. base(String.Format(@"
  83. Unable to open the SSIS catalog : {0}, it does not exist on the server", catalogName))
  84. {
  85. }
  86. }
  87.  
  88. private class FolderException : Exception
  89. {
  90. public FolderException(string folderName) :
  91. base(String.Format(@"
  92. Unable to open the folder : {0}, it does not exist on the server", folderName))
  93. {
  94. }
  95. }
  96.  
  97. private class ProjectException : Exception
  98. {
  99. public ProjectException(string projectName) :
  100. base(String.Format(@"
  101. Unable to open the project: {0}, it does not exist on the server", projectName))
  102. {
  103. }
  104. }
  105.  
  106. private class PackageException : Exception
  107. {
  108. public PackageException(string packageName) :
  109. base(String.Format(@"
  110. Unable to open the package: {0}, it does not exist on the server", packageName))
  111. {
  112. }
  113. }
  114.  
  115.  
  116. private int doit()
  117. {
  118. try
  119. {
  120. // Open the SISS catalog on the server
  121. Catalog catalog = integrationServices.Catalogs[catalogName];
  122. if (catalog == null)
  123. throw new CatalogException(catalogName);
  124.  
  125. // Open the folder in the catalog
  126. CatalogFolder folder = catalog.Folders[folderName];
  127. if (folder == null)
  128. throw new FolderException(folderName);
  129.  
  130. // Open the project in the folder
  131. ProjectInfo projectInfo = folder.Projects[projectName];
  132. if (projectInfo == null)
  133. throw new ProjectException(projectName);
  134.  
  135. // Check if the package exists
  136. if (!projectInfo.Packages.Contains(packageName))
  137. throw new PackageException(packageName);
  138.  
  139. return (int)ExitCode.Sucess;
  140. }
  141. catch (Exception e)
  142. {
  143. Console.WriteLine(e.Message);
  144. return (int)ExitCode.Failure;
  145. }
  146. }
  147.  
  148. try
  149. {
  150. // Open the SISS catalog on the server
  151. var catalog = integrationServices.Catalogs[catalogName];
  152. if (catalog == null)
  153. {
  154. throw new System.Exception("Unable to open the SSIS catalog : " + catalogName + ", it does not exist on the server");
  155. }
  156. /*...*/
  157. return (int)ExitCode.Success;
  158. }
  159. catch (System.Exception x)
  160. {
  161. System.Console.WriteLine(x.Message);
  162. return (int)ExitCode.Failure;
  163. }
  164.  
  165. try
  166. {
  167. // Open the project in the catalog
  168. var catalog = integrationServices.Catalogs[catalogName];
  169. var folder = catalog.Folders[folderName];
  170. var projectInfo = folder.Projects[projectName];
  171.  
  172. // Check if the package exists
  173. if (!projectInfo.Packages.Contains(packageName))
  174. {
  175. throw new System.Exception("Unable to open the package : " + packageName
  176. + ", it does not exist on the server");
  177. }
  178. /*...*/
  179. return (int)ExitCode.Success;
  180. }
  181. catch
  182. {
  183. return (int)ExitCode.Failure;
  184. }
  185.  
  186. public int ExecuteSSISPackage()
  187. {
  188. string whatFailed = null;
  189. if (integrationServices.Catalogs.Contains(catalogName))
  190. {
  191. var catalog = integrationServices.Catalogs[catalogName];
  192. if (catalog.Folders.Contains(folderName))
  193. {
  194. var folder = catalog.Folders[folderName];
  195. if (folder.Projects.Contains(projectName))
  196. {
  197. var project = folder.Projects[projectName];
  198. if (project.Packages.Contains(packageName))
  199. {
  200. var package = project.Packages[packageName];
  201.  
  202. //... Execute package?
  203.  
  204. } else whatFailed = String.Format("package: {0}", packageName);
  205. } else whatFailed = String.Format("project: {0}", projectName);
  206. } else whatFailed = String.Format("folder: {0}", folderName);
  207. } else whatFailed = String.Format("SSIS catalog: {0}", catalogName);
  208.  
  209. if (whatFailed != null)
  210. {
  211. Console.WriteLine("Unable to open the {0}, it does not exist on the server", whatFailed);
  212. return (int)ExitCode.Failure;
  213. }
  214. else
  215. return (int)ExitCode.Success;
  216.  
  217. Catalog catalog = integrationServices.Catalogs[catalogName];
  218. if (catalog == null)
  219. {
  220. Console.WriteLine("Unable to open the SSIS catalog : " + catalogName
  221. + ", it does not exist on the server");
  222. return (int)ExitCode.Failure;
  223. }
  224.  
  225. public Catalog this[string key]
  226. {
  227. get
  228. {
  229. Catalog catalog;
  230.  
  231. if(_dictionary.TryGetValue(key, out catalog))
  232. return catalog;
  233.  
  234. return null;
  235. }
  236. }
  237.  
  238. public Catalog this[string catalogName]
  239. {
  240. get
  241. {
  242. Catalog catalog;
  243.  
  244. if(_dictionary.TryGetValue(key, out catalog))
  245. return catalog;
  246.  
  247. throw new Exception("Unable to open the SSIS catalog : " + catalogName +
  248. ", it does not exist on the server";
  249. }
  250. }
  251.  
  252. public Catalog GetCatalog(string catalogName)
  253. {
  254. Catalog catalog;
  255.  
  256. if(_dictionary.TryGetValue(key, out catalog))
  257. return catalog;
  258.  
  259. throw new Exception("Unable to open the SSIS catalog : " + catalogName +
  260. ", it does not exist on the server";
  261. }
  262.  
  263. try
  264. {
  265. // Open the SISS catalog on the server
  266. Catalog catalog = integrationServices.GetCatalog(catalogName);
  267.  
  268. // Open the folder in the catalog
  269. CatalogFolder folder = catalog.GetFolder(folderName);
  270.  
  271. // Open the project in the folder
  272. ProjectInfo projectInfo = folder.GetProject(projectName);
  273.  
  274. // Check if the package exists
  275. var package = projectInfo.GetPackage(packageName);
  276.  
  277. return package; // or do whatever it is you need the package for
  278. }
  279. catch (Exception ex)
  280. {
  281. Console.WriteLine(ex.Message);
  282. //return (int)ExitCode.Failure;
  283. throw;
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement