public void CommitChanges(IAssetCache assetCache)
        {
            if (!connector.IsConnected)
            {
                Logger.Error("Not connected to VersionOne.");
            }

            try {
                var validationResult = new Dictionary <Asset, List <RequiredFieldsDto> >();
                var internalCache    = assetCache.ToInternalCache();

                var workitems = assetCache.GetWorkitems(true);

                foreach (var item in workitems)
                {
                    if (!ValidateWorkitemAndCommitOnSuccess(item, internalCache.Efforts, validationResult))
                    {
                        continue;
                    }

                    foreach (var child in item.Children)
                    {
                        ValidateWorkitemAndCommitOnSuccess(child, internalCache.Efforts, validationResult);
                    }
                }

                if (validationResult.Count > 0)
                {
                    throw new ValidatorException(requiredFieldsValidator.CreateErrorMessage(validationResult));
                }
            } catch (APIException ex) {
                Logger.Error("Failed to commit changes.", ex);
            }
        }
        public void GetWorkitems(IAssetCache assetCache)
        {
            if (!connector.IsConnected)
            {
                Logger.Error("Not connected to VersionOne.");
            }

            if (CurrentProjectId == null)
            {
                throw new DataLayerException("Current project is not selected");
            }

            if (assetCache.IsSet)
            {
                return;
            }

            try {
                var parentDef = workitemType.GetAttributeDefinition("Parent");

                var query = new Query(workitemType, parentDef);
                AddSelection(query, Entity.TaskType);
                AddSelection(query, Entity.StoryType);
                AddSelection(query, Entity.DefectType);
                AddSelection(query, Entity.TestType);

                query.Filter = GetScopeFilter(workitemType);

                query.OrderBy.MajorSort(primaryWorkitemType.DefaultOrderBy, OrderBy.Order.Ascending);
                query.OrderBy.MinorSort(workitemType.DefaultOrderBy, OrderBy.Order.Ascending);

                var assetList = connector.Services.Retrieve(query);
                assetCache.ToInternalCache().Set(assetList.Assets);
            } catch (MetaException ex) {
                Logger.Error("Unable to get workitems.", ex);
            } catch (WebException ex) {
                connector.IsConnected = false;
                Logger.Error("Unable to get workitems.", ex);
            } catch (Exception ex) {
                Logger.Error("Unable to get workitems.", ex);
            }
        }
        public void CommitChanges(IAssetCache assetCache) {
            if(!connector.IsConnected) {
                Logger.Error("Not connected to VersionOne.");
            }

            try {
                var validationResult = new Dictionary<Asset, List<RequiredFieldsDto>>();
                var internalCache = assetCache.ToInternalCache();

                var workitems = assetCache.GetWorkitems(true);

                foreach(var item in workitems) {
                    if(!ValidateWorkitemAndCommitOnSuccess(item, internalCache.Efforts, validationResult)) {
                        continue;
                    }

                    foreach(var child in item.Children) {
                        ValidateWorkitemAndCommitOnSuccess(child, internalCache.Efforts, validationResult);
                    }
                }

                if(validationResult.Count > 0) {
                    throw new ValidatorException(requiredFieldsValidator.CreateErrorMessage(validationResult));
                }

            } catch(APIException ex) {
                Logger.Error("Failed to commit changes.", ex);
            }
        }
        public void GetWorkitems(IAssetCache assetCache) {
            if(!connector.IsConnected) {
                Logger.Error("Not connected to VersionOne.");
            }
            
            if(CurrentProjectId == null) {
                throw new DataLayerException("Current project is not selected");
            }

            if(assetCache.IsSet) {
                return;
            }
            
            try {
                var parentDef = workitemType.GetAttributeDefinition("Parent");

                var query = new Query(workitemType, parentDef);
                AddSelection(query, Entity.TaskType);
                AddSelection(query, Entity.StoryType);
                AddSelection(query, Entity.DefectType);
                AddSelection(query, Entity.TestType);

                query.Filter = GetScopeFilter(workitemType);

                query.OrderBy.MajorSort(primaryWorkitemType.DefaultOrderBy, OrderBy.Order.Ascending);
                query.OrderBy.MinorSort(workitemType.DefaultOrderBy, OrderBy.Order.Ascending);

                var assetList = connector.Services.Retrieve(query);
                assetCache.ToInternalCache().Set(assetList.Assets);
            } catch(MetaException ex) {
                Logger.Error("Unable to get workitems.", ex);
            } catch(WebException ex) {
                connector.IsConnected = false;
                Logger.Error("Unable to get workitems.", ex);
            } catch(Exception ex) {
                Logger.Error("Unable to get workitems.", ex);
            }
        }