Example #1
0
			private FieldDescriptionPlus(FieldDescription fldDsc)
			{
				if (fldDsc == null) return;
				var mbc = MetaBriefcase.OpenInstance;
				if (mbc == null) return;

				_fieldDescription = fldDsc;
				var catsWhereThisFieldWasAssignedBefore = mbc.Categories.Where(cat => cat != null && cat.FieldDescriptionIds != null && cat.Id != null
					&& (fldDsc.JustAssignedToCats == null || !fldDsc.JustAssignedToCats.Contains(cat.Id)) && cat.FieldDescriptionIds.Contains(fldDsc.Id));

				if (catsWhereThisFieldWasAssignedBefore?.Any() == true)
				{
					if (GetIsElevated()) _isAllowDelete = PermissionLevels.WithCaution;
				}
				else _isAllowDelete = PermissionLevels.Yes;

				string currCatId = mbc.CurrentCategoryId;
				if (!string.IsNullOrEmpty(currCatId))
				{
					if (fldDsc.JustAssignedToCats.Contains(currCatId)) _isAllowUnassign = PermissionLevels.Yes;
					else
					{
						if (GetIsElevated()) _isAllowUnassign = PermissionLevels.WithCaution;
					}
				}
				else _isAllowUnassign = PermissionLevels.Yes;
			}
		private async Task SelectAssFldDsc(FieldDescription fldDsc)
		{
			var vm = VM;
			if (vm != null)
			{
				await vm.SetCurrentFieldDescriptionAsync(fldDsc);
				UnassignedLV.DeselectRange(new ItemIndexRange(UnassignedLV.SelectedIndex, 1));
			}
		}
		internal static bool Check(FieldDescription fldDsc)
		{
			return fldDsc != null && fldDsc.Id != DEFAULT_ID && fldDsc.PossibleValues != null && !string.IsNullOrWhiteSpace(fldDsc.Caption);
		}
Example #4
0
		public Task<bool> RemoveFieldDescriptionAsync(FieldDescription fldDsc)
		{
			return RunFunctionIfOpenAsyncTB(async delegate
			{
				if (fldDsc != null && (fldDsc.IsJustAdded || IsElevated))
				{
					bool isRemoved = false;
					var catsWithFldDsc = new List<string>();
					await RunInUiThreadAsync(delegate
					{
						foreach (var cat in _categories)
						{
							if (cat.RemoveFieldDescription(fldDsc)) catsWithFldDsc.Add(cat.Id);
						}
						isRemoved = _fieldDescriptions.Remove(fldDsc);
					}).ConfigureAwait(false);

					await _rubbishBin.AddFieldDescriptionAsync(catsWithFldDsc, fldDsc);
					if (CurrentFieldDescriptionId == fldDsc.Id)
					{
						if (_fieldDescriptions.Any()) CurrentFieldDescriptionId = _fieldDescriptions[0]?.Id;
						else CurrentFieldDescriptionId = null;
					}
					return isRemoved;
				}
				return false;
			});
		}
		//public void Dispose()
		//{
		//	if (_isDisposed) return;
		//	_isDisposed = true;

		//	_possibleValues?.Dispose();
		//	_possibleValues = null;
		//}

		// private volatile bool _isDisposed = false;
		//[IgnoreDataMember]
		//public bool IsDisposed { get { return _isDisposed; } }
		#endregion ctor and dispose


		internal static void Copy(FieldDescription source, ref FieldDescription target)
		{
			if (source != null && target != null)
			{
				target.Caption = source._caption;
				target.Id = source._id;
				target.IsCustom = source._isCustom;
				// target.IsJustAdded = source._isJustAdded; // we don't actually want this
				// target.JustAssignedToCats = source._justAssignedToCats; // we don't actually want this
				target.IsAnyValueAllowed = source._isAnyValueAllowed;
				FieldValue.Copy(source._possibleValues, target.PossibleValues);
				target.Typez = source._typez;
			}
		}
		internal static void Copy(SwitchableObservableCollection<FieldDescription> source, ref SwitchableObservableCollection<FieldDescription> target)
		{
			if (source != null && target != null)
			{
				target.IsObserving = false;
				target.Clear();
				foreach (var sourceRecord in source)
				{
					var targetRecord = new FieldDescription();
					Copy(sourceRecord, ref targetRecord);
					target.Add(targetRecord);
				}
				target.IsObserving = true;
			}
		}
Example #7
0
		public Task<bool> UnassignFieldDescriptionFromCurrentCategoryAsync(FieldDescription fldDsc)
		{
			return RunFunctionIfOpenAsyncTB(async delegate
			{
				if (fldDsc == null || _currentCategory == null || (!fldDsc.JustAssignedToCats.Contains(_currentCategoryId) && !IsElevated)) return false;

				bool isRemoved = false;
				await RunInUiThreadAsync(() => isRemoved = _currentCategory.RemoveFieldDescription(fldDsc)).ConfigureAwait(false);
				return isRemoved;
			});
		}
Example #8
0
		private void UpdateCurrentFieldDescription2()
		{
			if (_fieldDescriptions != null && _currentFieldDescriptionId != null)
			{
				CurrentFieldDescription = _fieldDescriptions.FirstOrDefault(fd => fd.Id == _currentFieldDescriptionId);
				//CurrentFieldDescription = _currentCategory.FieldDescriptions.FirstOrDefault(fd => fd.Id == _currentFieldDescriptionId);
			}
			else
			{
				CurrentFieldDescription = null;
			}
		}
Example #9
0
		public Task SetCurrentFieldDescriptionAsync(FieldDescription newItem)
		{
			return RunFunctionIfOpenAsyncT(async delegate
			{
				var mbc = _briefcase?.MetaBriefcase;
				if (mbc == null) return;

				await mbc.SetCurrentFieldDescriptionAsync(newItem);
			});
		}
Example #10
0
		internal bool RemoveFieldDescription(FieldDescription fdToBeRemoved)
		{
			if (fdToBeRemoved != null)
			{
				fdToBeRemoved.RemoveFromJustAssignedToCats(this);
				_fieldDescriptions?.Remove(fdToBeRemoved);
				bool isOk = _fieldDescriptionIds.Remove(fdToBeRemoved.Id);
				return isOk;
			}
			return false;
		}
Example #11
0
		public Task<bool> AddNewFieldDescriptionAsync()
		{
			return RunFunctionIfOpenAsyncTB(async delegate
			{
				string name = RuntimeData.GetText("NewFieldDescription");
				var fldDsc = new FieldDescription(name, true, true);

				if (FieldDescription.Check(fldDsc) && !_fieldDescriptions.Any(fd => fd.Caption == fldDsc.Caption || fd.Id == fldDsc.Id))
				{
					await RunInUiThreadAsync(() => _fieldDescriptions.Add(fldDsc)).ConfigureAwait(false);
					return true;
				}
				return false;
			});
		}
Example #12
0
		public Task<bool> UnassignFieldDescriptionFromCurrentCategoryAsync(FieldDescription fldDsc)
		{
			return RunFunctionIfOpenAsyncTB(async delegate
			{
				var mbc = _briefcase?.MetaBriefcase;
				if (mbc == null) return false;

				if (await mbc.UnassignFieldDescriptionFromCurrentCategoryAsync(fldDsc))
				{
					await UpdateAssignedUnassignedFieldsAsync().ConfigureAwait(false);
					return true;
				}
				return false;
			});
		}
Example #13
0
		public Task SetCurrentFieldDescriptionAsync(FieldDescription fldDsc)
		{
			return RunFunctionIfOpenAsyncA(delegate
			{
				if (fldDsc != null)
				{
					CurrentFieldDescriptionId = fldDsc.Id;
				}
			});
		}
Example #14
0
		private bool CopyXMLPropertiesFrom(MetaBriefcaseRubbishBin source)
		{
			if (source == null) return false;

			Category.Copy(source._deletedCategories, ref _deletedCategories, _mbc.FieldDescriptions);

			_deletedFieldDescriptions.Clear();
			if (source._deletedFieldDescriptions != null)
			{
				foreach (var srcLine in source._deletedFieldDescriptions)
				{
					var fldDsc = new FieldDescription();
					FieldDescription.Copy(srcLine.Item2, ref fldDsc);
					_deletedFieldDescriptions.Add(Tuple.Create(srcLine.Item1, fldDsc));
				}
			}

			_deletedFieldValues.Clear();
			if (source._deletedFieldValues != null)
			{
				foreach (var srcLine in source._deletedFieldValues)
				{
					var fldDsc = new FieldDescription();
					FieldDescription.Copy(srcLine.Item1, ref fldDsc);
					var fldVal = new FieldValue();
					FieldValue.Copy(srcLine.Item2, ref fldVal);
					_deletedFieldValues.Add(Tuple.Create(fldDsc, fldVal));
				}
			}

			return true;
		}
Example #15
0
		internal Tuple<FieldDescription, FieldValue> GetPossibleValue2(FieldDescription fieldDescription, string vaalue)
		{
			Tuple<FieldDescription, FieldValue> result = _deletedFieldValues.FirstOrDefault(pv => pv.Item1.Id == fieldDescription.Id && pv.Item2.Vaalue == vaalue);
			return result;
		}
Example #16
0
		internal Task AddPossibleValueAsync(FieldDescription fieldDescription, FieldValue fieldValue)
		{
			if (fieldDescription == null || fieldValue == null) return Task.CompletedTask;
			return RunFunctionIfOpenAsyncA(() =>
			{
				_deletedFieldValues.RemoveAll(pv => pv.Item1.Id == fieldDescription.Id && pv.Item2.Vaalue == fieldValue.Vaalue);
				_deletedFieldValues.Add(Tuple.Create(fieldDescription, fieldValue));
			});
		}
Example #17
0
		internal Task AddFieldDescriptionAsync(List<string> catsWithFldDsc, FieldDescription fieldDescription)
		{
			if (catsWithFldDsc == null || fieldDescription == null) return Task.CompletedTask;
			return RunFunctionIfOpenAsyncA(() =>
			{
				_deletedFieldDescriptions.RemoveAll(fd => fd.Item2.Caption == fieldDescription.Caption);
				_deletedFieldDescriptions.Add(Tuple.Create(catsWithFldDsc, fieldDescription));
			});
		}
Example #18
0
		/// <summary>
		/// Save metaBriefcase, in case there is a crash before the next Suspend.
		/// LOLLO NOTE This is the only method that is not called by SettingsVM, which saves when closing.
		/// </summary>
		/// <param name="fldDsc"></param>
		/// <param name="newFldVal"></param>
		/// <param name="save"></param>
		/// <returns></returns>
		public async Task<FieldValue> AddPossibleValueToFieldDescriptionAsync(FieldDescription fldDsc, string newVaalue)
		{
			if (fldDsc == null || string.IsNullOrEmpty(newVaalue)) return null;

			FieldValue newFldVal = null;
			bool isAdded = false;

			await RunFunctionIfOpenAsyncT(async delegate
			{
				if (fldDsc == null || string.IsNullOrEmpty(newVaalue)) return;

				var recycledFldVal = _rubbishBin.GetPossibleValue2(fldDsc, newVaalue);
				newFldVal = recycledFldVal?.Item2 ?? new FieldValue(newVaalue, true, true);

				await RunInUiThreadAsync(() => isAdded = fldDsc.AddPossibleValue(newFldVal)).ConfigureAwait(false);
				if (isAdded)
				{
					isAdded = await Save2Async().ConfigureAwait(false);
					if (isAdded) _oneDriveReaderWriter.RaiseUpdateOneDriveMetaBriefcaseRequested();
				}
			}).ConfigureAwait(false);

			if (isAdded) return newFldVal; else return null;
		}
Example #19
0
		public Task<bool> AssignFieldDescriptionToCurrentCategoryAsync(FieldDescription fldDsc)
		{
			return RunFunctionIfOpenAsyncTB(async delegate
			{
				if (fldDsc == null || _currentCategory == null) return false;

				bool isAdded = false;
				await RunInUiThreadAsync(() => isAdded = _currentCategory.AddFieldDescription(fldDsc)).ConfigureAwait(false);
				return isAdded;
			});
		}
Example #20
0
		private async Task<bool> TrySetFieldValueId(FieldDescription fldDsc, string newVaalue)
		{
			if (fldDsc == null) return false;
			var bc = Briefcase.GetCurrentInstance();

			var availableFldVal = fldDsc.GetValueFromPossibleValues(newVaalue);
			if (availableFldVal != null)
			{
				FieldValueId = availableFldVal.Id;
				return true;
			}

			if (fldDsc.IsAnyValueAllowed && bc?.IsWantAndCannotUseOneDrive == false)
			{
				var mb = MetaBriefcase.OpenInstance;
				if (mb != null)
				{
					// LOLLO NOTE save metaBriefcase, in case there is a crash before the next Suspend.
					// This problem actually affects all XML-based stuff, because they only save on closing.
					// We only take extra care of MetaBriefcase because Briefcase and Binder do not save critical data.
					// The DB, instead, saves at once. If there is a crash between the DB and the XML being saved, the next startup will have corrupt data.
					var newFldVal = await mb.AddPossibleValueToFieldDescriptionAsync(fldDsc, newVaalue);
					if (newFldVal == null) return false;

					FieldValueId = newFldVal.Id;
					return true;
				}
			}
			return false;
		}
Example #21
0
		//public void Dispose()
		//{
		//	if (_isDisposed) return;
		//	_isDisposed = true;

		//	_fieldDescriptions?.Dispose();
		//	_fieldDescriptionIds?.Dispose();
		//}

		//private volatile bool _isDisposed = false;
		//[IgnoreDataMember]
		//public bool IsDisposed { get { return _isDisposed; } }
		#endregion ctor and dispose


		internal bool AddFieldDescription(FieldDescription newFldDsc)
		{
			if (newFldDsc != null && FieldDescriptions.All(fds => fds.Caption != newFldDsc.Caption && fds.Id != newFldDsc.Id))
			{
				_fieldDescriptions.Add(newFldDsc);
				_fieldDescriptionIds.Add(newFldDsc.Id);
				newFldDsc.AddToJustAssignedToCats(this);
				return true;
			}
			return false;
		}