public static void EmitScriptProject(SsisObject o, string indent)
        {
            // Find the script object child
            var script = o.GetChildByType("DTS:ObjectData").GetChildByType("ScriptProject");

            // Create a folder for this script
            string project_folder = Path.Combine(AppFolder, o.GetFolderName());

            Directory.CreateDirectory(project_folder);

            // Extract all the individual script files in this script
            foreach (SsisObject child in script.Children)
            {
                string fn  = project_folder + child.Attributes["Name"];
                string dir = Path.GetDirectoryName(fn);
                Directory.CreateDirectory(dir);

                if (child.DtsObjectType == "BinaryItem")
                {
                    byte[] contents = System.Convert.FromBase64String(child.ContentValue);
                    File.WriteAllBytes(fn, contents);
                }
                else if (child.DtsObjectType == "ProjectItem")
                {
                    File.WriteAllText(fn, child.ContentValue);
                }

                // Handle DLL files specially - they are binary!  Oh yeah base64 encoded
                if (fn.EndsWith(".dll"))
                {
                    DllFiles.Add(fn);

                    // Note this as a potential problem
                    SourceWriter.Help(o, "The Visual Basic project " + child.Attributes["Name"] + " was embedded in the DTSX project.  Visual Basic code cannot be automatically converted.");

                    // Show the user that this is how the script should be executed, if they want to fix it
                    SourceWriter.WriteLine(@"{0}//{1}.ScriptMain sm = new {1}.ScriptMain();", indent, Path.GetFileNameWithoutExtension(fn).Replace("scripttask", "ScriptTask"));
                    SourceWriter.WriteLine(@"{0}//sm.Main();", indent);

                    // Is this a project file?
                }
                else if (fn.EndsWith(".vbproj") || fn.EndsWith(".csproj"))
                {
                    ProjectFiles.Add(fn);
                }
                else
                {
                    AllFiles.Add(fn);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Write a program file that has all the major executable instructions as functions
        /// </summary>
        /// <param name="variables"></param>
        /// <param name="functions"></param>
        /// <param name="p"></param>
        private static void WriteProgram(IEnumerable <SsisObject> variables, IEnumerable <SsisObject> functions, string filename, string appname)
        {
            using (SourceWriter.SourceFileStream = new StreamWriter(filename, false, Encoding.UTF8)) {
                string smo_using        = "";
                string tableparamstatic = "";

                // Are we using SMO mode?
                if (ProjectWriter.UseSqlServerManagementObjects)
                {
                    smo_using = Resource1.SqlSmoUsingTemplate;
                }

                // Are we using SQL 2008 mode?
                if (gSqlMode == SqlCompatibilityType.SQL2008)
                {
                    tableparamstatic = Resource1.TableParameterStaticTemplate;
                }

                // Write the header in one fell swoop
                SourceWriter.Write(
                    Resource1.ProgramHeaderTemplate
                    .Replace("@@USINGSQLSMO@@", smo_using)
                    .Replace("@@NAMESPACE@@", appname)
                    .Replace("@@TABLEPARAMSTATIC@@", tableparamstatic)
                    .Replace("@@MAINFUNCTION@@", functions.FirstOrDefault().GetFunctionName())
                    );

                // Write each variable out as if it's a global
                SourceWriter.WriteLine(@"#region Global Variables");
                foreach (SsisObject v in variables)
                {
                    v.EmitVariable("        ", true);
                }
                SourceWriter.WriteLine(@"#endregion");
                SourceWriter.WriteLine();
                SourceWriter.WriteLine();


                // Write each executable out as a function
                SourceWriter.WriteLine(@"#region SSIS Code");
                foreach (SsisObject v in functions)
                {
                    v.EmitFunction("        ", new List <ProgramVariable>());
                }
                SourceWriter.WriteLine(Resource1.ProgramFooterTemplate);
            }
        }