private void AddRowToScalars() { IList <IDataListItemModel> blankList = ScalarCollection.Where(c => c.IsBlank).ToList(); if (blankList.Count == 0) { IDataListItemModel scalar = DataListItemModelFactory.CreateDataListModel(string.Empty); ScalarCollection.Add(scalar); Validator.Add(scalar); } }
/// <summary> /// Sorts the scalars. /// </summary> private void SortScalars() { IList <IDataListItemModel> newScalarCollection = ScalarCollection.OrderBy(c => c.DisplayName).Where(c => !c.IsBlank).ToList(); ScalarCollection.Clear(); foreach (IDataListItemModel item in newScalarCollection) { ScalarCollection.Add(item); } ScalarCollection.Add(DataListItemModelFactory.CreateDataListModel(string.Empty)); }
void ProcessScalarPart(IDataListVerifyPart part) { var scalarsToRemove = ScalarCollection.Where(c => c.Name == part.Field); scalarsToRemove.ToList().ForEach(scalarToRemove => { if (scalarToRemove != null) { scalarToRemove.IsUsed = false; } }); }
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(); }
void AddRowToScalars() { List <IDataListItemModel> blankList = ScalarCollection.Where(c => c.IsBlank).ToList(); if (blankList.Count != 0) { return; } IDataListItemModel scalar = DataListItemModelFactory.CreateDataListModel(string.Empty); ScalarCollection.Add(scalar); }
public string WriteToResourceModel() { ScalarCollection.ForEach(_scalarHandler.FixNamingForScalar); _recordsetHandler.AddRecordsetNamesIfMissing(); var result = GetDataListString(); if (Resource != null) { Resource.DataList = result; } return(result); }
/// <summary> /// Creates the list of data list item view model to bind to. /// </summary> /// <param name="_resource">The resource model.</param> /// <param name="errorString">The error string.</param> /// <returns></returns> private void CreateListsOfIDataListItemModelToBindTo(out string errorString) { ErrorResultTO errors = new ErrorResultTO(); errorString = string.Empty; if (!string.IsNullOrEmpty(_resource.DataList)) { IBinaryDataList binarnyDL = CreateBinaryDataListFromXmlData(_resource.DataList, out errors); if (!errors.HasErrors()) { ConvertBinaryDataListToListOfIDataListItemModels(binarnyDL, out errorString); } else { string errorMessage = string.Empty; foreach (string error in errors.FetchErrors()) { errorMessage += error; } throw new Exception(errorMessage); } _compiler.ForceDeleteDataListByID(binarnyDL.UID); } else { RecsetCollection = new OptomizedObservableCollection <IDataListItemModel>(); AddRecordSet(); ScalarCollection = new OptomizedObservableCollection <IDataListItemModel>(); ScalarCollection.Add(DataListItemModelFactory.CreateDataListModel(string.Empty)); } BaseCollection = new OptomizedObservableCollection <DataListHeaderItemModel>(); DataListHeaderItemModel VarNode = DataListItemModelFactory.CreateDataListHeaderItem("Variables"); if (ScalarCollection.Count == 0) { ScalarCollection.Add(DataListItemModelFactory.CreateDataListModel(string.Empty)); } VarNode.Children = ScalarCollection; BaseCollection.Add(VarNode); DataListHeaderItemModel RecordsetsNode = DataListItemModelFactory.CreateDataListHeaderItem("Recordsets"); if (RecsetCollection.Count == 0) { AddRecordSet(); } RecordsetsNode.Children = RecsetCollection; BaseCollection.Add(RecordsetsNode); }
public void ScalarCollectionJson() { ScalarCollection sc = new ScalarCollection(); sc.AddInt(2); sc.AddInt(3); sc.AddInt(4); sc.AddInt(5); sc.AddInt(6); sc.AddInt(7); SimplTypesScope scalarCollectionSimplTypesScope = SimplTypesScope.Get( "scalarCollectionTScope", typeof(ScalarCollection)); TestMethods.TestSimplObject(sc, scalarCollectionSimplTypesScope, Format.Json); }
public void RemoveUnusedDataListItems(IList <IDataListVerifyPart> parts, bool async) { IList <IDataListItemModel> tmpRecsets = new List <IDataListItemModel>(); foreach (IDataListVerifyPart part in parts) { if (part.IsScalar) { IDataListItemModel scalarToRemove = ScalarCollection.FirstOrDefault(c => c.Name == part.Field); if (scalarToRemove != null) { ScalarCollection.Remove(scalarToRemove); Validator.Remove(scalarToRemove); } } else { IDataListItemModel recsetToRemove = RecsetCollection.FirstOrDefault(c => c.Name == part.Recordset && c.IsRecordset); if (string.IsNullOrEmpty(part.Field)) { if (recsetToRemove != null) { tmpRecsets.Add(recsetToRemove); } } else { IDataListItemModel childToRemove = recsetToRemove.Children.FirstOrDefault(c => c.Name == part.Field && c.IsField); if (childToRemove != null) { recsetToRemove.Children.Remove(childToRemove); recsetToRemove.Validator.Remove(childToRemove); } } } } foreach (IDataListItemModel item in tmpRecsets) { RecsetCollection.Remove(item); Validator.Remove(item); } WriteToResourceModel(); Mediator.SendMessage(MediatorMessages.UpdateIntelisense, this); }
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); } }
/// <summary> /// Sorts the scalars. /// </summary> private void SortScalars(bool ascending) { IList <IDataListItemModel> newScalarCollection; if (ascending) { newScalarCollection = ScalarCollection.OrderBy(c => c.DisplayName) .Where(c => !c.IsBlank).ToList(); } else { newScalarCollection = ScalarCollection.OrderByDescending(c => c.DisplayName) .Where(c => !c.IsBlank).ToList(); } ScalarCollection.Clear(); foreach (var item in newScalarCollection) { ScalarCollection.Add(item); } ScalarCollection.Add(DataListItemModelFactory.CreateDataListModel(string.Empty)); }
public void RemoveUnusedDataListItems() { var unusedScalars = ScalarCollection.Where(c => c.IsUsed == false).ToList(); if (unusedScalars.Any()) { foreach (var dataListItemModel in unusedScalars) { ScalarCollection.Remove(dataListItemModel); } } var unusedRecordsets = RecsetCollection.Where(c => c.IsUsed == false).ToList(); if (unusedRecordsets.Any()) { foreach (var dataListItemModel in unusedRecordsets) { RecsetCollection.Remove(dataListItemModel); } } foreach (var recset in RecsetCollection) { if (recset.Children.Count > 0) { var unusedRecsetChildren = recset.Children.Where(c => c.IsUsed == false).ToList(); if (unusedRecsetChildren.Any()) { foreach (var unusedRecsetChild in unusedRecsetChildren) { recset.Children.Remove(unusedRecsetChild); } } } } WriteToResourceModel(); EventPublisher.Publish(new UpdateIntellisenseMessage()); }
/// <summary> /// Converts a binary data list to list a data list item view models. /// </summary> /// <param name="dataListToConvert">The data list to convert.</param> /// <param name="errorString">The error string.</param> /// <returns></returns> private void ConvertBinaryDataListToListOfIDataListItemModels(IBinaryDataList dataListToConvert, out string errorString) { errorString = string.Empty; RecsetCollection.Clear(); ScalarCollection.Clear(); IList <IBinaryDataListEntry> listOfEntries = dataListToConvert.FetchAllEntries(); foreach (var entry in listOfEntries) { if (entry.IsRecordset) { var recset = DataListItemModelFactory.CreateDataListModel(entry.Namespace, entry.Description, entry.ColumnIODirection); recset.IsEditable = entry.IsEditable; foreach (var col in entry.Columns) { var child = DataListItemModelFactory.CreateDataListModel(col.ColumnName, col.ColumnDescription, col.ColumnIODirection); child.Parent = recset; child.IsEditable = col.IsEditable; recset.Children.Add(child); } RecsetCollection.Add(recset); } else { var scalar = DataListItemModelFactory.CreateDataListModel(entry.Namespace, entry.Description, entry.ColumnIODirection); scalar.IsEditable = entry.IsEditable; ScalarCollection.Add(scalar); } } }
public void RemoveDataListItem(IDataListItemModel itemToRemove) { if (itemToRemove != null) { if (!itemToRemove.IsRecordset && !itemToRemove.IsField) { ScalarCollection.Remove(itemToRemove); Validator.Remove(itemToRemove); } else if (itemToRemove.IsRecordset) { RecsetCollection.Remove(itemToRemove); Validator.Remove(itemToRemove); } else { foreach (IDataListItemModel recset in RecsetCollection) { recset.Children.Remove(itemToRemove); recset.Validator.Remove(itemToRemove); } } } }
public void AddMissingDataListItems(IList <IDataListVerifyPart> parts, bool async) { IList <IDataListItemModel> tmpRecsetList = new List <IDataListItemModel>(); foreach (var part in parts) { if (part.IsScalar) { if (ScalarCollection.FirstOrDefault(c => c.Name == part.Field) == null) { IDataListItemModel scalar = DataListItemModelFactory.CreateDataListModel(part.Field, part.Description, enDev2ColumnArgumentDirection .None); if (ScalarCollection.Count > ScalarCollection.Count - 1) { ScalarCollection.Insert(ScalarCollection.Count - 1, scalar); } else { ScalarCollection.Insert(ScalarCollection.Count, scalar); } } } else { IDataListItemModel recsetToAddTo = RecsetCollection. FirstOrDefault(c => c.Name == part.Recordset && c.IsRecordset); IDataListItemModel tmpRecset = tmpRecsetList.FirstOrDefault(c => c.Name == part.Recordset); if (recsetToAddTo != null) { if (recsetToAddTo.Children.FirstOrDefault(c => c.Name == part.Field) == null) { IDataListItemModel child = DataListItemModelFactory.CreateDataListModel(part.Field, part.Description, recsetToAddTo); if (recsetToAddTo.Children.Count > 0) { recsetToAddTo.Children.Insert(recsetToAddTo.Children.Count - 1, child); } else { recsetToAddTo.Children.Add(child); } } } else if (tmpRecset != null) { IDataListItemModel child = DataListItemModelFactory.CreateDataListModel (part.Field, part.Description, tmpRecset); child.Name = part.Recordset + "()." + part.Field; tmpRecset.Children.Add(child); } else { IDataListItemModel recset = DataListItemModelFactory.CreateDataListModel (part.Recordset, part.Description, enDev2ColumnArgumentDirection.None); tmpRecsetList.Add(recset); } } } foreach (var item in tmpRecsetList) { if (item.Children.Count == 0) { item.Children.Add(DataListItemModelFactory.CreateDataListModel(string.Empty, string.Empty, item)); } if (RecsetCollection.Count > 0) { RecsetCollection.Insert(RecsetCollection.Count - 1, item); } else { RecsetCollection.Add(item); } } WriteToResourceModel(); EventPublisher.Publish(new UpdateIntellisenseMessage()); RemoveBlankScalars(); RemoveBlankRecordsets(); RemoveBlankRecordsetFields(); if (parts.Count > 0) { AddBlankRow(null); } }
public void AddMissingDataListItems(IList <IDataListVerifyPart> parts, bool async) { IList <IDataListItemModel> tmpRecsetList = new List <IDataListItemModel>(); foreach (IDataListVerifyPart part in parts) { if (part.IsScalar) { IDataListItemModel scalar = DataListItemModelFactory.CreateDataListModel(part.Field, part.Description, enDev2ColumnArgumentDirection.None); ScalarCollection.Insert(ScalarCollection.Count - 1, scalar); Validator.Add(scalar); } else { IDataListItemModel recsetToAddTo = RecsetCollection.FirstOrDefault(c => c.Name == part.Recordset && c.IsRecordset); IDataListItemModel tmpRecset = tmpRecsetList.FirstOrDefault(c => c.Name == part.Recordset); if (recsetToAddTo != null) { IDataListItemModel child = DataListItemModelFactory.CreateDataListModel(part.Field, part.Description, recsetToAddTo); if (recsetToAddTo.Children.Count > 0) { recsetToAddTo.Children.Insert(recsetToAddTo.Children.Count - 1, child); } else { recsetToAddTo.Children.Add(child); } recsetToAddTo.Validator.Add(child); } else if (tmpRecset != null) { IDataListItemModel child = DataListItemModelFactory.CreateDataListModel(part.Field, part.Description, tmpRecset); tmpRecset.Children.Add(child); tmpRecset.Validator.Add(child); } else { IDataListItemModel recset = DataListItemModelFactory.CreateDataListModel(part.Recordset, part.Description, enDev2ColumnArgumentDirection.None); tmpRecsetList.Add(recset); } } } foreach (IDataListItemModel item in tmpRecsetList) { if (item.Children.Count == 0) { item.Children.Add(DataListItemModelFactory.CreateDataListModel(string.Empty, string.Empty, item)); } if (RecsetCollection.Count > 0) { RecsetCollection.Insert(RecsetCollection.Count - 1, item); } else { RecsetCollection.Add(item); } Validator.Add(item); } WriteToResourceModel(); Mediator.SendMessage(MediatorMessages.UpdateIntelisense, this); RemoveBlankScalars(); RemoveBlankRecordsets(); RemoveBlankRecordsetFields(); AddBlankRow(null); }