} //for serialization internal ServerInfo(string name, string ipAddress, int port, ChannelType channel) { Preconditions.CheckNotNull(name); Preconditions.CheckNotEmpty(ipAddress); Preconditions.Check(() => port > 0, "Port should be > 0"); ServerName = name; IpAddress = IPAddress.Parse(ipAddress).ToString(); Port = port; ChannelType = Enum.GetName(channel.GetType(), channel); }
/** * ChannelType */ public static ChannelTypeAttribute GetChannelTypeAttribute(this ChannelType value) { FieldInfo info = value.GetType().GetField(value.ToString()); Assert.IsNotNull(info, "找不到info"); object[] attributes = info.GetCustomAttributes(typeof(ChannelTypeAttribute), true); Assert.IsTrue(attributes.Length > 0, "没有attributes"); ChannelTypeAttribute channelTypeAttribute = (ChannelTypeAttribute)attributes[0]; return(channelTypeAttribute); }
private async Task NotifyAsync(NcMonitor monitor, string subject, string message, bool notifyUp) { TimeSpan?timeInErrorStatus = monitorManager.TimeInErrorStatus(monitor.Id); if (notifyUp && timeInErrorStatus != null || //ma se odeslat upozorneni o nahozeni, ale monitor je stale v chybovem stavu !notifyUp && timeInErrorStatus == null) //ma se odeslat upozorneni o spadnuti, ale monitor neni v chybovem stavu { return; } List <NcChannel> channels; if (notifyUp) {//oznamit vsem kanalum co j*z byly upozorneni, ze web j*z bezi channels = monitorManager.GetChannelsToLastCycleTest(monitor); } else {//oznamit vsem kanalum co jeste nebyly upozorneni a maji byt upozorneni channels = monitorManager.GetChannelsBetweenLastErrorAndTestCycle(monitor, timeInErrorStatus ?? TimeSpan.Zero); } bool foundChannels = channels.Count > 0; if (foundChannels) { foreach (NcChannel channel in channels) { ChannelType chnlType = channel.ChannelTypeEnum(); Func <NcChannelSubscriber, string> contactSelect; switch (chnlType) { case ChannelType.Email: contactSelect = x => x.User.Email; break; default: logger.LogError($"Method '{nameof(NotifyAsync)}' is not implemented for '{chnlType.GetType()}.{chnlType}' yet."); continue; } await queue.PushAsync(QueueType.Notification, new NotifyItem { ChannelType = chnlType, Subject = subject, Message = message, Contact = string.Join(";", channel.NcChannelSubscriber.Select(contactSelect)), }); } await monitorManager.SetLastTestCycleIntervalsAsync(monitor, timeInErrorStatus); } }
/// <summary> /// Creates a new channel in a specific team and group. /// </summary> /// <param name="team">Team to create channel in</param> /// <param name="group">Group to create channel in</param> /// <param name="type">Channel type</param> /// <param name="public">If channel should be public</param> /// <returns>Async task</returns> public async Task CreateChannelAsync(GId team, GId group, ChannelType type, bool @public, string name) => await ExecuteRequest <object>(new Endpoint($"teams/{team}/groups/{group}/channels", Method.POST), new JsonBody($"{{\"name\": {name}, \"contentType\": {EnumConverter.ConvertTo(type, type.GetType())}, \"isPublic\": {@public}}}"));