main
1 function combine_paths($path1,$path2)
2 {
3 return [System.IO.Path]::Combine($path1,$path2)
4 }
5
6 function touch($file_path)
7{
8 new-item -path $file_path -force -itemtype File
9}
10
11 function drop_folder($path)
12 {
13 if (test-path $path)
14 {
15 remove-item $path -force -recurse
16 }
17 }
18
19 function make_folder($path)
20 {
21 new-item -path $path -type directory | out-null
22 }
23
24 function get_filename($full_path){
25 return [System.IO.Path]::GetFileName($full_path)
26 }
27
28 function process_sql_files($files,$sql_tool,$connection_string)
29 {
30 $files | foreach-object{ .$sql_tool $connection_string -i "$_" }
31 }
32
33 function copy_and_replace_tokens($template_file_path,$settings)
34 {
35 $contents = [System.IO.File]::ReadAllText($template_file_path)
36 $settings.keys | foreach-object{
37 $contents = $contents.Replace("@${_}@",$settings[$_])
38 }
39 $new_file = strip_template_extension $template_file_path
40 [System.IO.File]::WriteAllText($new_file,$contents)
41 }
42
43 function files_have_changed($files_to_check,[System.String]$timestamp_file_path){
44
45 $timestamp_exists = test-path $timestamp_file_path
46 if($timestamp_exists -eq $false){return $true}
47
48 $reference_file = get-item -path $timestamp_file_path
49 $last_write_time = $reference_file.LastWriteTime
50 $reference_file = $null
51
52 foreach($file in $files_to_check)
53 {
54 $actual_file = get-item -path $file
55 if($actual_file.LastWriteTime -gt $last_write_time)
56 {
57 $actual_file = $null
58 return $true
59 }
60 }
61 return $false
62 }
63
64 function get_file_names($files)
65 {
66 $file_names = new-object -typename System.Collections.ArrayList
67 foreach ($file in $files)
68 {
69 [void]$file_names.Add($file.FullName)
70 }
71 return $file_names.ToArray()
72 }
73
74 function strip_template_extension($path){
75 if ($path.EndsWith(".template"))
76 {
77 return $path.Replace(".template","")
78 }
79 return $path
80 }
81
82 function expand_all_template_files($files,$settings)
83 {
84 $files | foreach-object{ copy_and_replace_tokens $_ $settings}
85 }
86
87 function kill_exe($name){
88 taskkill "/f /im $name /fi 'STATUS eq RUNNING'"
89 }
90
91 function make_iis_dir($application_name,$path){
92 $directory_entry = new-object System.DirectoryServices.DirectoryEntry -argumentList "IIS://localhost/W3SVC/1/Root"
93 $child_directories = $directory_entry.psbase.Children
94 $child_directories | where {$_.psbase.path.contains($application_name)} |foreach-object {
95 $child_directories.remove($_)
96 }
97
98 $virtual_directory = $child_directories.Add($application_name,"IISWebVirtualDir")
99 $virtual_directory.psbase.CommitChanges()
100 $virtual_directory.psbase.Properties["Path"][0]= $path
101 $virtual_directory.AppFriendlyName = $application_name
102 $virtual_directory.psbase.CommitChanges()
103 $virtual_directory.psbase.Invoke("AppCreate",$false)
104 }
105
106 function add_iis_mapping($application_name,$check_file_exists,$extension,$verbs,$executable){
107 $mapping = "$extension,$executable,"
108
109 if ($check_file_exists)
110 {
111 $mapping = $mapping + "5"
112 }
113 else
114 {
115 $mapping = $mapping + "1"
116 }
117 $mapping = $mapping + ",$verbs"
118 $directory_entry = new-object System.DirectoryServices.DirectoryEntry -argumentList "IIS://localhost/W3SVC/1/Root/$application_name"
119
120 if ($directory_entry -ne $null)
121 {
122 $directory_entry.psbase.RefreshCache()
123 $directory_entry.ScriptMaps.Add($mapping)
124 $directory_entry.psbase.CommitChanges()
125 $directory_entry.psbase.Close()
126 }
127 }