Exemplo n.º 1
0
        public void StopMovingElements()
        {
            try
            {
                MoveElementsTask moveElementsTask = (MoveElementsTask)AppTask;
                foreach (var uuid in moveElementsTask.Uuids)
                {
                    IStructureItem elementToMove = App.Kp2a.GetDb().KpDatabase.RootGroup.FindObject(uuid, true, null);
                    if (elementToMove.ParentGroup != Group)
                    {
                        App.Kp2a.GetDb().Dirty.Add(elementToMove.ParentGroup);
                    }
                }
            }
            catch (Exception e)
            {
                //don't crash if adding to dirty fails but log the exception:
                Kp2aLog.LogUnexpectedError(e);
            }

            AppTask = new NullTask();
            AppTask.SetupGroupBaseActivityButtons(this);
            BaseAdapter adapter = (BaseAdapter)ListAdapter;

            adapter.NotifyDataSetChanged();
        }
Exemplo n.º 2
0
 public MoveElement(IStructureItem elementToMove, PwGroup targetGroup, Context ctx, IKp2aApp app, OnFinish finish)
     : base(finish)
 {
     _elementToMove = elementToMove;
     _targetGroup = targetGroup;
     _ctx = ctx;
     _app = app;
 }
Exemplo n.º 3
0
        public Database FindDatabaseForElement(IStructureItem element)
        {
            var db = TryFindDatabaseForElement(element);

            if (db == null)
            {
                throw new Exception("Database element not found!");
            }
            return(db);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Looks for the root group of the given item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static PwGroup GetRootGroup(this IStructureItem item)
        {
            PwGroup group = item is PwGroup ? item as PwGroup : item.ParentGroup;

            while (group.ParentGroup != null)
            {
                group = group.ParentGroup;
            }
            return(group);
        }
Exemplo n.º 5
0
 public Database TryFindDatabaseForElement(IStructureItem element)
 {
     foreach (var db in OpenDatabases)
     {
         if (db.Elements.Contains(element))
         {
             return(db);
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Checks if the given item is directly or indirectly contained in the given parent
        /// </summary>
        /// <param name="item"></param>
        /// <param name="origParent"></param>
        /// <returns></returns>
        public static bool IsInsideParent(this IStructureItem item, IStructureItem parent)
        {
            Debug.Assert(null != item);
            Debug.Assert(null != parent);

            if (item.ParentGroup == null)
            {
                return(false);
            }
            return(item.ParentGroup == parent ||
                   IsInsideParent(item.ParentGroup, parent));
        }
Exemplo n.º 7
0
 public Database TryFindDatabaseForElement(IStructureItem element)
 {
     foreach (var db in OpenDatabases)
     {
         //we compare UUIDs and not by reference. this is more robust and works with history items as well
         if (db.Elements.Any(e => e.Uuid?.Equals(element.Uuid) == true))
         {
             return(db);
         }
     }
     return(null);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Compares the two databases. uses Asserts
        /// TODO: implement this with many more checks or use serialization?
        /// </summary>
        protected void AssertDatabasesAreEqual(PwDatabase db1, PwDatabase db2)
        {
            db1.RootGroup.GetObjects(true, null)
            .ForEach(
                item =>
            {
                IStructureItem foundItem = db2.RootGroup.FindObject(item.Uuid, true, null);
                Assert.IsNotNull(foundItem, "didn't find item with uuid=" + item.Uuid.ToHexString());
                Assert.IsTrue(item.ParentGroup.Uuid.EqualsValue(foundItem.ParentGroup.Uuid), "item.ParentGroup.Uuid (" + item.ParentGroup.Uuid + ") != " + foundItem.ParentGroup.Uuid);
            }
                );

            Assert.AreEqual(db1.RootGroup.GetObjects(true, null).Count(), db2.RootGroup.GetObjects(true, null).Count(), "Wrong Object Count");
        }
Exemplo n.º 9
0
		internal void RelocateGroups(PwObjectPool ppOrgStructure,
			PwObjectPool ppSrcStructure)
		{
			PwObjectList<PwGroup> vGroups = m_pgRootGroup.GetGroups(true);

			foreach(PwGroup pg in vGroups)
			{
				if((m_slStatus != null) && !m_slStatus.ContinueWork()) break;

				// PwGroup pgOrg = pgOrgStructure.FindGroup(pg.Uuid, true);
				IStructureItem ptOrg = ppOrgStructure.Get(pg.Uuid);
				if(ptOrg == null) continue;
				// PwGroup pgSrc = pgSrcStructure.FindGroup(pg.Uuid, true);
				IStructureItem ptSrc = ppSrcStructure.Get(pg.Uuid);
				if(ptSrc == null) continue;

				PwGroup pgOrgParent = ptOrg.ParentGroup;
				PwGroup pgSrcParent = ptSrc.ParentGroup;
				if(pgOrgParent.Uuid.EqualsValue(pgSrcParent.Uuid))
				{
					pg.LocationChanged = ((ptSrc.LocationChanged > ptOrg.LocationChanged) ?
						ptSrc.LocationChanged : ptOrg.LocationChanged);
					continue;
				}

				if(ptSrc.LocationChanged > ptOrg.LocationChanged)
				{
					PwGroup pgLocal = m_pgRootGroup.FindGroup(pgSrcParent.Uuid, true);
					if(pgLocal == null) { Debug.Assert(false); continue; }

					if(pgLocal.IsContainedIn(pg)) continue;

					pg.ParentGroup.Groups.Remove(pg);
					pgLocal.AddGroup(pg, true);
					pg.LocationChanged = ptSrc.LocationChanged;
				}
				else
				{
					Debug.Assert(pg.ParentGroup.Uuid.EqualsValue(pgOrgParent.Uuid));
					Debug.Assert(pg.LocationChanged == ptOrg.LocationChanged);
				}
			}

			Debug.Assert(m_pgRootGroup.GetGroups(true).UCount == vGroups.UCount);
		}
Exemplo n.º 10
0
		/// <summary>
		/// Method to check whether a reordering is required. This fast test
		/// allows to skip the reordering routine, resulting in a large
		/// performance increase.
		/// </summary>
		internal bool ObjectListRequiresReorder<T>(PwObjectList<T> vItems,
			PwObjectPool ppOrgStructure, PwObjectPool ppSrcStructure, bool bEntries)
			where T : class, IStructureItem, IDeepClonable<T>
		{
			Debug.Assert(ppOrgStructure.ContainsOnlyType(bEntries ? typeof(PwEntry) : typeof(PwGroup)));
			Debug.Assert(ppSrcStructure.ContainsOnlyType(bEntries ? typeof(PwEntry) : typeof(PwGroup)));
			if(vItems.UCount <= 1) return false;

			if((m_slStatus != null) && !m_slStatus.ContinueWork()) return false;

			T ptFirst = vItems.GetAt(0);
			// IStructureItem ptOrg = pgOrgStructure.FindObject(ptFirst.Uuid, true, bEntries);
			IStructureItem ptOrg = ppOrgStructure.Get(ptFirst.Uuid);
			if(ptOrg == null) return true;
			// IStructureItem ptSrc = pgSrcStructure.FindObject(ptFirst.Uuid, true, bEntries);
			IStructureItem ptSrc = ppSrcStructure.Get(ptFirst.Uuid);
			if(ptSrc == null) return true;

			if(ptFirst.ParentGroup == null) { Debug.Assert(false); return true; }
			PwGroup pgOrgParent = ptOrg.ParentGroup;
			if(pgOrgParent == null) return true; // Root might be in tree
			PwGroup pgSrcParent = ptSrc.ParentGroup;
			if(pgSrcParent == null) return true; // Root might be in tree

			if(!ptFirst.ParentGroup.Uuid.EqualsValue(pgOrgParent.Uuid)) return true;
			if(!pgOrgParent.Uuid.EqualsValue(pgSrcParent.Uuid)) return true;

			List<IStructureItem> lOrg = pgOrgParent.GetObjects(false, bEntries);
			List<IStructureItem> lSrc = pgSrcParent.GetObjects(false, bEntries);
			if(vItems.UCount != (uint)lOrg.Count) return true;
			if(lOrg.Count != lSrc.Count) return true;

			for(uint u = 0; u < vItems.UCount; ++u)
			{
				IStructureItem pt = vItems.GetAt(u);
				Debug.Assert(pt.ParentGroup == ptFirst.ParentGroup);

				if(!pt.Uuid.EqualsValue(lOrg[(int)u].Uuid)) return true;
				if(!pt.Uuid.EqualsValue(lSrc[(int)u].Uuid)) return true;
				if(pt.LocationChanged != lOrg[(int)u].LocationChanged) return true;
				if(pt.LocationChanged != lSrc[(int)u].LocationChanged) return true;
			}

			return false;
		}
Exemplo n.º 11
0
		internal void RelocateEntries(PwObjectPool ppOrgStructure,
			PwObjectPool ppSrcStructure)
		{
			PwObjectList<PwEntry> vEntries = m_pgRootGroup.GetEntries(true);

			foreach(PwEntry pe in vEntries)
			{
				if((m_slStatus != null) && !m_slStatus.ContinueWork()) break;

				// PwEntry peOrg = pgOrgStructure.FindEntry(pe.Uuid, true);
				IStructureItem ptOrg = ppOrgStructure.Get(pe.Uuid);
				if(ptOrg == null) continue;
				// PwEntry peSrc = pgSrcStructure.FindEntry(pe.Uuid, true);
				IStructureItem ptSrc = ppSrcStructure.Get(pe.Uuid);
				if(ptSrc == null) continue;

				PwGroup pgOrg = ptOrg.ParentGroup;
				PwGroup pgSrc = ptSrc.ParentGroup;
				if(pgOrg.Uuid.EqualsValue(pgSrc.Uuid))
				{
					pe.LocationChanged = ((ptSrc.LocationChanged > ptOrg.LocationChanged) ?
						ptSrc.LocationChanged : ptOrg.LocationChanged);
					continue;
				}

				if(ptSrc.LocationChanged > ptOrg.LocationChanged)
				{
					PwGroup pgLocal = m_pgRootGroup.FindGroup(pgSrc.Uuid, true);
					if(pgLocal == null) { Debug.Assert(false); continue; }

					pe.ParentGroup.Entries.Remove(pe);
					pgLocal.AddEntry(pe, true);
					pe.LocationChanged = ptSrc.LocationChanged;
				}
				else
				{
					Debug.Assert(pe.ParentGroup.Uuid.EqualsValue(pgOrg.Uuid));
					Debug.Assert(pe.LocationChanged == ptOrg.LocationChanged);
				}
			}

			Debug.Assert(m_pgRootGroup.GetEntries(true).UCount == vEntries.UCount);
		}
Exemplo n.º 12
0
		internal static uint FindLocationChangedPivot<T>(PwObjectList<T> vItems,
			KeyValuePair<uint, uint> kvpRange, PwObjectPool ppOrgStructure,
			PwObjectPool ppSrcStructure, Queue<PwUuid> qBefore, Queue<PwUuid> qAfter,
			bool bEntries)
			where T : class, IStructureItem, IDeepClonable<T>
		{
			uint uPosMax = kvpRange.Key;
			DateTime dtMax = DateTime.MinValue;
			List<IStructureItem> vNeighborSrc = null;

			for(uint u = kvpRange.Key; u <= kvpRange.Value; ++u)
			{
				T pt = vItems.GetAt(u);

				// IStructureItem ptOrg = pgOrgStructure.FindObject(pt.Uuid, true, bEntries);
				IStructureItem ptOrg = ppOrgStructure.Get(pt.Uuid);
				if((ptOrg != null) && (ptOrg.LocationChanged > dtMax))
				{
					uPosMax = u;
					dtMax = ptOrg.LocationChanged; // No 'continue'
					vNeighborSrc = ptOrg.ParentGroup.GetObjects(false, bEntries);
				}

				// IStructureItem ptSrc = pgSrcStructure.FindObject(pt.Uuid, true, bEntries);
				IStructureItem ptSrc = ppSrcStructure.Get(pt.Uuid);
				if((ptSrc != null) && (ptSrc.LocationChanged > dtMax))
				{
					uPosMax = u;
					dtMax = ptSrc.LocationChanged; // No 'continue'
					vNeighborSrc = ptSrc.ParentGroup.GetObjects(false, bEntries);
				}
			}

			GetNeighborItems(vNeighborSrc, vItems.GetAt(uPosMax).Uuid, qBefore, qAfter);
			return uPosMax;
		}
Exemplo n.º 13
0
 public ElementAndDatabaseId(Database db, IStructureItem element)
 {
     DatabaseId      = db.IocAsHexString();
     ElementIdString = element.Uuid.ToHexString();
 }
Exemplo n.º 14
0
        /// <summary>
        /// Checks if the given item is directly or indirectly contained in the given parent
        /// </summary>
        /// <param name="item"></param>
        /// <param name="origParent"></param>
        /// <returns></returns>
        public static bool IsInsideParent(this IStructureItem item, IStructureItem parent)
        {
            Debug.Assert( null != item );
            Debug.Assert( null != parent );

            if( item.ParentGroup == null )
            {
                return false;
            }
            return item.ParentGroup == parent
                || IsInsideParent( item.ParentGroup, parent );
        }