11using System ;
2- using System . Diagnostics ;
32using System . IO ;
43using XElement . CloudSyncHelper . DataTypes ;
54
6- namespace XElement . CloudSyncHelper . Logic . Execution
5+ namespace XElement . CloudSyncHelper . Logic . Execution . Link
76{
87#region not unit-tested
98 internal abstract class LinkBase : ILinkInt
109 {
11- public LinkBase ( IApplicationInfo appInfo ,
12- ILinkInfo linkInfo ,
13- PathVariablesDTO pathVariablesDTO )
10+ public LinkBase ( LinkParametersDTO parametersDTO ,
11+ DependenciesDTO dependenciesDTO )
1412 {
15- this . _linkInfo = linkInfo ;
16- this . _pathVariablesDTO = pathVariablesDTO ;
13+ this . _mkLinkExecutorFactory = dependenciesDTO . MkLinkExecutorFactory ;
14+
15+ this . _linkInfo = parametersDTO . LinkInfo ;
16+ this . _pathVariablesDTO = parametersDTO . PathVariablesDTO ;
1717 this . _symLinkHelper = new SymbolicLinkHelper ( ) ;
1818
19- Initialize ( appInfo ) ;
19+ Initialize ( parametersDTO . ApplicationInfo ) ;
2020 }
2121
22+
2223 private void CreatePathToDestinationTarget ( )
2324 {
2425 Directory . CreateDirectory ( this . PathToDestinationTarget ) ;
2526 }
2627
28+
2729 public void /*ILink.*/ Do ( )
2830 {
2931 this . CreatePathToDestinationTarget ( ) ;
3032 this . Undo ( ) ;
31- this . ExecuteCmd ( ) ;
32- }
3333
34- private void ExecuteCmd ( )
35- {
36- var mkLink = this . GetCmdCommand ( ) ;
37- var process = new Process ( ) ;
38- process . StartInfo . FileName = "cmd.exe" ;
39- process . StartInfo . Arguments = "/c " + mkLink ;
40- process . StartInfo . CreateNoWindow = true ;
41- process . StartInfo . UseShellExecute = false ;
42- process . StartInfo . Verb = "runas" ;
43- process . Start ( ) ;
44-
45- process . WaitForExit ( ) ;
34+ var mkLinkParams = new MkLink . ParametersDTO
35+ {
36+ Link = this . LinkPath ,
37+ Target = this . TargetPath ,
38+ Type = this . MkLinkType
39+ } ;
40+ this . _mkLinkExecutorFactory . Get ( mkLinkParams ) . Execute ( ) ;
4641 }
4742
43+
4844 private bool DoesSymbolicLinkPointToExpectedPath
4945 {
5046 get
@@ -54,13 +50,9 @@ private bool DoesSymbolicLinkPointToExpectedPath
5450 }
5551 }
5652
53+
5754 protected abstract FileSystemInfo FileSystemInfo { get ; }
5855
59- private string GetCmdCommand ( )
60- {
61- return String . Format ( "MKLINK {0} \" {1}\" \" {2}\" " , this . MkLinkParams ,
62- this . LinkPath , this . TargetPath ) ;
63- }
6456
6557 private void Initialize ( IApplicationInfo programInfo )
6658 {
@@ -74,8 +66,10 @@ private void Initialize( IApplicationInfo programInfo )
7466 }
7567 }
7668
69+
7770 public abstract bool /*ILink.*/ IsInCloud { get ; }
7871
72+
7973 public bool /*ILink.*/ IsLinked
8074 {
8175 get
@@ -85,6 +79,7 @@ public bool /*ILink.*/IsLinked
8579 }
8680 }
8781
82+
8883 private bool IsSymbolicLink
8984 {
9085 get
@@ -94,6 +89,7 @@ private bool IsSymbolicLink
9489 }
9590 }
9691
92+
9793 public string /*ILink.*/ LinkPath
9894 {
9995 get
@@ -104,16 +100,20 @@ public string /*ILink.*/LinkPath
104100 }
105101 }
106102
107- protected abstract string MkLinkParams { get ; }
103+
104+ protected abstract MkLink . Type MkLinkType { get ; }
105+
108106
109107 public void /*ILink.*/ MoveToCloud ( )
110108 {
111109 Directory . CreateDirectory ( this . PathToCloudUserFolder ) ;
112110 this . MoveToCloud_CopyStuff ( ) ;
113111 }
114112
113+
115114 protected abstract void MoveToCloud_CopyStuff ( ) ;
116115
116+
117117 private string PathToDestinationTarget
118118 {
119119 get
@@ -123,6 +123,7 @@ private string PathToDestinationTarget
123123 }
124124 }
125125
126+
126127 private string PathToCloudUserFolder
127128 {
128129 get
@@ -135,6 +136,7 @@ private string PathToCloudUserFolder
135136 }
136137 }
137138
139+
138140 public string /*ILink.*/ TargetPath
139141 {
140142 get
@@ -144,9 +146,12 @@ public string /*ILink.*/TargetPath
144146 }
145147 }
146148
149+
147150 public abstract void /*ILink.*/ Undo ( ) ; // TODO: Delete folders if they are empty
148151
152+
149153 private ILinkInfo _linkInfo ;
154+ private MkLink . IFactory _mkLinkExecutorFactory ;
150155 private PathVariablesDTO _pathVariablesDTO ;
151156 private IApplicationLogic _programLogic ;
152157 private SymbolicLinkHelper _symLinkHelper ;
0 commit comments