{"action":"created","comment":{"url":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/comments/23782505","id":23782505,"diff_hunk":"@@ -1,51 +1,137 @@\n-﻿// Copyright (c) 2014 SIL International\n+﻿// Copyright (c) 2014-2015 SIL International\n // This software is licensed under the MIT License (http://opensource.org/licenses/MIT)\n using System;\n using System.Diagnostics;\n-using System.Drawing.Text;\n using System.Globalization;\n-using System.Linq;\n-using System.Net;\n-using Bloom.ImageProcessing;\n using System.IO;\n-using L10NSharp;\n+using System.Threading;\n using Microsoft.Win32;\n+using L10NSharp;\n using Palaso.IO;\n using Bloom.Collection;\n-\n+using Bloom.ImageProcessing;\n \n namespace Bloom.web\n {\n \t/// <summary>\n \t/// A local http server that can serve (low-res) images plus other files.\n \t/// </summary>\n+\t/// <remarks>geckofx makes concurrent requests of URLs which this class handles. This means\n+\t/// that the methods of this class get called on different threads, so it has to be\n+\t/// thread-safe.</remarks>\n \tpublic class EnhancedImageServer: ImageServer\n \t{\n \t\tprivate FileSystemWatcher _sampleTextsWatcher;\n \t\tprivate bool _sampleTextsChanged = true;\n+\t\tprivate const int RWLockTimeOut = 100;\n \n \t\tpublic CollectionSettings CurrentCollectionSettings { get; set; }\n \n \t\tpublic EnhancedImageServer(LowResImageCache cache): base(cache)\n \t\t{\n+\t\t\tLock = new ReaderWriterLock();\n+\t\t}\n+\n+\t\t// We use three different locks to synchronize access to the methods of this class.\n+\t\t// This allows certain methods to run concurrently.\n+\n+\t\t// used to synchronize access to properties. Use this lock when you want to allow\n+\t\t// multiple concurrent readers, but no one else when writing the property.\n+\t\tprivate ReaderWriterLock Lock { get; set; }\n+\t\t// used to synchronize access to I18N methods\n+\t\tprivate object I18NLock = new object();\n+\t\t// used to synchronize access to various methods\n+\t\tprivate object SyncObj = new object();\n+\n+\t\tprivate string _currentPageContent;\n+\t\tprivate string _accordionContent;\n+\t\tprivate bool _authorMode;\n+\n+\t\tpublic string CurrentPageContent\n+\t\t{\n+\t\t\tget { return ReaderLock(() => _currentPageContent); }\n+\t\t\tset { WriterLock(() => _currentPageContent = value); }\n \t\t}\n \n-\t\tpublic string CurrentPageContent { get; set; }\n-\t\tpublic string AccordionContent { get; set; }\n-\t\tpublic bool AuthorMode { get; set; }\n+\t\tpublic string AccordionContent\n+\t\t{\n+\t\t\tget { return ReaderLock(() => _accordionContent); }\n+\t\t\tset { WriterLock(() => _accordionContent = value); }\n+\t\t}\n+\n+\t\tpublic bool AuthorMode\n+\t\t{\n+\t\t\tget { return ReaderLock(() => _authorMode); }\n+\t\t\tset { WriterLock(() => _authorMode = value); }\n+\t\t}\n \n \t\t/// <summary>\n-\t\t/// There can really only be one of these globally, since ReadersHandler is static. But for now that's true anyway\n-\t\t/// because we use a fixed port. See comments on the ReadersHandler property.\n+\t\t/// There can really only be one of these globally, since ReadersHandler is static. But for\n+\t\t/// now that's true anyway because we use a fixed port. See comments on the ReadersHandler\n+\t\t/// property.\n \t\t/// </summary>\n \t\tpublic Book.Book CurrentBook\n \t\t{\n-\t\t\tget { return ReadersHandler.CurrentBook; }\n-\t\t\tset { ReadersHandler.CurrentBook = value; }\n+\t\t\tget\n+\t\t\t{\n+\t\t\t\tlock (SyncObj)","path":"src/BloomExe/web/EnhancedImageServer.cs","position":91,"original_position":91,"commit_id":"b7eeb2799c57efc8d40173a61601057cc0e8cd22","original_commit_id":"b7eeb2799c57efc8d40173a61601057cc0e8cd22","user":{"login":"JohnThomson","id":1360521,"avatar_url":"https://avatars.githubusercontent.com/u/1360521?v=3","gravatar_id":"","url":"https://api.github.com/users/JohnThomson","html_url":"https://github.com/JohnThomson","followers_url":"https://api.github.com/users/JohnThomson/followers","following_url":"https://api.github.com/users/JohnThomson/following{/other_user}","gists_url":"https://api.github.com/users/JohnThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/JohnThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohnThomson/subscriptions","organizations_url":"https://api.github.com/users/JohnThomson/orgs","repos_url":"https://api.github.com/users/JohnThomson/repos","events_url":"https://api.github.com/users/JohnThomson/events{/privacy}","received_events_url":"https://api.github.com/users/JohnThomson/received_events","type":"User","site_admin":false},"body":"It's no obvious why this isn't a Reader/Writer lock situation...because the ReadersHandler might change? A comment might be helpful.","created_at":"2015-01-29T16:54:47Z","updated_at":"2015-01-29T16:54:47Z","html_url":"https://github.com/BloomBooks/BloomDesktop/pull/251#discussion_r23782505","pull_request_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/251","_links":{"self":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/comments/23782505"},"html":{"href":"https://github.com/BloomBooks/BloomDesktop/pull/251#discussion_r23782505"},"pull_request":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/251"}}},"pull_request":{"url":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/251","id":28185581,"html_url":"https://github.com/BloomBooks/BloomDesktop/pull/251","diff_url":"https://github.com/BloomBooks/BloomDesktop/pull/251.diff","patch_url":"https://github.com/BloomBooks/BloomDesktop/pull/251.patch","issue_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/issues/251","number":251,"state":"open","locked":false,"title":"Make EnhancedImageServer thread safe","user":{"login":"ermshiperete","id":181336,"avatar_url":"https://avatars.githubusercontent.com/u/181336?v=3","gravatar_id":"","url":"https://api.github.com/users/ermshiperete","html_url":"https://github.com/ermshiperete","followers_url":"https://api.github.com/users/ermshiperete/followers","following_url":"https://api.github.com/users/ermshiperete/following{/other_user}","gists_url":"https://api.github.com/users/ermshiperete/gists{/gist_id}","starred_url":"https://api.github.com/users/ermshiperete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ermshiperete/subscriptions","organizations_url":"https://api.github.com/users/ermshiperete/orgs","repos_url":"https://api.github.com/users/ermshiperete/repos","events_url":"https://api.github.com/users/ermshiperete/events{/privacy}","received_events_url":"https://api.github.com/users/ermshiperete/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-28T11:18:03Z","updated_at":"2015-01-29T16:54:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aab9fe56c40a20f6cd0171eed177c3f7712bdbd6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/251/commits","review_comments_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/251/comments","review_comment_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/comments/{number}","comments_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/issues/251/comments","statuses_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/statuses/b7eeb2799c57efc8d40173a61601057cc0e8cd22","head":{"label":"ermshiperete:BL-865","ref":"BL-865","sha":"b7eeb2799c57efc8d40173a61601057cc0e8cd22","user":{"login":"ermshiperete","id":181336,"avatar_url":"https://avatars.githubusercontent.com/u/181336?v=3","gravatar_id":"","url":"https://api.github.com/users/ermshiperete","html_url":"https://github.com/ermshiperete","followers_url":"https://api.github.com/users/ermshiperete/followers","following_url":"https://api.github.com/users/ermshiperete/following{/other_user}","gists_url":"https://api.github.com/users/ermshiperete/gists{/gist_id}","starred_url":"https://api.github.com/users/ermshiperete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ermshiperete/subscriptions","organizations_url":"https://api.github.com/users/ermshiperete/orgs","repos_url":"https://api.github.com/users/ermshiperete/repos","events_url":"https://api.github.com/users/ermshiperete/events{/privacy}","received_events_url":"https://api.github.com/users/ermshiperete/received_events","type":"User","site_admin":false},"repo":{"id":24838683,"name":"BloomDesktop","full_name":"ermshiperete/BloomDesktop","owner":{"login":"ermshiperete","id":181336,"avatar_url":"https://avatars.githubusercontent.com/u/181336?v=3","gravatar_id":"","url":"https://api.github.com/users/ermshiperete","html_url":"https://github.com/ermshiperete","followers_url":"https://api.github.com/users/ermshiperete/followers","following_url":"https://api.github.com/users/ermshiperete/following{/other_user}","gists_url":"https://api.github.com/users/ermshiperete/gists{/gist_id}","starred_url":"https://api.github.com/users/ermshiperete/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ermshiperete/subscriptions","organizations_url":"https://api.github.com/users/ermshiperete/orgs","repos_url":"https://api.github.com/users/ermshiperete/repos","events_url":"https://api.github.com/users/ermshiperete/events{/privacy}","received_events_url":"https://api.github.com/users/ermshiperete/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ermshiperete/BloomDesktop","description":"My contributions to BloomDesktop","fork":true,"url":"https://api.github.com/repos/ermshiperete/BloomDesktop","forks_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/forks","keys_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/teams","hooks_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/hooks","issue_events_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/issues/events{/number}","events_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/events","assignees_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/assignees{/user}","branches_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/branches{/branch}","tags_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/tags","blobs_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/git/refs{/sha}","trees_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/statuses/{sha}","languages_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/languages","stargazers_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/stargazers","contributors_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/contributors","subscribers_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/subscribers","subscription_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/subscription","commits_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/commits{/sha}","git_commits_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/git/commits{/sha}","comments_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/comments{/number}","issue_comment_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/issues/comments/{number}","contents_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/contents/{+path}","compare_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/merges","archive_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/downloads","issues_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/issues{/number}","pulls_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/pulls{/number}","milestones_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/milestones{/number}","notifications_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/labels{/name}","releases_url":"https://api.github.com/repos/ermshiperete/BloomDesktop/releases{/id}","created_at":"2014-10-06T08:29:31Z","updated_at":"2014-12-17T08:26:52Z","pushed_at":"2015-01-29T15:27:39Z","git_url":"git://github.com/ermshiperete/BloomDesktop.git","ssh_url":"git@github.com:ermshiperete/BloomDesktop.git","clone_url":"https://github.com/ermshiperete/BloomDesktop.git","svn_url":"https://github.com/ermshiperete/BloomDesktop","homepage":"","size":39604,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"BloomBooks:master","ref":"master","sha":"328139b94e59bdd9db5a16cbc98f0df053222c5c","user":{"login":"BloomBooks","id":5853716,"avatar_url":"https://avatars.githubusercontent.com/u/5853716?v=3","gravatar_id":"","url":"https://api.github.com/users/BloomBooks","html_url":"https://github.com/BloomBooks","followers_url":"https://api.github.com/users/BloomBooks/followers","following_url":"https://api.github.com/users/BloomBooks/following{/other_user}","gists_url":"https://api.github.com/users/BloomBooks/gists{/gist_id}","starred_url":"https://api.github.com/users/BloomBooks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BloomBooks/subscriptions","organizations_url":"https://api.github.com/users/BloomBooks/orgs","repos_url":"https://api.github.com/users/BloomBooks/repos","events_url":"https://api.github.com/users/BloomBooks/events{/privacy}","received_events_url":"https://api.github.com/users/BloomBooks/received_events","type":"Organization","site_admin":false},"repo":{"id":14133680,"name":"BloomDesktop","full_name":"BloomBooks/BloomDesktop","owner":{"login":"BloomBooks","id":5853716,"avatar_url":"https://avatars.githubusercontent.com/u/5853716?v=3","gravatar_id":"","url":"https://api.github.com/users/BloomBooks","html_url":"https://github.com/BloomBooks","followers_url":"https://api.github.com/users/BloomBooks/followers","following_url":"https://api.github.com/users/BloomBooks/following{/other_user}","gists_url":"https://api.github.com/users/BloomBooks/gists{/gist_id}","starred_url":"https://api.github.com/users/BloomBooks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BloomBooks/subscriptions","organizations_url":"https://api.github.com/users/BloomBooks/orgs","repos_url":"https://api.github.com/users/BloomBooks/repos","events_url":"https://api.github.com/users/BloomBooks/events{/privacy}","received_events_url":"https://api.github.com/users/BloomBooks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BloomBooks/BloomDesktop","description":"Bloom Desktop is a hybrid c#/javascript/html/css Windows application that dramatically \"lowers the bar\" for language communities who want books in their own languages. Bloom delivers a low-training, high-output system where mother tongue speakers and their advocates work together to foster both community authorship and access to external material in the vernacular.","fork":false,"url":"https://api.github.com/repos/BloomBooks/BloomDesktop","forks_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/forks","keys_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/teams","hooks_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/hooks","issue_events_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/issues/events{/number}","events_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/events","assignees_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/assignees{/user}","branches_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/branches{/branch}","tags_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/tags","blobs_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/git/refs{/sha}","trees_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/statuses/{sha}","languages_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/languages","stargazers_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/stargazers","contributors_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/contributors","subscribers_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/subscribers","subscription_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/subscription","commits_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/commits{/sha}","git_commits_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/git/commits{/sha}","comments_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/comments{/number}","issue_comment_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/issues/comments/{number}","contents_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/contents/{+path}","compare_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/merges","archive_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/downloads","issues_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/issues{/number}","pulls_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls{/number}","milestones_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/milestones{/number}","notifications_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/labels{/name}","releases_url":"https://api.github.com/repos/BloomBooks/BloomDesktop/releases{/id}","created_at":"2013-11-05T06:12:57Z","updated_at":"2015-01-29T16:43:53Z","pushed_at":"2015-01-29T16:43:53Z","git_url":"git://github.com/BloomBooks/BloomDesktop.git","ssh_url":"git@github.com:BloomBooks/BloomDesktop.git","clone_url":"https://github.com/BloomBooks/BloomDesktop.git","svn_url":"https://github.com/BloomBooks/BloomDesktop","homepage":"http://bloomlibrary.org/","size":53204,"stargazers_count":2,"watchers_count":2,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":10,"forks":9,"open_issues":10,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/251"},"html":{"href":"https://github.com/BloomBooks/BloomDesktop/pull/251"},"issue":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/issues/251"},"comments":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/issues/251/comments"},"review_comments":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/251/comments"},"review_comment":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/pulls/251/commits"},"statuses":{"href":"https://api.github.com/repos/BloomBooks/BloomDesktop/statuses/b7eeb2799c57efc8d40173a61601057cc0e8cd22"}}}}