refactoring functions to one main function

guys i have several function using the same method to call another function or do certain thing 

function myFunction

{

if ($getProject -match 'all') { foreach ($project in $projectAllowedLst) { # params to be passed to the script block below in this case it is $project

# the command or function that are being called are to be set here (based on the $project) } } elseif ($getProject -match ',') { $projects = $getProject -split (',') foreach ($project in $projects) {

         # params to be passed to the script block below in this case it is $project

# the command or function that are being called are to be set here (based on the $project) } } elseif ($getProject -notmatch ',') {

# params to be passed to the script block below in this case it is $getProject

# the command or function that are being called are to be set here (based on the $getProject)

}

}

in all the function the 

my functions look like this

if (testBeforeBackup $project){doProjectBackup $project} else {updateXML $project}

and sometime a block with switch and function like this  

switch($project)
            {
                'de'{ 
                        if (testBeforeBackup $project)
                        {
                            deleteFiles $e_dst_folder $noDeleteEfolders 
                        } 
                    }
                'home'{
                        if (testBeforeBackup $project)
                        {
                            deleteFiles $home_dst_folder $noDeleteHomefolders
                        }
                    }
                'idm'{
                        if (testBeforeBackup $project)
                        {
                            deleteFiles $idm_dst_folder $noDeleteIfolders
                        }
                    }
            }
            copyProject $project

there are some variables that they will be accessed from the Script scope so no worries about the other variables.

how can i refactor it in a better way.. thanks.



  • Edited by Vagharsh Wednesday, June 24, 2015 2:19 PM
June 24th, 2015 12:13pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics