public CloseWorkitemDialog(Workitem workitem) {
            this.workitem = workitem;

            InitializeComponent();
            BindControls();

            btnOK.Click +=  btnOK_Click;
        }
 private EffortTrackingLevel GetParentLevel(Workitem workitem) {
     switch (workitem.Parent.TypePrefix) {
         case Entity.StoryType:
             return StoryTrackingLevel;
         case Entity.DefectType:
             return DefectTrackingLevel;
         default:
             throw new InvalidOperationException("Unexpected parent asset type.");
     }
 }
        public void Cleanup(Workitem item) {
            if(item.Parent != null && AllAssets.Contains(item.Parent.Asset)) {
                item.Parent.Asset.Children.Remove(item.Asset);
            }

            AllAssets.Remove(item.Asset);
            Efforts.Remove(item.Asset);
            
            foreach(var child in item.Asset.Children) {
                Efforts.Remove(child);
            }
        }
 public bool AreEffortTrackingPropertiesReadOnly(Workitem workitem) {
     switch (workitem.TypePrefix) {
         case Entity.StoryType:
             return AreEffortTrackingPropertiesForPrimaryWorkitemReadOnly(StoryTrackingLevel);
         case Entity.DefectType:
             return AreEffortTrackingPropertiesForPrimaryWorkitemReadOnly(DefectTrackingLevel);
         case Entity.TaskType:
         case Entity.TestType:
             var parentLevel = GetParentLevel(workitem);
             return AreEffortTrackingPropertiesForSecondaryWorkitemReadOnly(parentLevel);
         default:
             throw new NotSupportedException("Unexpected asset type.");
     }
 }
        public static Workitem CreateWorkitem(AssetFactory assetFactory, string assetType, Workitem parent, IEntityContainer entityContainer) {
            Asset asset;

            switch (assetType) {
                case Entity.TaskType:
                case Entity.TestType:
                    asset = assetFactory.CreateAssetForSecondaryWorkitem(assetType, parent);
                    var workitem = CreateWorkitem(asset, parent, entityContainer);
                    parent.Children.Add(workitem);
                    break;
                case Entity.DefectType:
                    asset = assetFactory.CreateAssetForPrimaryWorkitem(Entity.DefectType);
                    break;
                default:
                    throw new NotSupportedException(assetType + " is not supported.");
            }

            return CreateWorkitem(asset, parent, entityContainer);
        }
        internal Workitem(Asset asset, Workitem parent, IEntityContainer entityContainer) : base(asset, entityContainer) {
            Parent = parent;

            //TODO maybe make one more constructor for tests instead of this?
            // the following check is for unit tests            
            if(asset == null || asset.Children == null) {
                return;
            }

            if(!SupportedTypes.Contains(asset.AssetType.Token)) {
                throw new ArgumentException(string.Format("Illegal asset type, '{0}' is not supported.", asset.AssetType.Token));
            }

            foreach (var childAsset in asset.Children.Where(childAsset => DataLayer.ShowAllTasks || DataLayer.AssetPassesShowMyTasksFilter(childAsset))) {
                Children.Add(WorkitemFactory.CreateWorkitem(childAsset, this, entityContainer));
                Children.Sort(new WorkitemComparer(TestType, TaskType));
            }

            Children.TrimExcess();
        }
        internal Asset CreateAssetForSecondaryWorkitem(string typeToken, Workitem parent) {
            var type = ResolveAssetTypeFor(typeToken);

            try {
                var asset = new Asset(type);

                SetupAssetAttributes(asset, typeToken);
                SetAssetAttribute(asset, "Parent", parent.Asset.Oid);
                LoadAssetAttribute(asset, "Scope.Name", currentProject.GetProperty(Entity.NameProperty));
                LoadAssetAttribute(asset, "Parent.Name", parent.GetProperty(Entity.NameProperty));
                LoadAssetAttribute(asset, "Timebox.Name", parent.GetProperty("Timebox.Name"));

                parent.Asset.Children.Add(asset);

                return asset;
            } catch(MetaException ex) {
                throw new DataLayerException("Cannot create new " + typeToken, ex);
            } catch(APIException ex) {
                throw new DataLayerException("Cannot create new " + typeToken, ex);
            }
        }
Beispiel #8
0
        internal Workitem(Asset asset, Workitem parent, IEntityContainer entityContainer) : base(asset, entityContainer)
        {
            Parent = parent;

            //TODO maybe make one more constructor for tests instead of this?
            // the following check is for unit tests
            if (asset == null || asset.Children == null)
            {
                return;
            }

            if (!SupportedTypes.Contains(asset.AssetType.Token))
            {
                throw new ArgumentException(string.Format("Illegal asset type, '{0}' is not supported.", asset.AssetType.Token));
            }

            foreach (var childAsset in asset.Children.Where(childAsset => DataLayer.ShowAllTasks || DataLayer.AssetPassesShowMyTasksFilter(childAsset)))
            {
                Children.Add(WorkitemFactory.CreateWorkitem(childAsset, this, entityContainer));
                Children.Sort(new WorkitemComparer(TestType, TaskType));
            }

            Children.TrimExcess();
        }
        private bool ValidateWorkitemAndCommitOnSuccess(Workitem item, IDictionary<Asset, double> efforts, IDictionary<Asset, List<RequiredFieldsDto>> validationResults) {
            var itemValidationResult = requiredFieldsValidator.Validate(item.Asset);

            if(itemValidationResult.Count == 0) {
                item.CommitChanges();
                //TODO do we really need 2 commits effort? in item.ComitChanges() effort already commited
                CommitEffort(efforts, item.Asset);
                return true;
            }

            validationResults.Add(item.Asset, itemValidationResult);
            return false;
        }
 // TODO refactor, move logic to Controller
 private void UpdateMenuItemsVisibility(Workitem workitem) {
     miSave.Enabled = workitem != null && workitem.HasChanges && !(workitem.Parent != null && workitem.Parent.IsVirtual);
     miRevert.Enabled = workitem != null && workitem.HasChanges;
     miSignup.Enabled = workitem != null && !workitem.IsMine() && workitem.CanSignup && !workitem.IsVirtual;
     miQuickClose.Enabled = workitem != null && workitem.CanQuickClose && !workitem.IsVirtual;
     miClose.Enabled = workitem != null && !workitem.IsVirtual;
     miNewTask.Enabled = workitem != null && AddTaskCommandEnabled;
     miNewTest.Enabled = workitem != null && AddTestCommandEnabled;
     miNewDefect.Enabled = AddDefectCommandEnabled;
 }
        /// <summary>
        /// Refreshes data for Asset wrapped by specified Workitem.
        /// </summary>
        // TODO refactor
        public void RefreshAsset(Workitem workitem, IList<Asset> containingAssetCollection) {
            try {
                var stateDef = workitem.Asset.AssetType.GetAttributeDefinition("AssetState");
                
                var query = new Query(workitem.Asset.Oid.Momentless, false);
                AddSelection(query, workitem.TypePrefix);
                query.Selection.Add(stateDef);
                
                var newAssets = connector.Services.Retrieve(query);

                var containedIn = workitem.Parent == null ? containingAssetCollection : workitem.Parent.Asset.Children;

                if(newAssets.TotalAvaliable != 1) {
                    containedIn.Remove(workitem.Asset);
                    return;
                }

                var newAsset = newAssets.Assets[0];
                var newAssetState = (AssetState) newAsset.GetAttribute(stateDef).Value;
                
                if(newAssetState == AssetState.Closed) {
                    containedIn.Remove(workitem.Asset);
                    return;
                }

                containedIn[containedIn.IndexOf(workitem.Asset)] = newAsset;
                newAsset.Children.AddRange(workitem.Asset.Children);
            } 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 CloseItem(Workitem workitem) {
     RunTaskAsync(view.GetWaitCursor(),
                  workitem.Close,
                  () => { workitem.Remove(); EventDispatcher.Notify(null, new ModelChangedArgs(EventReceiver.WorkitemView, EventContext.WorkitemsChanged)); },
                  ex =>
                  {
                      if (ex.GetType() == typeof(ValidatorException))
                      {
                          Logger.Warn("Cannot save workitem before closing it because of validation errors", ex);
                          view.ShowValidationInformationDialog(ex.Message);
                      }
                      else if (ex.GetType() == typeof(DataLayerException))
                      {
                          Logger.Error("Failed to close workitem", ex);
                          view.ShowErrorMessage("Server communication error. Failed to close workitem. " + Environment.NewLine + ex.Message);
                      }
                  });
 }
 public void Commit(Workitem item) {
     dataLayer.CommitAsset(Efforts, item.Asset);
 }
 public void Revert(Workitem item) {
     item.Asset.RejectChanges();
     Efforts.Remove(item.Asset);
 }
 public Workitem CreateWorkitem(string assetType, Workitem parent, IEntityContainer entityContainer) {
     var assetFactory = new AssetFactory(this, CurrentProject, LoggerFactory, AttributesToQuery);
     return WorkitemFactory.CreateWorkitem(assetFactory, assetType, parent, entityContainer);
 }
 public Asset Refresh(Workitem item) {
     return dataLayer.RefreshAsset(item, AllAssets);
 }
 public void Add(Workitem item) {
     AllAssets.Add(item.Asset);
 }
 public static Workitem CreateWorkitem(Asset asset, Workitem parent, IEntityContainer entityContainer) {
     return asset.Oid.IsNull ? CreateVirtualWorkitem(asset, parent, entityContainer) : CreatePersistentWorkitem(asset, parent, entityContainer);
 }
 public void SelectWorkitem(Workitem item) {
     var foundNode = tvWorkitems.FindNodeByMather(node => {
                                                      var descriptor = node.Tag as WorkitemDescriptor;
                                                      return descriptor != null && item.Equals(descriptor.Workitem);
                                                  });
     if(foundNode != null) {
         tvWorkitems.SelectedNode = foundNode;
         SendKeys.Send("{F2}");
     }
 }
 private static Workitem CreateVirtualWorkitem(Asset asset, Workitem parent, IEntityContainer entityContainer) {
     return new VirtualWorkitem(asset, parent, entityContainer);
 }
 private static Workitem CreatePersistentWorkitem(Asset asset, Workitem parent, IEntityContainer entityContainer) {
     return new Workitem(asset, parent, entityContainer);
 }
 internal VirtualWorkitem(Asset asset, Workitem parent, IEntityContainer entityContainer) : base(asset, parent, entityContainer) { }
 public void Refresh(Workitem item) {
     dataLayer.RefreshAsset(item, AllAssets);
 }