private void makeRequests(Post post,PostFinishedPlaying callback) { ThreadPool.QueueUserWorkItem(state => { for (int i = 0; i < blocks.Count; i++) { bingService.GetAsAudio2(blocks[i], i, r => { System.Diagnostics.Debug.WriteLine("Block " + r + " Downloaded"); blocksAvaliability[r] = true; if (r == 0 || ((r - 1 == playedLast) && !isPlaying)) { playAudioBlock(r, callback); } }); } }); }
public static IEnumerable<Post> parsePosts(string content) { System.Diagnostics.Debug.WriteLine(content); List<Post> parsedValues = new List<Post>(); JArray jArray = JArray.Parse(content); System.Diagnostics.Debug.WriteLine("JArray size = " + jArray.Count); JObject nextAndPreviousPosts = (JObject)jArray[0]; int postsBefore = (int)nextAndPreviousPosts.SelectToken("before"); int postsAfter = (int)nextAndPreviousPosts.SelectToken("after"); ContextUtil.Instance.postsAfter = postsAfter; ContextUtil.Instance.postsBefore = postsBefore; for (int i = 1; i < jArray.Count; i++) { JObject innerObject = (JObject)jArray[i]; Post post = new Post(); post._id = (int)innerObject.SelectToken("id"); try { post.parentId = (int)innerObject.SelectToken("parent_id"); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Erro no parentid"); post.parentId = 0; } post.discussionId = ContextUtil.Instance.Discussion; System.Diagnostics.Debug.WriteLine("ContextUtil mod"); post.userId = (int)innerObject.SelectToken("user_id"); System.Diagnostics.Debug.WriteLine("user_id OK"); post.content = HttpUtils.Strip((string)innerObject.SelectToken("content")); System.Diagnostics.Debug.WriteLine("content OK"); post.userName = (string)innerObject.SelectToken("user_nick"); System.Diagnostics.Debug.WriteLine("user_nick OK"); //post.updatedAt = (string)innerObject.SelectToken("updated_at"); post.updatedAt = Convert.ToString(innerObject.SelectToken("updated_at")); System.Diagnostics.Debug.WriteLine("Updated At OK"); post.level = (int)innerObject.SelectToken("level"); System.Diagnostics.Debug.WriteLine("Level OK"); parsedValues.Add(post); } return parsedValues; }
public void createBlocks(Post post) { blocks = new List<string>(); //generateHeader(Post post) string content = post.content.Trim(); int end = content.Length; while (end > 0) { int cut = Math.Min(content.Length, MIN_BLOCK_LENGTH); /* if (cut == content.Length) { if (containsLetter(content)) // TODO { System.Diagnostics.Debug.WriteLine("BlockContent = " + content); blocks.Add(content); } break; } * */ string blockContent = content.Substring(0, cut); content = content.Substring(cut); int occurrenceOfDot = content.IndexOf(".") == -1 ? 999 : content .IndexOf(".") + 1; int occurrenceOfInterrogation = content.IndexOf("?") == -1 ? 999 : content.IndexOf("?") + 1; int occurrenceOfExclamation = content.IndexOf("!") == -1 ? 999 : content.IndexOf("!") + 1; int occurrenceOfSemi = content.IndexOf(";") == -1 ? 999 : content .IndexOf(";") + 1; int occurenceOfPause = Math.Min(Math.Min(Math.Min(Math.Min( Math.Min(content.Length, MAX_BLOCK_LENGTH), occurrenceOfDot), occurrenceOfExclamation), occurrenceOfInterrogation), occurrenceOfSemi); blockContent = blockContent + content.Substring(0, occurenceOfPause); if (occurenceOfPause == content.Length) { content = ""; end = 0; } else { content = content.Substring(occurenceOfPause); if (occurenceOfPause == MAX_BLOCK_LENGTH) { blockContent = blockContent + content.Substring(0, content.IndexOf(" ")); content = content.Substring(content.IndexOf(" ")); } end = content.Length; } System.Diagnostics.Debug.WriteLine("Block content = " + blockContent); if (blockContent != null) { blocks.Add(blockContent); } else { System.Diagnostics.Debug.WriteLine("ContentBlock is null"); break; } } System.Diagnostics.Debug.WriteLine("BlockLenght = " + blocks.Count); blocksAvaliability = new bool[blocks.Count]; }
public void start(Post post, PostFinishedPlaying callback) { releaseResources(); // createBlocks(post); makeRequests(post,callback); }
/* public bool containsLetter(string content) { } */ public void generateHeader(Post post) { /* string header = post.userName(); String date = posts.get(postIndex).getDate(); int year = Integer.parseInt(date.substring(0, 4)); int month = Integer.parseInt(date.substring(5, 7)); int day = Integer.parseInt(date.substring(8, 10)); int hour = Integer.parseInt(date.substring(11, 13)); int minute = Integer.parseInt(date.substring(14, 16)); * */ }