Exemplo n.º 1
0
        /// <summary>
        /// Handles the GetResources message of the Discovery protocol.
        /// </summary>
        /// <param name="args">The ProtocolEventArgs{GetResources, IList{Resource}} instance containing the event data.</param>
        protected override void HandleGetResources(ProtocolEventArgs <GetResources, IList <Resource> > args)
        {
            if (!EtpUri.IsRoot(args.Message.Uri))
            {
                var uri = this.CreateAndValidateUri(args.Message.Uri, args.Header.MessageId);

                if (!uri.IsValid)
                {
                    args.Cancel = true;
                    return;
                }
            }

            var max = WitsmlSettings.MaxGetResourcesResponse;

            foreach (var provider in Providers.OrderBy(x => x.DataSchemaVersion))
            {
                // TODO: Optimize inside each version specific provider
                if (args.Context.Count >= max)
                {
                    break;
                }

                provider.GetResources(args);
            }

            // Limit max number of GetResourcesResponse returned to customer
            while (args.Context.Count > max)
            {
                args.Context.RemoveAt(args.Context.Count - 1);
            }
        }
        /// <summary>
        /// Gets a collection of resources associated to the specified URI.
        /// </summary>
        /// <param name="args">The <see cref="ProtocolEventArgs{GetResources, IList}"/> instance containing the event data.</param>
        public void GetResources(ProtocolEventArgs <GetResources, IList <Resource> > args)
        {
            if (EtpUri.IsRoot(args.Message.Uri))
            {
                args.Context.Add(DiscoveryStoreProvider.NewProtocol(EtpUris.Witsml131, "WITSML Store (1.3.1.1)"));
                return;
            }

            var uri       = new EtpUri(args.Message.Uri);
            var parentUri = uri.Parent;

            // Append query string, if any
            if (!string.IsNullOrWhiteSpace(uri.Query))
            {
                parentUri = new EtpUri(parentUri + uri.Query);
            }

            if (!uri.IsRelatedTo(EtpUris.Witsml131))
            {
                return;
            }
            if (uri.IsBaseUri || (string.IsNullOrWhiteSpace(uri.ObjectId) && ObjectTypes.Well.EqualsIgnoreCase(uri.ObjectType)))
            {
                _wellDataProvider.GetAll(uri)
                .ForEach(x => args.Context.Add(ToResource(x)));
            }
            else if (string.IsNullOrWhiteSpace(uri.ObjectId) && ObjectTypes.Wellbore.EqualsIgnoreCase(parentUri.ObjectType))
            {
                var objectType   = ObjectTypes.PluralToSingle(uri.ObjectType);
                var dataProvider = _container.Resolve <IEtpDataProvider>(new ObjectName(objectType, uri.Version));

                dataProvider
                .GetAll(parentUri)
                .Cast <IWellboreObject>()
                .ForEach(x => args.Context.Add(ToResource(x)));
            }
            else if (ObjectTypes.Well.EqualsIgnoreCase(uri.ObjectType))
            {
                _wellboreDataProvider.GetAll(uri)
                .ForEach(x => args.Context.Add(ToResource(x)));
            }
            else if (ObjectTypes.Wellbore.EqualsIgnoreCase(uri.ObjectType))
            {
                var wellboreObjectType = typeof(IWellboreObject);

                Providers
                .OfType <IWitsmlDataAdapter>()
                .Where(x => wellboreObjectType.IsAssignableFrom(x.DataObjectType))
                .Select(x => ObjectTypes.GetObjectType(x.DataObjectType))
                .OrderBy(x => x)
                .ForEach(x => args.Context.Add(DiscoveryStoreProvider.NewFolder(uri, x, ObjectTypes.SingleToPlural(x, false))));
            }
            else if (ObjectTypes.Log.EqualsIgnoreCase(uri.ObjectType))
            {
                var log = _logDataProvider.Get(uri);
                log?.LogCurveInfo?.ForEach(x => args.Context.Add(ToResource(log, x)));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called when the GetResources response is received.
        /// </summary>
        /// <param name="header">The header.</param>
        /// <param name="message">The message.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="uri">The URI.</param>
        private void OnGetResourcesResponse(IMessageHeader header, ISpecificRecord message, IResource resource, string uri)
        {
            //int id = Thread.CurrentThread.ManagedThreadId;
            var viewModel = ResourceViewModel.NoData;

            // Handle case when "No Data" Acknowledge message was received
            if (resource != null)
            {
                viewModel = new ResourceViewModel(Runtime, resource)
                {
                    LoadChildren = GetResources
                };

                resource.FormatLastChanged();
            }

            //  Handle when message is received from JSON Message tab
            if (string.IsNullOrWhiteSpace(uri))
            {
                return;
            }

            //  If the message URI equals "/" or the current base URI then treat
            //  it as a root object.
            if (EtpUri.IsRoot(uri))
            {
                Resources.ForEach(x => x.IsSelected = false);
                viewModel.IsSelected = true;
                Resources.Add(viewModel);

                if (header.MessageFlags == 3)
                {
                    _messageRespondedEvent.Set();
                }

                return;
            }

            var parent = Resources.FindByMessageId(header.CorrelationId);

            if (parent == null)
            {
                return;
            }

            viewModel.Parent = parent;
            parent.Children.Add(viewModel);

            viewModel.IsChecked        = CheckedUris.Contains(viewModel.Resource.Uri);
            viewModel.PropertyChanged += ResourcePropertyChanged;

            if (header.MessageFlags == 3)
            {
                _messageRespondedEvent.Set();
            }
        }
Exemplo n.º 4
0
        protected override void HandleGetResources(ProtocolEventArgs <GetResources, IList <Resource> > args)
        {
            if (EtpUri.IsRoot(args.Message.Uri))
            {
                args.Context.Add(New(
                                     x => BaseUri,
                                     contentType: Witsml141,
                                     resourceType: ResourceTypes.UriProtocol,
                                     name: "WITSML Store (1.4.1.1)"));
            }
            else if (BaseUri.Equals(args.Message.Uri, StringComparison.InvariantCultureIgnoreCase))
            {
                args.Context.Add(New(
                                     uuid => String.Format("{0}/well({1})", args.Message.Uri, uuid),
                                     contentType: Witsml141 + "type=well",
                                     resourceType: ResourceTypes.DataObject,
                                     name: "Well 01"));

                args.Context.Add(New(
                                     uuid => String.Format("{0}/well({1})", args.Message.Uri, uuid),
                                     contentType: Witsml141 + "type=well",
                                     resourceType: ResourceTypes.DataObject,
                                     name: "Well 02"));
            }
            else if (args.Message.Uri.Contains("/well(") && !args.Message.Uri.Contains("/wellbore("))
            {
                args.Context.Add(New(
                                     uuid => String.Format("{0}/wellbore({1})", args.Message.Uri, uuid),
                                     contentType: Witsml141 + "type=wellbore",
                                     resourceType: ResourceTypes.DataObject,
                                     name: "Wellbore 01-01"));

                args.Context.Add(New(
                                     uuid => String.Format("{0}/wellbore({1})", args.Message.Uri, uuid),
                                     contentType: Witsml141 + "type=wellbore",
                                     resourceType: ResourceTypes.DataObject,
                                     name: "Wellbore 01-02"));
            }
            else if (args.Message.Uri.Contains("/wellbore("))
            {
                args.Context.Add(New(
                                     uuid => String.Format("{0}/log({1})", args.Message.Uri, uuid),
                                     contentType: Witsml141 + "type=log",
                                     resourceType: ResourceTypes.DataObject,
                                     name: "Depth Log 01",
                                     count: 0));

                args.Context.Add(New(
                                     uuid => String.Format("{0}/log({1})", args.Message.Uri, uuid),
                                     contentType: Witsml141 + "type=log",
                                     resourceType: ResourceTypes.DataObject,
                                     name: "Time Log 01",
                                     count: 0));
            }
        }
        protected override void HandleGetTreeResources(ProtocolEventArgs <GetTreeResources, IList <Resource> > args)
        {
            if (EtpUri.IsRoot(args.Message.Context.Uri))
            {
                args.Context.Add(New(
                                     Guid.NewGuid().ToString(),
                                     EtpUris.Witsml141,
                                     contentType: EtpContentTypes.Witsml141,
                                     resourceType: ResourceTypes.UriProtocol,
                                     name: "WITSML 1.4.1.1 Store"));
            }
            else if (args.Message.Context.Uri == EtpUris.Witsml141)
            {
                args.Context.Add(New(
                                     Simulation.WellUid,
                                     string.Format("{0}/well({1})", EtpUris.Witsml141, Simulation.WellUid),
                                     contentType: EtpContentTypes.Witsml141.For(ObjectTypes.Well),
                                     resourceType: ResourceTypes.DataObject,
                                     name: Simulation.WellName));
            }
            else if (string.Format("{0}/well({1})", EtpUris.Witsml141, Simulation.WellUid).EqualsIgnoreCase(args.Message.Context.Uri))
            {
                args.Context.Add(New(
                                     Simulation.WellboreUid,
                                     string.Format("{0}/well({1})/wellbore({2})", EtpUris.Witsml141, Simulation.WellUid, Simulation.WellboreUid),
                                     contentType: EtpContentTypes.Witsml141.For(ObjectTypes.Wellbore),
                                     resourceType: ResourceTypes.DataObject,
                                     name: Simulation.WellboreName));
            }
            else if (string.Format("{0}/well({1})/wellbore({2})", EtpUris.Witsml141, Simulation.WellUid, Simulation.WellboreUid).EqualsIgnoreCase(args.Message.Context.Uri))
            {
                args.Context.Add(New(
                                     Simulation.LogUid,
                                     string.Format("{0}/well({1})/wellbore({2})/log({3})", EtpUris.Witsml141, Simulation.WellUid, Simulation.WellboreUid, Simulation.LogUid),
                                     contentType: EtpContentTypes.Witsml141.For(ObjectTypes.Log),
                                     resourceType: ResourceTypes.DataObject,
                                     name: Simulation.LogName));
            }
            else if (string.Format("{0}/well({1})/wellbore({2})/log({3})", EtpUris.Witsml141, Simulation.WellUid, Simulation.WellboreUid, Simulation.LogUid).EqualsIgnoreCase(args.Message.Context.Uri))
            {
                foreach (var channel in Simulation.Channels)
                {
                    channel.ChannelUri = string.Format("{0}/well({1})/wellbore({2})/log({3})/curve({4})", EtpUris.Witsml141, Simulation.WellUid, Simulation.WellboreUid, Simulation.LogUid, channel.Uuid);

                    args.Context.Add(New(
                                         channel.Uuid,
                                         channel.ChannelUri,
                                         contentType: EtpContentTypes.Witsml141.For("logCurveInfo"),
                                         resourceType: ResourceTypes.DataObject,
                                         name: channel.ChannelName,
                                         count: 0));
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called when the GetResources response is received.
        /// </summary>
        /// <param name="header">The header.</param>
        /// <param name="message">The message.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="uri">The URI.</param>
        private void OnGetResourcesResponse(IMessageHeader header, ISpecificRecord message, IResource resource, string uri)
        {
            var viewModel = ResourceViewModel.NoData;

            // Handle case when "No Data" Acknowledge message was received
            if (resource != null)
            {
                viewModel = new ResourceViewModel(Runtime, resource)
                {
                    LoadChildren = GetResources
                };

                resource.FormatLastChanged();
            }

            LogObjectDetails(new ProtocolEventArgs <ISpecificRecord>(header, message));

            //  Handle when message is received from JSON Message tab
            if (string.IsNullOrWhiteSpace(uri))
            {
                return;
            }

            //  If the message URI equals "/" or the current base URI then treat
            //  it as a root object.
            if (EtpUri.IsRoot(uri) || uri.EqualsIgnoreCase(Model.BaseUri))
            {
                Resources.ForEach(x => x.IsSelected = false);
                viewModel.IsSelected = true;
                Resources.Add(viewModel);
                return;
            }

            var parent = Resources.FindByMessageId(header.CorrelationId);

            if (parent == null)
            {
                return;
            }

            viewModel.Parent = parent;
            parent.Children.Add(viewModel);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Called when the GetResources response is received.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ProtocolEventArgs{GetResourcesResponse, String}"/> instance containing the event data.</param>
        private void OnGetResourcesResponse(object sender, ProtocolEventArgs <GetResourcesResponse, string> e)
        {
            var viewModel = ResourceViewModel.NoData;

            // Handle case when "No Data" Acknowledge message was received
            if (e.Message.Resource != null)
            {
                viewModel = new ResourceViewModel(Runtime, e.Message.Resource);
                viewModel.LoadChildren = GetResources;
            }

            LogObjectDetails(e);

            //  Handle when message is received from JSON Message tab
            if (e.Context == null)
            {
                return;
            }

            //  If the message URI equals "/" or the current base URI then treat
            //  it as a root object.
            if (EtpUri.IsRoot(e.Context) || e.Context.EqualsIgnoreCase(Model.BaseUri))
            {
                Resources.ForEach(x => x.IsSelected = false);
                viewModel.IsSelected = true;
                Resources.Add(viewModel);
                return;
            }

            var parent = Resources.FindByMessageId(e.Header.CorrelationId);

            if (parent == null)
            {
                return;
            }

            viewModel.Parent = parent;
            parent.Children.Add(viewModel);
        }
        /// <summary>
        /// Gets a collection of resources associated to the specified URI.
        /// </summary>
        /// <param name="args">The <see cref="ProtocolEventArgs{GetResources, IList}"/> instance containing the event data.</param>
        public void GetResources(ProtocolEventArgs <GetResources, IList <Resource> > args)
        {
            if (EtpUri.IsRoot(args.Message.Uri))
            {
                args.Context.Add(DiscoveryStoreProvider.NewProtocol(EtpUris.Witsml200, "WITSML Store (2.0)"));
                return;
            }

            var uri       = new EtpUri(args.Message.Uri);
            var parentUri = uri.Parent;

            // Append query string, if any
            if (!string.IsNullOrWhiteSpace(uri.Query))
            {
                parentUri = new EtpUri(parentUri + uri.Query);
            }

            if (!uri.IsRelatedTo(EtpUris.Witsml200) && !uri.IsRelatedTo(EtpUris.Eml210))
            {
                return;
            }
            if (uri.IsBaseUri)
            {
                CreateFoldersByObjectType(uri)
                .ForEach(args.Context.Add);
            }
            else if (string.IsNullOrWhiteSpace(uri.ObjectId))
            {
                var wellboreUri = parentUri.Parent;

                // Append query string, if any
                if (!string.IsNullOrWhiteSpace(uri.Query))
                {
                    wellboreUri = new EtpUri(wellboreUri + uri.Query);
                }

                if (ObjectFolders.Logs.EqualsIgnoreCase(uri.ObjectType))
                {
                    var logs       = _logDataProvider.GetAll(wellboreUri);
                    var timeCount  = logs.Count(x => ObjectFolders.Time.EqualsIgnoreCase(x.TimeDepth));
                    var depthCount = logs.Count(x => ObjectFolders.Depth.EqualsIgnoreCase(x.TimeDepth));
                    var otherCount = logs.Count - (timeCount + depthCount);

                    args.Context.Add(DiscoveryStoreProvider.NewFolder(uri, ObjectTypes.Log, ObjectFolders.Time, timeCount));
                    args.Context.Add(DiscoveryStoreProvider.NewFolder(uri, ObjectTypes.Log, ObjectFolders.Depth, depthCount));

                    if (otherCount > 0)
                    {
                        args.Context.Add(DiscoveryStoreProvider.NewFolder(uri, ObjectTypes.Log, ObjectFolders.Other, otherCount));
                    }
                }
                else if (ObjectFolders.Logs.EqualsIgnoreCase(parentUri.ObjectType) &&
                         (ObjectFolders.Time.EqualsIgnoreCase(uri.ObjectType) || ObjectFolders.Depth.EqualsIgnoreCase(uri.ObjectType) || ObjectFolders.Other.EqualsIgnoreCase(uri.ObjectType)))
                {
                    var logs = _logDataProvider.GetAll(wellboreUri).AsEnumerable();

                    logs = ObjectFolders.Other.EqualsIgnoreCase(uri.ObjectType)
                        ? logs.Where(x => !ObjectFolders.Time.EqualsIgnoreCase(x.TimeDepth) && !ObjectFolders.Depth.EqualsIgnoreCase(x.TimeDepth))
                        : logs.Where(x => x.TimeDepth.EqualsIgnoreCase(uri.ObjectType));

                    logs.ForEach(x => args.Context.Add(ToResource(x)));
                }
                else if (ObjectFolders.ChannelSets.EqualsIgnoreCase(uri.ObjectType) && ObjectTypes.Log.EqualsIgnoreCase(parentUri.ObjectType))
                {
                    var log = _logDataProvider.Get(parentUri);
                    log?.ChannelSet?.ForEach(x => args.Context.Add(ToResource(x)));
                }
                else if (ObjectFolders.Channels.EqualsIgnoreCase(uri.ObjectType) && ObjectTypes.ChannelSet.EqualsIgnoreCase(parentUri.ObjectType))
                {
                    var set = _channelSetDataProvider.Get(parentUri);
                    set?.Channel?.ForEach(x => args.Context.Add(ToResource(set, x)));
                }
                else
                {
                    var dataProvider = GetDataProvider(uri.ObjectType);
                    var hasChildren  = uri.IsRelatedTo(EtpUris.Eml210) ? 0 : -1;

                    dataProvider
                    .GetAll(parentUri)
                    .Cast <AbstractObject>()
                    .ForEach(x => args.Context.Add(ToResource(x, hasChildren)));
                }
            }
            else if (ObjectTypes.Log.EqualsIgnoreCase(uri.ObjectType))
            {
                var log         = _logDataProvider.Get(uri);
                var hasChildren = log?.ChannelSet?.Count ?? 0;

                CreateFoldersByObjectType(uri, "Log", ObjectTypes.ChannelSet, hasChildren)
                .ForEach(args.Context.Add);
            }
            else if (ObjectTypes.ChannelSet.EqualsIgnoreCase(uri.ObjectType))
            {
                var set         = _channelSetDataProvider.Get(uri);
                var hasChildren = set?.Channel?.Count ?? 0;

                CreateFoldersByObjectType(uri, "ChannelSet", ObjectTypes.Channel, hasChildren)
                .ForEach(args.Context.Add);
            }
            else
            {
                var propertyName = ObjectTypes.PluralToSingle(uri.ObjectType).ToPascalCase();

                CreateFoldersByObjectType(uri, propertyName)
                .ForEach(args.Context.Add);
            }
        }