/// <summary> /// Adds the specified channel. /// </summary> /// <param name="channel">The channel.</param> public static ChannelInstance Add(ChannelConfiguration channel) { var channelInstance = new ChannelInstance(channel); _Channels.Add(channelInstance); return channelInstance; }
public static void Dock(ChannelInstance channel, string keyword) { EnsureList(); _list.Add(new DockedChannel { ChannelId = channel.Configuration.ChannelId, Keyword = keyword }); SaveValue(); }
public static void Undock(ChannelInstance channel) { EnsureList(); _list.RemoveAll(l => l.ChannelId == channel.Configuration.ChannelId); SaveValue(); }
public ChannelSearchStreamToolbarElement(ChannelInstance channel) { this.channel = channel; this.SearchResults = new AdvancedObservableCollection<ChannelStatusUpdate>(); this.SearchResultsViewSource = new CollectionViewSource { Source = SearchResults }; InitializeComponent(); DataContext = this; }
public override void OnCompleted() { channel = null; EventBroker.Publish(AppEvents.ReceiveFinished); // Schedule next execution new Run("Receive").After(SettingsManager.ClientSettings.AppConfiguration.ReceiveConfiguration.ReceiveInterval).Minutes().Call(Tasks.Receive); base.OnCompleted(); }
internal static void SendExecute(ChannelInstance sourceChannel, ExecutedRoutedEventArgs e) { var source = (ButtonBase)e.OriginalSource; var inreplyto = source.DataContext as UserStatus; // Reply to parent if that is available, othwerwise facebook replies // will break down. if (inreplyto != null && inreplyto.Parent != null) inreplyto = inreplyto.Parent; var channel = inreplyto == null ? sourceChannel : ChannelsManager.GetChannelObject(inreplyto.SourceChannel.ChannelId); Send(new[] { channel }, inreplyto == null ? null : inreplyto.ChannelStatusKey, e); }
public int Save(ChannelInstance instance) { using (var db = new LiteDatabase(DbPath())) { var Channels = db.GetCollection <ChannelInstance>(CHANNELS); if (instance.Id == 0) { return(Channels.Insert(instance)); } else { Channels.Upsert(instance); } return(instance.Id); } }
void ToggleChannelInstance(ChannelInstance channel) { if (SelectedChannels.Contains(channel.Configuration.ChannelId)) { SelectedChannels.Remove(channel.Configuration.ChannelId); } else { SelectedChannels.Add(channel.Configuration.ChannelId); } // Forces a propertychanged event, which resets our toggle button channel.IsVisible = channel.IsVisible; OnPropertyChanged("HasTwitter"); }
public EndToEndTestContext() { Instance = new ChannelInstance(new ChannelConfig() { Channel = "quantumdota", DotaAuth = new SteamUser.LogOnDetails() { Username = "******", Password = "******" }, TwitchAuth = new AuthInfo() { Username = "******", Password = "******" } }); }
internal static void SendExecute(ChannelInstance sourceChannel, ExecutedRoutedEventArgs e) { var source = (ButtonBase)e.OriginalSource; var inreplyto = source.DataContext as UserStatus; // Reply to parent if that is available, othwerwise facebook replies // will break down. if (inreplyto != null && inreplyto.Parent != null) { inreplyto = inreplyto.Parent; } var channel = inreplyto == null ? sourceChannel : ChannelsManager.GetChannelObject(inreplyto.SourceChannel.ChannelId); Send(new[] { channel }, inreplyto == null ? null : inreplyto.ChannelStatusKey, e); }
private static DateTime[] ParseTimeData(ChannelInstance channelInstance) { SeriesInstance timeSeries; SeriesDefinition timeSeriesDefinition; DateTime[] timeData; DateTime startTime; if (!channelInstance.SeriesInstances.Any()) { return(null); } timeSeries = channelInstance.SeriesInstances[0]; timeSeriesDefinition = timeSeries.Definition; if (timeSeriesDefinition.ValueTypeID != SeriesValueType.Time) { return(null); } if (timeSeriesDefinition.QuantityUnits == QuantityUnits.Timestamp) { timeData = timeSeries.OriginalValues .Select(Convert.ToDateTime) .ToArray(); } else if (timeSeriesDefinition.QuantityUnits == QuantityUnits.Seconds) { startTime = channelInstance.ObservationRecord.StartTime; timeData = timeSeries.OriginalValues .Select(Convert.ToDouble) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .Select(timeSpan => startTime + timeSpan) .ToArray(); } else { return(null); } return(timeData); }
public void AddQuote(ChatMessage lastMessage) { if (lastMessage.UserRole <= Role.VIP) { FilterOutSegments(lastMessage.Message, out int _, out string authorFilter, out string quoteTextFilter); if (quoteTextFilter != "") { var newQuote = new Storage.Quote(authorFilter, quoteTextFilter); ChannelQuotes.QuotesList.Add(newQuote); ChannelQuotes.Save(); ChannelInstance.SendChatMessageResponse(lastMessage, string.Format("Added new quote (ID: {0}): {1}", ChannelQuotes.QuotesList.Count - 1, newQuote)); } } else { ChannelInstance.SendChatMessage("Only VIPs and Moderators can add quotes. Sorry."); } }
private static Channel ParseSeries(SeriesInstance seriesInstance) { Channel channel = new Channel(); Series series = new Series(); ChannelInstance channelInstance = seriesInstance.Channel; ChannelDefinition channelDefinition = channelInstance.Definition; SeriesDefinition seriesDefinition = seriesInstance.Definition; QuantityMeasured quantityMeasured = channelDefinition.QuantityMeasured; Phase phase = channelDefinition.Phase; // Populate channel properties channel.Name = channelDefinition.ChannelName; channel.HarmonicGroup = channelInstance.ChannelGroupID; channel.MeasurementType = new MeasurementType(); channel.MeasurementCharacteristic = new MeasurementCharacteristic(); channel.Phase = new Database.Phase(); if (seriesInstance.Definition.HasElement(SeriesDefinition.SeriesNominalQuantityTag)) { channel.PerUnitValue = seriesInstance.Definition.SeriesNominalQuantity; } // Populate series properties series.SeriesType = new SeriesType(); series.Channel = channel; series.SourceIndexes = string.Empty; // Populate measurement type properties channel.MeasurementType.Name = quantityMeasured.ToString(); // Populate characteristic properties channel.MeasurementCharacteristic.Name = QuantityCharacteristic.ToName(seriesDefinition.QuantityCharacteristicID) ?? seriesDefinition.QuantityCharacteristicID.ToString(); channel.MeasurementCharacteristic.Description = QuantityCharacteristic.ToString(seriesDefinition.QuantityCharacteristicID); // Popuplate phase properties channel.Phase.Name = phase.ToString(); // Populate series type properties series.SeriesType.Name = SeriesValueType.ToString(seriesDefinition.ValueTypeID) ?? seriesDefinition.ValueTypeName ?? seriesDefinition.ValueTypeID.ToString(); series.SeriesType.Description = seriesDefinition.ValueTypeName; return(channel); }
public RealtimeStream(ChannelInstance channel, string keyword) { this.Channel = channel; this.Keyword = keyword; this.mailbox = VirtualMailBox.Current; this.markreadtimer = new DispatcherTimer(DispatcherPriority.Normal, Dispatcher) { Interval = TimeSpan.FromMilliseconds(400), IsEnabled = false }; this.markreadtimer.Tick += MarkReadTimerTick; InitializeComponent(); StreamStatusUpdatesSource = new CollectionViewSource { Source = State.StatusUpdates }; MentionsStatusUpdatesSource = new CollectionViewSource { Source = State.StatusUpdates }; StreamStatusUpdatesSource.SortDescriptions.Add(new SortDescription("ParentSortDate", ListSortDirection.Descending)); StreamStatusUpdatesSource.SortDescriptions.Add(new SortDescription("SortDate", ListSortDirection.Ascending)); StreamStatusUpdatesSource.View.Filter = StreamStatusUpdatesSourceFilter; MentionsStatusUpdatesSource.SortDescriptions.Add(new SortDescription("ParentSortDate", ListSortDirection.Descending)); MentionsStatusUpdatesSource.SortDescriptions.Add(new SortDescription("SortDate", ListSortDirection.Ascending)); MentionsStatusUpdatesSource.View.Filter = MentionsStatusUpdatesSourceFilter; DataContext = this; mailbox.InboxLoadComplete += delegate { StreamStatusUpdatesSource.View.Refresh(); MentionsStatusUpdatesSource.View.Refresh(); }; EventBroker.Subscribe(AppEvents.SyncStatusUpdatesFinished, () => ThreadPool.QueueUserWorkItem(UpdateCountAsync)); Responder.SetIsFirstResponder(SupportsMentions ? Stream2ListView : Stream1ListView, true); ThreadPool.QueueUserWorkItem(UpdateCountAsync); }
private ParsedChannel MakeParsedChannel(ChannelInstance channel) { // Get the time series and value series for the given channel SeriesInstance timeSeries = channel.SeriesInstances.Single(series => series.Definition.ValueTypeID == SeriesValueType.Time); SeriesInstance valuesSeries = channel.SeriesInstances.Single(series => series.Definition.ValueTypeID == SeriesValueType.Val); // Set up parsed channel to be returned ParsedChannel parsedChannel = new ParsedChannel() { Name = channel.Definition.ChannelName, YValues = valuesSeries.OriginalValues }; if (timeSeries.Definition.QuantityUnits == QuantityUnits.Seconds) { // If time series is in seconds from start time of the observation record, // TimeValues must be calculated by adding values to start time parsedChannel.TimeValues = timeSeries.OriginalValues .Select(Convert.ToDouble) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .Select(timeSpan => channel.ObservationRecord.StartTime + timeSpan) .ToList(); parsedChannel.XValues = timeSeries.OriginalValues; } else if (timeSeries.Definition.QuantityUnits == QuantityUnits.Timestamp) { // If time series is a collection of absolute time, seconds from start time // must be calculated by subtracting the start time of the observation record parsedChannel.TimeValues = timeSeries.OriginalValues.Cast <DateTime>().ToList(); parsedChannel.XValues = timeSeries.OriginalValues .Cast <DateTime>() .Select(time => time - channel.ObservationRecord.StartTime) .Select(timeSpan => timeSpan.TotalSeconds) .Cast <object>() .ToList(); } return(parsedChannel); }
public void CallApi(ChannelInstance ch, string apiName, byte[] param, out byte[] output) { ch.sw.Write(CH_CALL); Byte[] s = Encoding.GetEncoding(936).GetBytes(apiName); Byte[] apiNameBytes = new Byte[32]; for (int i = 0; i < s.Length; i++) { apiNameBytes[i] = s[i]; } ch.sw.Write(apiNameBytes); ch.sw.Write(param.Length); if (param.Length > 0) { ch.sw.Write(param); } output = GetMessage(ch); }
public void NamedPipeWorkerThread(object e) { NamedPipeServerStream channel = e as NamedPipeServerStream; try { using (BinaryReader sr = new BinaryReader(channel)) { using (BinaryWriter sw = new BinaryWriter(channel)) { ChannelInstance ch = new ChannelInstance(); ch.channel = channel; ch.sr = sr; ch.sw = sw; NotifyCreateConnect(ch); while (true) { GetMessage(ch); } } } } catch (System.IO.EndOfStreamException) { ChannelInstance ch = new ChannelInstance(); ch.channel = channel; NotifyCloseConnect(ch); } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } channel.Close(); }
private static TimeSpan[] ParseTimeSpanData(SeriesInstance seriesInstance, double systemFrequency) { TimeSpan[] timeSpanData; SeriesDefinition timeSeriesDefinition = seriesInstance.Definition; if (timeSeriesDefinition.ValueTypeID != SeriesValueType.Duration) { return(null); } VectorElement seriesValues = seriesInstance.SeriesValues; if (timeSeriesDefinition.QuantityUnits == QuantityUnits.Cycles) { ChannelInstance channelInstance = seriesInstance.Channel; double nominalFrequency = channelInstance.ObservationRecord?.Settings.NominalFrequency ?? systemFrequency; timeSpanData = seriesInstance.OriginalValues .Select(Convert.ToDouble) .Select(cycles => cycles / nominalFrequency) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .ToArray(); } else { timeSpanData = seriesInstance.OriginalValues .Select(Convert.ToDouble) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .ToArray(); } return(timeSpanData); }
public RealtimeStream(ChannelInstance channel, string keyword) { this.Channel = channel; this.Keyword = keyword; this.mailbox = VirtualMailBox.Current; this.markreadtimer = new DispatcherTimer(DispatcherPriority.Normal, Dispatcher) { Interval = TimeSpan.FromMilliseconds(400), IsEnabled = false }; this.markreadtimer.Tick += MarkReadTimerTick; InitializeComponent(); StreamStatusUpdatesSource = new CollectionViewSource { Source = State.StatusUpdates }; MentionsStatusUpdatesSource = new CollectionViewSource { Source = State.StatusUpdates }; StreamStatusUpdatesSource.SortDescriptions.Add(new SortDescription("ParentSortDate", ListSortDirection.Descending)); StreamStatusUpdatesSource.SortDescriptions.Add(new SortDescription("SortDate", ListSortDirection.Ascending)); StreamStatusUpdatesSource.View.Filter = StreamStatusUpdatesSourceFilter; MentionsStatusUpdatesSource.SortDescriptions.Add(new SortDescription("ParentSortDate", ListSortDirection.Descending)); MentionsStatusUpdatesSource.SortDescriptions.Add(new SortDescription("SortDate", ListSortDirection.Ascending)); MentionsStatusUpdatesSource.View.Filter = MentionsStatusUpdatesSourceFilter; DataContext = this; mailbox.InboxLoadComplete += delegate { StreamStatusUpdatesSource.View.Refresh(); MentionsStatusUpdatesSource.View.Refresh(); }; EventBroker.Subscribe(AppEvents.SyncStatusUpdatesFinished, () => ThreadPool.QueueUserWorkItem(UpdateCountAsync)); Responder.SetIsFirstResponder(SupportsMentions ? Stream2ListView : Stream1ListView, true); ThreadPool.QueueUserWorkItem(UpdateCountAsync); }
internal static RealtimeStream Get(ChannelInstance channel, string keyword, bool isColumnView) { RealtimeStream stream; if (!String.IsNullOrEmpty(keyword)) { // Search stream if (!searchDict.ContainsKey(keyword)) { stream = new RealtimeStream(channel, keyword); searchDict.Add(keyword, stream); } // Return cached copy var view = searchDict[keyword]; view.IsColumnView = isColumnView; return view; } else { if (!channelsDict.ContainsKey(channel)) { stream = new RealtimeStream(channel, keyword); channelsDict.Add(channel, stream); } var view = channelsDict[channel]; view.IsColumnView = isColumnView; // Return cached copy return view; } }
private void btnAddChannel_Click(object sender, EventArgs e) { ChannelInstance chi = new ChannelInstance(); chi.Name = ""; chi.Description = ""; chi.DeviceName = ""; chi.Setting = ""; FormChannel frm = new FormChannel(chi); //frm.Channel = chi; if (frm.ShowDialog(this) == DialogResult.OK) { Program.ConfigMgr.Config.Channels.Add(frm.Channel); ListViewItem lvi = new ListViewItem((lViewChannels.Items.Count + 1).ToString()); lvi.SubItems.Add(frm.Channel.Name); lvi.SubItems.Add(frm.Channel.DeviceName); lvi.SubItems.Add(frm.Channel.Description); lvi.SubItems.Add(frm.Channel.Enable.ToString()); lViewChannels.Items.Add(lvi); } }
internal static RealtimeStream Get(ChannelInstance channel, string keyword, bool isColumnView) { RealtimeStream stream; if (!String.IsNullOrEmpty(keyword)) { // Search stream if (!searchDict.ContainsKey(keyword)) { stream = new RealtimeStream(channel, keyword); searchDict.Add(keyword, stream); } // Return cached copy var view = searchDict[keyword]; view.IsColumnView = isColumnView; return(view); } else { if (!channelsDict.ContainsKey(channel)) { stream = new RealtimeStream(channel, keyword); channelsDict.Add(channel, stream); } var view = channelsDict[channel]; view.IsColumnView = isColumnView; // Return cached copy return(view); } }
public ReceiveTask(ReceiveRange range, ChannelInstance channel) { this.range = range; this.channel = channel; }
void ToggleChannelInstance(ChannelInstance channel) { if (SelectedChannels.Contains(channel.Configuration.ChannelId)) { SelectedChannels.Remove(channel.Configuration.ChannelId); } else { SelectedChannels.Add(channel.Configuration.ChannelId); } // Forces a propertychanged event, which resets our toggle button channel.IsVisible = channel.IsVisible; OnPropertyChanged("HasTwitter"); }
/// <summary> /// Adds a new channel instance to the collection /// of channel instances in this observation record. /// </summary> public ChannelInstance AddNewChannelInstance() { CollectionElement channelInstancesElement = m_physicalRecord.Body.Collection.GetCollectionByTag(ChannelInstancesTag); CollectionElement channelInstanceElement = new CollectionElement() { TagOfElement = OneChannelInstanceTag }; ChannelInstance channelInstance = new ChannelInstance(channelInstanceElement, this); if ((object)channelInstancesElement == null) { channelInstancesElement = new CollectionElement() { TagOfElement = OneChannelInstanceTag }; m_physicalRecord.Body.Collection.AddElement(channelInstancesElement); } channelInstancesElement.AddElement(channelInstanceElement); return channelInstance; }
IEnumerable<SourceAddress> FilterByTargetChannel(IEnumerable<SourceAddress> source, ChannelInstance channel) { foreach (var address in source) { if (channel.Configuration.Charasteristics.SupportsEmail) { // Mail channels allow everything that is a valid email address if (SourceAddress.IsValidEmail(address.Address)) yield return address; } else { // Social channels only allow entries that are available in the addressbook SourceAddress address1 = address; using (mailbox.Profiles.ReaderLock) if (mailbox.Profiles.Where(p => p.Address == address1.Address).Count() > 0) yield return address; } } }
public OverviewColumnTabItem(ChannelInstance channel, string keyword) : this() { Channel = channel; Keyword = keyword; }
public SyncTask(ChannelInstance channel) { this.channel = channel; }
/// <summary> /// Removes the specified channel. /// </summary> /// <param name="channel">The channel.</param> public static void Remove(ChannelInstance channel) { _Channels.Remove(channel); }
public ChannelControler(IChannel chn, ChannelInstance chnCfg) { ChannelImpl = chn; ChannelConfig = chnCfg; }
public static void Sync(ChannelInstance channel) { new SyncTask(channel) { OverrideCanExecute = true }.ExecuteAsync(); }
public ReceiveTask(ReceiveRange range, ChannelInstance channel) { this.range = range; this.channel = channel; }
public static void Receive(ChannelInstance channel) { new ReceiveTask(new ReceiveRange { OnlyNew = true, PageSize = DebugKeys.DefaultPageSize }, channel) { OverrideCanExecute = true }.ExecuteAsync(); }
public SyncTask(ChannelInstance channel) { this.channel = channel; }
public OverviewColumnTabItem(ChannelInstance channel, string keyword) : this() { Channel = channel; Keyword = keyword; }
public void RemoveQuote(ChatMessage lastMessage) { if (lastMessage.UserRole <= Role.Mod) { if (ChannelQuotes.QuotesList.Count == 0) { ChannelInstance.SendChatMessageResponse(lastMessage, "Channel doesn't have any quotes."); return; } FilterOutSegments(lastMessage.Message, out int quoteID, out string authorFilter, out string quoteTextFilter); if (quoteID == -2) { quoteID = ChannelQuotes.QuotesList.Count - 1; } if (quoteID >= 0 && (authorFilter != "" || quoteTextFilter != "")) { ChannelInstance.SendChatMessageResponse(lastMessage, "ID search is not meant to be used in conjunction with Author Filter or Quote Text Filter!"); } else { if (quoteID < ChannelQuotes.QuotesList.Count && quoteID >= 0) { var quote = ChannelQuotes.QuotesList[quoteID]; ChannelQuotes.QuotesList.RemoveAt(quoteID); ChannelQuotes.Save(); ChannelInstance.SendChatMessageResponse(lastMessage, "Removed quote: " + quote.ToString()); } else if (quoteID == -1) { var advSearch = AdvancedSearch(authorFilter, quoteTextFilter); if (advSearch == null) { ChannelInstance.SendChatMessageResponse(lastMessage, "Nothing found!"); } else { if (advSearch.Length > 1) { ChannelInstance.SendChatMessageResponse(lastMessage, string.Format("Found {0} results, so nothing was removed.", advSearch.Length)); } else { var removedQuote = advSearch[0]; ChannelQuotes.QuotesList.Remove(removedQuote); ChannelQuotes.Save(); ChannelInstance.SendChatMessageResponse(lastMessage, string.Format("Removed: {0}", removedQuote.ToString())); } } } else { ChannelInstance.SendChatMessageResponse(lastMessage, string.Format("Provided ID is higher than total count of Quotes (total: {0}).", ChannelQuotes.QuotesList.Count)); } } } else { ChannelInstance.SendChatMessage("Only VIPs and Moderators can remove quotes. Sorry."); } }
public ChannelSearchStreamToolbarPlugin(ChannelInstance channel) { this.channel = channel; }
private void SearchQuote(ChatMessage lastMessage) { FilterOutSegments(lastMessage.Message, out int quoteID, out string authorFilter, out string quoteTextFilter); if (quoteID == -2) { quoteID = ChannelQuotes.QuotesList.Count - 1; } if (quoteID < 0 && authorFilter == "" && quoteTextFilter == "") { ChannelInstance.SendChatMessageResponse(lastMessage, "No search data provided or incorrect format"); } else if (quoteID >= 0 && (authorFilter != "" || quoteTextFilter != "")) { ChannelInstance.SendChatMessageResponse(lastMessage, "ID search is not meant to be used in conjunction with Author Filter or Quote Text Filter!"); } else if (quoteID >= 0) { if (quoteID < ChannelQuotes.QuotesList.Count) { ChannelInstance.SendChatMessageResponse(lastMessage, ChannelQuotes.QuotesList[quoteID].ToString()); } else { ChannelInstance.SendChatMessageResponse(lastMessage, string.Format("Provided ID is higher than total count of Quotes (total: {0}).", ChannelQuotes.QuotesList.Count)); } } else { Regex authorRegex = null; Regex quoteRegex = null; try { if (authorFilter != "") { authorRegex = new Regex(authorFilter, RegexOptions.IgnoreCase); } } catch { ChannelInstance.SendChatMessageResponse(lastMessage, "Author regex failed to compile"); return; } try { if (quoteTextFilter != "") { quoteRegex = new Regex(quoteTextFilter, RegexOptions.IgnoreCase); } } catch { ChannelInstance.SendChatMessageResponse(lastMessage, "Quote regex failed to compile"); return; } var advSearchQuotes = AdvancedSearch(authorRegex, quoteRegex); if (advSearchQuotes == null) { ChannelInstance.SendChatMessageResponse(lastMessage, "Nothing found."); } else { if (advSearchQuotes.Length > 1) { List <int> ids = new List <int>(); foreach (var foundQuote in advSearchQuotes) { ids.Add(ChannelQuotes.QuotesList.IndexOf(foundQuote)); } ChannelInstance.SendChatMessageResponse(lastMessage, $"Found {advSearchQuotes.Length} results: {string.Join(", ", ids).TrimEnd(',')}."); } else { ChannelInstance.SendChatMessageResponse(lastMessage, advSearchQuotes[0].ToString()); } } } }
/// <summary> /// Removes the given channel instance from the collection of channel instances. /// </summary> /// <param name="channelInstance">The channel instance to be removed.</param> public void Remove(ChannelInstance channelInstance) { CollectionElement channelInstancesElement = m_physicalRecord.Body.Collection.GetCollectionByTag(ChannelInstancesTag); List<CollectionElement> channelInstanceElements; ChannelInstance instance; if ((object)channelInstancesElement == null) return; channelInstanceElements = channelInstancesElement.GetElementsByTag(OneChannelInstanceTag).Cast<CollectionElement>().ToList(); foreach (CollectionElement channelSettingElement in channelInstanceElements) { instance = new ChannelInstance(channelSettingElement, this); if (Equals(channelInstance, instance)) channelInstancesElement.RemoveElement(channelSettingElement); } }
private ParsedChannel MakeParsedChannel(ChannelInstance channel) { // Get the time series and value series for the given channel SeriesInstance timeSeries = channel.SeriesInstances.Single(series => series.Definition.ValueTypeID == SeriesValueType.Time); SeriesInstance valuesSeries = channel.SeriesInstances.Single(series => series.Definition.ValueTypeID == SeriesValueType.Val); // Set up parsed channel to be returned ParsedChannel parsedChannel = new ParsedChannel() { Name = channel.Definition.ChannelName, YValues = valuesSeries.OriginalValues }; if (timeSeries.Definition.QuantityUnits == QuantityUnits.Seconds) { // If time series is in seconds from start time of the observation record, // TimeValues must be calculated by adding values to start time parsedChannel.TimeValues = timeSeries.OriginalValues .Select(Convert.ToDouble) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .Select(timeSpan => channel.ObservationRecord.StartTime + timeSpan) .ToList(); parsedChannel.XValues = timeSeries.OriginalValues; } else if (timeSeries.Definition.QuantityUnits == QuantityUnits.Timestamp) { // If time series is a collection of absolute time, seconds from start time // must be calculated by subtracting the start time of the observation record parsedChannel.TimeValues = timeSeries.OriginalValues.Cast<DateTime>().ToList(); parsedChannel.XValues = timeSeries.OriginalValues .Cast<DateTime>() .Select(time => time - channel.ObservationRecord.StartTime) .Select(timeSpan => timeSpan.TotalSeconds) .Cast<object>() .ToList(); } return parsedChannel; }
public void Dispose() { Instance.Stop(); Instance = null; }
public virtual void NotifyCallerProcedure(ChannelInstance ch, APICaller caller) { }
public ChannelModule(CachedManager manager) { Get["/"] = _ => { //Profile.Trace("/ from:{0}", Request.UserHostAddress); return(View["ChannelIndex.html", manager.List()]); }; //curl http://127.0.0.1:2018/Test Get["/Test"] = _ => { var data = new { this.Request.UserHostAddress, this.Request.Headers, this.Request.Query, this.Request.Form, this.Request.Method, this.Request.Url, this.Request.Path }; return(Response.AsText(serializer.Serialize(data), "application/json")); }; //curl http://127.0.0.1:2018/Api/Types Get["/Api/Types"] = _ => { return(manager.Plugins); }; //curl http://127.0.0.1:2018/Api/Index Get["/Api/Index"] = _ => { return(manager.List()); }; //curl http://127.0.0.1:2018/Api/ById/1 Get["/Api/ById/{id:int}"] = p => { return(manager.LoadById(p["id"])); }; //curl http://127.0.0.1:2018/Api/ByName/ECHO1 Get["/Api/ByName/{name}"] = p => { return(manager.LoadByName(p["name"])); }; //curl http://127.0.0.1:2018/Api/List/Echo //curl http://127.0.0.1:2018/Api/List/Serial //curl http://127.0.0.1:2018/Api/List/Modbus //curl http://127.0.0.1:2018/Api/List/Socket Get["/Api/List/{type}"] = p => { return(ChannelUtils.List(p["type"])); }; Get["/New{type}Channel"] = p => { var instance = new ChannelInstance(p["type"]); var view = string.Format("Edit{0}Channel.html", p["type"]); return(View[view, new ChannelModel(instance)]); }; Get["/EditChannel/{id:int}"] = p => { var model = manager.LoadById(p["id"]); if (model == null) { return(new RedirectResponse("/")); } var view = string.Format("Edit{0}Channel.html", model.Type); return(View[view, model]); }; Post["/UpdateChannel/{id:int}/{access}"] = p => { if (IsLoopback(Request.UserHostAddress)) { var access = Enum.Parse(typeof(ChannelAccess), p["access"]); manager.Update(p["id"], access); } return(new RedirectResponse("/")); }; Post["/SaveChannel"] = p => { if (IsLoopback(Request.UserHostAddress)) { var instance = this.Bind <ChannelInstance>(); int id = manager.Save(instance); } return(new RedirectResponse("/")); }; Post["/RemoveChannel/{id:int}"] = p => { if (IsLoopback(Request.UserHostAddress)) { manager.Delete(p["id"]); } return(new RedirectResponse("/")); }; }
IEnumerable <SourceAddress> FilterByTargetChannel(IEnumerable <SourceAddress> source, ChannelInstance channel) { foreach (var address in source) { if (channel.Configuration.Charasteristics.SupportsEmail) { // Mail channels allow everything that is a valid email address if (SourceAddress.IsValidEmail(address.Address)) { yield return(address); } } else { // Social channels only allow entries that are available in the addressbook SourceAddress address1 = address; using (mailbox.Profiles.ReaderLock) if (mailbox.Profiles.Where(p => p.Address == address1.Address).Count() > 0) { yield return(address); } } } }
public virtual void NotifyCloseConnect(ChannelInstance ch) { }
private static DateTime[] ParseTimeData(ChannelInstance channelInstance) { SeriesInstance timeSeries; SeriesDefinition timeSeriesDefinition; VectorElement seriesValues; DateTime[] timeData; DateTime startTime; double nominalFrequency; if (!channelInstance.SeriesInstances.Any()) return null; timeSeries = channelInstance.SeriesInstances[0]; timeSeriesDefinition = timeSeries.Definition; if (timeSeriesDefinition.ValueTypeID != SeriesValueType.Time) return null; seriesValues = timeSeries.SeriesValues; if (seriesValues.TypeOfValue == PhysicalType.Timestamp) { timeData = timeSeries.OriginalValues .Select(Convert.ToDateTime) .ToArray(); } else if (timeSeriesDefinition.QuantityUnits == QuantityUnits.Cycles) { startTime = channelInstance.ObservationRecord.StartTime; nominalFrequency = channelInstance.ObservationRecord?.Settings.NominalFrequency ?? 60.0D; timeData = timeSeries.OriginalValues .Select(Convert.ToDouble) .Select(cycles => cycles / nominalFrequency) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .Select(timeSpan => startTime + timeSpan) .ToArray(); } else { startTime = channelInstance.ObservationRecord.StartTime; timeData = timeSeries.OriginalValues .Select(Convert.ToDouble) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .Select(timeSpan => startTime + timeSpan) .ToArray(); } return timeData; }
/// <summary> /// Removes the specified channel. /// </summary> /// <param name="channel">The channel.</param> public static void Remove(ChannelInstance channel) { _Channels.Remove(channel); }