scorch /SanitizeExport/SanitizeExport/Program.cs

Language C# Lines 216
MD5 Hash dbf374bda3eb087eb77ccd74041799cb Estimated Cost $4,959 (why?)
Repository https://scorch.svn.codeplex.com/svn View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Xml;
using System.Security;
using System.IO;
using System.Reflection;
using Microsoft.SystemCenter.Orchestrator.Integration.Administration;
using Microsoft.SystemCenter.Orchestrator.Integration.Administration.OIS_Export;

namespace SanitizeExport
{
    class Program
    {
        #region Gobals
        private static XmlDocument finalDocument = new XmlDocument();
        private static XmlDocument inputXML = new XmlDocument();

        private static XmlNode finalConfigNode;
        private static XmlNode finalCountersNode;
        private static XmlNode finalVariablesNode;
        private static XmlNode finalSchedulesNode;
        private static XmlNode finalComputerGroupsNode;

        private static string configurationNodePath = @"//GlobalConfigurations";
        private static string countersNodePath = @"//GlobalSettings/Counters/Folder";
        private static string variablesNodePath = @"//GlobalSettings/Variables/Folder";
        private static string schedulesNodePath = @"//GlobalSettings/Schedules/Folder";
        private static string computerGroupsNodePath = @"//GlobalSettings/ComputerGroups/Folder";
        private static string policiesFolderPath = @"//Policies/Folder";
        private static string CommonData = "LogCommonData";
        private static string SpecificData = "LogSpecificData";

        private static bool verbose = false;
        #endregion 

        static void Main(string[] args)
        {
            FileInfo inputFile = null;
            FileInfo outputFile = null;
            
            bool sanitizeGlobals = true;
            bool applyLinkBestPractices = true;
            bool updateMaxParallel = true;

            String ObjectSpecificLogging = String.Empty;
            String GenericObjectLogging = String.Empty;

            if (parseInputs(args, ref inputFile, ref outputFile, ref sanitizeGlobals, ref ObjectSpecificLogging, ref GenericObjectLogging, ref applyLinkBestPractices, ref updateMaxParallel))
            {
                ExportFile export = new ExportFile(inputFile);

                if (sanitizeGlobals)
                {
                    export.cleanGlobalConfigurations();
                    export.cleanGlobalComputerGroupsNode();
                    export.cleanGlobalCountersNode();
                    export.cleanGlobalSchedulesNode();
                    export.cleanGlobalVariablesNode();
                }

                if (applyLinkBestPractices) { export.modifyExportLinkApplyBestPractices(); }
                if (updateMaxParallel) { export.modifyExportSetMaxParallelRequestSettingNameBased(); }
                              
                export.modifyGenericLogging(GenericObjectLogging);
                export.modifyObjectSpecificLogging(ObjectSpecificLogging);

                export.OISExport.Save(outputFile.FullName);
            }
        }

        #region Input Parameter Parsing and Validation
        private static bool parseInputs(string[] args, ref FileInfo inputFile, ref FileInfo outputFile, ref bool sanitizeGlobals, ref String ObjectSpecificLogging, ref String GenericObjectLogging, ref bool applyLinkBestPractices, ref bool updateMaxParallel)
        {
            bool force = false;

            if (args.Count() == 0 || args.Contains("-help") || args.Contains("/?"))
            {
                printHelp();
                return false;
            }
            else
            {
                for (int i = 0; i < args.Count(); i++)
                {
                    parseInput(args, ref inputFile, ref outputFile, ref force, ref sanitizeGlobals, ref ObjectSpecificLogging, ref GenericObjectLogging, ref i, ref applyLinkBestPractices, ref updateMaxParallel);
                }

                return verifyMandatoryParameters(inputFile, outputFile, force);
            }
        }
        private static void printHelp()
        {
            Console.WriteLine("SanitizeExport.exe -ExportFilePath <String> -SanitizedExportFilePath <String> [-ObjectSpecificLogging (On|Off)] [-GenericObjectLogging (On|Off)] [-DoNotSanitizeGlobals] [-Force]\n\n");
            Console.WriteLine("-ExportFilePath <String> :  Path to the ois_export file to sanitize");
            Console.WriteLine("-SanitizedExportFilePath <String> : Path to save the sanitized export file to");
            Console.WriteLine("-ObjectSpecificLogging (On|Off) : Turns On or Off object specific logging for all runbooks in export file");
            Console.WriteLine("-GenericObjectLogging (On|Off) : Turns On or Off generic object logging for all runbooks in export file");
            Console.WriteLine("-ApplyLinkBestPractices (True|False) : Applys link best practice naming and coloring");
            Console.WriteLine("-UpdateMaxParallel (True|False) : Updates the max concurrent settings for Runbooks based on folder names");
            Console.WriteLine("-DoNotSanitizeGlobals : If set no manipulations of Globals (configurations, variables, counters etc) will be done");
            Console.WriteLine("-Force : If set any file at SanitizedExportFilePath will be overwritten");
            Console.WriteLine("-Verbose : Prints detailed information on what the tool is doing");
            Console.WriteLine("-Help : Prints this Help Page");
        }
        private static void parseInput(string[] args, ref FileInfo inputFile, ref FileInfo outputFile, ref bool force, ref bool sanitizeGlobals, ref String ObjectSpecificLogging, ref String GenericObjectLogging, ref int i, ref bool applyLinkBestPractices, ref bool updateMaxParallel)
        {
            switch (args[i].ToLower())
            {
                case "-applylinkbestpractices":
                case "-a":
                    i++;
                    applyLinkBestPractices = Convert.ToBoolean(args[i]);
                    break;
                case "-updatemaxparallel":
                case "-u":
                    i++;
                    updateMaxParallel = Convert.ToBoolean(args[i]);
                    break;
                case "-exportfilepath":
                    i++;
                    inputFile = new FileInfo(args[i]);
                    break;
                case "-e":
                    i++;
                    inputFile = new FileInfo(args[i]);
                    break;
                case "-sanitizedexportfilepath":
                    i++;
                    outputFile = new FileInfo(args[i]);
                    break;
                case "-s":
                    i++;
                    outputFile = new FileInfo(args[i]);
                    break;
                case "-objectspecificlogging":
                    i++;
                    ObjectSpecificLogging = args[i];
                    break;
                case "-o":
                    i++;
                    ObjectSpecificLogging = args[i];
                    break;
                case "-genericobjectlogging":
                    i++;
                    GenericObjectLogging = args[i];
                    break;
                case "-g":
                    i++;
                    GenericObjectLogging = args[i];
                    break;
                case "-donotsanitizeglobals":
                    sanitizeGlobals = false;
                    break;
                case "-d":
                    sanitizeGlobals = false;
                    break;
                case "-force":
                    force = true;
                    break;
                case "-f":
                    force = true;
                    break;
                case "-verbose":
                    verbose = true;
                    break;
                case "-v":
                    verbose = true;
                    break;
                default:
                    break;
            }
        }
        private static bool verifyMandatoryParameters(FileInfo inputFile, FileInfo outputFile, bool force)
        {
            if (inputFile == null)
            {
                Console.WriteLine("Please specifiy an export file to sanitize using -ExportFilePath \"\\\\path\\to\\exportfile.ois_export\"");
                return false;
            }
            else
            {
                if(!inputFile.Exists)
                {
                    return false;
                }
            }
            if (outputFile == null)
            {
                Console.WriteLine("Please specifiy a path to store the output file using -SanitizedExportFilePath \"\\\\path\\to\\exportfile.ois_export\"");
                return false;
            }
            else
            {
                if (outputFile.Exists)
                {
                    if (force)
                    {
                        outputFile.Delete();
                    }
                    else
                    {
                        Console.WriteLine("Output file path already exsits, please remove before running or specify -Force\n" + outputFile.FullName);
                        return false;
                    }
                }
            }
            return true;
        }
        #endregion
    
    }
}
Back to Top