Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Open the SISS catalog on the server
- Catalog catalog = integrationServices.Catalogs[catalogName];
- if (catalog == null)
- {
- Console.WriteLine("Unable to open the SSIS catalog : " + catalogName
- + ", it does not exist on the server");
- return (int)ExitCode.Failure;
- }
- // Open the folder in the catalog
- CatalogFolder folder = catalog.Folders[folderName];
- if (folder == null)
- {
- Console.WriteLine("Unable to open the folder : " + folderName
- + ", it does not exist on the server");
- return (int)ExitCode.Failure;
- }
- // Open the project in the folder
- ProjectInfo projectInfo = folder.Projects[projectName];
- if (projectInfo == null)
- {
- Console.WriteLine("Unable to open the project : " + projectName
- + ", it does not exist on the server");
- return (int)ExitCode.Failure;
- }
- // Check if the package exists
- if (!projectInfo.Packages.Contains(packageName))
- {
- Console.WriteLine("Unable to open the package : " + packageName
- + ", it does not exist on the server");
- return (int)ExitCode.Failure;
- }
- private T Extract(string itemType, string itemName, Func<T> itemExtractor) where T : class
- {
- var res = itemExtractor();
- if (res == null)
- {
- Console.WriteLine("Unable to open the {0}: {1}", itemType, itemName);
- return null;
- }
- return res;
- }
- Catalog catalog = Extract("catalog", catalogName, () => integrationServices.Catalogs[catalogName]);
- if (catalog == null) return (int)ExitCode.Failure;
- CatalogFolder folder = Extract("folder", folderName, () => catalog.Folders[folderName]);
- if (folder == null) return (int)ExitCode.Failure;
- ProjectInfo projectInfo = Extract("project", projectName, () => folder.Projects[projectName]);
- if (projectInfo == null) return (int)ExitCode.Failure;
- string package = Extract("package", packageName, () => projectInfo.Packages.Contains(packageName) ? packageName : null);
- if (package == null) return (int)ExitCode.Failure;
- private T Extract(string itemType, string itemName, Func<T> itemExtractor) where T : class
- {
- var res = itemExtractor();
- if (res == null)
- {
- throw new ItemNotFoundException(string.Format("Unable to open the {0}: {1}", itemType, itemName));
- }
- return res;
- }
- try
- {
- Catalog catalog = Extract("catalog", catalogName, () => integrationServices.Catalogs[catalogName]);
- CatalogFolder folder = Extract("folder", folderName, () => catalog.Folders[folderName]);
- ProjectInfo projectInfo = Extract("project", projectName, () => folder.Projects[projectName]);
- string package = Extract("package", packageName, () => projectInfo.Packages.Contains(packageName) ? packageName : null);
- }
- catch (ItemNotFoundException ex)
- {
- Console.WriteLine(ex.Message);
- return (int)ExitCode.Failure;
- }
- private class CatalogException : Exception
- {
- public CatalogException(string catalogName) :
- base(String.Format(@"
- Unable to open the SSIS catalog : {0}, it does not exist on the server", catalogName))
- {
- }
- }
- private class FolderException : Exception
- {
- public FolderException(string folderName) :
- base(String.Format(@"
- Unable to open the folder : {0}, it does not exist on the server", folderName))
- {
- }
- }
- private class ProjectException : Exception
- {
- public ProjectException(string projectName) :
- base(String.Format(@"
- Unable to open the project: {0}, it does not exist on the server", projectName))
- {
- }
- }
- private class PackageException : Exception
- {
- public PackageException(string packageName) :
- base(String.Format(@"
- Unable to open the package: {0}, it does not exist on the server", packageName))
- {
- }
- }
- private int doit()
- {
- try
- {
- // Open the SISS catalog on the server
- Catalog catalog = integrationServices.Catalogs[catalogName];
- if (catalog == null)
- throw new CatalogException(catalogName);
- // Open the folder in the catalog
- CatalogFolder folder = catalog.Folders[folderName];
- if (folder == null)
- throw new FolderException(folderName);
- // Open the project in the folder
- ProjectInfo projectInfo = folder.Projects[projectName];
- if (projectInfo == null)
- throw new ProjectException(projectName);
- // Check if the package exists
- if (!projectInfo.Packages.Contains(packageName))
- throw new PackageException(packageName);
- return (int)ExitCode.Sucess;
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- return (int)ExitCode.Failure;
- }
- }
- try
- {
- // Open the SISS catalog on the server
- var catalog = integrationServices.Catalogs[catalogName];
- if (catalog == null)
- {
- throw new System.Exception("Unable to open the SSIS catalog : " + catalogName + ", it does not exist on the server");
- }
- /*...*/
- return (int)ExitCode.Success;
- }
- catch (System.Exception x)
- {
- System.Console.WriteLine(x.Message);
- return (int)ExitCode.Failure;
- }
- try
- {
- // Open the project in the catalog
- var catalog = integrationServices.Catalogs[catalogName];
- var folder = catalog.Folders[folderName];
- var projectInfo = folder.Projects[projectName];
- // Check if the package exists
- if (!projectInfo.Packages.Contains(packageName))
- {
- throw new System.Exception("Unable to open the package : " + packageName
- + ", it does not exist on the server");
- }
- /*...*/
- return (int)ExitCode.Success;
- }
- catch
- {
- return (int)ExitCode.Failure;
- }
- public int ExecuteSSISPackage()
- {
- string whatFailed = null;
- if (integrationServices.Catalogs.Contains(catalogName))
- {
- var catalog = integrationServices.Catalogs[catalogName];
- if (catalog.Folders.Contains(folderName))
- {
- var folder = catalog.Folders[folderName];
- if (folder.Projects.Contains(projectName))
- {
- var project = folder.Projects[projectName];
- if (project.Packages.Contains(packageName))
- {
- var package = project.Packages[packageName];
- //... Execute package?
- } else whatFailed = String.Format("package: {0}", packageName);
- } else whatFailed = String.Format("project: {0}", projectName);
- } else whatFailed = String.Format("folder: {0}", folderName);
- } else whatFailed = String.Format("SSIS catalog: {0}", catalogName);
- if (whatFailed != null)
- {
- Console.WriteLine("Unable to open the {0}, it does not exist on the server", whatFailed);
- return (int)ExitCode.Failure;
- }
- else
- return (int)ExitCode.Success;
- Catalog catalog = integrationServices.Catalogs[catalogName];
- if (catalog == null)
- {
- Console.WriteLine("Unable to open the SSIS catalog : " + catalogName
- + ", it does not exist on the server");
- return (int)ExitCode.Failure;
- }
- public Catalog this[string key]
- {
- get
- {
- Catalog catalog;
- if(_dictionary.TryGetValue(key, out catalog))
- return catalog;
- return null;
- }
- }
- public Catalog this[string catalogName]
- {
- get
- {
- Catalog catalog;
- if(_dictionary.TryGetValue(key, out catalog))
- return catalog;
- throw new Exception("Unable to open the SSIS catalog : " + catalogName +
- ", it does not exist on the server";
- }
- }
- public Catalog GetCatalog(string catalogName)
- {
- Catalog catalog;
- if(_dictionary.TryGetValue(key, out catalog))
- return catalog;
- throw new Exception("Unable to open the SSIS catalog : " + catalogName +
- ", it does not exist on the server";
- }
- try
- {
- // Open the SISS catalog on the server
- Catalog catalog = integrationServices.GetCatalog(catalogName);
- // Open the folder in the catalog
- CatalogFolder folder = catalog.GetFolder(folderName);
- // Open the project in the folder
- ProjectInfo projectInfo = folder.GetProject(projectName);
- // Check if the package exists
- var package = projectInfo.GetPackage(packageName);
- return package; // or do whatever it is you need the package for
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- //return (int)ExitCode.Failure;
- throw;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement