/// <summary> /// Creates a new <see cref="UserState{TState}"/> object. /// </summary> /// <param name="storage">The storage provider to use.</param> /// <param name="settings">The state persistance options to use.</param> public UserState(IStorage storage, StateSettings settings = null) : base(storage, PropertyName, (context) => $"user/{context.Activity.ChannelId}/{context.Activity.From.Id}", settings) { }
public async Task <TableLayoutPanel> GetLayoutPanelAsync(User i_LoggedInUser) { StateSettings appConfigServiceStateSettings = AppConfigService.GetInstance().StateSettings; TableLayoutPanel panel = new TableLayoutPanel { ColumnCount = 1, AutoScroll = true }; ILikeService likeService = new LikesService(i_LoggedInUser); // get data as defined in settings List <Task> getDataTasks = new List <Task>(); Dictionary <string, int> allPostemItemsLikes = new Dictionary <string, int>(); foreach (KeyValuePair <eLikedItem, bool> keyValuePair in appConfigServiceStateSettings.LikedItems.Where(i_Item => i_Item.Value)) { Task getDataTask = Task.Run( async() => { PropertyInfo propertyInfo = i_LoggedInUser.GetType() .GetProperty(keyValuePair.Key.ToString()); if (propertyInfo != null) { try { object prop = propertyInfo.GetValue(i_LoggedInUser, null); IEnumerable collectionOfUnknownType = (IEnumerable)prop; ObservableCollection <PostedItem> currentPostedItems = new ObservableCollection <PostedItem>(); foreach (PostedItem o in collectionOfUnknownType) { currentPostedItems.Add(o); } Dictionary <string, int> currenLikes = await likeService.GetLikesHistogram(currentPostedItems).ConfigureAwait(false); allPostemItemsLikes.AddRange <string, int>(currenLikes); } catch (Exception) { Console.WriteLine(Resources.FailedToRretrieveDataLikesForErrorMessage + propertyInfo); } } }); getDataTasks.Add(getDataTask); } await Task.WhenAll(getDataTasks); Chart likeMeTheMostChart = ChartsUtil.CreateChart("Who Likes me the most!", DockStyle.Top, allPostemItemsLikes.OrderByDescending(i_L => i_L.Value). Take(appConfigServiceStateSettings.NumberOfFriend)); Chart likeMeTheLeastChart = ChartsUtil.CreateChart("Who Likes me the least!", DockStyle.Bottom, allPostemItemsLikes.OrderBy(i_L => i_L.Value). Take(appConfigServiceStateSettings.NumberOfFriend)); panel.Controls.Add(likeMeTheMostChart, 0, 0); panel.Controls.Add(likeMeTheLeastChart, 0, 1); return(panel); }
/// <summary> /// Initializes a new instance of the <see cref="ConversationState{TState}"/> class. /// </summary> /// <param name="storage">The storage provider to use.</param> /// <param name="settings">The state persistance options to use.</param> public ConversationState(IStorage storage, StateSettings settings = null) : base( storage, _propertyName, (context) => $"conversation/{context.Activity.ChannelId}/{context.Activity.Conversation.Id}", settings) { }
public static Chart CreateChart(string i_ChartTitle, DockStyle i_DockStyle, IEnumerable <KeyValuePair <string, int> > i_DataCollection) { StateSettings appConfigServiceStateSettings = AppConfigService.GetInstance().StateSettings; Chart chart = new Chart(); ((ISupportInitialize)chart).BeginInit(); ChartArea chartsArea = new ChartArea(); chart.ChartAreas.Add(chartsArea); chart.Dock = i_DockStyle; if (appConfigServiceStateSettings.SelectedChartType == SeriesChartType.Pie) { Legend legend = new Legend { BackColor = Color.White, ForeColor = Color.Black }; chart.Legends.Add(legend); } Title title = chart.Titles.Add(i_ChartTitle); title.Font = new Font(AppUtil.sr_FontFamily, 16, FontStyle.Bold); title.Alignment = ContentAlignment.TopCenter; chart.Series.Clear(); chart.ChartAreas[0].BackColor = Color.Transparent; chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false; chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false; Series series = new Series { IsVisibleInLegend = true, ChartType = appConfigServiceStateSettings.SelectedChartType }; chart.Series.Add(series); int i = 0; Random rnd = new Random(); foreach (KeyValuePair <string, int> userLikesPhoto in i_DataCollection) { series.Points.Add(userLikesPhoto.Value); DataPoint dataPoint = series.Points[i]; Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); dataPoint.Color = randomColor; dataPoint.AxisLabel = userLikesPhoto.Key; dataPoint.LegendText = userLikesPhoto.Key; dataPoint.Label = userLikesPhoto.Value.ToString(); i++; } chart.Invalidate(); ((ISupportInitialize)chart).EndInit(); return(chart); }
void ResetStateSettings() { stateSettings = StateSettings.Default; }
/// <summary> /// Unfreeze the puppet with the specified StateSettings. /// </summary> public void Freeze(StateSettings stateSettings) { this.stateSettings = stateSettings; state = State.Frozen; }
/// <summary> /// Kill the puppet with the specified StateSettings /// </summary> public void Kill(StateSettings stateSettings) { this.stateSettings = stateSettings; state = State.Dead; }
public void ProcessBatch() { bool needToLeave = false; busy = true; try { // used to block the Terminate from BizTalk if (!this.control.Enter()) { needToLeave = false; return; } needToLeave = true; StateSettings stateSettings = new StateSettings(); stateSettings.FindFirst = this.properties.FirdFirst; stateSettings.WorkingFeed = this.properties.FirstFeed; stateSettings.Id = atomState.LastEntryId; AtomReader atom = new AtomReader(this.properties.Uri, stateSettings, this.properties.SecuritySettings, this.properties.FeedMax); Feed feed = null; bool discard = atom.IdFound; string stateId = atomState.LastEntryId; string lastId = String.Empty; while ((feed = atom.NextFeed()) != null && feed.Entries.Count > 0) { ManualResetEvent orderedEvent = null; CommittableTransaction transaction = null; //using (SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(this.transportProxy, this.control, 1)) Entry entry = feed.Entries.PopOrNUll(); while (entry != null) { if (discard == false) { orderedEvent = new ManualResetEvent(false); transaction = new CommittableTransaction(); atomState.LastEntryId = entry.Id; atomState.LastUpdated = feed.Updated; atomState.LastFeed = feed.Uri; SaveState(transaction); using (SingleMessageReceiveTxnBatch batch = new SingleMessageReceiveTxnBatch(this.transportProxy, this.control, transaction, orderedEvent)) { batch.SubmitMessage(CreateMessage(entry)); batch.Done(); orderedEvent.WaitOne(); } } if (stateId == entry.Id) { discard = false; } entry = feed.Entries.PopOrNUll(); } } // no exception in Done so we will be getting a BatchComplete which will do the necessary Leave needToLeave = false; } catch (MaxDeepthException deepth) { this.transportProxy.ReceiverShuttingdown(this.properties.Uri, deepth); } catch (InvalidConfiguration arg) { this.transportProxy.ReceiverShuttingdown(this.properties.Uri, arg); } catch (WebException ex) { this.transportProxy.ReceiverShuttingdown(this.properties.Uri, ex); } catch (Exception e) { this.transportProxy.SetErrorInfo(e); } finally { busy = false; // if this is true there must have been some exception in or before Done if (needToLeave) { this.control.Leave(); } } }
static void Main(string[] args) { string test = null; string root = @"C:\atom\"; //string filename = "recent.xml"; string filename = "state.xml"; Console.WriteLine("START..."); // FileStream stm = new FileStream(root + filename, FileMode.CreateNew); X509Certificate2 ClientCertificate = CertificateStore.GetCertByThumbprint("b6e3448a8d92572cc9273b833f0d08248da681e7"); string Id = "23acff5e-0be0-11e8-8f5b-0f7a53ac4427"; string initFeed = "https://api.mit-integration.ladok.se:443/uppfoljning/feed/276367"; //inner state cannot be the same as stae i reader .... StateSettings state = new StateSettings { Id = Id, WorkingFeed = initFeed, LastUpdated = DateTime.Parse("2018-01-15T08:27:42.873Z") }; AtomReader atom = new AtomReader("https://api.mit-integration.ladok.se/uppfoljning/feed/recent", state, new SecuritySettings { ClientCertificate = CertificateStore.GetCertByThumbprint("b6e3448a8d92572cc9273b833f0d08248da681e7") }, 2); //atom.MoveToFirstFeed(); Feed feed = null; bool discard = atom.IdFound; while ((feed = atom.NextFeed()) != null && feed.Entries.Count > 0) { Console.WriteLine("FEED"); Console.WriteLine(feed.Uri); Entry entry = feed.Entries.PopOrNUll(); while (entry != null) { //atom.IdFound == true discard all until id is found if (discard == true) { Console.WriteLine(String.Format("DISCARD...{0} {1}", entry.Updated, entry.Id)); } else { Console.WriteLine(String.Format("PROCESS...{0} {1}", entry.Updated, entry.Id)); } if (Id == entry.Id) { discard = false; } entry = feed.Entries.PopOrNUll(); } } /* * Stack<Queue<Entry>> stk = atom.Entries(); * * * while (stk.Count > 0) * { * Queue<Entry> queueEntry = stk.Pop(); * * while (queueEntry.Count > 0) * { * Entry entry = queueEntry.Dequeue(); * * File.AppendAllText(String.Format("{0}{1}.xml", root, entry.Id), entry.Content); * * } * * * * } */ /* * BizTalk.Adapter.Atom.AtomState atom = new BizTalk.Adapter.Atom.AtomState(); * atom.LastEntryId = "1234"; * atom.LastUpdated = DateTime.Now; * * XmlSerializer atomstate = new XmlSerializer(typeof(BizTalk.Adapter.Atom.AtomState)); * * atomstate.Serialize(stm, atom); */ Console.WriteLine("...S**T"); Console.ReadKey(); }