/// <summary> /// Creates the list of data list item view model to bind to. /// </summary> /// <param name="errorString">The error string.</param> /// <returns></returns> public void CreateListsOfIDataListItemModelToBindTo(out string errorString) { errorString = string.Empty; if (!string.IsNullOrEmpty(Resource.DataList)) { ErrorResultTO errors = new ErrorResultTO(); try { if (!string.IsNullOrEmpty(Resource.DataList)) { ConvertDataListStringToCollections(Resource.DataList); } } catch (Exception) { errors.AddError(ErrorResource.InvalidVariableList); } } else { RecsetCollection.Clear(); ScalarCollection.Clear(); ComplexObjectCollection.Clear(); _recordsetHandler.AddRecordSet(); } BaseCollection = new OptomizedObservableCollection <DataListHeaderItemModel>(); DataListHeaderItemModel variableNode = DataListItemModelFactory.CreateDataListHeaderItem("Variable"); if (ScalarCollection.Count == 0) { IScalarItemModel dataListItemModel = DataListItemModelFactory.CreateScalarItemModel(string.Empty); dataListItemModel.IsComplexObject = false; dataListItemModel.AllowNotes = false; ScalarCollection.Add(dataListItemModel); } BaseCollection.Add(variableNode); DataListHeaderItemModel recordsetsNode = DataListItemModelFactory.CreateDataListHeaderItem("Recordset"); if (RecsetCollection.Count == 0) { _recordsetHandler.AddRecordSet(); } BaseCollection.Add(recordsetsNode); DataListHeaderItemModel complexObjectNode = DataListItemModelFactory.CreateDataListHeaderItem("Object"); BaseCollection.Add(complexObjectNode); AddBlankRow(null); BaseCollection[0].Children = ScalarCollection; BaseCollection[1].Children = RecsetCollection; BaseCollection[2].Children = ComplexObjectCollection; WriteToResourceModel(); }
public void RemoveDataListItem(IDataListItemModel itemToRemove) { if (itemToRemove == null) { return; } var complexObj = itemToRemove as IComplexObjectItemModel; if (complexObj != null) { var complexObjectItemModels = complexObj.Children; var allChildren = complexObjectItemModels.Flatten(model => model.Children).ToList(); var notUsedItems = allChildren.Where(x => !x.IsUsed).ToList(); foreach (var complexObjectItemModel in notUsedItems) { RemoveUnusedChildComplexObjects(complexObj, complexObjectItemModel); } if (complexObj.Children.Count == 0) { ComplexObjectCollection.Remove(complexObj); } else { complexObj.IsUsed = true; } } if (itemToRemove is IScalarItemModel) { var item = itemToRemove as IScalarItemModel; ScalarCollection.Remove(item); CheckDataListItemsForDuplicates(DataList); } else if (itemToRemove is IRecordSetItemModel) { var item = itemToRemove as IRecordSetItemModel; RecsetCollection.Remove(item); CheckDataListItemsForDuplicates(DataList); } else { foreach (var recset in RecsetCollection) { var item = itemToRemove as IRecordSetFieldItemModel; recset.Children.Remove(item); CheckDataListItemsForDuplicates(recset.Children); } } FindUnusedAndMissingCommand.RaiseCanExecuteChanged(); DeleteCommand.RaiseCanExecuteChanged(); }
private bool HasAnyUnusedItems() { if (!HasItems()) { return(false); } bool hasUnused; if (ScalarCollection != null) { hasUnused = ScalarCollection.Any(sc => !sc.IsUsed); if (hasUnused) { DeleteCommand.RaiseCanExecuteChanged(); return(true); } } if (RecsetCollection != null) { hasUnused = RecsetCollection.Any(sc => !sc.IsUsed); if (!hasUnused) { hasUnused = RecsetCollection.SelectMany(sc => sc.Children).Any(sc => !sc.IsUsed); } if (hasUnused) { DeleteCommand.RaiseCanExecuteChanged(); return(true); } } if (ComplexObjectCollection != null) { hasUnused = ComplexObjectCollection.Any(sc => !sc.IsUsed); if (hasUnused) { DeleteCommand.RaiseCanExecuteChanged(); return(true); } } return(false); }
private string GetDataListString() { StringBuilder result = new StringBuilder("<" + RootTag + ">"); foreach (var recSet in RecsetCollection.Where(model => !string.IsNullOrEmpty(model.DisplayName))) { IEnumerable <IDataListItemModel> filledRecordSet = recSet.Children.Where(c => !c.IsBlank && !c.HasError); IList <Dev2Column> cols = filledRecordSet.Select(child => DataListFactory.CreateDev2Column(child.DisplayName, child.Description, child.IsEditable, child.ColumnIODirection)).ToList(); AddItemToBuilder(result, recSet); result.Append(">"); foreach (var col in cols) { result.AppendFormat("<{0} {1}=\"{2}\" {3}=\"{4}\" {5}=\"{6}\" />", col.ColumnName , Description , col.ColumnDescription , IsEditable , col.IsEditable , GlobalConstants.DataListIoColDirection , col.ColumnIODirection); } result.Append("</"); result.Append(recSet.DisplayName); result.Append(">"); } IList <IScalarItemModel> filledScalars = ScalarCollection?.Where(scalar => !scalar.IsBlank && !scalar.HasError).ToList() ?? new List <IScalarItemModel>(); foreach (var scalar in filledScalars) { AddItemToBuilder(result, scalar); result.Append("/>"); } var complexObjectItemModels = ComplexObjectCollection.Where(model => !string.IsNullOrEmpty(model.DisplayName) && !model.HasError); foreach (var complexObjectItemModel in complexObjectItemModels) { _complexObjectHandler.AddComplexObjectsToBuilder(result, complexObjectItemModel); } result.Append("</" + RootTag + ">"); return(result.ToString()); }
public void ConvertDataListStringToCollections(string dataList) { RecsetCollection.Clear(); ScalarCollection.Clear(); ComplexObjectCollection.Clear(); try { var xDoc = new XmlDocument(); xDoc.LoadXml(dataList); if (xDoc.DocumentElement == null) { return; } var children = xDoc.DocumentElement.ChildNodes; foreach (XmlNode child in children) { if (DataListUtil.IsSystemTag(child.Name)) { continue; } if (IsJsonAttribute(child)) { _complexObjectHandler.AddComplexObjectFromXmlNode(child, null); } else { if (child.HasChildNodes) { _recordsetHandler.AddRecordSets(child); } else { AddScalars(child); } } } } catch (Exception e) { Dev2Logger.Error(e); } }