private MassDownloadChangeInfo GetChangeInfo(Changeset changeset, Change change)
        {
            var ci = new MassDownloadChangeInfo
            {
                Change    = change,
                Changeset = changeset,
                File      = change.Item.ServerItem.Split('/').Last()
            };

            ci.FileTypeInfo = this.Config.KnownFileTypes.GetTypeForFilenameExt(ci.File);
            ci.TaskChanges  = _taskChanges.Where(x => x.TaskChangeSets.Contains(changeset)).ToList();

            // i.e. DownloadPath\Database or DownloadPath\Reports
            ci.TargetDirectory = Path.Combine(this.DownloadPath, ci.FileTypeInfo.TypeName);

            var extText = ci.File.Substring(ci.File.LastIndexOf("."));

            ci.Extension = ci.FileTypeInfo.GetFileExtension(extText);

            if (ci.IsDatabase)
            {
                // i.e. DownloadPath\Database
                if (string.IsNullOrEmpty(this.Config.RootDatabasePath))
                {
                    this.Config.RootDatabasePath = ci.TargetDirectory;
                }

                ci.DatabaseSchema = ci.File.Substring(0, ci.File.IndexOf(".") - 0);
                // i.e. DownloadPath\Database\Schema\VIEWS
                ci.TargetDirectory = Path.Combine(ci.TargetDirectory, ci.DatabaseSchema, ci.Extension.Category);
            }

            if (ci.HasIncompleteTask)
            {
                ci.TargetDirectory = Path.Combine(ci.TargetDirectory, "_Incomplete");
            }

            if (ci.IsDeleted)
            {
                ci.TargetFilenameDeleted = Path.Combine(ci.TargetDirectory, ci.File);
                ci.TargetDirectory       = Path.Combine(ci.TargetDirectory, Constants.DELETED_SUB_DIR_NAME);
            }

            DirUtility.EnsureDir(ci.TargetDirectory);
            ci.TargetFilename = Path.Combine(ci.TargetDirectory, ci.File);

            return(ci);
        }
        public void HandleDatabaseChange(MassDownloadChangeInfo info)
        {
            // incomplete task handling?
            // database paths will be used for combining sql scripts. don't want deleted paths in there or incomplete
            if (info.IsDatabase && !info.HasIncompleteTask && !info.IsDeleted && !_databasePaths.Contains(info.TargetDirectory))
            {
                _databasePaths.Add(info.TargetDirectory);
            }

            var dbChange = _databaseChanges.Where(x => x.Filename == info.TargetFilename).FirstOrDefault() ??
                           new DatabaseChange
            {
                Schema     = info.DatabaseSchema,
                Extension  = info.Extension,
                Filename   = info.TargetFilename,
                ServerItem = info.ServerItem
            };

            info.Tasks.ForEach(t => dbChange.AddTask(
                                   new WorkItemInfo {
                Id = t.Id, Title = t.Title, State = t.State, AssignedTo = t.GetAssignedTo()
            }));

            // change.Item.CheckinDate is DateTime.MinValue
            var checkinDate = info.Changeset.CreationDate;

            if (null == dbChange.FirstChanged)
            {
                dbChange.FirstChanged = checkinDate;
            }

            if (dbChange.LastChanged == null || checkinDate > dbChange.LastChanged)
            {
                dbChange.LastChanged = checkinDate;
            }

            dbChange.AddChangeType((ChangeTypes)(int)info.Change.ChangeType);

            if (!_databaseChanges.Any(x => x.Filename == info.TargetFilename))
            {
                var replacePath = this.RootDatabaseFolder + @"\";
                dbChange.FilePath = dbChange.Filename.Replace(replacePath, string.Empty);
                _databaseChanges.Add(dbChange);
            }
        }