public string ProcessEmoticons(Emoticons emoticons) { if (_Message != null && emoticons != null) { try { foreach (Emoticon myEmoticon in emoticons.List) { _Message = _Message //upper case .Replace(myEmoticon.Tag.ToUpper(), this.EmoticonTemplate .Replace("<FILENAME>", myEmoticon.Filename) .Replace("<WIDTH>", myEmoticon.Width.ToString()) .Replace("<HEIGHT>", myEmoticon.Height.ToString())) //lower case .Replace(myEmoticon.Tag.ToLower(), this.EmoticonTemplate .Replace("<FILENAME>", myEmoticon.Filename) .Replace("<WIDTH>", myEmoticon.Width.ToString()) .Replace("<HEIGHT>", myEmoticon.Height.ToString())) ; } } catch (Exception) { //throw; } } return(_Message); }
public void SetEmoticon(Emoticons _emoticons, bool _open = false) { GameObject Et; CleanEmoticonIcons(); switch (_emoticons) { case Emoticons.vfx_emo_angry: case Emoticons.vfx_emo_exclamative: case Emoticons.vfx_emo_happy: case Emoticons.vfx_emo_interrogative: case Emoticons.vfx_emo_negative: case Emoticons.vfx_emo_positive: Et = Instantiate(Resources.Load(EMOTICON_PREFS_PATH + _emoticons.ToString()), EmoticonParentBone, false) as GameObject; break; default: Debug.LogWarningFormat("Emoticons {0} not found!", _emoticons.ToString()); break; } if (_open) { Open(true); } }
async Task CaptureAndProcessEmotionAsync() { try { await Dispatcher.RunAsync(CoreDispatcherPriority.High, async() => { var emotions = await CaptureEmotionAsync(); var mostProbable = emotions.ToResults() .Where(result => result != Result.Empty) .FirstOrDefault(); _emoticon.Text = Emoticons.From(mostProbable.Emotion); var current = _messageLabel.Text; var message = EmotionMessages.Messages[mostProbable.Emotion] .First(msg => msg != current); _messageLabel.Text = message; await ChangeStreamStateAsync(false); await _speechEngine.SpeakAsync(message, _speaker); await _speechEngine.SetRecognitionModeAsync(SpeechRecognitionMode.CommandPhrases); }); } catch (Exception ex) when(DebugHelper.IsHandled <MainPage>(ex)) { } }
void OpenEmoticons(Emoticons icon) { if (!currentEmoticon.HasValue || (currentEmoticon.HasValue && currentEmoticon.Value != icon)) { currentEmoticon = icon; emoticonsController.SetEmoticon(icon, true); UpdateEmoticonsColor(); } emoticonsCloseTimer = emoticonsCloseTime; emoticonsClosed = false; }
private void UpdateSmiles() { try { WebClient wc = new WebClient(); string js = wc.DownloadString(UpdateSmilesUri); Emoticons asex = JsonConvert.DeserializeObject <Emoticons>(js); Smiles = (from porno in asex.EmoticonsArray where porno.AllowToAdd() select new TwitchSmile(porno)).ToArray(); } catch (Exception e) { MessageBox.Show("Фак смайлы: " + e.Message); } }
private void loadSmiles() { this.Status = true; _smiles = new Dictionary <string, string>(); try { WebClient wc = new WebClient(); string js = wc.DownloadString(_smilesUri); _smiles.Clear(); Emoticons o = JsonConvert.DeserializeObject <Emoticons>(js); foreach (var smile in o.Smiles) { _smiles[smile.Code] = "http://gamerstv.ru/smiles/" + smile.Img; } } catch { } }
private void loadSmiles() { _smiles = new Dictionary <string, string>(); try { WebClient wc = new WebClient(); string js = wc.DownloadString(updateSmilesUri); _smiles.Clear(); int start = js.IndexOf('['); int end = js.IndexOf(';'); string s = "{\"smiles\":" + js.Substring(start, end - start) + "}"; Emoticons o = JsonConvert.DeserializeObject <Emoticons>(s); Directory.CreateDirectory(App.DataLocalFolder + "/img"); Directory.CreateDirectory(App.DataLocalFolder + "/img/sc2tv"); foreach (var smile in o.Smiles) { string[] d = smile.Img.Split('?'); string fileName = App.DataLocalFolder + "/img/sc2tv/" + d[0]; if (!File.Exists(fileName)) { // dowload and save WebClient wsc = new WebClient(); byte[] data = wsc.DownloadData("http://chat.sc2tv.ru/img/" + smile.Img); File.WriteAllBytes(fileName, data); } _smiles[":s" + smile.Code] = "asset://rat/img/sc2tv/" + d[0]; } } catch { } }
public void CheckingEmoticons() { Emoticons e = new Emoticons(); Assert.IsTrue(e.SendEmoticons()); }
public IMMessage(String senderName, String messageText, String messageGUID, DateTime messageDateTime, MessageStyle style, MessageTemplateType template, Emoticons emoticons) { if (messageDateTime == null || messageDateTime == DateTime.MinValue) { messageDateTime = DateTime.Now; } this.Time = messageDateTime; if (messageGUID == null) { messageGUID = Guid.NewGuid().ToString(); } this.ID = NormalizeGUID(messageGUID); MessageTemplate tmplMessageTemplate = new MessageTemplate(template); tmplMessageTemplate.Message = tmplMessageTemplate.Message .Replace("<HEADER_ROW_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, Color.White)) .Replace("<DATETIME_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, Color.Gray, Color.White)) .Replace("<HEADER_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.HeaderColor, Color.White)) .Replace("<ROW_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, style.BackColor)) .Replace("<MESSAGE_STYLE>", tmplMessageTemplate.BuildStyle(style.Font, style.ForeColor, style.BackColor)) .Replace("<HEADER_TEXT>", senderName != "" ? senderName : "") .Replace("<DATETIME_TEXT>", messageDateTime.ToShortDateString() + " " + messageDateTime.ToShortTimeString()) .Replace("<GUID>", this.ID) .Replace("<MESSAGE_TEXT>", messageText.Replace("\r\n", "<BR />").Replace("\n", "<BR />")); tmplMessageTemplate.ProcessEmoticons(emoticons); this.HTML = tmplMessageTemplate.Message; this.Text = messageText; this.Style = style; }
public bool OpenConnection(string connectionString) { if (string.IsNullOrWhiteSpace(connectionString)) { Logger.Log(this, "Unable to connect to the SQL database: No connection specified.", LogLevel.Error); return(false); } internalState = ConnectionState.Connecting; connection = PostgreSQLTools.CreateDataConnection(connectionString); internalState = ConnectionState.Open; connection.OnClosing += (sender, args) => internalState = ConnectionState.Closed; connection.OnClosed += (sender, args) => internalState = ConnectionState.Closed; metadata = connection.GetTable <Metadata>(); try { var version = from entry in metadata where entry.Key == "version" select entry.Value; var count = version.Count(); if (count != 1) { Logger.Log(this, "Zero or multiple 'version' entries found in the Metadata table. The database connection will be dropped.", LogLevel.Error); HandleConnectionFailure(); return(false); } if (version.First() != Bot.DatabaseVersion) { Logger.Log(this, $"Bot and database version do not match (bot is at {Bot.DatabaseVersion}, database is at {version.First()}). The database will now be upgraded.", LogLevel.Info); if (!UpgradeDatabase(version.First())) { Logger.Log(this, "Upgrade failed. The database connection will be dropped.", LogLevel.Warning); HandleConnectionFailure(); return(false); } } } catch (NpgsqlException e) { if (e.Message.ToLower().Contains("metadata") && e.Message.ToLower().Contains("does not exist")) { Logger.Log(this, "Metadata table not found. A new tableset will be created.", LogLevel.Warning); try { DropTables(); CreateTables(); } catch (NpgsqlException f) { Logger.Log(this, $"Unable to create a new tableset: An exception occurred({f.GetType()}: {f.Message}). The database connection will be dropped.", LogLevel.Error); HandleConnectionFailure(); return(false); } AddMetadata(); Logger.Log(this, "Writing metadata...", LogLevel.Info); } else { Logger.Log(this, $"Unable to retrieve the database version: An exception occurred ({e.GetType()}: {e.Message}). The database connection will be dropped.", LogLevel.Error); HandleConnectionFailure(); return(false); } } //UserCredentials = connection.GetTable<UserCredential>(); Quotes = connection.GetTable <Quote>(); UserStatistics = connection.GetTable <UserStatistic>(); Emoticons = connection.GetTable <UsedEmoticon>(); KeyValuePairs = connection.GetTable <KeyValuePair>(); LinkedUrls = connection.GetTable <LinkedUrl>(); Users = connection.GetTable <User>(); Words = connection.GetTable <UsedWord>(); ChatLog = connection.GetTable <ChatLog>(); MiscData = connection.GetTable <MiscData>(); try { // These methods are actually not pure, because they'll throw an exception // if their backing database tables are not found. It's a bit of a hack, // but this is the easiest way to check whether those tables exist. // ReSharper disable ReturnValueOfPureMethodIsNotUsed //UserCredentials.FirstOrDefault(); Quotes.FirstOrDefault(); UserStatistics.FirstOrDefault(); Emoticons.FirstOrDefault(); KeyValuePairs.FirstOrDefault(); LinkedUrls.FirstOrDefault(); Users.FirstOrDefault(); Words.FirstOrDefault(); ChatLog.FirstOrDefault(); MiscData.FirstOrDefault(); // ReSharper restore ReturnValueOfPureMethodIsNotUsed } catch (Exception e) { Logger.Log(this, $"Database integrity check failed ({e.GetType().Name}: {e.Message})", LogLevel.Error); HandleConnectionFailure(); return(false); } return(true); }
async void ProcessCurrentVideoFrame(object sender, object e) { // If a lock is being held it means we're still waiting for processing work on the previous frame to complete. // In this situation, don't wait on the semaphore but exit immediately. if (!_isStreaming || !_frameProcessingSemaphore.Wait(0)) { return; } try { using (var previewFrame = new VideoFrame(BitmapPixelFormat.Nv12, (int)_videoProperties.Width, (int)_videoProperties.Height)) { await _mediaManager.GetPreviewFrameAsync(previewFrame); IList <DetectedFace> faces = null; // The returned VideoFrame should be in the supported NV12 format but we need to verify this. if (FaceDetector.IsBitmapPixelFormatSupported(previewFrame.SoftwareBitmap.BitmapPixelFormat)) { faces = await _faceTracker.ProcessNextFrameAsync(previewFrame); } //// Create our visualization using the frame dimensions and face results but run it on the UI thread. var previewFrameSize = new Size(previewFrame.SoftwareBitmap.PixelWidth, previewFrame.SoftwareBitmap.PixelHeight); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { SetupVisualization(previewFrameSize, faces); if (_isProcessing) { return; } var emotions = await CaptureEmotionAsync(); if (emotions.IsNullOrEmpty() == false) { var mostProbable = emotions.ToResults() .Where(result => result != Result.Empty) .FirstOrDefault(); if (mostProbable == null) { _messageLabel.Text = string.Empty; _emoticon.Text = string.Empty; } else { _emoticon.Text = Emoticons.From(mostProbable.Emotion); var current = _messageLabel.Text; var message = EmotionMessages.Messages[mostProbable.Emotion].RandomElement(); while (current == message) { message = EmotionMessages.Messages[mostProbable.Emotion].RandomElement(); } _messageLabel.Text = message; await _speechEngine.SpeakAsync(message, _speaker); ++_captureCounter; if (_captureCounter >= MaxCaptureBeforeReset) { await ChangeStreamStateAsync(false); } } } }); } } catch (Exception ex) when(DebugHelper.IsHandled <MainPage>(ex)) { } finally { _frameProcessingSemaphore.Release(); } }