Exemplo n.º 1
0
        /// <summary>
        /// Gets the names and IDs of wellbore objects.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="parentUri">The parent URI.</param>
        /// <returns>The names and IDs of wellbore objects of specified type.</returns>
        public override IEnumerable <IWellboreObject> GetWellboreObjectIds(string objectType, EtpUri parentUri)
        {
            var queryIn = GetTemplateAndSetIds(objectType, parentUri, OptionsIn.ReturnElements.IdOnly);

            var queryOptionsIn = IsVersion131(parentUri)
                ? OptionsIn.ReturnElements.Requested
                : OptionsIn.ReturnElements.IdOnly;

            return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), optionsIn: queryOptionsIn));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Partials the delete entity.
 /// </summary>
 /// <param name="parser">The parser.</param>
 /// <param name="uri">The URI.</param>
 protected void PartialDeleteEntity(WitsmlQueryParser parser, EtpUri uri)
 {
     PartialDeleteEntity <T>(DbCollectionName, parser, uri);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Audits the partial delete operation.
 /// </summary>
 /// <param name="uri">The URI.</param>
 protected virtual void AuditPartialDelete(EtpUri uri)
 {
     AuditEntity(uri, Witsml141.ReferenceData.ChangeInfoType.update);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Updates an object in the data store.
 /// </summary>
 /// <param name="parser">The WITSML query parser.</param>
 /// <param name="uri">The data object URI.</param>
 protected void UpdateEntity(WitsmlQueryParser parser, EtpUri uri)
 {
     UpdateEntity <T>(DbCollectionName, parser, uri);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Replaces an object in the data store.
        /// </summary>
        /// <typeparam name="TObject">The type of the object.</typeparam>
        /// <param name="dbCollectionName">The name of the database collection.</param>
        /// <param name="entity">The object to be replaced.</param>
        /// <param name="uri">The data object URI.</param>
        /// <param name="ignoreServerProperties">if set to <c>true</c> ignores server properties.</param>
        /// <exception cref="WitsmlException"></exception>
        protected void ReplaceEntity <TObject>(string dbCollectionName, TObject entity, EtpUri uri, bool ignoreServerProperties = true)
        {
            try
            {
                Logger.DebugFormat("Replacing {0} MongoDb collection", dbCollectionName);

                var collection = GetCollection <TObject>(dbCollectionName);
                var current    = GetEntity <TObject>(uri, dbCollectionName);
                //var updates = MongoDbUtility.CreateUpdateFields<TObject>();
                var ignores = MongoDbUtility.CreateIgnoreFields <TObject>(null, true);

                if (ignoreServerProperties)
                {
                    ignores.AddRange(GetIgnoredElementNamesForUpdate(null) ?? Enumerable.Empty <string>());
                }

                var mapper = new DataObjectMapper <TObject>(Container, null, ignores);
                mapper.Map(current, entity);

                // Update Last Change Date
                AuditHistoryAdapter.SetDateTimeLastChange(entity);

                var filter = GetEntityFilter <TObject>(uri, IdPropertyName);
                collection.ReplaceOne(filter, entity);

                var transaction = Transaction;
                transaction.Attach(MongoDbAction.Update, dbCollectionName, IdPropertyName, current.ToBsonDocument(), uri);
                transaction.Save();

                AuditUpdate(uri);
            }
            catch (MongoException ex)
            {
                Logger.ErrorFormat("Error replacing {0} MongoDb collection: {1}", dbCollectionName, ex);
                throw new WitsmlException(ErrorCodes.ErrorReplacingInDataStore, ex);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the entity filter for the specified URI.
 /// </summary>
 /// <param name="uri">The URI.</param>
 /// <returns>The entity filter.</returns>
 protected virtual FilterDefinition <T> GetEntityFilter(EtpUri uri)
 {
     return(GetEntityFilter <T>(uri, IdPropertyName));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Inserts an object into the data store.
        /// </summary>
        /// <typeparam name="TObject">The data object type.</typeparam>
        /// <param name="entity">The object to be inserted.</param>
        /// <param name="dbCollectionName">The name of the database collection.</param>
        /// <param name="uri">The data object URI.</param>
        /// <exception cref="WitsmlException"></exception>
        protected void InsertEntity <TObject>(TObject entity, string dbCollectionName, EtpUri uri)
        {
            try
            {
                Logger.DebugFormat("Inserting into {0} MongoDb collection.", dbCollectionName);

                var collection = GetCollection <TObject>(dbCollectionName);
                collection.InsertOne(entity);

                var transaction = Transaction;
                transaction.Attach(MongoDbAction.Add, dbCollectionName, IdPropertyName, null, uri);
                transaction.Save();

                AuditInsert(uri);
            }
            catch (MongoException ex)
            {
                Logger.ErrorFormat("Error inserting into {0} MongoDb collection:{1}{2}", dbCollectionName, Environment.NewLine, ex);
                throw new WitsmlException(ErrorCodes.ErrorAddingToDataStore, ex);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Sets additional default values for the specified data object and URI.
 /// </summary>
 /// <param name="dataObject">The data object.</param>
 /// <param name="uri">The data object URI.</param>
 partial void SetAdditionalDefaultValues(Well dataObject, EtpUri uri)
 {
     dataObject.TimeZone = GetTimeZoneOffset();
 }
 /// <summary>
 /// Sets additional default values for the specified data object and URI.
 /// </summary>
 /// <param name="dataObject">The data object.</param>
 /// <param name="uri">The data object URI.</param>
 partial void SetAdditionalDefaultValues(Tubular dataObject, EtpUri uri);
Exemplo n.º 10
0
 /// <summary>
 /// Gets the object details.
 /// </summary>
 /// <param name="objectType">Type of the object.</param>
 /// <param name="uri">The URI.</param>
 /// <returns>The object detail.</returns>
 public override IDataObject GetObjectDetails(string objectType, EtpUri uri)
 {
     return(GetObjectDetails(objectType, uri, OptionsIn.ReturnElements.All));
 }
Exemplo n.º 11
0
 private bool IsVersion131(EtpUri uri)
 {
     return(uri.Version == null?OptionsIn.DataVersion.Version131.Equals(DataSchemaVersion) : OptionsIn.DataVersion.Version131.Equals(uri.Version));
 }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the growing objects id-only with active status.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="parentUri">The parent URI.</param>
        /// <param name="indexType">Type of the index.</param>
        /// <returns>The wellbore objects of specified type with header.</returns>
        public override IEnumerable <IWellboreObject> GetGrowingObjectsWithStatus(string objectType, EtpUri parentUri, string indexType = null)
        {
            var queryIn = GetTemplateAndSetIds(objectType, parentUri, OptionsIn.ReturnElements.IdOnly);
            var xpath   = $"//{objectType}";

            _template.Add(queryIn, xpath, "objectGrowing");

            if (ObjectTypes.Log.EqualsIgnoreCase(objectType))
            {
                _template.Add(queryIn, xpath, "indexType", "startIndex", "endIndex", "startDateTimeIndex", "endDateTimeIndex", "direction", "indexCurve");
                _template.Add(queryIn, $"{xpath}/startIndex", "@uom");
                _template.Add(queryIn, $"{xpath}/endIndex", "@uom");

                try
                {
                    if (!string.IsNullOrEmpty(indexType))
                    {
                        var indexTypeName = (LogIndexType)typeof(LogIndexType).ParseEnum(indexType);
                        _template.Set(queryIn, $"{xpath}/indexType", indexTypeName.GetName());
                    }
                }
                catch
                {
                    //ignore
                }
            }
            else if (ObjectTypes.Trajectory.EqualsIgnoreCase(objectType))
            {
                _template.Add(queryIn, xpath, "mdMn", "mdMx");
                _template.Add(queryIn, $"{xpath}/mdMn", "@uom");
                _template.Add(queryIn, $"{xpath}/mdMx", "@uom");
            }
            else if (ObjectTypes.MudLog.EqualsIgnoreCase(objectType))
            {
                _template.Add(queryIn, xpath, "startMd", "endMd");
                _template.Add(queryIn, $"{xpath}/startMd", "@uom");
                _template.Add(queryIn, $"{xpath}/endMd", "@uom");
            }

            AddCommonDataElements(queryIn, xpath);

            return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), OptionsIn.ReturnElements.Requested));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the name and IDs of growing objects with active status.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="parentUri">The parent URI.</param>
        /// <param name="logXmlResponse">If set to <c>true</c> then log the XML response.</param>
        /// <returns>/// The name and IDs of the wellbore objects of specified type.</returns>
        public override IEnumerable <IWellboreObject> GetGrowingObjects(string objectType, EtpUri parentUri, bool logXmlResponse = true)
        {
            var queryIn = GetTemplateAndSetIds(objectType, parentUri, OptionsIn.ReturnElements.IdOnly);
            var xpath   = $"//{objectType}";

            _template.Add(queryIn, xpath, "objectGrowing");
            _template.Set(queryIn, $"{xpath}/objectGrowing", true);

            var queryOptionsIn = IsVersion131(parentUri)
                ? OptionsIn.ReturnElements.Requested
                : OptionsIn.ReturnElements.IdOnly;

            return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), logXmlResponse: logXmlResponse, returnNullIfError: true, optionsIn: queryOptionsIn));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the growing object header only.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="uri">The URI.</param>
        /// <returns>The header for the specified growing objects.</returns>
        public override IWellboreObject GetGrowingObjectHeaderOnly(string objectType, EtpUri uri)
        {
            var templateType   = OptionsIn.ReturnElements.IdOnly;
            var queryOptionsIn = OptionsIn.ReturnElements.HeaderOnly;

            if (IsVersion131(uri))
            {
                templateType   = OptionsIn.ReturnElements.HeaderOnly;
                queryOptionsIn = OptionsIn.ReturnElements.Requested;
            }

            var queryIn = GetTemplateAndSetIds(objectType, uri, templateType);

            return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), optionsIn: queryOptionsIn).FirstOrDefault());
        }
Exemplo n.º 15
0
 /// <summary>
 /// Determines whether the entity exists in the data store.
 /// </summary>
 /// <param name="uri">The data object URI.</param>
 /// <param name="dbCollectionName">The name of the database collection.</param>
 /// <typeparam name="TObject">The data object type.</typeparam>
 /// <returns>true if the entity exists; otherwise, false</returns>
 protected bool Exists <TObject>(EtpUri uri, string dbCollectionName)
 {
     return(GetEntity <TObject>(uri, dbCollectionName, IdPropertyName) != null);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Sets the default values for the specified data object.
        /// </summary>
        /// <param name="dataObject">The data object.</param>
        /// <param name="uri">The data object URI.</param>
        protected override void SetDefaultValues(Activity dataObject, EtpUri uri)
        {
            base.SetDefaultValues(dataObject, uri);

            SetAdditionalDefaultValues(dataObject, uri);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Gets an object from the data store by uid
 /// </summary>
 /// <param name="uri">The data object URI.</param>
 /// <param name="fields">The requested fields.</param>
 /// <returns>The object represented by the UID.</returns>
 protected T GetEntity(EtpUri uri, params string[] fields)
 {
     return(GetEntity <T>(uri, DbCollectionName, fields));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Sets additional default values for the specified data object and URI.
 /// </summary>
 /// <param name="dataObject">The data object.</param>
 /// <param name="uri">The data object URI.</param>
 partial void SetAdditionalDefaultValues(Activity dataObject, EtpUri uri);
Exemplo n.º 19
0
 /// <summary>
 /// Gets the entity filter for the specified URI.
 /// </summary>
 /// <typeparam name="TObject">The type of the object.</typeparam>
 /// <param name="uri">The URI.</param>
 /// <param name="idPropertyName">Name of the identifier property.</param>
 /// <returns>The entity filter.</returns>
 protected virtual FilterDefinition <TObject> GetEntityFilter <TObject>(EtpUri uri, string idPropertyName)
 {
     return(MongoDbUtility.GetEntityFilter <TObject>(uri, idPropertyName));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Gets the entity id for the specified data object.
 /// </summary>
 /// <param name="entity">The data object entity.</param>
 /// <param name="uri">The data object uri.</param>
 /// <returns></returns>
 protected virtual string GetEntityId(T entity, EtpUri uri)
 {
     return(uri.ObjectId);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Audits the insert operation.
 /// </summary>
 /// <param name="uri">The URI.</param>
 protected virtual void AuditInsert(EtpUri uri)
 {
     AuditEntity(uri, Witsml141.ReferenceData.ChangeInfoType.add);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Builds the entity filter from the specified uri.
 /// </summary>
 /// <param name="entity">The data object entity.</param>
 /// <param name="uri">The data object uri.</param>
 /// <returns>The filter definition.</returns>
 protected virtual FilterDefinition <T> BuildEntityFilter(T entity, EtpUri uri)
 {
     return(MongoDbUtility.GetEntityFilter <T>(uri, IdPropertyName));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Replaces an object in the data store.
 /// </summary>
 /// <param name="entity">The object to be replaced.</param>
 /// <param name="uri">The data object URI.</param>
 /// <param name="ignoreServerProperties">if set to <c>true</c> ignores server properties.</param>
 protected void ReplaceEntity(T entity, EtpUri uri, bool ignoreServerProperties = true)
 {
     ReplaceEntity(DbCollectionName, entity, uri, ignoreServerProperties);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Sets additional default values for the specified data object and URI.
 /// </summary>
 /// <param name="dataObject">The data object.</param>
 /// <param name="uri">The data object URI.</param>
 partial void SetAdditionalDefaultValues(StimJob dataObject, EtpUri uri);
Exemplo n.º 25
0
 /// <summary>
 /// Deletes a data object by the specified identifier.
 /// </summary>
 /// <param name="uri">The data object URI.</param>
 /// <exception cref="WitsmlException"></exception>
 protected void DeleteEntity(EtpUri uri)
 {
     DeleteEntity <T>(uri, DbCollectionName);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Gets a data object by the specified UUID.
 /// </summary>
 /// <param name="uri">The data object URI.</param>
 /// <param name="fields">The requested fields.</param>
 /// <returns>The data object instance.</returns>
 public override T Get(EtpUri uri, params string[] fields)
 {
     return(GetEntity(uri, fields));
 }
Exemplo n.º 27
0
        /// <summary>
        /// Partials the delete entity.
        /// </summary>
        /// <typeparam name="TObject">The type of the object.</typeparam>
        /// <param name="dbCollectionName">Name of the database collection.</param>
        /// <param name="parser">The parser.</param>
        /// <param name="uri">The URI.</param>
        /// <exception cref="WitsmlException"></exception>
        protected void PartialDeleteEntity <TObject>(string dbCollectionName, WitsmlQueryParser parser, EtpUri uri)
        {
            try
            {
                Logger.DebugFormat("Partial Deleting {0} MongoDb collection", dbCollectionName);

                var collection = GetCollection <TObject>(dbCollectionName);
                var current    = GetEntity <TObject>(uri, dbCollectionName);
                var updates    = MongoDbUtility.CreateUpdateFields <TObject>();
                var ignores    = MongoDbUtility.CreateIgnoreFields <TObject>(GetIgnoredElementNamesForUpdate(parser));

                var partialDelete = new MongoDbDelete <TObject>(Container, collection, parser, IdPropertyName, ignores);
                partialDelete.PartialDelete(current, uri, updates);

                var transaction = Transaction;
                transaction.Attach(MongoDbAction.Update, dbCollectionName, IdPropertyName, current.ToBsonDocument(), uri);
                transaction.Save();

                AuditPartialDelete(uri);
            }
            catch (MongoException ex)
            {
                Logger.ErrorFormat("Error partial deleting {0} MongoDb collection: {1}", dbCollectionName, ex);
                throw new WitsmlException(ErrorCodes.ErrorUpdatingInDataStore, ex);
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Determines whether the entity exists in the data store.
 /// </summary>
 /// <param name="uri">The data object URI.</param>
 /// <returns>true if the entity exists; otherwise, false</returns>
 public override bool Exists(EtpUri uri)
 {
     return(Exists <T>(uri, DbCollectionName));
 }
 /// <summary>
 /// Sets additional default values for the specified data object and URI.
 /// </summary>
 /// <param name="dataObject">The data object.</param>
 /// <param name="uri">The data object URI.</param>
 partial void SetAdditionalDefaultValues(Attachment dataObject, EtpUri uri);
Exemplo n.º 30
0
        /// <summary>
        /// Gets the wellbore objects.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="parentUri">The parent URI.</param>
        /// <param name="logXmlResponse">If set to <c>true</c> then log the XML response.</param>
        /// <returns>The wellbore objects of specified type.</returns>
        public override IEnumerable <IWellboreObject> GetWellboreObjects(string objectType, EtpUri parentUri, bool logXmlResponse = true)
        {
            var queryIn = GetTemplateAndSetIds(objectType, parentUri, OptionsIn.ReturnElements.IdOnly);

            AddCommonDataElements(queryIn, $"//{objectType}");

            return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), optionsIn: OptionsIn.ReturnElements.Requested, logXmlResponse: logXmlResponse));
        }