예제 #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Resources.Resource resource = null;
            switch (this.cmbResourceType.SelectedItem.ToString())
            {
            case "Sequence File":
                resource = new Resources.SeqFileResource(
                    txtDisplayName.Text, txtFilename.Text);
                break;

            case "Weight File":
                resource = new Resources.WgtFileResource(
                    txtDisplayName.Text, txtFilename.Text);
                break;

            case "PSSM":
                break;

            case "Family":
                resource = new Resources.CompositeResource(txtFilename.Text);
                break;
            }

            resource.Notes = txtNotes.Text;
            Program.CurrentResources.Root.Add(resource, txtFamily.Text);
            this.DialogResult = DialogResult.OK;
            Close();
        }
예제 #2
0
        public DynResourceForm(Resources.Resource resource)
        {
            InitializeComponent();

            this.cmbResourceType.Items.Add(resource.ResourceType);
            cmbResourceType.SelectedIndex = 0;

            /// this must be after the combobox item is changed
            /// because the combobox item change deletes the current resource
            /// and generates a new default resource of the given type
            SelectedResource = resource;

            fieldFamily.Readonly         = true;
            fieldFamily.SelectedResource = resource.Parent;

            fieldName.Readonly  = true;
            fieldName.FieldText = resource.Name;

            textField1.Readonly  = true;
            textField1.FieldText = resource.ID.ToString();

            /// now fill in the field values
            foreach (FieldValueList fieldValue in SelectedResource.Fields.Values)
            {
                this.Fields[fieldValue.Type.Name].LoadFromFieldValue(fieldValue);
            }
        }
예제 #3
0
 private void btnWgtBrowse_Click(object sender, EventArgs e)
 {
     FamiliesForm familiesForm = new FamiliesForm();
     if (familiesForm.ShowDialog() == DialogResult.OK) {
         Weights = familiesForm.SelectedResource;
         txtWgtFile.Text = familiesForm.SelectedResource.QualifiedName;
     }
 }
예제 #4
0
        private TreeNode CreateTreeNode(Resources.Resource resource)
        {
            TreeNode treeNode = new TreeNode();

            treeNode.Tag = resource;
            SetupNode(treeNode);

            return(treeNode);
        }
예제 #5
0
        private void btnWgtBrowse_Click(object sender, EventArgs e)
        {
            FamiliesForm familiesForm = new FamiliesForm();

            if (familiesForm.ShowDialog() == DialogResult.OK)
            {
                Weights         = familiesForm.SelectedResource;
                txtWgtFile.Text = familiesForm.SelectedResource.QualifiedName;
            }
        }
예제 #6
0
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            Resources.Resource resource = (Resources.Resource)e.Node.Tag;
            DynResourceForm    form     = new DynResourceForm(resource);

            if (form.ShowDialog() == DialogResult.OK)
            {
                Controller.CurrentResources.SaveResources();
                SetupNode(e.Node);
                BuildTree(e.Node);
            }
        }
예제 #7
0
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            Resources.Resource resource = (Resources.Resource)e.Node.Tag;
            DynResourceForm    form     = new DynResourceForm(resource);

            if (form.ShowDialog() == DialogResult.OK)
            {
                Controller.CurrentResources.SaveResources();

                // TODO: do this more economically, since only one resource has to be updated
                BuildTree();
            }
        }
예제 #8
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (SelectedResource == null)
            {
                SelectedResource = Controller.CurrentResources.FindResource(this.txtFamilyName.Text);
                if (SelectedResource == null)
                {
                    return;
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
예제 #9
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            Resources.Resource resource      = (Resources.Resource)treeView1.SelectedNode.Tag;
            string             qualifiedname = resource.QualifiedName;

            if (System.Windows.Forms.MessageBox.Show(this, "This will remove the " + qualifiedname + " resource and all its sub-resources. Are you sure?",
                                                     "Removing resources",
                                                     MessageBoxButtons.OKCancel,
                                                     MessageBoxIcon.Question,
                                                     MessageBoxDefaultButton.Button2
                                                     ) == DialogResult.OK)
            {
                resource.MyParent.Children.Remove(resource.Name);
                treeView1.SelectedNode.Remove();
            }
        }
예제 #10
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (SelectedResource == null)
            {
                SelectedResource = Controller.CurrentResources.FindResource(this.txtFamilyName.Text);
                if (SelectedResource == null)
                {
                    return;
                }
            }

            InternalRefFieldType.Mask mask = (InternalRefFieldType.Mask) this.comboBox1.SelectedItem;
            if (mask.IsAccepted(SelectedResource.MyType))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
예제 #11
0
        public ResourceForm(Resources.Resource resource)
        {
            InitializeComponent();

            if (resource.Parent != null)
            {
                Family = resource.Parent.QualifiedName;
            }
            btnFamilyBrowse.Enabled = false;

            /// name and notes are subject to change
            DisplayName = resource.Name;
            Notes       = resource.Notes;

            btnFilenameBrowse.Enabled = false;
            if (resource is Resources.FileResource)
            {
                Filename = (resource as Resources.FileResource).Filename;
            }

            cmbResourceType.Items.Add(new ResourceTypeItem(resource));
            cmbResourceType.SelectedIndex = 0;
        }
예제 #12
0
        public DynResourceForm(Resources.Resource resource)
        {
            InitializeComponent();
            InitStaticFields(
                resource.Name,
                (resource.MyParent != null) ? resource.MyParent.QualifiedName : string.Empty
                );

            this.cmbResourceType.Items.Add(resource.MyType);
            cmbResourceType.SelectedIndex = 0;

            /// this must be after the combobox item is changed
            /// because the combobox item change deletes the current resource
            /// and generates a new default resource of the given type
            SelectedResource = resource;

            //fieldFamily.Readonly = true;
            //fieldName.Readonly = true;
            //fieldParent.Readonly = true;
            //fieldName.Readonly = true;

            //textField1.Readonly = true;
            //textField1.FieldText = resource.ID.ToString();
        }
예제 #13
0
        private TreeNode CreateTreeNode(Resources.Resource resource)
        {
            TreeNode treeNode = new TreeNode(resource.Name);

            treeNode.Name = resource.QualifiedName;
            treeNode.Tag  = resource;
            switch (resource.GetType().Name)
            {
            case "CompositeResource":
                treeNode.BackColor = this.lblFamilyColor.BackColor;
                break;

            case "SeqFileResource":
                treeNode.BackColor = this.lblSequenceColor.BackColor;
                break;

            case "WgtFileResource":
                treeNode.BackColor = this.lblWeightColor.BackColor;
                break;
            }

            // TODO: change the color of node according to type
            return(treeNode);
        }
예제 #14
0
        private void button6_Click(object sender, EventArgs e)
        {
            Resources.Resource parent = null;

            /// only composite resources can have a sub-resource
            if (treeView1.SelectedNode != null)
            {
                parent = ((Resources.Resource)treeView1.SelectedNode.Tag);
            }
            else
            {
                parent = (Resources.Resource) this.treeView1.Nodes[0].Tag;
            }

            Resources.Resource resource = new Resources.Resource(
                Guid.NewGuid(),
                Controller.CurrentResources.ResourceTypes["Family"],
                "new family");
            int attempt = 2;

            while (parent.Children[resource.Name] != null)
            {
                /// this family already exists in the parent, try another one
                resource.Name = "new family " + attempt++;
            }

            parent.Children.Add(resource);

            TreeNode treeNode = CreateTreeNode(resource);

            AddNode(treeView1.SelectedNode, treeNode);
            treeView1.SelectedNode.Expand();
            treeNode.BeginEdit();

            // TODO: add this to the resource tree?
        }
예제 #15
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (SelectedResource == null)
            {
                SelectedResource = Controller.CurrentResources.FindResource(this.txtFamilyName.Text);
                if (SelectedResource == null)
                    return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
예제 #16
0
 public ResourceTypeItem(Resources.Resource resource)
 {
     _resource = resource;
 }
 private static void ValidateHttpWebRequestActivity(Activity activityToValidate, Resources.Resource expectedResource, bool responseExpected)
 {
     Assert.Equal(ActivityKind.Client, activityToValidate.Kind);
     Assert.Equal(expectedResource, activityToValidate.GetResource());
 }
        public void ToOtlpResourceSpansTest(bool addResource, string optionsServiceName)
        {
            var evenTags = new[] { new KeyValuePair <string, object>("k0", "v0") };
            var oddTags  = new[] { new KeyValuePair <string, object>("k1", "v1") };
            var sources  = new[]
            {
                new ActivitySource("even", "2.4.6"),
                new ActivitySource("odd", "1.3.5"),
            };

            var builder = Sdk.CreateTracerProviderBuilder()
                          .AddSource(sources[0].Name)
                          .AddSource(sources[1].Name);

            Resources.Resource resource = null;
            if (addResource)
            {
                resource = new Resources.Resource(
                    new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(Resources.Resource.ServiceNameKey, "service-name"),
                    new KeyValuePair <string, object>(Resources.Resource.ServiceNamespaceKey, "ns1"),
                });

                builder.SetResource(resource);
            }

            using var openTelemetrySdk = builder.Build();

            var       processor  = new BatchExportProcessor <Activity>(new TestExporter <Activity>(RunTest));
            const int numOfSpans = 10;
            bool      isEven;

            for (var i = 0; i < numOfSpans; i++)
            {
                isEven = i % 2 == 0;
                var source       = sources[i % 2];
                var activityKind = isEven ? ActivityKind.Client : ActivityKind.Server;
                var activityTags = isEven ? evenTags : oddTags;

                using Activity activity = source.StartActivity($"span-{i}", activityKind, parentContext: default, activityTags);
                processor.OnEnd(activity);
            }

            processor.Shutdown();

            void RunTest(Batch <Activity> batch)
            {
                var request = new OtlpCollector.ExportTraceServiceRequest();

                request.AddBatch(
                    new OtlpExporter(
                        new OtlpExporterOptions
                {
                    ServiceName = optionsServiceName,
                },
                        new NoopTraceServiceClient()),
                    batch);

                Assert.Single(request.ResourceSpans);
                var oltpResource = request.ResourceSpans.First().Resource;

                if (addResource)
                {
                    Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == Resources.Resource.ServiceNameKey && kvp.Value.StringValue == "service-name");
                    Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == Resources.Resource.ServiceNamespaceKey && kvp.Value.StringValue == "ns1");
                }
                else
                {
                    Assert.Contains(oltpResource.Attributes, (kvp) => kvp.Key == Resources.Resource.ServiceNameKey && kvp.Value.StringValue == optionsServiceName);
                }

                foreach (var instrumentationLibrarySpans in request.ResourceSpans.First().InstrumentationLibrarySpans)
                {
                    Assert.Equal(numOfSpans / 2, instrumentationLibrarySpans.Spans.Count);
                    Assert.NotNull(instrumentationLibrarySpans.InstrumentationLibrary);

                    var expectedSpanNames = new List <string>();
                    var start             = instrumentationLibrarySpans.InstrumentationLibrary.Name == "even" ? 0 : 1;
                    for (var i = start; i < numOfSpans; i += 2)
                    {
                        expectedSpanNames.Add($"span-{i}");
                    }

                    var otlpSpans = instrumentationLibrarySpans.Spans;
                    Assert.Equal(expectedSpanNames.Count, otlpSpans.Count);

                    var kv0 = new OtlpCommon.KeyValue {
                        Key = "k0", Value = new OtlpCommon.AnyValue {
                            StringValue = "v0"
                        }
                    };
                    var kv1 = new OtlpCommon.KeyValue {
                        Key = "k1", Value = new OtlpCommon.AnyValue {
                            StringValue = "v1"
                        }
                    };

                    var expectedTag = instrumentationLibrarySpans.InstrumentationLibrary.Name == "even"
                        ? kv0
                        : kv1;

                    foreach (var otlpSpan in otlpSpans)
                    {
                        Assert.Contains(otlpSpan.Name, expectedSpanNames);
                        Assert.Contains(expectedTag, otlpSpan.Attributes);
                    }
                }
            }
        }
예제 #19
0
 public ResourceTypeItem(Resources.Resource resource)
 {
     _resource = resource;
 }
예제 #20
0
        private static void ValidateAspNetCoreActivity(Activity activityToValidate, string expectedHttpPath, Resources.Resource expectedResource)
        {
            Assert.Equal(ActivityKind.Server, activityToValidate.Kind);
            Assert.Equal(expectedHttpPath, activityToValidate.Tags.FirstOrDefault(i => i.Key == SpanAttributeConstants.HttpPathKey).Value);
            Assert.Equal(expectedResource, activityToValidate.GetResource());
            var request = activityToValidate.GetCustomProperty(HttpInListener.RequestCustomPropertyName);

            Assert.NotNull(request);
            Assert.True(request is HttpRequest);

            var response = activityToValidate.GetCustomProperty(HttpInListener.ResponseCustomPropertyName);

            Assert.NotNull(response);
            Assert.True(response is HttpResponse);
        }
        private static void ValidateHttpWebRequestActivity(Activity activityToValidate, Resources.Resource expectedResource, bool responseExpected)
        {
            Assert.Equal(ActivityKind.Client, activityToValidate.Kind);
            Assert.Equal(expectedResource, activityToValidate.GetResource());
            var request = activityToValidate.GetCustomProperty(HttpWebRequestActivitySource.RequestCustomPropertyName);

            Assert.NotNull(request);
            Assert.True(request is HttpWebRequest);

            if (responseExpected)
            {
                var response = activityToValidate.GetCustomProperty(HttpWebRequestActivitySource.ResponseCustomPropertyName);
                Assert.NotNull(response);
                Assert.True(response is HttpWebResponse);
            }
        }
예제 #22
0
 private static void ValidateAspNetCoreActivity(Activity activityToValidate, string expectedHttpPath, Resources.Resource expectedResource)
 {
     Assert.Equal(ActivityKind.Server, activityToValidate.Kind);
     Assert.Equal(expectedHttpPath, activityToValidate.GetTagValue(SpanAttributeConstants.HttpPathKey) as string);
     Assert.Equal(expectedResource, activityToValidate.GetResource());
 }
예제 #23
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (SelectedResource == null)
            {
                SelectedResource = Controller.CurrentResources.FindResource(this.txtFamilyName.Text);
                if (SelectedResource == null)
                    return;
            }

            InternalRefFieldType.Mask mask = (InternalRefFieldType.Mask) this.comboBox1.SelectedItem;
            if (mask.IsAccepted(SelectedResource.MyType))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
예제 #24
0
        public void ToOtlpResourceSpansTest()
        {
            var evenTags = new[] { new KeyValuePair <string, object>("k0", "v0") };
            var oddTags  = new[] { new KeyValuePair <string, object>("k1", "v1") };
            var sources  = new[]
            {
                new ActivitySource("even", "2.4.6"),
                new ActivitySource("odd", "1.3.5"),
            };

            var resource = new Resources.Resource(
                new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(Resources.Resource.ServiceNamespaceKey, "ns1"),
            });

            // This following is done just to set Resource to Activity.
            using var openTelemetrySdk = Sdk.CreateTracerProviderBuilder()
                                         .AddSource(sources[0].Name)
                                         .AddSource(sources[1].Name)
                                         .SetResource(resource)
                                         .Build();

            var       activities = new List <Activity>();
            Activity  activity   = null;
            const int numOfSpans = 10;
            bool      isEven;

            for (var i = 0; i < numOfSpans; i++)
            {
                isEven = i % 2 == 0;
                var source       = sources[i % 2];
                var activityKind = isEven ? ActivityKind.Client : ActivityKind.Server;
                var activityTags = isEven ? evenTags : oddTags;

                activity = source.StartActivity($"span-{i}", activityKind, activity?.Context ?? default, activityTags);
                activities.Add(activity);
            }

            activities.Reverse();

            var otlpResourceSpans = activities.ToOtlpResourceSpans();

            Assert.Single(otlpResourceSpans);
            var oltpResource = otlpResourceSpans.First().Resource;

            Assert.Equal(resource.Attributes.First().Key, oltpResource.Attributes.First().Key);
            Assert.Equal(resource.Attributes.First().Value, oltpResource.Attributes.First().Value.StringValue);

            foreach (var instrumentationLibrarySpans in otlpResourceSpans.First().InstrumentationLibrarySpans)
            {
                Assert.Equal(numOfSpans / 2, instrumentationLibrarySpans.Spans.Count);
                Assert.NotNull(instrumentationLibrarySpans.InstrumentationLibrary);

                var expectedSpanNames = new List <string>();
                var start             = instrumentationLibrarySpans.InstrumentationLibrary.Name == "even" ? 0 : 1;
                for (var i = start; i < numOfSpans; i += 2)
                {
                    expectedSpanNames.Add($"span-{i}");
                }

                var otlpSpans = instrumentationLibrarySpans.Spans;
                Assert.Equal(expectedSpanNames.Count, otlpSpans.Count);

                var kv0 = new OtlpCommon.KeyValue {
                    Key = "k0", Value = new AnyValue {
                        StringValue = "v0"
                    }
                };
                var kv1 = new OtlpCommon.KeyValue {
                    Key = "k1", Value = new AnyValue {
                        StringValue = "v1"
                    }
                };

                var expectedTag = instrumentationLibrarySpans.InstrumentationLibrary.Name == "even"
                    ? kv0
                    : kv1;

                foreach (var otlpSpan in otlpSpans)
                {
                    Assert.Contains(otlpSpan.Name, expectedSpanNames);
                    Assert.Contains(expectedTag, otlpSpan.Attributes);
                }
            }
        }
예제 #25
0
        private void button6_Click(object sender, EventArgs e)
        {
            Resources.Resource parent = null;

            /// only composite resources can have a sub-resource
            if (treeView1.SelectedNode != null)
                parent = ((Resources.Resource)treeView1.SelectedNode.Tag);
            else
                parent = (Resources.Resource)this.treeView1.Nodes[0].Tag;

            Resources.Resource resource = new Resources.Resource (
                Guid.NewGuid (),
                Controller.CurrentResources.ResourceTypes["Family"],
                "new family");
            int attempt = 2;
            while(parent.Children[resource.Name] != null) {
                /// this family already exists in the parent, try another one
                resource.Name = "new family " + attempt++;
            }

            parent.Children.Add(resource);

            TreeNode treeNode = CreateTreeNode(resource);
            AddNode(treeView1.SelectedNode, treeNode);
            treeView1.SelectedNode.Expand();
            treeNode.BeginEdit();

            // TODO: add this to the resource tree?
        }