public DirectorySynchronizerProgramm Prepare(Action<string> writelog = null) {
     if(Source.noContent()) throw new InvalidOperationException("source is empty");
     if(Target.noContent()) throw new InvalidOperationException("target is empty");
     writelog = writelog ?? (s => {});
     source = Source.normalizePath();
     target = Target.normalizePath();
     if(!Directory.Exists(source)) throw new InvalidOperationException("source directory not exists");
     if(!Directory.Exists(target)) Directory.CreateDirectory(target);
     sourcefiles = getFileDictionary(source);
     targetfiles = getFileDictionary(target);
     var result = new DirectorySynchronizerProgramm();
     if(this.Behaviour.CreateNewFiles && !this.Behaviour.RewriteNewFiles) {
         collectNewFiles(result, writelog);
     }
     if(this.Behaviour.UpdateOldFiles && !this.Behaviour.RewriteNewFiles) {
         collectUpdates(result, writelog);
     }
     if(this.Behaviour.DeleteFiles) {
         collectDeletes(result, writelog);
     }
     if(this.Behaviour.RewriteNewFiles) {
         collectRewrites(result, writelog);
     }
     foreach (var task in result) {
         task.Emulate = Behaviour.Emulate;
     }
     return result;
 }
 private void collectRewrites(DirectorySynchronizerProgramm result, Action<string> writelog) {
     foreach (var sf in sourcefiles) {
         var tf = adaptSourceNameToTarget(sf.Key);
         var task = new DirectorySynchronizerTask
                        {
                            Command = DirectorySynchronizerCommandType.Create,
                            Source = sf.Key,
                            Target = tf
                        };
         result.Add(task);
     }
 }
 private void collectDeletes(DirectorySynchronizerProgramm result, Action<string> writelog) {
     foreach (var tf in targetfiles) {
         var sf = adaptTargetNameToSource(tf.Key);
         if(!sourcefiles.ContainsKey(sf)) {
             var task = new DirectorySynchronizerTask
                            {
                                Command = DirectorySynchronizerCommandType.Delete,
                                Source = tf.Key,
                                Target = tf.Key,
                            };
             result.Add(task);
         }
     }
 }
 private void collectUpdates(DirectorySynchronizerProgramm result, Action<string> writelog) {
     foreach (var sf in sourcefiles) {
         var tf = adaptSourceNameToTarget(sf.Key);
         if(targetfiles.ContainsKey(tf)) {
             if(targetfiles[tf].LastWriteTime < sf.Value.LastWriteTime) {
                 var task = new DirectorySynchronizerTask
                                {
                                    Command = DirectorySynchronizerCommandType.Update,
                                    Source = sf.Key,
                                    Target = tf
                                };
                 result.Add(task);
             }
         }
     }
 }