Example #1
0
        /// <summary>
        /// Sets the properties of the <see cref="DataObject"/> instance.
        /// </summary>
        /// <typeparam name="T">The type of entity.</typeparam>
        /// <param name="dataObject">The data object.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="uri">The URI.</param>
        /// <param name="name">The name.</param>
        /// <param name="childCount">The child count.</param>
        /// <param name="lastChanged">The last changed in microseconds.</param>
        /// <param name="compress">if set to <c>true</c> compress the data object.</param>
        public static void SetDataObject<T>(DataObject dataObject, T entity, EtpUri uri, string name, int childCount = -1, long lastChanged = 0, bool compress = true)
        {
            if (entity == null)
            {
                dataObject.SetString(null);
            }
            else if (entity is string)
            {
                dataObject.SetString(entity.ToString());
            }
            else
            {
                var data = EtpContentType.Json.EqualsIgnoreCase(uri.ContentType.Format)
                    ? Energistics.Common.EtpExtensions.Serialize(entity)
                    : WitsmlParser.ToXml(entity);

                dataObject.SetString(data, compress);
            }

            dataObject.Resource = new Resource()
            {
                Uri = uri,
                Uuid = uri.ObjectId,
                Name = name,
                HasChildren = childCount,
                ContentType = uri.ContentType,
                ResourceType = ResourceTypes.DataObject.ToString(),
                CustomData = new Dictionary<string, string>(),
                LastChanged = lastChanged,
                ChannelSubscribable = uri.IsChannelSubscribable(),
                ObjectNotifiable = uri.IsObjectNotifiable()
            };
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="Resource" /> using the specified parameters.
 /// </summary>
 /// <param name="uuid">The UUID.</param>
 /// <param name="uri">The URI.</param>
 /// <param name="resourceType">Type of the resource.</param>
 /// <param name="name">The name.</param>
 /// <param name="count">The count.</param>
 /// <param name="lastChanged">The last changed in microseconds.</param>
 /// <returns>The resource instance.</returns>
 public static Resource New(string uuid, EtpUri uri, ResourceTypes resourceType, string name, int count = 0, long lastChanged = 0)
 {
     return(new Resource
     {
         Uuid = uuid ?? string.Empty,
         Uri = uri,
         Name = name,
         ChildCount = count,
         ContentType = uri.ContentType,
         ResourceType = resourceType.ToString(),
         CustomData = new Dictionary <string, string>(),
         LastChanged = lastChanged,
         ChannelSubscribable = uri.IsChannelSubscribable(),
         ObjectNotifiable = uri.IsObjectNotifiable()
     });
 }
Example #3
0
        /// <summary>
        /// Sets the properties of the <see cref="IDataObject"/> instance.
        /// </summary>
        /// <typeparam name="T">The type of entity.</typeparam>
        /// <param name="dataObject">The data object.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="uri">The URI.</param>
        /// <param name="name">The name.</param>
        /// <param name="childCount">The child count.</param>
        /// <param name="lastChanged">The last changed in microseconds.</param>
        public static void SetDataObject <T>(IDataObject dataObject, T entity, EtpUri uri, string name, int childCount = -1, long lastChanged = 0)
        {
            if (entity == null)
            {
                dataObject.SetString(null);
            }
            else if (entity is string)
            {
                dataObject.SetString(entity.ToString());
            }
            else
            {
                var data = EtpContentType.Json.EqualsIgnoreCase(uri.ContentType.Format)
                    ? Energistics.Etp.Common.EtpExtensions.Serialize(entity)
                    : WitsmlParser.ToXml(entity, removeTypePrefix: true);

                dataObject.SetString(data, false);
            }

            double version;
            var    uuid = double.TryParse(uri.Version, out version) && version >= 2.0 ? uri.ObjectId : null;

            if (string.IsNullOrWhiteSpace(uuid))
            {
                uuid = entity.GetPropertyValue <string>(ObjectTypes.Uuid);
            }

            dataObject.Resource = new Resource
            {
                Uri                 = uri,
                Uuid                = uuid ?? string.Empty,
                Name                = name,
                ChildCount          = childCount,
                ContentType         = uri.ContentType,
                ResourceType        = ResourceTypes.DataObject.ToString(),
                CustomData          = new Dictionary <string, string>(),
                LastChanged         = lastChanged,
                ChannelSubscribable = uri.IsChannelSubscribable(),
                ObjectNotifiable    = uri.IsObjectNotifiable()
            };
        }