private void HandleDatabaseTaskAttachment(FileInfo fiAttach, string attachSqlDir)
        {
            var workItemId     = fiAttach.Directory.Name.Replace("TFS-", string.Empty); // ick
            var targetFilename = Path.Combine(attachSqlDir, "TFS-" + workItemId + "_" + fiAttach.Name);

            File.Copy(fiAttach.FullName, targetFilename);

            var result = this.MassDownload.TaskChanges.Where(x => x.Task.Id == Convert.ToInt32(workItemId)).FirstOrDefault();

            if (null == result)
            {
                return;
            }
            result.AddTaskFile(targetFilename, this.MassDownload.Config.DownloadPath, "[Task Attachment]", isDelete: false);

            if (null == _databaseChanges || _databaseChanges.Any(x => x.Filename == targetFilename))
            {
                return;
            }

            var fileType = this.MassDownload.Config.KnownFileTypes.GetTypeForFilenameExt(targetFilename);
            var ext      = fileType.GetFileExtensionForFile(targetFilename);
            var file     = targetFilename.Replace(this.RootDatabaseFolder + @"\", string.Empty);

            var change = new DatabaseChange
            {
                Extension    = ext,
                Filename     = targetFilename,
                FilePath     = file,
                Schema       = null, // indeterminate really
                IsAttachment = true
            };

            change.AddChangeType(ChangeTypes.Add);

            var task       = result.Task;
            var taskAttach = task.Attachments.OfType <Attachment>().Where(x => x.Name == fiAttach.Name).FirstOrDefault();

            if (null != taskAttach)
            {
                change.FirstChanged = taskAttach.CreationTime;
                change.LastChanged  = taskAttach.LastWriteTime;
            }

            change.AddTask(new WorkItemInfo
            {
                Id         = task.Id,
                State      = task.State,
                Title      = task.Title,
                AssignedTo = task.GetAssignedTo()
            });

            _databaseChanges.Add(change);
        }
        private void CombineDbFilesInDir(string path)
        {
            var di     = new DirectoryInfo(path);
            var schema = di.Parent.Name;

            var files = di.GetFiles("*.*", SearchOption.TopDirectoryOnly).Where(
                f => !f.Extension.StartsWith(".deleted")).ToList();

            // still want to combine if only one actually
            //if (files.Count < 2) return;

            const string combineSuffix    = ".combined.sql";
            var          combinedFilename = Path.Combine(path, string.Format("_{0}.{1} ({2}){3}", schema, di.Name, files.Count, combineSuffix));

            foreach (var fi in files)
            {
                if (fi.FullName.EndsWith(combineSuffix))
                {
                    continue;
                }

                var contents = File.ReadAllText(fi.FullName);
                File.AppendAllText(combinedFilename, contents + Environment.NewLine + Environment.NewLine);

                if (!_databaseChanges.Any(x => x.Filename == combinedFilename))
                {
                    var dbChange = new DatabaseChange {
                        Filename = combinedFilename, Schema = schema
                    };
                    dbChange.AddChangeType(ChangeTypes.Add);
                    var fileType = this.MassDownload.Config.KnownFileTypes.GetTypeForFilenameExt(combinedFilename);
                    dbChange.FilePath     = combinedFilename.Replace(this.RootDatabaseFolder + @"\", string.Empty);
                    dbChange.Extension    = fileType.GetFileExtension(".sql");
                    dbChange.FirstChanged = DateTime.Now;
                    dbChange.LastChanged  = dbChange.FirstChanged;
                    _databaseChanges.Add(dbChange);
                }
            }
        }