コード例 #1
0
        private void SavePackages()
        {
            //foreach (PackageItem package in CensusProject.PackageItems)
            //{
            //	string filePath = $"{PackageDirectoryPath}\\{package.StreamName}";

            FileInfo fileInfo = new FileInfo(PackageFilePath);

            if (fileInfo.Directory == null)
            {
                throw new ArgumentException($"{PackageFilePath} is not a valid package path");
            }

            if (!fileInfo.Directory.Exists)
            {
                fileInfo.Directory.Create();
            }

            if (fileInfo.Exists)
            {
                fileInfo.Delete();
            }

            CensusApplication.SaveToXml(PackageFilePath, CensusPackage, null);

            //}
        }
コード例 #2
0
        //private bool InitializeProject()
        //{
        //	bool success = false;
        //	try
        //	{
        //		FileInfo filePath = new FileInfo(ProjectFilePath);

        //		if (filePath.Directory == null)
        //		{
        //			throw new DirectoryNotFoundException($"The directory provided in the project file path does not appear to be a valid directory.");
        //		}

        //		if (!filePath.Directory.Exists)
        //			filePath.Directory.Create();

        //		CensusProject = filePath.Exists
        //							? Project.OpenProject(ProjectFilePath, Project.AccessMode.ReadWrite, null, new DefaultEvents())
        //							: Project.CreateProject(ProjectFilePath);

        //		CensusProject.Name = ProjectName;
        //		CensusProject.CreatorName = "Anthony Hart";
        //		CensusProject.Description = ProjectDescription;

        //		CensusProject.Save();

        //		success = CensusProject == null;
        //	}
        //	catch (Exception e)
        //	{
        //		Console.WriteLine(e);
        //	}
        //	finally
        //	{
        //		Console.WriteLine($"Project Initialization: {(success ? "Succeeded" : "Failed")}");
        //	}
        //	return success;
        //}

        private bool InitializePackage()
        {
            bool success;

            try
            {
                FileInfo filePath = new FileInfo(PackageFilePath);

                if (filePath.Directory == null)
                {
                    throw new DirectoryNotFoundException($"The directory provided in the package file path does not appear to be a valid directory.");
                }

                if (!filePath.Directory.Exists)
                {
                    filePath.Directory.Create();
                }

                CensusPackage = File.Exists(PackageFilePath)
                                    ? CensusApplication.LoadPackage(PackageFilePath, new DefaultEvents())
                                    : new Package();

                CensusPackage.Name         = DefaultPackageName;
                CensusPackage.CreatorName  = "Anthony Hart";
                CensusPackage.Description  = DefaultPackageDescription;
                CensusPackage.PackageType  = DTSPackageType.Default;
                CensusPackage.DesignEvents = new SSISEventHandler();

                ConnectionManager manager = GetDefaultConnection();

                Save();

                success = CensusPackage != null && manager != null && manager == DefaultConnection;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(success);
        }