private Activity?StartActivity(string name, ActivityKind kind, ActivityContext context, string?parentId, IEnumerable <KeyValuePair <string, object?> >?tags, IEnumerable <ActivityLink>?links, DateTimeOffset startTime)
        {
            // _listeners can get assigned to null in Dispose.
            SynchronizedList <ActivityListener>?listeners = _listeners;

            if (listeners == null || listeners.Count == 0)
            {
                return(null);
            }

            Activity?activity = null;
            ActivityTagsCollection?samplerTags;

            ActivitySamplingResult samplingResult = ActivitySamplingResult.None;

            if (parentId != null)
            {
                var aco        = new ActivityCreationOptions <string>(this, name, parentId, kind, tags, links);
                var acoContext = new ActivityCreationOptions <ActivityContext>(this, name, aco.GetContext(), kind, tags, links);

                listeners.EnumWithFunc((ActivityListener listener, ref ActivityCreationOptions <string> data, ref ActivitySamplingResult result, ref ActivityCreationOptions <ActivityContext> dataWithContext) => {
                    SampleActivity <string>?sampleUsingParentId = listener.SampleUsingParentId;
                    if (sampleUsingParentId != null)
                    {
                        ActivitySamplingResult sr = sampleUsingParentId(ref data);
                        if (sr > result)
                        {
                            result = sr;
                        }
                    }
                    else
                    {
                        // In case we have a parent Id and the listener not providing the SampleUsingParentId, we'll try to find out if the following conditions are true:
                        //   - The listener is providing the Sample callback
                        //   - Can convert the parent Id to a Context. ActivityCreationOptions.TraceId != default means parent id converted to a valid context.
                        // Then we can call the listener Sample callback with the constructed context.
                        SampleActivity <ActivityContext>?sample = listener.Sample;
                        if (sample != null && data.GetContext() != default) // data.GetContext() != default means parent Id parsed correctly to a context
                        {
                            ActivitySamplingResult sr = sample(ref dataWithContext);
                            if (sr > result)
                            {
                                result = sr;
                            }
                        }
                    }
                }, ref aco, ref samplingResult, ref acoContext);

                if (context == default && aco.GetContext() != default)
                {
                    context  = aco.GetContext();
                    parentId = null;
                }

                samplerTags = aco.GetSamplingTags();
                ActivityTagsCollection?atc = acoContext.GetSamplingTags();
                if (atc != null)
                {
                    if (samplerTags == null)
                    {
                        samplerTags = atc;
                    }
                    else
                    {
                        foreach (KeyValuePair <string, object?> tag in atc)
                        {
                            samplerTags.Add(tag);
                        }
                    }
                }
            }
            else
            {
                bool useCurrentActivityContext = context == default && Activity.Current != null;
                var  aco = new ActivityCreationOptions <ActivityContext>(this, name, useCurrentActivityContext ? Activity.Current !.Context : context, kind, tags, links);
                listeners.EnumWithFunc((ActivityListener listener, ref ActivityCreationOptions <ActivityContext> data, ref ActivitySamplingResult result, ref ActivityCreationOptions <ActivityContext> unused) => {
                    SampleActivity <ActivityContext>?sample = listener.Sample;
                    if (sample != null)
                    {
                        ActivitySamplingResult dr = sample(ref data);
                        if (dr > result)
                        {
                            result = dr;
                        }
                    }
                }, ref aco, ref samplingResult, ref aco);

                if (!useCurrentActivityContext)
                {
                    // We use the context stored inside ActivityCreationOptions as it is possible the trace id get automatically generated during the sampling.
                    // We don't use the context stored inside ActivityCreationOptions only in case if we used Activity.Current context, the reason is we need to
                    // create the new child activity with Parent set to Activity.Current.
                    context = aco.GetContext();
                }

                samplerTags = aco.GetSamplingTags();
            }

            if (samplingResult != ActivitySamplingResult.None)
            {
                activity = Activity.CreateAndStart(this, name, kind, parentId, context, tags, links, startTime, samplerTags, samplingResult);
                listeners.EnumWithAction((listener, obj) => listener.ActivityStarted?.Invoke((Activity)obj), activity);
            }

            return(activity);
        }
Пример #2
0
 private void getFeedGallery_Click(object sender, RibbonControlEventArgs e)
 {
     this.ShowActivitiesCTP();
     SampleActivity sampleActivity = new SampleActivity();
     sampleActivity.Run(string.Format(@"{0}\{1}", getFeedGallery.SelectedItem.Tag, getFeedGallery.SelectedItem.Label));
 }
Пример #3
0
			public OnClickListenerAnonymousInnerClassHelper13(SampleActivity outerInstance, SsdkUnsupportedException e)
			{
				this.outerInstance = outerInstance;
				this.e = e;
			}
Пример #4
0
 void runToolStripButton_Click(object sender, EventArgs e)
 {
     this.ShowActivitiesCTP();
     SampleActivity sampleActivity = new SampleActivity();
     sampleActivity.Run(designerForm.WorkflowPath);
 }