// Create a Metric using the TagKeys and TagValues. /// <summary> /// Generate Stackdriver Metric from Opencensus View /// </summary> /// <param name="view"></param> /// <param name="tagValues"></param> /// <param name="metricDescriptor">Stackdriver Metric Descriptor</param> /// <param name="domain"></param> /// <returns></returns> public static Metric GetMetric( IView view, IList <ITagValue> tagValues, MetricDescriptor metricDescriptor, string domain) { var metric = new Metric(); metric.Type = metricDescriptor.Type; IList <ITagKey> columns = view.Columns; // Populate metric labels for (int i = 0; i < tagValues.Count; i++) { ITagKey key = columns[i]; ITagValue value = tagValues[i]; if (value == null) { continue; } string labelKey = GetStackdriverLabelKey(key.Name); metric.Labels.Add(labelKey, value.AsString); } metric.Labels.Add(Constants.OPENCENSUS_TASK, Constants.OPENCENSUS_TASK_VALUE_DEFAULT); // TODO - zeltser - make sure all the labels from the metric descriptor were fulfilled return(metric); }
/// <summary> /// Fired when frequency channel value changes /// </summary> /// <param name="value">new tag value</param> private void OnFrequencyChannelValueChange(ITagValue value) { double newChannelValue = (double)value.Value; using (AcquireReadLock()) { // The visual parent is null if the item is deleted, this is not null for models that are within a container // and are not directly the children of the screen surface. if (VisualParent == null) { return; } ScreenModel screenModel = ScreenModel.GetScreen(this); // add an action to the collator. the collator will limit the number of actions coming from the gateway and only // process the most recent action. This keeps us from falling behind in time if we can't process the gateway updates as fast as they are received. screenModel.FromGatewayActionCollator.AddAction( _frequencyCollatorOwner, () => { using (AcquireReadLock()) { // The item could get deleted after the action has been dispatched. if (VisualParent != null) { if (!Equals(FrequencyChannelValue, newChannelValue)) { FrequencyChannelValue = newChannelValue; OnFrequencyChannelValueChangedEvent(); } } } }); } }
internal static IDictionary <ITagKey, ITagValue> ParseTags(MemoryStream buffer) { IDictionary <ITagKey, ITagValue> tags = new Dictionary <ITagKey, ITagValue>(); long limit = buffer.Length; int totalChars = 0; // Here chars are equivalent to bytes, since we're using ascii chars. while (buffer.Position < limit) { int type = buffer.ReadByte(); if (type == TAG_FIELD_ID) { ITagKey key = CreateTagKey(DecodeString(buffer)); ITagValue val = CreateTagValue(key, DecodeString(buffer)); totalChars += key.Name.Length; totalChars += val.AsString.Length; tags[key] = val; } else { // Stop parsing at the first unknown field ID, since there is no way to know its length. // TODO(sebright): Consider storing the rest of the byte array in the TagContext. break; } } if (totalChars > TAGCONTEXT_SERIALIZED_SIZE_LIMIT) { throw new TagContextDeserializationException( "Size of TagContext exceeds the maximum serialized size " + TAGCONTEXT_SERIALIZED_SIZE_LIMIT); } return(tags); }
/// <summary> /// Fired when the duty cyle channel value changes /// </summary> /// <param name="value">new tag value</param> private void OnDutyCycleChannelValueChange(ITagValue value) { double newChannelValue = (double)value.Value; using (AcquireReadLock()) { // The visual parent is null if the item is deleted, this is not null for models that are within a container // and are not directly the children of the screen surface. if (VisualParent == null) { return; } ScreenModel screenModel = ScreenModel.GetScreen(this); screenModel.FromGatewayActionCollator.AddAction( _dutyCycleCollatorOwner, () => { using (AcquireReadLock()) { // The item could get deleted after the action has been dispatched. if (VisualParent != null) { DutyCycleChannelValue = newChannelValue; OnDutyCycleChannelValueChangedEvent(); } } }); } }
public override ITagContextBuilder Put(ITagKey key, ITagValue value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } this.Tags[key] = value ?? throw new ArgumentNullException(nameof(value)); return(this); }
public void AddArgument(ITagValue tagValue) { if (tagValue == null) { throw new ArgumentNullException("tagValue"); } if (!_Arguments.Exists(tv => Equals(tv.Tag, tagValue.Tag))) { _Arguments.Add(tagValue); } }
protected override void BeforeFormat(INoticeMessage message, ITagValue[] tagsValues) { _nvelocityContext = new VelocityContext(); _nvelocityContext.AttachEventCartridge(new EventCartridge()); _nvelocityContext.EventCartridge.ReferenceInsertion += EventCartridgeReferenceInsertion; foreach (var tagValue in tagsValues) { _nvelocityContext.Put(tagValue.Tag, tagValue.Value); } base.BeforeFormat(message, tagsValues); }
protected override string FormatText(string text, ITagValue[] tagsValues) { if (String.IsNullOrEmpty(text)) return text; var formattedText = RegEx.Replace(text, match => { var value = Array.Find(tagsValues, v => v.Tag == match.Groups["tagName"].Value); return value != null && value.Value != null ? Convert.ToString(value.Value) : match.Value; }); return formattedText; }
public void FormatMessage(INoticeMessage message, ITagValue[] tagsValues) { if (message == null) throw new ArgumentNullException("message"); if (message.Pattern == null) throw new ArgumentException("message"); if (tagsValues == null) throw new ArgumentNullException("tagsValues"); BeforeFormat(message, tagsValues); message.Subject = FormatText(doformat ? message.Subject : message.Pattern.Subject, tagsValues); message.Body = FormatText(doformat ? message.Body : message.Pattern.Body, tagsValues); AfterFormat(message); }
internal Tag(ITagKey key, ITagValue value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } this.Key = key; if (value == null) { throw new ArgumentNullException(nameof(value)); } this.Value = value; }
private void NotifyNewComment(FeedComment comment, Feed feed) { var feedType = feed.FeedType == FeedType.Poll ? "poll" : "feed"; var tags = new ITagValue[] { new TagValue(NewsConst.TagFEED_TYPE, feedType), //new TagValue(NewsConst.TagAnswers, feed.Variants.ConvertAll<string>(v => v.Name)), new TagValue(NewsConst.TagCaption, feed.Caption), new TagValue("CommentBody", HtmlUtility.GetFull(comment.Comment)), new TagValue(NewsConst.TagDate, comment.Date.ToShortString()), new TagValue(NewsConst.TagURL, CommonLinkUtility.GetFullAbsolutePath("~/Products/Community/Modules/News/Default.aspx?docid=" + feed.Id)), new TagValue("CommentURL", CommonLinkUtility.GetFullAbsolutePath("~/Products/Community/Modules/News/Default.aspx?docid=" + feed.Id + "#container_" + comment.Id.ToString(CultureInfo.InvariantCulture))), new TagValue(NewsConst.TagUserName, DisplayUserSettings.GetFullUserName(SecurityContext.CurrentAccount.ID)), new TagValue(NewsConst.TagUserUrl, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(SecurityContext.CurrentAccount.ID))) }; var initatorInterceptor = new InitiatorInterceptor(new DirectRecipient(comment.Creator, "")); try { NewsNotifyClient.NotifyClient.AddInterceptor(initatorInterceptor); var mentionedUsers = MentionProvider.GetMentionedUsers(comment.Comment); var mentionedUserIds = mentionedUsers.Select(u => u.ID.ToString()); var provider = NewsNotifySource.Instance.GetSubscriptionProvider(); var objectID = feed.Id.ToString(CultureInfo.InvariantCulture); var recipients = provider .GetRecipients(NewsConst.NewComment, objectID) .Where(r => !mentionedUserIds.Contains(r.ID)) .ToArray(); NewsNotifyClient.NotifyClient.SendNoticeToAsync(NewsConst.NewComment, objectID, recipients, false, tags); if (mentionedUsers.Length > 0) { NewsNotifyClient.NotifyClient.SendNoticeToAsync(NewsConst.MentionForFeedComment, objectID, mentionedUsers, false, tags); } } finally { NewsNotifyClient.NotifyClient.RemoveInterceptor(initatorInterceptor.Name); } }
protected internal List <ITagValue> GetTagValuesInColumnOrder(IList <ITagKey> columns, List <KeyValuePair <string, string> > tags) { ITagValue[] tagValues = new ITagValue[columns.Count]; foreach (var kvp in tags) { var key = TagKey.Create(kvp.Key); var value = TagValue.Create(kvp.Value); int indx = columns.IndexOf(key); if (indx < 0) { return(null); } tagValues[indx] = value; } return(new List <ITagValue>(tagValues)); }
protected abstract string FormatText(string text, ITagValue[] tagsValues);
private NotifyRequest CreateRequest(INotifyAction action, string objectID, IRecipient recipient, SendNoticeCallback sendCallback, ITagValue[] args, string[] senders, bool checkSubsciption) { if (action == null) throw new ArgumentNullException("action"); if (recipient == null) throw new ArgumentNullException("recipient"); if (sendCallback != null) throw new NotImplementedException("sendCallback"); var request = new NotifyRequest(notifySource, action, objectID, recipient); request.SenderNames = senders; request.IsNeedCheckSubscriptions = checkSubsciption; if (args != null) request.Arguments.AddRange(args); return request; }
public void FormatMessage(ASC.Notify.Messages.INoticeMessage message, ITagValue[] tagsValues) { throw new NotImplementedException(); }
internal Tag(ITagKey key, ITagValue value) { this.Key = key ?? throw new ArgumentNullException(nameof(key)); this.Value = value ?? throw new ArgumentNullException(nameof(value)); }
protected override string FormatText(string text, ITagValue[] tagsValues) { if (String.IsNullOrEmpty(text)) return text; return VelocityFormatter.FormatText(text, _nvelocityContext); }
public void AddArgument(ITagValue tagValue) { if (tagValue == null) throw new ArgumentNullException("tagValue"); if (!_Arguments.Exists(tv => Equals(tv.Tag, tagValue.Tag))) _Arguments.Add(tagValue); }
protected virtual void BeforeFormat(INoticeMessage message, ITagValue[] tagsValues) { }
public abstract ITagContextBuilder Put(ITagKey key, ITagValue value);
public void FormatMessage(INoticeMessage message, ITagValue[] tagsValues) { }
public static ITag Create(ITagKey key, ITagValue value) { return(new Tag(key, value)); }
public void SaveComment(Comment comment, Post post) { CommunitySecurity.DemandPermissions(post, Constants.Action_AddComment); SaveComment(comment); var initiatorInterceptor = new InitiatorInterceptor(new DirectRecipient(comment.UserID.ToString(), "")); try { NotifyClient.BeginSingleRecipientEvent("asc_blog_c"); NotifyClient.AddInterceptor(initiatorInterceptor); var tags = new ITagValue[] { new TagValue(Constants.TagPostSubject, post.Title), new TagValue(Constants.TagPostPreview, post.GetPreviewText(500)), new TagValue(Constants.TagUserName, DisplayUserSettings.GetFullUserName(comment.UserID)), new TagValue(Constants.TagUserURL, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(comment.UserID))), new TagValue(Constants.TagDate, string.Format("{0:d} {0:t}", comment.Datetime)), new TagValue(Constants.TagCommentBody, comment.Content), new TagValue(Constants.TagURL, CommonLinkUtility.GetFullAbsolutePath(Constants.ViewBlogPageUrl + "?blogid=" + post.ID.ToString())), new TagValue(Constants.TagCommentURL, CommonLinkUtility.GetFullAbsolutePath(Constants.ViewBlogPageUrl + "?blogid=" + post.ID.ToString() + "#container_" + comment.ID.ToString())) }; var mentionedUsers = MentionProvider.GetMentionedUsers(comment.Content); var mentionedUserIds = mentionedUsers.Select(u => u.ID.ToString()); var provider = _notifySource.GetSubscriptionProvider(); var objectID = post.ID.ToString(); var recipients = provider .GetRecipients(Constants.NewComment, objectID) .Where(r => !mentionedUserIds.Contains(r.ID)) .ToArray(); NotifyClient.SendNoticeToAsync(Constants.NewComment, objectID, recipients, false, tags); if (mentionedUsers.Length > 0) { NotifyClient.SendNoticeToAsync(Constants.MentionForPostComment, objectID, mentionedUsers, false, tags); } NotifyClient.EndSingleRecipientEvent("asc_blog_c"); } finally { NotifyClient.RemoveInterceptor(initiatorInterceptor.Name); } var subscriptionProvider = NotifySource.GetSubscriptionProvider(); if (!subscriptionProvider.IsUnsubscribe((IDirectRecipient)NotifySource.GetRecipientsProvider(). GetRecipient(SecurityContext.CurrentAccount.ID.ToString()), Constants.NewComment, post.ID.ToString())) { subscriptionProvider.Subscribe( Constants.NewComment, post.ID.ToString(), NotifySource.GetRecipientsProvider(). GetRecipient(SecurityContext.CurrentAccount.ID.ToString()) ); } }