Example #1
0
        internal SelectedChangesGroupInfo GetSelectedChangesGroupInfo()
        {
            SelectedChangesGroupInfo result = new SelectedChangesGroupInfo();

            IList <int> selectedIds = GetSelection();

            if (selectedIds.Count == 0)
            {
                return(result);
            }

            foreach (KeyValuePair <PendingChangeInfo, int> item
                     in mTreeViewItemIds.GetInfoItems())
            {
                if (!selectedIds.Contains(item.Value))
                {
                    continue;
                }

                ChangeInfo changeInfo = item.Key.ChangeInfo;

                result.SelectedCount++;
                result.IsAnyDirectorySelected   |= changeInfo.IsDirectory;
                result.IsAnyPrivateSelected     |= !ChangeInfoType.IsControlled(changeInfo);
                result.IsAnyControlledSelected  |= ChangeInfoType.IsControlled(changeInfo);
                result.IsAnyLocalChangeSelected |= ChangeInfoType.IsLocalChange(changeInfo);

                result.FilterInfo.IsAnyIgnoredSelected       |= ChangeInfoType.IsIgnored(changeInfo);
                result.FilterInfo.IsAnyHiddenChangedSelected |= ChangeInfoType.IsHiddenChanged(changeInfo);

                string wkRelativePath = InternalNames.RootDir +
                                        WorkspacePath.GetWorkspaceRelativePath(
                    mWkInfo.ClientPath, changeInfo.GetFullPath());

                if (result.SelectedCount == 1)
                {
                    result.FilterInfo.CommonName      = Path.GetFileName(changeInfo.GetFullPath());
                    result.FilterInfo.CommonExtension = changeInfo.GetExtension();
                    result.FilterInfo.CommonFullPath  = wkRelativePath;
                    continue;
                }

                if (result.FilterInfo.CommonName != Path.GetFileName(changeInfo.GetFullPath()))
                {
                    result.FilterInfo.CommonName = null;
                }

                if (result.FilterInfo.CommonExtension != changeInfo.GetExtension())
                {
                    result.FilterInfo.CommonExtension = null;
                }

                if (result.FilterInfo.CommonFullPath != wkRelativePath)
                {
                    result.FilterInfo.CommonFullPath = null;
                }
            }

            return(result);
        }
        /// <summary>
        /// Gets the date time last change based on the current change type.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <param name="changeType">The type of change.</param>
        /// <returns>The date time of last change.</returns>
        private DateTimeOffset?GetDateTimeLastChange(DateTimeOffset?date, ChangeInfoType changeType)
        {
            if (changeType == ChangeInfoType.delete)
            {
                date = null;
            }

            return(date ?? DateTimeOffset.UtcNow);
        }
Example #3
0
        internal bool GetSelectedPathsToDelete(
            out List <string> privateDirectories,
            out List <string> privateFiles)
        {
            privateDirectories = new List <string>();
            privateFiles       = new List <string>();

            List <ChangeInfo> dirChanges  = new List <ChangeInfo>();
            List <ChangeInfo> fileChanges = new List <ChangeInfo>();

            IList <int> selectedIds = GetSelection();

            if (selectedIds.Count == 0)
            {
                return(false);
            }

            foreach (KeyValuePair <PendingChangeInfo, int> item
                     in mTreeViewItemIds.GetInfoItems())
            {
                if (!selectedIds.Contains(item.Value))
                {
                    continue;
                }

                ChangeInfo changeInfo = item.Key.ChangeInfo;

                if (ChangeInfoType.IsControlled(changeInfo))
                {
                    continue;
                }

                if (changeInfo.IsDirectory)
                {
                    dirChanges.Add(changeInfo);
                    continue;
                }

                fileChanges.Add(changeInfo);
            }

            mPendingChangesTree.FillWithMeta(fileChanges);
            mPendingChangesTree.FillWithMeta(dirChanges);

            privateDirectories = dirChanges.Select(
                d => d.GetFullPath()).ToList();
            privateFiles = fileChanges.Select(
                f => f.GetFullPath()).ToList();

            return(true);
        }
Example #4
0
        protected void AssertChangeLog(object entity, int expectedHistoryCount, ChangeInfoType expectedChangeType)
        {
            var dataObject       = entity as IDataObject;
            var commonDataObject = entity as ICommonDataObject;
            var commonData       = commonDataObject?.CommonData;

            // Assert that the entity is not null and has a UID
            Assert.IsNotNull(dataObject?.Uid);

            // Assert that the entity has CommonData with a DateTimeLastChange
            Assert.IsNotNull(commonData);
            Assert.IsTrue(commonData.DateTimeLastChange.HasValue);

            // Fetch the changeLog for the entity just added
            var changeLogQuery = DevKit.CreateChangeLog(dataObject.GetUri());
            var changeLog      = DevKit.QueryAndAssert <ChangeLogList, ChangeLog>(changeLogQuery);

            // TODO: Fetch the changeHistory using the entity's DateTimeLastChange
            // TODO: Do this when the common data interface is added.
            // TODO: var changeHistory = changeLog.ChangeHistory.FirstOrDefault(c => c.DateTimeChange == commonData.DateTimeLastChange);
            var changeHistory = changeLog.ChangeHistory.LastOrDefault();

            // Verify that we found a changeHistory for the latest change.
            Assert.IsNotNull(changeHistory);

            // The SourceName of the change log MUST match the Source name of the entity
            Assert.AreEqual(commonData.SourceName, changeLog.SourceName);

            // Verify that the LastChangeType exists and was an Add
            Assert.IsTrue(changeLog.LastChangeType.HasValue);
            Assert.AreEqual(expectedChangeType, changeLog.LastChangeType.Value);

            // Verify that there is only one changeHistory
            Assert.AreEqual(expectedHistoryCount, changeLog.ChangeHistory.Count);

            // The LastChangeType of the changeLog MUST match the ChangeType of the last changeHistory added
            Assert.AreEqual(changeLog.LastChangeType, changeHistory.ChangeType);

            // The LastChangeInfo of the changeLog MUST match the ChangeInfo of the last changeHistory added
            Assert.AreEqual(changeLog.LastChangeInfo, changeHistory.ChangeInfo);

            // If the entity was deleted then we don't have a DateTimeLastChange to compare
            if (expectedChangeType != ChangeInfoType.delete)
            {
                // Verify that the changeHistory has a DateTimeLastChange and it matches
                //... the entity DateTimeLastChange
                Assert.IsTrue(changeHistory.DateTimeChange.HasValue);
                // TODO: Waiting for fix in DbAuditHistoryDataAdapter that requires CommonData interface
                // TODO: Assert.AreEqual(commonData.DateTimeLastChange.Value, changeHistory.DateTimeChange.Value);
            }
        }
        /// <summary>
        /// Gets or creates the audit history for the changed entity.
        /// </summary>
        /// <param name="uri">The URI of the changed entity.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="changeType">Type of the change.</param>
        /// <returns>A new or existing DbAuditHistory for the entity.</returns>
        public DbAuditHistory GetAuditHistory(EtpUri uri, object entity, ChangeInfoType changeType)
        {
            var abstractObject   = entity as Energistics.DataAccess.WITSML200.AbstractObject;
            var commonDataObject = entity as ICommonDataObject;
            var dataObject       = entity as IDataObject;
            var wellObject       = entity as IWellObject;
            var wellboreObject   = entity as IWellboreObject;

            var uriLower     = uri.Uri.ToLowerInvariant();
            var changeInfo   = $"{changeType:G} {uri.ObjectType}";
            var auditHistory = GetQuery().FirstOrDefault(x => x.Uri == uriLower);

            // Creating audit history entry
            if (auditHistory == null)
            {
                auditHistory = new DbAuditHistory
                {
                    ObjectType     = uri.ObjectType,
                    LastChangeInfo = changeInfo,
                    LastChangeType = changeType,
                    CommonData     = new CommonData(),
                    ChangeHistory  = new List <ChangeHistory>(),
                    UidWellbore    = wellboreObject?.UidWellbore,
                    UidWell        = wellObject?.UidWell ?? wellboreObject?.UidWell,
                    UidObject      = uri.ObjectId,
                    Uri            = uriLower
                };
            }
            else // Updating existing entry
            {
                auditHistory.LastChangeInfo = changeInfo;
                auditHistory.LastChangeType = changeType;
            }

            // Keep audit history name properties in sync with the entity name properties.
            auditHistory.NameWellbore = wellboreObject?.NameWellbore;
            auditHistory.NameWell     = wellObject?.NameWell ?? wellboreObject?.NameWell;
            auditHistory.NameObject   = dataObject?.Name ?? abstractObject?.Citation?.Title;

            // Keep audit history source name property in sync
            auditHistory.SourceName = commonDataObject?.CommonData?.SourceName ?? abstractObject?.Citation?.Originator;

            // Keep date/time of last change in sync with the entity
            auditHistory.CommonData.DateTimeLastChange = GetDateTimeLastChange(
                commonDataObject?.CommonData?.DateTimeLastChange ??
                (DateTimeOffset?)abstractObject?.Citation?.LastUpdate,
                changeType);

            // Make sure date/time created matches first date/time last change
            auditHistory.CommonData.DateTimeCreation = auditHistory.CommonData.DateTimeCreation ??
                                                       auditHistory.CommonData.DateTimeLastChange;

            // Update current ChangeHistory entry to match the ChangeLog header
            var changeHistory = GetCurrentChangeHistory();

            // Use the message from the changeHistory if it was specfied
            var message = string.IsNullOrWhiteSpace(changeHistory.ChangeInfo)
                ? auditHistory.LastChangeInfo
                : changeHistory.ChangeInfo;

            auditHistory.LastChangeInfo  = message;
            changeHistory.ChangeInfo     = message;
            changeHistory.ChangeType     = auditHistory.LastChangeType;
            changeHistory.DateTimeChange = auditHistory.CommonData.DateTimeLastChange;

            // Append current ChangeHistory entry
            auditHistory.ChangeHistory.Add(changeHistory);

            // Remove ChangeHistory entry from current context
            WitsmlOperationContext.Current.ChangeHistory = null;

            return(auditHistory);
        }