Compare commits

...

191 Commits

Author SHA1 Message Date
Shannon d1be38be64 reverts profiler changes, we'll inlcude in 7.4 2016-01-28 18:37:56 +01:00
Shannon 8916c68a0c reverts profiler changes, we'll inlcude in 7.4 2016-01-28 18:35:29 +01:00
Shannon 6faa7e2fc9 dont' have RebuildOnAppStart set for dev purposes! 2016-01-28 18:31:47 +01:00
Shannon a6093f41bd Fixes installer login for user and adds notes 2016-01-28 18:02:22 +01:00
Stephan 107e66e4da Merge pull request #1071 from umbraco/temp-U4-7682
U4-7682 Add option to DatabaseServerMessengerOptions to force a Cold …
2016-01-28 14:33:02 +01:00
Shannon 256849f8a6 adds nicer profiling during startup for app event handlers. 2016-01-28 14:19:38 +01:00
Stephan c9c451be65 U4-7682 Minor review adjustments 2016-01-28 14:19:32 +01:00
Shannon 1fcea083e7 Ensures no profiling occurs when not in debug mode 2016-01-28 14:10:13 +01:00
Shannon 85d6ee5713 Merge branch '7.3.6' of https://github.com/umbraco/Umbraco-CMS into 7.3.6 2016-01-28 13:50:55 +01:00
Shannon ec81583741 Fixes case sensitive matching on alias in TemplateRepository 2016-01-28 13:50:45 +01:00
Sebastiaan Janssen 332da9bf2d Merge pull request #1070 from umbraco/temp-RepoCachePerf736
Temp repo cache perf736
2016-01-28 12:15:24 +01:00
Shannon a0036d925e U4-7682 Add option to DatabaseServerMessengerOptions to force a Cold Boot if there are too many instructions 2016-01-28 12:14:30 +01:00
Shannon 81a99d6f7d adds null check and ensures that SetInternalRedirectPublishedContent cannot be called with a null result 2016-01-28 10:19:51 +01:00
Shannon e912238574 Saw there was another place with the incorrect case for the column name AllowedId 2016-01-28 09:32:01 +01:00
Shannon 9a830e5de6 fixes tests 2016-01-27 19:44:36 +01:00
Shannon 7d9ba0e36e manually backports changes from 7.4 fixes 2016-01-27 19:42:06 +01:00
Shannon 6c5e09fd84 Ensures that the main content type repositories are returning the correct result from their GetAll methods. Fixes the FullDataSetRepositoryCachePolicy to ensure that any request with Ids actually returns the result of GetAll and then filters to ensure caching is correct. 2016-01-27 19:26:08 +01:00
Sebastiaan Janssen 2f8c43c689 Merge pull request #1057 from umbraco/temp-U4-7836
U4-7836 YSOD when upgrading Umbraco with error during AddUserDataClaims
2016-01-26 19:25:04 +01:00
Shannon 7a25cb52b2 updates the repository cache policies so that we aren't keeping everything in cache unnecessarily 2016-01-26 19:13:42 +01:00
Shannon 19bc97a7fd Removes the static (hack) cache for content types for creating published content 2016-01-26 18:56:29 +01:00
Shannon 72900ef3b3 U4-7813 Enable MiniProfiler to profiler during startup
Conflicts:
	src/Umbraco.Core/Umbraco.Core.csproj
2016-01-26 17:56:25 +01:00
Shannon 74ddd09c5d U4-7836 YSOD when upgrading Umbraco with error during AddUserDataClaims - this also ensures that no empty/null sections can be added to the user object since this is where the original exception was coming from. 2016-01-26 17:05:46 +01:00
Sebastiaan Janssen e461cb92da U4-7787 Shorthand use of ?altTemplate= doesn't work
#U4-7787 Fixed
2016-01-26 16:07:44 +01:00
Mads Rasmussen e91b53e66d back ported: https://github.com/Umbraco/Umbraco-CMS/commit/2d0f198f58071f5113d5c3437f10f2b85220c348 2016-01-25 11:09:20 +01:00
Shannon b5e8cb29dd ensure appctx and security isn't nulled on disposal (it's an application singleton it doesn't need to be nulled), creates new CreateContext method for creating standalone UmbracoContext instances. 2016-01-23 12:38:08 +01:00
Shannon 20dc4f5bc4 fixes merge issue/build 2016-01-23 12:27:40 +01:00
Shannon 2c399860ca Fixes DisposableTimer so that the profiled step is disposed - and thus tracked/timed properly! 2016-01-22 17:27:46 +01:00
Shannon 4dc4c36581 U4-7811 Content type repositories should use FullDataSetRepositoryCachePolicyFactory for performance
Conflicts:
	src/Umbraco.Core/Persistence/Repositories/ContentTypeBaseRepository.cs
	src/Umbraco.Core/Persistence/Repositories/ContentTypeRepository.cs
	src/Umbraco.Core/Persistence/Repositories/Interfaces/IMediaTypeRepository.cs
	src/Umbraco.Core/Persistence/Repositories/MediaTypeRepository.cs
2016-01-22 17:08:21 +01:00
Shannon fe774f557c Fixes ms value: U4-7810 DatabaseServerRegistrar should not execute as soon as a request is made, this slows down app start 2016-01-22 17:06:14 +01:00
Shannon 3ecb9d0f86 U4-7807 Domain, language, public access cache (GetAll) caches not working when there are no items 2016-01-22 17:05:27 +01:00
Shannon f78a425985 U4-7816 The IsolatedCache instance in the RepositoryFactory differs from the ApplicationContext singleton instance 2016-01-22 16:37:47 +01:00
Sebastiaan Janssen 9f365727e0 Bumps version 2016-01-20 14:10:31 +01:00
Sebastiaan Janssen 74d73cfe94 U4-7796 Get UrlRewritingNet from the official NuGet location
#U4-7796 Fixed
2016-01-20 13:57:35 +01:00
Sebastiaan Janssen 7fb9d430a9 changes default upload limit to 50 mb 2016-01-20 10:54:43 +01:00
Sebastiaan Janssen 7cd8ba13c0 U4-7781 Setting a user's start node causes YSOD
#U4-7781 Fixed
2016-01-20 10:45:40 +01:00
Sebastiaan Janssen 1888888650 Update ImageProcessor, this time also in the nuspec file 2016-01-19 11:07:17 +01:00
Sebastiaan Janssen 39b1357a2a Ensure correct assembly redirects for System.Web.WebPages.Razor and HtmlAgilityPack 2016-01-15 15:07:53 +01:00
Claus e1ee8a1437 Fix to ensure config array is copied and not referenced. 2016-01-15 10:00:05 +01:00
Claus 21ba88a34d Fixes: U4-6297 Add Settings to Grid Controls
Reusing the existing code for calling the dialog instead of having a separate method for this.
2016-01-15 09:43:01 +01:00
Shannon b5abbc7c30 Adds some null checks 2016-01-14 18:11:48 +01:00
Shannon 7958b5fcb1 U4-7740 Speed up the current user's culture lookup 2016-01-14 16:43:31 +01:00
Shannon 44b22503e1 Merge branch 'dev-v7' of https://github.com/umbraco/Umbraco-CMS into dev-v7 2016-01-14 16:36:13 +01:00
Shannon bfa12856db Fixes issue with DefaultRepositoryCachePolicy when creating new items - we were generating the cache key before actually calling the method to create the item therefore there was no id assigned yet (it would be zero). 2016-01-14 16:36:03 +01:00
Sebastiaan Janssen d9542f4ca5 Merge branch 'dev-v7' of https://github.com/umbraco/Umbraco-CMS into dev-v7 2016-01-14 15:06:39 +01:00
Sebastiaan Janssen f057976f78 U4-7735 Localization fallback doesn't seem to work.
#U4-7735 Fixed
2016-01-14 15:06:16 +01:00
Claus 151c28a20f Merge pull request #642 from AussieInSeattle/U4-6297
U4 6297
2016-01-14 14:35:54 +01:00
Claus d2c8268fc4 Merge pull request #1014 from kvakulo/fix-media-item-without-image
Fix the media picker not rendering when a media item has no image
2016-01-14 13:46:12 +01:00
Claus 13a9f40815 Fixes: U4-7728 Folder view in media section gives an exception
Ensuring umbracoFile property isn't accessed if this is called on a folder.
2016-01-14 09:40:40 +01:00
Claus 67f8141015 Merge branch 'bjarnef-dev-v7-mediapicker-only-images' into dev-v7 2016-01-14 08:56:34 +01:00
bjarnef 06a098215b Add media picker config to restrict the editors to only pick images 2016-01-14 00:36:53 +01:00
bjarnef 051b320904 Merge remote-tracking branch 'refs/remotes/umbraco/dev-v7' into dev-v7 2016-01-13 23:16:10 +01:00
Shannon 5aab50ba3b Ensures fcnMode and file size maximums are set for the debug web config transform and also for the nuget transform. 2016-01-13 17:27:56 +01:00
Shannon 5b9cbae860 Fixes: U4-7712 fcnMode = Single by default 2016-01-13 17:17:39 +01:00
Claus 59759c4919 Merge pull request #1018 from umbraco/temp-U4-5982
U4-5982 Webpages unpublishing by themselves
2016-01-13 14:29:37 +01:00
Shannon 68ddea2776 refactors a bit of code from the PR, adds more translations to the other english file. 2016-01-13 12:33:57 +01:00
Shannon 8857b2db59 Merge branch 'JJCLane-UKFest-6322' into temp-U4-5982 2016-01-13 12:24:00 +01:00
Shannon fae5618865 Merge branch 'UKFest-6322' of https://github.com/JJCLane/Umbraco-CMS into JJCLane-UKFest-6322 2016-01-13 12:23:26 +01:00
Shannon 40dbcbd7d9 Merge branch 'dev-v7' of https://github.com/umbraco/Umbraco-CMS into dev-v7 2016-01-13 12:10:22 +01:00
Shannon 074d894271 Fixes: U4-7706 Property Type UniqueIds do not stay consistent during package installation 2016-01-13 12:10:04 +01:00
Mads Rasmussen eb6ae95039 Merge pull request #1015 from umbraco/temp-U4-7561
U4-7561 Backoffice Media Section should provide information on physic…
2016-01-13 10:40:54 +01:00
Shannon 5e461b0cec adds packaging test 2016-01-13 10:29:44 +01:00
Shannon d6a49f275f adds test that fails - need to fix it now 2016-01-13 10:29:26 +01:00
Sebastiaan Janssen 8e024fccff Don't hardcode the umbracoFile constant 2016-01-12 20:05:22 +01:00
Sebastiaan Janssen 43227d4510 Support for multiple properties spawning a url - adding more uploadfields to umbracoSettings.config (autoFillImageProperties) 2016-01-12 19:46:05 +01:00
Sebastiaan Janssen 79cc4cd2fa Change "umbracoFile" to the constant for this value 2016-01-12 18:16:55 +01:00
Sebastiaan Janssen ff83d2e1f4 U4-7561 Backoffice Media Section should provide information on physical location of files 2016-01-12 17:41:53 +01:00
Regin Larsen cb7df58fdd Fix the media picker not rendering when a media item has no image 2016-01-12 16:25:29 +01:00
Sebastiaan Janssen 5cc274a580 Merge pull request #1004 from umbraco/temp-U4-7681
U4-7681 Legacy CMSNode.Parent uses old SqlHelper API and doesn't keep…
2016-01-12 14:48:54 +01:00
Sebastiaan Janssen 6c5b5ee637 Merge branch 'Phosworks-U4-7312-2' into dev-v7 2016-01-12 14:20:40 +01:00
Sebastiaan Janssen 9bfac0fdcd Still create the thumbnails upon upload (for backwards compatibility) 2016-01-12 14:20:25 +01:00
Sebastiaan Janssen bd5823f0de Merge branch 'U4-7312-2' of https://github.com/Phosworks/Umbraco-CMS into Phosworks-U4-7312-2 2016-01-12 13:24:42 +01:00
Sebastiaan Janssen 70035632b6 Update ImageProcessor and UrlRewritingNet dependencies 2016-01-12 11:22:49 +01:00
Stephan 20f5560767 Merge pull request #1002 from umbraco/temp-U4-7558-2
U4-7558 Fix GetAll repository level caching for repositories that return a query result based on the result of GetAll
2016-01-11 15:14:00 +01:00
Shannon ecd024c462 U4-7681 Legacy CMSNode.Parent uses old SqlHelper API and doesn't keep a reference 2016-01-08 13:59:40 +01:00
Shannon ba91bf0b9c missing a file save 2016-01-07 19:33:55 +01:00
Shannon 2b13297c36 Changes method name to be shorter and makes internal instead of protected. 2016-01-07 19:27:59 +01:00
Shannon fb5faa3db7 Fixes tests, adds LanguageId to the interface 2016-01-07 18:59:59 +01:00
Shannon d7a142e724 Refactors DictionaryItem and DictionaryTranslation so that the attached ILanguage entity is not cached nor cloned. This will save on lots of memory and cloning cycles especially if there are quire a few dictioanry items. Unfortunatley to achieve this requires a not so pretty hack where we need to assign an internal callback to the model so it knows how to retrieve the language when it needs it. In v8, the ILanguage entity will not be attached at all. This also fixes a cache refresher issue for when a language is deleted -> all dictionary cache must be removed. This commit also changes a method name: ClearAllIsolatedCacheByRepositoryEntityType 2016-01-07 18:44:04 +01:00
Shannon 63785ae70f Adds cache policy tests 2016-01-07 17:54:55 +01:00
Shannon 68aa6ff093 Moves repository caching logic into new CachePolicies. 2016-01-07 16:31:20 +01:00
Shannon 3e985acef1 ensures that the public access cache refresher is called when a public access item is deleted. 2016-01-07 12:18:57 +01:00
Shannon 6d13d33cfd Changes PublicAccessRepository to use GetAllCacheAsCollection option and return a single result by ID based on the cache of GetAll 2016-01-07 12:03:32 +01:00
Shannon Deminick ced0a852b1 Merge pull request #1000 from bjarnef/dev-v7-U4-7648
Set focus on input by clicking label
2016-01-07 10:14:07 +01:00
bjarnef ba0da15f7f Set focus on input by clicking label 2016-01-07 01:04:55 +01:00
bjarnef 2875cd10f3 Merge remote-tracking branch 'refs/remotes/umbraco/dev-v7' into dev-v7 2016-01-06 22:01:33 +01:00
Shannon b91661cf65 fixes issue with RepositoryBase - it would cache all entities with a single key even if there were ids specified which is wrong. Updates TemplateRepository to use a single GetAll query as its base source and it uses the GetAllCacheAsCollection option, also massively simplifies its GetDescendants methods, obsoletes some unused code, 2016-01-06 19:27:15 +01:00
Shannon 827f7a7bc8 Updates DictionaryRepository(s) to have custom GetAll caching options - to basically disable it since there could be tons of these and currently an IDictionaryItem is a massive entity (need to fix that) 2016-01-06 18:34:07 +01:00
Shannon ff829d49a3 Updates all cache refreshers to reference the IsolatedRuntimeCache where required, refactors how IsolatedRuntimeCache is exposed on the CacheHelper, ensures that IsolatedRuntimeCache is used in all repositories instead of the global RuntimeCache, changes all obsolete usages of CacheHelper to the non obsolete equivalent, obsoletes many of the cache keys, obsoletes a couple cache refreshers that aren't used anymore in 7.3, simplifies CacheHelper with regards to it's 'disabled' cache state. 2016-01-06 18:08:14 +01:00
Sebastiaan Janssen d2483159bc Fixes unit tests, not all packages will have the sort order in there 2016-01-06 15:59:23 +01:00
Sebastiaan Janssen 48ab3f580c Fixes the build 2016-01-06 15:21:45 +01:00
Claus c524d67a37 Fixes: U4-7553 Importing Document Type doesn't respect property sort order
Handling sortOrder property in both import/export.

(cherry picked from commit 378479b4c1)

# Conflicts:
#	src/Umbraco.Core/Services/PackagingService.cs
2016-01-06 14:56:31 +01:00
Shannon 4f40fff5ee Moves DeepCloneRuntimeCacheProvider to Cache namespace. Creates DeepCloneableList + tests. Updates RepositoryBase to use DeepCloneableList when GetAllCacheAsCollection is used (so that all entries that get cached are deep cloned into and out-of the cache). Adds test for DeepCloneRuntimeCacheProvider for dealing with this list type. 2016-01-06 14:17:51 +01:00
Shannon b04d0fc886 Adds Isolated cache to the CacheHelper, adds cache option: GetAllCacheAsCollection, changes the default repository cache to be an isolated cache (instead of part of the single main dictionary cache), adds the logic for the cache option GetAllCacheAsCollection to RepositoryBase, updates Language and Domain repositories to use GetAllCacheAsCollection, updates RepositoryFactory to be the one responsible for injecting a DeepCloneRuntimeCacheProvider and to use a single _noCache instance. 2016-01-06 13:48:03 +01:00
Shannon 4c3258812c normalize culture for test 2016-01-06 12:50:41 +01:00
Shannon bc98f5e8fc code cleanup.
Conflicts:
	src/Umbraco.Core/ObjectExtensions.cs
2016-01-06 12:49:18 +01:00
Shannon 6f2f6c088b Merge branch 'dev-v7' of https://github.com/umbraco/Umbraco-CMS into dev-v7 2016-01-06 12:48:36 +01:00
Shannon da91923577 Changes ObjectExtensions NormalizeNumberDecimalSeparator to use normal Culture (not UI Culture) 2016-01-06 12:48:26 +01:00
Sebastiaan Janssen fbc46d8046 Merge pull request #989 from umbraco/temp-U4-7643
U4-7643 DatabaseServerMessenger.cs causes lucene indexes to rebuild o…
2016-01-06 12:43:36 +01:00
Shannon e8a0fae557 adds notes 2016-01-06 12:24:09 +01:00
Shannon Deminick e0baf45247 Merge pull request #992 from umbraco/temp-U4-5168
U4-5168 Media Items label says "Document Type" instead of  "Media Type"
2016-01-06 12:22:53 +01:00
Sebastiaan Janssen 43e983e27a Corrects spelling of localStorateDir to localStorageDir 2016-01-06 12:17:48 +01:00
Sebastiaan Janssen b882806847 Merge pull request #980 from umbraco/temp-U4-7614
U4-7614 Allow Examine's local temp storage to exist in the current Us…
2016-01-06 12:09:31 +01:00
Shannon 58c30cd7a6 removes erroneous reverse call 2016-01-06 12:00:50 +01:00
Shannon Deminick ae1b6d95b8 Merge pull request #990 from umbraco/temp-PVS-Studio
Temp pvs studio
2016-01-06 12:00:28 +01:00
Sebastiaan Janssen 403af78ba9 U4-5168 Media Items label says "Document Type" instead of "Media Type" 2016-01-06 11:22:15 +01:00
Sebastiaan Janssen 59fe690a88 Code sample No.10 2016-01-05 23:34:30 +01:00
Sebastiaan Janssen a15b005d95 Code sample No.6, No.7 2016-01-05 23:22:16 +01:00
Sebastiaan Janssen b94c396d4e Code sample No.5 2016-01-05 23:20:47 +01:00
Sebastiaan Janssen 8afc4f5ad1 Code sample No.3 2016-01-05 23:15:25 +01:00
Sebastiaan Janssen f68b2de9e3 Code sample No.2 2016-01-05 23:13:37 +01:00
Sebastiaan Janssen f4e29d90e0 Code sample No.1 2016-01-05 23:12:09 +01:00
Sebastiaan Janssen 5ad5e945c4 Merge pull request #813 from TimGeyssens/dev-v7
Fixes U4-7249 Insert Macro split button, when selecting a macro that …
2016-01-05 19:49:14 +01:00
Sebastiaan Janssen 4ef7b7735e Fixes U4-6510 again as merging PR apparently went wrong 2016-01-05 17:04:11 +01:00
Sebastiaan Janssen db538d95ba Bumps version 2016-01-05 16:11:59 +01:00
Sebastiaan Janssen cef7cd1ca7 Merge pull request #981 from umbraco/temp-U4-7583
U4-7583
2016-01-05 16:02:51 +01:00
Shannon 726416fe0c Fixes: U4-7624 Datepicker Sql server error
Since we are not saving the formatted value, don't try parsing the date with formatting config.
Added in explicit parsing format compatible with the one used when saving the value, just to ensure parsing is done the same way.
2016-01-05 15:47:42 +01:00
Shannon Deminick 1957d8bb3b Merge pull request #928 from kiasyn/patch-1
U4-7400 - Datepicker is not updating scope model value in time for 3r…
2016-01-05 15:19:31 +01:00
Shannon fab30d353a U4-7223 GetCropUrl outputs html entities in url when used in css 2016-01-05 14:54:02 +01:00
Shannon 75990b5961 U4-7643 DatabaseServerMessenger.cs causes lucene indexes to rebuild on app startup 2016-01-05 14:20:13 +01:00
Shannon 18900d0e25 Fixes: U4-6659 Examine: Specific doctype not being indexed 2016-01-05 12:38:13 +01:00
Shannon d08f4230c8 U4-7538 GetRemainingTimeoutSeconds is double setting the cookie in 7.4 2016-01-05 12:35:06 +01:00
Shannon 15d06557e9 U4-7605 Colons/Parens Unnecessarily Removed From Data Type Names 2016-01-05 11:42:02 +01:00
Shannon 8d2e708d1c Adds exception handling for the BackOfficeUserStore - this will occur if the external OAuth provider doesn't return the Email or Name correctly, then an exception is swallowed at the service level and the user is not actually created, but the BackOfficeUserStore could not detect this, so it's detecting this now. 2016-01-05 11:36:52 +01:00
Shannon 280573be28 Merge branch 'dev-v7' of https://github.com/umbraco/Umbraco-CMS into dev-v7 2016-01-05 11:35:35 +01:00
Shannon 415aaf3e2b U4-7477 xss char stripping on data type names is being too agressive 2016-01-05 11:35:24 +01:00
Sebastiaan Janssen 5081027482 Improve batch files: SETLOCAL makes sure we don't change the user's actual path, so no need to revert changes any more either 2016-01-05 11:33:10 +01:00
Wincent 96b24d7ee0 Removes dependency to System.IO.File 2015-12-31 12:01:35 +01:00
Shannon ac1785bc08 U4-7583 2015-12-28 16:20:48 +01:00
Shannon 1da1a20734 ensures the setting is enabled for the searcher too 2015-12-28 13:43:47 +01:00
Shannon c765ab9112 U4-7614 Allow Examine's local temp storage to exist in the current User's temp storage location - useful for Azure 2015-12-28 13:37:56 +01:00
Shannon Deminick 664aa3842d Merge pull request #979 from robertjf/dev-v7
fix for issue U4-7609/U4-7610 - IE related problems
2015-12-28 10:09:29 +01:00
Robert Foster fbee58e445 Added json mimetype Mapping to web.config.template to support things like manifest.json in certain browsers (e.g. IE). 2015-12-26 19:05:44 +11:00
Robert Foster a5e87dcedf Fix for IE not being able to install packages in Umbraco backoffice. 2015-12-26 18:57:24 +11:00
Wincent 53f9e104ec Merge branch 'dev-v7' of https://github.com/umbraco/Umbraco-CMS into U4-7312-2
Conflicts:
	src/Umbraco.Web/Editors/ImagesController.cs - Removed changes from upstream
2015-12-19 11:16:30 +01:00
Robert Foster ffe41fe060 Merge remote-tracking branch 'refs/remotes/umbraco/dev-v7' 2015-12-18 22:45:46 +11:00
Shannon Deminick e89cc24d51 Merge pull request #958 from lars-erik/overridable-domain-repository
Can't log into youtrack. Simple changes to repositoryfactory and umbr…
2015-12-16 10:19:25 +01:00
Claus 61f3b2ae4a Added CultureInvariant to regex. 2015-12-16 09:53:15 +01:00
Claus a752c7ee4b Merge branch 'rasmusjp-U4-7462' into dev-v7 2015-12-16 09:52:36 +01:00
Lars-Erik Aabech a14f0021bd Can't log into youtrack. Simple changes to repositoryfactory and umbraco.web.ui assemblyinfo. 2015-12-16 09:50:17 +01:00
Claus 5eb5549448 Merge branch 'U4-7462' of git://github.com/rasmusjp/Umbraco-CMS into rasmusjp-U4-7462 2015-12-16 09:36:49 +01:00
Claus f5e9151ffd Localized some texts on the slider configuration. 2015-12-15 15:42:14 +01:00
bjarnef 5a9dd11a7c Change margin-top for triangle and re-order config properties 2015-12-15 15:42:14 +01:00
bjarnef 9e6123abd3 Modify properties and styling 2015-12-15 15:42:13 +01:00
bjarnef 6c3ef2aaa9 Add more config properties 2015-12-15 15:42:13 +01:00
bjarnef 95ae504c9b Change "reversed" property to boolean 2015-12-15 15:42:12 +01:00
bjarnef 88fadcf74e Add slider bootstrap-slider v5.2.6
Add newer version of script and add addtional properties.
2015-12-15 15:42:12 +01:00
Sebastiaan Janssen bb4994f9fc Merge pull request #935 from torerikk/dev-v7
Update Norwegian translations
2015-12-15 15:10:46 +01:00
Claus c334f94d72 Fixed a few comments. 2015-12-15 14:47:19 +01:00
Claus ddf525db40 Merge branch 'AffinityID-u4-7522' into dev-v7 2015-12-15 14:43:22 +01:00
Claus 9c7ef46222 Merge pull request #941 from bugsancho/dev-v7
U4-7508 - IsChildOfListView should be populated for Media items
2015-12-15 14:18:27 +01:00
Sebastiaan Janssen eacc7f7fb3 Whoops, was supposed to be en-US by default 2015-12-15 13:50:19 +01:00
Sebastiaan Janssen 80f597a7eb U4-7424 - Also update all other errors displayed in the frontend 2015-12-15 12:51:45 +01:00
Sebastiaan Janssen d069da8a4f Make LocalizedTextService fall back to en-GB if the key is not found in the current file 2015-12-15 12:51:03 +01:00
Sebastiaan Janssen 44ebd8d9ea Proper formatting of this file, only whitespace changes 2015-12-15 12:18:23 +01:00
Sebastiaan Janssen 2fd6dc3603 Merge branch 'engern-U4-7424' into dev-v7 2015-12-15 12:14:07 +01:00
Sebastiaan Janssen 0629b49112 Merge branch 'U4-7424' of https://github.com/engern/Umbraco-CMS into engern-U4-7424 2015-12-15 12:13:35 +01:00
Sebastiaan Janssen 4958c5a59a Merge branch 'jamescoxhead-U4-7503-Disable-X-AspNetMvc-Version-Header' into dev-v7 2015-12-15 11:21:23 +01:00
Sebastiaan Janssen 523501db8c Merge branch 'U4-7503-Disable-X-AspNetMvc-Version-Header' of https://github.com/jamescoxhead/Umbraco-CMS into jamescoxhead-U4-7503-Disable-X-AspNetMvc-Version-Header 2015-12-15 11:21:11 +01:00
Sebastiaan Janssen 23cd2b09ca Merge branch 'dev-v7' of https://github.com/umbraco/Umbraco-CMS into dev-v7 2015-12-15 11:13:22 +01:00
Sebastiaan Janssen a1ff1d4543 Merge branch 'TimoPerplex-dev-v7' into dev-v7 2015-12-15 11:12:57 +01:00
Sebastiaan Janssen 1bf2a3b1bf Merge branch 'dev-v7' of https://github.com/TimoPerplex/Umbraco-CMS into TimoPerplex-dev-v7
Conflicts:
	src/Umbraco.Web/Editors/ImagesController.cs
2015-12-15 11:12:13 +01:00
Shannon 8598ab565c Fixes: U4-7536 Sign-out in back office will call all ASP.Net identity middleware sign out methods
publicises a few things too.
2015-12-15 10:34:11 +01:00
Rasmus John Pedersen a56936b6f9 Fixes bug with macro multiline parameters 2015-12-14 13:44:57 +01:00
Andrey Shchekin b3e21e0827 U4-7522 Removed unnecessary exception from DeepCloneHelper. 2015-12-10 14:33:52 +13:00
James Coxhead 739ff33ce1 Removed X-AspNet-Version and X-AspNetMvc-Version headers 2015-12-08 21:44:40 +00:00
James Coxhead f27a726a6e Disabled the X-AspNetMvc-Version header 2015-12-08 21:19:41 +00:00
Alexander Todorov aed906e682 U4-7508 - IsChildOfListView should be populated for Media items, similarly to Content items 2015-12-08 18:41:59 +02:00
Wincent e0ee786271 Re-enables support for non media thumbnails 2015-12-04 09:31:39 +01:00
Wincent 2664a75c84 Removed generation of old thumbnails 2015-12-03 17:33:40 +01:00
Wincent 5d9bde807e Changes GetBigThumbnail to image processor in mediahelper.service.js and fileupload.controller.js
Changed ImageController.GetBigThumbnail to redirect
Changed thumbnail paths to include rnd equal to UpdateDate
2015-12-03 17:27:47 +01:00
Tor-Erik Klausen 0370f9a1c8 Update Norwegian translations
Adds missing translations and removes some old ones. Based on current
en.xml
2015-12-02 20:09:06 +01:00
bjarnef b2d4eccf7b Merge remote-tracking branch 'refs/remotes/umbraco/dev-v7' into dev-v7 2015-11-25 20:13:15 +01:00
kiasyn dbece874dd U4-7400 - Datepicker is not updating scope model value in time for 3rd party plugins
Force set scope model value when the datetime changes, rather than just on formsubmit. This means that 3rd party plugins (such as grids) can use this editor.
2015-11-25 10:25:00 +13:00
engern 07c714fd11 Fixes U4-7424
Add the possibilty to change the error message when a macro partial view
fails to render.
2015-11-21 11:33:46 +01:00
Jordan Lane 8e6bac534a Fix a bug where PublishStatusType would fallback to FailedContentInvalid (and break) if it was expired or trashed and add error message for FailedHasExpired
TODO: Add error message to other languages
2015-10-29 15:23:40 +00:00
Jordan Lane c5cf1fa6b2 Checks if content has expired or is awaiting release before publishing 2015-10-29 15:21:15 +00:00
Jordan Lane 1e4c9c2505 Set the publish status of new content version to saved if validation of publication fails e.g. a release date of the future or past unpublish date 2015-10-29 15:20:35 +00:00
Jordan Lane a6b56db2f5 Fixes an issue with the contentService.RePublishAll() where it wouldn't publish an old published version if the newest version of the content wasn't published i.e had a scheduled date set because this would create a new version with status not published 2015-10-29 15:16:44 +00:00
TimoPerplex 43baba1733 Revert "Latest"
This reverts commit 95a9e4b5ff.
2015-10-27 13:10:25 +01:00
TimoPerplex 95a9e4b5ff Latest 2015-10-27 13:09:21 +01:00
TimoPerplex 9b0aa49d4d Merge remote-tracking branch 'refs/remotes/umbraco/dev-v7' into dev-v7 2015-10-27 13:08:32 +01:00
TimGeyssens 7eeb0c4966 Fixes U4-7249 Insert Macro split button, when selecting a macro that has parameters the dialog should immediately show those 2015-10-14 11:29:34 +02:00
Robert Foster e9d0aa87bd Merge remote-tracking branch 'refs/remotes/umbraco/dev-v7' 2015-09-21 20:32:43 +10:00
Robert Foster 803ca677c1 Merge remote-tracking branch 'umbraco/dev-v7' into dev-v7 2015-09-10 02:07:34 +10:00
TimoPerplex 68ff77f5b6 This commit removes the hardcoded .jpg thumbnails
This commit removes the hardcoded .jpg thumbnails and uses the image
original extension to create the thumbnail.
Because we now use the original extension the image is no longer masked
as another (extension is .jpg but the file is actually a .png)

This fixes issues with Internet Explorer used in combination with the
no-sniff header.
Ref topic:
https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/66788-adding-nosniff-header-breaks-png-images-in-internet-explorer
2015-07-24 16:27:26 +02:00
TimoPerplex 47e7469d65 Merge remote-tracking branch 'upstream/dev-v7' into dev-v7 2015-07-24 16:18:58 +02:00
AussieInSeattle 2276584c90 Update for when first control has settings
Adding style for when first control has settings - it was previously overlapping the "cog" icon above it
2015-03-11 11:52:57 -07:00
AussieInSeattle 05a0846e89 Update grid.controller.js 2015-03-09 11:22:16 -07:00
AussieInSeattle b2947264e1 edit function for settings on a custom grid editor 2015-02-19 15:49:03 -08:00
AussieInSeattle 066927742e Update UI for settings for a custom grid editor 2015-02-19 15:47:11 -08:00
TimoPerplex 4616afced4 Merge pull request #1 from umbraco/dev-v7
Update to latest data
2015-01-19 09:05:18 +01:00
233 changed files with 7724 additions and 4026 deletions
+5 -9
View File
@@ -1,4 +1,6 @@
@ECHO OFF
SETLOCAL
SET release=%1
ECHO Installing Npm NuGet Package
@@ -11,12 +13,9 @@ ECHO Current folder: %CD%
for /f "delims=" %%A in ('dir %nuGetFolder%node.js.* /b') do set "nodePath=%nuGetFolder%%%A\"
for /f "delims=" %%A in ('dir %nuGetFolder%npm.js.* /b') do set "npmPath=%nuGetFolder%%%A\tools\"
ECHO Temporarily adding Npm and Node to path
SET oldPath=%PATH%
path=%npmPath%;%nodePath%;%PATH%
ECHO %path%
ECHO Adding Npm and Node to path
REM SETLOCAL is on, so changes to the path not persist to the actual user's path
PATH=%npmPath%;%nodePath%;%PATH%
SET buildFolder=%CD%
@@ -29,8 +28,5 @@ call npm install -g grunt-cli --quiet
call npm install -g bower --quiet
call grunt build --buildversion=%release%
ECHO Reset path to what it was before
path=%oldPath%
ECHO Move back to the build folder
CD %buildFolder%
+5 -6
View File
@@ -1,19 +1,19 @@
@ECHO OFF
SET oldPath=%PATH%
SETLOCAL
REM SETLOCAL is on, so changes to the path not persist to the actual user's path
git.exe 2> NUL
if %ERRORLEVEL%==9009 GOTO :trydefaultpath
GOTO :EOF
:trydefaultpath
path=C:\Program Files (x86)\Git\cmd;%PATH%
path=C:\Program Files (x86)\Git\cmd;C:\Program Files\Git\cmd;%PATH%
git.exe 2> NUL
if %ERRORLEVEL%==9009 GOTO :showerror
GOTO :EOF
:showerror
path=%oldPath%
ECHO Git is not in your path and could not be found in C:\Program Files (x86)\Git\bin
ECHO Git is not in your path and could not be found in C:\Program Files (x86)\Git\cmd nor in C:\Program Files\Git\cmd
set /p install=" Do you want to install Git through Chocolatey [y/n]? " %=%
if %install%==y (
GOTO :installgit
@@ -29,5 +29,4 @@ GOTO :EOF
ECHO Installing Chocolatey first
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
ECHO Installing Git through Chocolatey
choco install git
path=C:\Program Files (x86)\Git\cmd;%path%
choco install git
+3 -3
View File
@@ -33,11 +33,12 @@
<dependency id="AutoMapper" version="[3.0.0, 3.1.0)" />
<dependency id="Newtonsoft.Json" version="[6.0.8, 7.0.0)" />
<dependency id="Examine" version="[0.1.68, 1.0.0)" />
<dependency id="ImageProcessor" version="[2.3.0, 3.0.0)" />
<dependency id="ImageProcessor.Web" version="[4.4.0, 5.0.0)" />
<dependency id="ImageProcessor" version="[2.3.2, 3.0.0)" />
<dependency id="ImageProcessor.Web" version="[4.5.1, 5.0.0)" />
<dependency id="semver" version="[1.1.2, 2.0.0)" />
<dependency id="Microsoft.AspNet.WebHelpers" version="[3.2.3, 4.0.0)" />
<dependency id="Microsoft.AspNet.WebPages.Data" version="[3.2.3, 4.0.0)" />
<dependency id="UrlRewritingNet" version="[2.0.7, 3.0.0)" />
</dependencies>
</metadata>
<files>
@@ -72,7 +73,6 @@
<file src="..\_BuildOutput\WebApp\bin\Umbraco.Web.UI.xml" target="lib\Umbraco.Web.UI.xml" />
<file src="..\_BuildOutput\WebApp\bin\UmbracoExamine.dll" target="lib\UmbracoExamine.dll" />
<file src="..\_BuildOutput\WebApp\bin\UmbracoExamine.xml" target="lib\UmbracoExamine.xml" />
<file src="..\_BuildOutput\WebApp\bin\UrlRewritingNet.UrlRewriter.dll" target="lib\UrlRewritingNet.UrlRewriter.dll" />
<file src="tools\install.core.ps1" target="tools\install.ps1" />
<!-- Added to be able to produce a symbols package -->
+19 -2
View File
@@ -54,7 +54,7 @@
</providers>
</siteMap>
<httpRuntime xdt:Transform="InsertIfMissing" />
<httpRuntime targetFramework="4.5" xdt:Transform="SetAttributes(targetFramework)" />
<httpRuntime targetFramework="4.5" maxRequestLength="51200" fcnMode="Single" xdt:Transform="SetAttributes(targetFramework,fcnMode,maxRequestLength)" />
<membership defaultProvider="DefaultMembershipProvider" xdt:Locator="Match(defaultProvider)" xdt:Transform="Remove" />
<roleManager defaultProvider="DefaultRoleProvider" xdt:Locator="Match(defaultProvider)" xdt:Transform="Remove"/>
<profile defaultProvider="DefaultProfileProvider" xdt:Locator="Match(defaultProvider)" xdt:Transform="Remove"/>>
@@ -140,6 +140,13 @@
<remove name="SpellChecker" xdt:Locator="Match(name)" xdt:Transform="Remove" />
<add name="SpellChecker" xdt:Locator="Match(name)" xdt:Transform="Remove" />
</handlers>
<security xdt:Transform="InsertIfMissing">
<requestFiltering xdt:Transform="InsertIfMissing">
<requestLimits maxAllowedContentLength="52428800" xdt:Transform="InsertIfMissing" />
</requestFiltering>
</security>
</system.webServer>
<system.codedom xdt:Transform="Remove" />
@@ -151,20 +158,26 @@
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='HtmlAgilityPack')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='System.Net.Http')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Newtonsoft.Json')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='System.Web.Mvc')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='System.Web.WebPages.Razor')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='System.Web.Http')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Owin')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Owin.Security.OAuth')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Owin.Security')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='Microsoft.Owin.Security.Cookies')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='System.Net.Http.Formatting')" xdt:Transform="Remove" />
<dependentAssembly xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/@name='System.Net.Http.Formatting')" xdt:Transform="Remove" />
</assemblyBinding>
</runtime>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="HtmlAgilityPack" publicKeyToken="bd319b19eaf3b43a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.4.9.0" newVersion="1.4.9.0" />
</dependentAssembly>
<dependentAssembly xdt:Transform="Insert">
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>
@@ -177,6 +190,10 @@
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
<dependentAssembly xdt:Transform="Insert">
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly xdt:Transform="Insert">
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
+1 -1
View File
@@ -1,2 +1,2 @@
# Usage: on line 2 put the release version, on line 3 put the version comment (example: beta)
7.3.4
7.3.6
+3 -3
View File
@@ -2,7 +2,7 @@
using System.Resources;
[assembly: AssemblyCompany("Umbraco")]
[assembly: AssemblyCopyright("Copyright © Umbraco 2015")]
[assembly: AssemblyCopyright("Copyright © Umbraco 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -11,5 +11,5 @@ using System.Resources;
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("7.3.4")]
[assembly: AssemblyInformationalVersion("7.3.4")]
[assembly: AssemblyFileVersion("7.3.6")]
[assembly: AssemblyInformationalVersion("7.3.6")]
+2 -1
View File
@@ -406,7 +406,8 @@ namespace Umbraco.Core
//clear the cache
if (ApplicationCache != null)
{
ApplicationCache.ClearAllCache();
ApplicationCache.RuntimeCache.ClearAllCache();
ApplicationCache.IsolatedRuntimeCache.ClearAllCaches();
}
//reset all resolvers
ResolverCollection.ResetAll();
+29 -2
View File
@@ -1,8 +1,9 @@
using System;
using System.ComponentModel;
using Umbraco.Core.CodeAnnotations;
namespace Umbraco.Core.Cache
{
/// <summary>
/// Constants storing cache keys used in caching
/// </summary>
@@ -12,52 +13,78 @@ namespace Umbraco.Core.Cache
public const string ApplicationsCacheKey = "ApplicationCache";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string UserTypeCacheKey = "UserTypeCache";
[Obsolete("This is no longer used and will be removed from the codebase in the future - it is referenced but no cache is stored against this key")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string ContentItemCacheKey = "contentItem";
[UmbracoWillObsolete("This cache key is only used for the legacy 'library' caching, remove in v8")]
public const string MediaCacheKey = "UL_GetMedia";
public const string MacroXsltCacheKey = "macroXslt_";
[UmbracoWillObsolete("This cache key is only used for legacy business logic caching, remove in v8")]
public const string MacroCacheKey = "UmbracoMacroCache";
public const string MacroHtmlCacheKey = "macroHtml_";
public const string MacroControlCacheKey = "macroControl_";
public const string MacroHtmlDateAddedCacheKey = "macroHtml_DateAdded_";
public const string MacroControlDateAddedCacheKey = "macroControl_DateAdded_";
[UmbracoWillObsolete("This cache key is only used for legacy 'library' member caching, remove in v8")]
public const string MemberLibraryCacheKey = "UL_GetMember";
[UmbracoWillObsolete("This cache key is only used for legacy business logic caching, remove in v8")]
public const string MemberBusinessLogicCacheKey = "MemberCacheItem_";
[UmbracoWillObsolete("This cache key is only used for legacy template business logic caching, remove in v8")]
public const string TemplateFrontEndCacheKey = "template";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string TemplateBusinessLogicCacheKey = "UmbracoTemplateCache";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string UserContextCacheKey = "UmbracoUserContext";
public const string UserContextTimeoutCacheKey = "UmbracoUserContextTimeout";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string UserCacheKey = "UmbracoUser";
public const string UserPermissionsCacheKey = "UmbracoUserPermissions";
[UmbracoWillObsolete("This cache key is only used for legacy business logic caching, remove in v8")]
public const string ContentTypeCacheKey = "UmbracoContentType";
[UmbracoWillObsolete("This cache key is only used for legacy business logic caching, remove in v8")]
public const string ContentTypePropertiesCacheKey = "ContentType_PropertyTypes_Content:";
[UmbracoWillObsolete("This cache key is only used for legacy business logic caching, remove in v8")]
public const string PropertyTypeCacheKey = "UmbracoPropertyTypeCache";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string LanguageCacheKey = "UmbracoLanguageCache";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string DomainCacheKey = "UmbracoDomainList";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string StylesheetCacheKey = "UmbracoStylesheet";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string StylesheetPropertyCacheKey = "UmbracoStylesheetProperty";
[Obsolete("This is no longer used and will be removed from the codebase in the future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public const string DataTypeCacheKey = "UmbracoDataTypeDefinition";
public const string DataTypePreValuesCacheKey = "UmbracoPreVal";
@@ -2,6 +2,7 @@
using Umbraco.Core.Events;
using Umbraco.Core.Sync;
using umbraco.interfaces;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
@@ -63,5 +64,15 @@ namespace Umbraco.Core.Cache
{
OnCacheUpdated(Instance, new CacheRefresherEventArgs(id, MessageType.RefreshById));
}
/// <summary>
/// Clears the cache for all repository entities of this type
/// </summary>
/// <typeparam name="TEntity"></typeparam>
internal void ClearAllIsolatedCacheByEntityType<TEntity>()
where TEntity : class, IAggregateRoot
{
ApplicationContext.Current.ApplicationCache.IsolatedRuntimeCache.ClearCache<TEntity>();
}
}
}
@@ -2,11 +2,10 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Caching;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Persistence.Repositories
namespace Umbraco.Core.Cache
{
/// <summary>
/// A wrapper for any IRuntimeCacheProvider that ensures that all inserts and returns
@@ -0,0 +1,286 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
/// <summary>
/// The default cache policy for retrieving a single entity
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TId"></typeparam>
/// <remarks>
/// This cache policy uses sliding expiration and caches instances for 5 minutes. However if allow zero count is true, then we use the
/// default policy with no expiry.
/// </remarks>
internal class DefaultRepositoryCachePolicy<TEntity, TId> : DisposableObject, IRepositoryCachePolicy<TEntity, TId>
where TEntity : class, IAggregateRoot
{
private readonly RepositoryCachePolicyOptions _options;
protected IRuntimeCacheProvider Cache { get; private set; }
private Action _action;
public DefaultRepositoryCachePolicy(IRuntimeCacheProvider cache, RepositoryCachePolicyOptions options)
{
if (cache == null) throw new ArgumentNullException("cache");
if (options == null) throw new ArgumentNullException("options");
_options = options;
Cache = cache;
}
public string GetCacheIdKey(object id)
{
if (id == null) throw new ArgumentNullException("id");
return string.Format("{0}{1}", GetCacheTypeKey(), id);
}
public string GetCacheTypeKey()
{
return string.Format("uRepo_{0}_", typeof(TEntity).Name);
}
public void CreateOrUpdate(TEntity entity, Action<TEntity> persistMethod)
{
if (entity == null) throw new ArgumentNullException("entity");
if (persistMethod == null) throw new ArgumentNullException("persistMethod");
try
{
persistMethod(entity);
//set the disposal action
SetCacheAction(() =>
{
//just to be safe, we cannot cache an item without an identity
if (entity.HasIdentity)
{
Cache.InsertCacheItem(GetCacheIdKey(entity.Id), () => entity,
timeout: TimeSpan.FromMinutes(5),
isSliding: true);
}
//If there's a GetAllCacheAllowZeroCount cache, ensure it is cleared
Cache.ClearCacheItem(GetCacheTypeKey());
});
}
catch
{
//set the disposal action
SetCacheAction(() =>
{
//if an exception is thrown we need to remove the entry from cache, this is ONLY a work around because of the way
// that we cache entities: http://issues.umbraco.org/issue/U4-4259
Cache.ClearCacheItem(GetCacheIdKey(entity.Id));
//If there's a GetAllCacheAllowZeroCount cache, ensure it is cleared
Cache.ClearCacheItem(GetCacheTypeKey());
});
throw;
}
}
public void Remove(TEntity entity, Action<TEntity> persistMethod)
{
if (entity == null) throw new ArgumentNullException("entity");
if (persistMethod == null) throw new ArgumentNullException("persistMethod");
persistMethod(entity);
//set the disposal action
var cacheKey = GetCacheIdKey(entity.Id);
SetCacheAction(() =>
{
Cache.ClearCacheItem(cacheKey);
//If there's a GetAllCacheAllowZeroCount cache, ensure it is cleared
Cache.ClearCacheItem(GetCacheTypeKey());
});
}
public TEntity Get(TId id, Func<TId, TEntity> getFromRepo)
{
if (getFromRepo == null) throw new ArgumentNullException("getFromRepo");
var cacheKey = GetCacheIdKey(id);
var fromCache = Cache.GetCacheItem<TEntity>(cacheKey);
if (fromCache != null)
return fromCache;
var entity = getFromRepo(id);
//set the disposal action
SetCacheAction(cacheKey, entity);
return entity;
}
public TEntity Get(TId id)
{
var cacheKey = GetCacheIdKey(id);
return Cache.GetCacheItem<TEntity>(cacheKey);
}
public bool Exists(TId id, Func<TId, bool> getFromRepo)
{
if (getFromRepo == null) throw new ArgumentNullException("getFromRepo");
var cacheKey = GetCacheIdKey(id);
var fromCache = Cache.GetCacheItem<TEntity>(cacheKey);
return fromCache != null || getFromRepo(id);
}
public virtual TEntity[] GetAll(TId[] ids, Func<TId[], IEnumerable<TEntity>> getFromRepo)
{
if (getFromRepo == null) throw new ArgumentNullException("getFromRepo");
if (ids.Any())
{
var entities = ids.Select(Get).ToArray();
if (ids.Length.Equals(entities.Length) && entities.Any(x => x == null) == false)
return entities;
}
else
{
var allEntities = GetAllFromCache();
if (allEntities.Any())
{
if (_options.GetAllCacheValidateCount)
{
//Get count of all entities of current type (TEntity) to ensure cached result is correct
var totalCount = _options.PerformCount();
if (allEntities.Length == totalCount)
return allEntities;
}
else
{
return allEntities;
}
}
else if (_options.GetAllCacheAllowZeroCount)
{
//if the repository allows caching a zero count, then check the zero count cache
if (HasZeroCountCache())
{
//there is a zero count cache so return an empty list
return new TEntity[] {};
}
}
}
//we need to do the lookup from the repo
var entityCollection = getFromRepo(ids)
//ensure we don't include any null refs in the returned collection!
.WhereNotNull()
.ToArray();
//set the disposal action
SetCacheAction(ids, entityCollection);
return entityCollection;
}
/// <summary>
/// Looks up the zero count cache, must return null if it doesn't exist
/// </summary>
/// <returns></returns>
protected virtual bool HasZeroCountCache()
{
var zeroCount = Cache.GetCacheItem<TEntity[]>(GetCacheTypeKey());
return (zeroCount != null && zeroCount.Any() == false);
}
/// <summary>
/// Performs the lookup for all entities of this type from the cache
/// </summary>
/// <returns></returns>
protected virtual TEntity[] GetAllFromCache()
{
var allEntities = Cache.GetCacheItemsByKeySearch<TEntity>(GetCacheTypeKey())
.WhereNotNull()
.ToArray();
return allEntities.Any() ? allEntities : new TEntity[] {};
}
/// <summary>
/// The disposal performs the caching
/// </summary>
protected override void DisposeResources()
{
if (_action != null)
{
_action();
}
}
/// <summary>
/// Sets the action to execute on disposal for a single entity
/// </summary>
/// <param name="cacheKey"></param>
/// <param name="entity"></param>
protected virtual void SetCacheAction(string cacheKey, TEntity entity)
{
if (entity == null) return;
SetCacheAction(() =>
{
//just to be safe, we cannot cache an item without an identity
if (entity.HasIdentity)
{
Cache.InsertCacheItem(cacheKey, () => entity,
timeout: TimeSpan.FromMinutes(5),
isSliding: true);
}
});
}
/// <summary>
/// Sets the action to execute on disposal for an entity collection
/// </summary>
/// <param name="ids"></param>
/// <param name="entityCollection"></param>
protected virtual void SetCacheAction(TId[] ids, TEntity[] entityCollection)
{
SetCacheAction(() =>
{
//This option cannot execute if we are looking up specific Ids
if (ids.Any() == false && entityCollection.Length == 0 && _options.GetAllCacheAllowZeroCount)
{
//there was nothing returned but we want to cache a zero count result so add an TEntity[] to the cache
// to signify that there is a zero count cache
//NOTE: Don't set expiry/sliding for a zero count
Cache.InsertCacheItem(GetCacheTypeKey(), () => new TEntity[] {});
}
else
{
//This is the default behavior, we'll individually cache each item so that if/when these items are resolved
// by id, they are returned from the already existing cache.
foreach (var entity in entityCollection.WhereNotNull())
{
var localCopy = entity;
//just to be safe, we cannot cache an item without an identity
if (localCopy.HasIdentity)
{
Cache.InsertCacheItem(GetCacheIdKey(entity.Id), () => localCopy,
timeout: TimeSpan.FromMinutes(5),
isSliding: true);
}
}
}
});
}
/// <summary>
/// Sets the action to execute on disposal
/// </summary>
/// <param name="action"></param>
protected void SetCacheAction(Action action)
{
_action = action;
}
}
}
@@ -0,0 +1,27 @@
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
/// <summary>
/// Creates cache policies
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TId"></typeparam>
internal class DefaultRepositoryCachePolicyFactory<TEntity, TId> : IRepositoryCachePolicyFactory<TEntity, TId>
where TEntity : class, IAggregateRoot
{
private readonly IRuntimeCacheProvider _runtimeCache;
private readonly RepositoryCachePolicyOptions _options;
public DefaultRepositoryCachePolicyFactory(IRuntimeCacheProvider runtimeCache, RepositoryCachePolicyOptions options)
{
_runtimeCache = runtimeCache;
_options = options;
}
public virtual IRepositoryCachePolicy<TEntity, TId> CreatePolicy()
{
return new DefaultRepositoryCachePolicy<TEntity, TId>(_runtimeCache, _options);
}
}
}
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Collections;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
/// <summary>
/// A caching policy that caches an entire dataset as a single collection
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TId"></typeparam>
/// <remarks>
/// This caching policy has no sliding expiration but uses the default ObjectCache.InfiniteAbsoluteExpiration as it's timeout, so it
/// should not leave the cache unless the cache memory is exceeded and it gets thrown out.
/// </remarks>
internal class FullDataSetRepositoryCachePolicy<TEntity, TId> : DefaultRepositoryCachePolicy<TEntity, TId>
where TEntity : class, IAggregateRoot
{
private readonly Func<TEntity, TId> _getEntityId;
public FullDataSetRepositoryCachePolicy(IRuntimeCacheProvider cache, Func<TEntity, TId> getEntityId) : base(cache,
new RepositoryCachePolicyOptions
{
//Definitely allow zero'd cache entires since this is a full set, in many cases there will be none,
// and we must cache this!
GetAllCacheAllowZeroCount = true
})
{
_getEntityId = getEntityId;
}
private bool? _hasZeroCountCache;
public override TEntity[] GetAll(TId[] ids, Func<TId[], IEnumerable<TEntity>> getFromRepo)
{
//process the base logic without any Ids - we want to cache them all!
var result = base.GetAll(new TId[] { }, getFromRepo);
//now that the base result has been calculated, they will all be cached.
// Now we can just filter by ids if they have been supplied
return ids.Any()
? result.Where(x => ids.Contains(_getEntityId(x))).ToArray()
: result;
}
/// <summary>
/// For this type of caching policy, we don't cache individual items
/// </summary>
/// <param name="cacheKey"></param>
/// <param name="entity"></param>
protected override void SetCacheAction(string cacheKey, TEntity entity)
{
//do nothing
}
/// <summary>
/// Sets the action to execute on disposal for an entity collection
/// </summary>
/// <param name="ids"></param>
/// <param name="entityCollection"></param>
protected override void SetCacheAction(TId[] ids, TEntity[] entityCollection)
{
//for this type of caching policy, we don't want to cache any GetAll request containing specific Ids
if (ids.Any()) return;
//set the disposal action
SetCacheAction(() =>
{
//We want to cache the result as a single collection
Cache.InsertCacheItem(GetCacheTypeKey(), () => new DeepCloneableList<TEntity>(entityCollection));
});
}
/// <summary>
/// Looks up the zero count cache, must return null if it doesn't exist
/// </summary>
/// <returns></returns>
protected override bool HasZeroCountCache()
{
if (_hasZeroCountCache.HasValue)
return _hasZeroCountCache.Value;
_hasZeroCountCache = Cache.GetCacheItem<DeepCloneableList<TEntity>>(GetCacheTypeKey()) != null;
return _hasZeroCountCache.Value;
}
/// <summary>
/// This policy will cache the full data set as a single collection
/// </summary>
/// <returns></returns>
protected override TEntity[] GetAllFromCache()
{
var found = Cache.GetCacheItem<DeepCloneableList<TEntity>>(GetCacheTypeKey());
//This method will get called before checking for zero count cache, so we'll just set the flag here
_hasZeroCountCache = found != null;
return found == null ? new TEntity[] { } : found.WhereNotNull().ToArray();
}
}
}
@@ -0,0 +1,28 @@
using System;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
/// <summary>
/// Creates cache policies
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TId"></typeparam>
internal class FullDataSetRepositoryCachePolicyFactory<TEntity, TId> : IRepositoryCachePolicyFactory<TEntity, TId>
where TEntity : class, IAggregateRoot
{
private readonly IRuntimeCacheProvider _runtimeCache;
private readonly Func<TEntity, TId> _getEntityId;
public FullDataSetRepositoryCachePolicyFactory(IRuntimeCacheProvider runtimeCache, Func<TEntity, TId> getEntityId)
{
_runtimeCache = runtimeCache;
_getEntityId = getEntityId;
}
public virtual IRepositoryCachePolicy<TEntity, TId> CreatePolicy()
{
return new FullDataSetRepositoryCachePolicy<TEntity, TId>(_runtimeCache, _getEntityId);
}
}
}
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
internal interface IRepositoryCachePolicy<TEntity, TId> : IDisposable
where TEntity : class, IAggregateRoot
{
TEntity Get(TId id, Func<TId, TEntity> getFromRepo);
TEntity Get(TId id);
bool Exists(TId id, Func<TId, bool> getFromRepo);
string GetCacheIdKey(object id);
string GetCacheTypeKey();
void CreateOrUpdate(TEntity entity, Action<TEntity> persistMethod);
void Remove(TEntity entity, Action<TEntity> persistMethod);
TEntity[] GetAll(TId[] ids, Func<TId[], IEnumerable<TEntity>> getFromRepo);
}
}
@@ -0,0 +1,9 @@
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
internal interface IRepositoryCachePolicyFactory<TEntity, TId> where TEntity : class, IAggregateRoot
{
IRepositoryCachePolicy<TEntity, TId> CreatePolicy();
}
}
@@ -0,0 +1,91 @@
using System;
using System.Collections.Concurrent;
namespace Umbraco.Core.Cache
{
/// <summary>
/// Used to get/create/manipulate isolated runtime cache
/// </summary>
/// <remarks>
/// This is useful for repository level caches to ensure that cache lookups by key are fast so
/// that the repository doesn't need to search through all keys on a global scale.
/// </remarks>
public class IsolatedRuntimeCache
{
internal Func<Type, IRuntimeCacheProvider> CacheFactory { get; set; }
/// <summary>
/// Constructor that allows specifying a factory for the type of runtime isolated cache to create
/// </summary>
/// <param name="cacheFactory"></param>
public IsolatedRuntimeCache(Func<Type, IRuntimeCacheProvider> cacheFactory)
{
CacheFactory = cacheFactory;
}
private readonly ConcurrentDictionary<Type, IRuntimeCacheProvider> _isolatedCache = new ConcurrentDictionary<Type, IRuntimeCacheProvider>();
/// <summary>
/// Returns an isolated runtime cache for a given type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public IRuntimeCacheProvider GetOrCreateCache<T>()
{
return _isolatedCache.GetOrAdd(typeof(T), type => CacheFactory(type));
}
/// <summary>
/// Returns an isolated runtime cache for a given type
/// </summary>
/// <returns></returns>
public IRuntimeCacheProvider GetOrCreateCache(Type type)
{
return _isolatedCache.GetOrAdd(type, t => CacheFactory(t));
}
/// <summary>
/// Tries to get a cache by the type specified
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public Attempt<IRuntimeCacheProvider> GetCache<T>()
{
IRuntimeCacheProvider cache;
if (_isolatedCache.TryGetValue(typeof(T), out cache))
{
return Attempt.Succeed(cache);
}
return Attempt<IRuntimeCacheProvider>.Fail();
}
/// <summary>
/// Clears all values inside this isolated runtime cache
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public void ClearCache<T>()
{
IRuntimeCacheProvider cache;
if (_isolatedCache.TryGetValue(typeof(T), out cache))
{
cache.ClearAllCache();
}
}
/// <summary>
/// Clears all of the isolated caches
/// </summary>
public void ClearAllCaches()
{
foreach (var key in _isolatedCache.Keys)
{
IRuntimeCacheProvider cache;
if (_isolatedCache.TryRemove(key, out cache))
{
cache.ClearAllCache();
}
}
}
}
}
@@ -0,0 +1,27 @@
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
/// <summary>
/// Creates cache policies
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TId"></typeparam>
internal class OnlySingleItemsRepositoryCachePolicyFactory<TEntity, TId> : IRepositoryCachePolicyFactory<TEntity, TId>
where TEntity : class, IAggregateRoot
{
private readonly IRuntimeCacheProvider _runtimeCache;
private readonly RepositoryCachePolicyOptions _options;
public OnlySingleItemsRepositoryCachePolicyFactory(IRuntimeCacheProvider runtimeCache, RepositoryCachePolicyOptions options)
{
_runtimeCache = runtimeCache;
_options = options;
}
public virtual IRepositoryCachePolicy<TEntity, TId> CreatePolicy()
{
return new SingleItemsOnlyRepositoryCachePolicy<TEntity, TId>(_runtimeCache, _options);
}
}
}
@@ -1,17 +1,34 @@
namespace Umbraco.Core.Persistence.Repositories
using System;
namespace Umbraco.Core.Cache
{
internal class RepositoryCacheOptions
internal class RepositoryCachePolicyOptions
{
/// <summary>
/// Constructor sets defaults
/// Ctor - sets GetAllCacheValidateCount = true
/// </summary>
public RepositoryCacheOptions()
public RepositoryCachePolicyOptions(Func<int> performCount)
{
PerformCount = performCount;
GetAllCacheValidateCount = true;
GetAllCacheAllowZeroCount = false;
GetAllCacheThresholdLimit = 100;
}
/// <summary>
/// Ctor - sets GetAllCacheValidateCount = false
/// </summary>
public RepositoryCachePolicyOptions()
{
PerformCount = null;
GetAllCacheValidateCount = false;
GetAllCacheAllowZeroCount = false;
}
/// <summary>
/// Callback required to get count for GetAllCacheValidateCount
/// </summary>
public Func<int> PerformCount { get; private set; }
/// <summary>
/// True/false as to validate the total item count when all items are returned from cache, the default is true but this
/// means that a db lookup will occur - though that lookup will probably be significantly less expensive than the normal
@@ -21,16 +38,11 @@ namespace Umbraco.Core.Persistence.Repositories
/// setting this to return false will improve performance of GetAll cache with no params but should only be used
/// for specific circumstances
/// </remarks>
public bool GetAllCacheValidateCount { get; set; }
public bool GetAllCacheValidateCount { get; private set; }
/// <summary>
/// True if the GetAll method will cache that there are zero results so that the db is not hit when there are no results found
/// </summary>
public bool GetAllCacheAllowZeroCount { get; set; }
/// <summary>
/// The threshold entity count for which the GetAll method will cache entities
/// </summary>
public int GetAllCacheThresholdLimit { get; set; }
}
}
@@ -0,0 +1,24 @@
using System.Linq;
using Umbraco.Core.Collections;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Cache
{
/// <summary>
/// A caching policy that ignores all caches for GetAll - it will only cache calls for individual items
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TId"></typeparam>
internal class SingleItemsOnlyRepositoryCachePolicy<TEntity, TId> : DefaultRepositoryCachePolicy<TEntity, TId>
where TEntity : class, IAggregateRoot
{
public SingleItemsOnlyRepositoryCachePolicy(IRuntimeCacheProvider cache, RepositoryCachePolicyOptions options) : base(cache, options)
{
}
protected override void SetCacheAction(TId[] ids, TEntity[] entityCollection)
{
//do nothing
}
}
}
+102 -222
View File
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@@ -11,20 +13,15 @@ using Umbraco.Core.Logging;
namespace Umbraco.Core
{
/// <summary>
/// Class that is exposed by the ApplicationContext for application wide caching purposes
/// </summary>
public class CacheHelper
{
private readonly bool _enableCache;
private readonly ICacheProvider _requestCache;
private readonly ICacheProvider _nullRequestCache = new NullCacheProvider();
private readonly ICacheProvider _staticCache;
private readonly ICacheProvider _nullStaticCache = new NullCacheProvider();
private readonly IRuntimeCacheProvider _httpCache;
private readonly IRuntimeCacheProvider _nullHttpCache = new NullCacheProvider();
private static readonly ICacheProvider NullRequestCache = new NullCacheProvider();
private static readonly ICacheProvider NullStaticCache = new NullCacheProvider();
private static readonly IRuntimeCacheProvider NullRuntimeCache = new NullCacheProvider();
/// <summary>
/// Creates a cache helper with disabled caches
/// </summary>
@@ -34,7 +31,7 @@ namespace Umbraco.Core
/// </remarks>
public static CacheHelper CreateDisabledCacheHelper()
{
return new CacheHelper(null, null, null, false);
return new CacheHelper(NullRuntimeCache, NullStaticCache, NullRequestCache, new IsolatedRuntimeCache(t => NullRuntimeCache));
}
/// <summary>
@@ -44,7 +41,8 @@ namespace Umbraco.Core
: this(
new HttpRuntimeCacheProvider(HttpRuntime.Cache),
new StaticCacheProvider(),
new HttpRequestCacheProvider())
new HttpRequestCacheProvider(),
new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider()))
{
}
@@ -56,93 +54,75 @@ namespace Umbraco.Core
: this(
new HttpRuntimeCacheProvider(cache),
new StaticCacheProvider(),
new HttpRequestCacheProvider())
new HttpRequestCacheProvider(),
new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider()))
{
}
/// <summary>
/// Initializes a new instance based on the provided providers
/// </summary>
/// <param name="httpCacheProvider"></param>
/// <param name="staticCacheProvider"></param>
/// <param name="requestCacheProvider"></param>
[Obsolete("Use the constructor the specifies all dependencies")]
[EditorBrowsable(EditorBrowsableState.Never)]
public CacheHelper(
IRuntimeCacheProvider httpCacheProvider,
ICacheProvider staticCacheProvider,
ICacheProvider requestCacheProvider)
: this(httpCacheProvider, staticCacheProvider, requestCacheProvider, true)
: this(httpCacheProvider, staticCacheProvider, requestCacheProvider, new IsolatedRuntimeCache(t => new ObjectCacheRuntimeCacheProvider()))
{
}
/// <summary>
/// Private ctor used for creating a disabled cache helper
/// </summary>
/// <param name="httpCacheProvider"></param>
/// <param name="staticCacheProvider"></param>
/// <param name="requestCacheProvider"></param>
/// <param name="enableCache"></param>
private CacheHelper(
/// <summary>
/// Initializes a new instance based on the provided providers
/// </summary>
/// <param name="httpCacheProvider"></param>
/// <param name="staticCacheProvider"></param>
/// <param name="requestCacheProvider"></param>
/// <param name="isolatedCacheManager"></param>
public CacheHelper(
IRuntimeCacheProvider httpCacheProvider,
ICacheProvider staticCacheProvider,
ICacheProvider requestCacheProvider,
bool enableCache)
ICacheProvider requestCacheProvider,
IsolatedRuntimeCache isolatedCacheManager)
{
if (enableCache)
{
_httpCache = httpCacheProvider;
_staticCache = staticCacheProvider;
_requestCache = requestCacheProvider;
}
else
{
_httpCache = null;
_staticCache = null;
_requestCache = null;
}
_enableCache = enableCache;
if (httpCacheProvider == null) throw new ArgumentNullException("httpCacheProvider");
if (staticCacheProvider == null) throw new ArgumentNullException("staticCacheProvider");
if (requestCacheProvider == null) throw new ArgumentNullException("requestCacheProvider");
if (isolatedCacheManager == null) throw new ArgumentNullException("isolatedCacheManager");
RuntimeCache = httpCacheProvider;
StaticCache = staticCacheProvider;
RequestCache = requestCacheProvider;
IsolatedRuntimeCache = isolatedCacheManager;
}
/// <summary>
/// Returns the current Request cache
/// </summary>
public ICacheProvider RequestCache
{
get { return _enableCache ? _requestCache : _nullRequestCache; }
}
/// <summary>
/// Returns the current Runtime cache
/// </summary>
public ICacheProvider StaticCache
{
get { return _enableCache ? _staticCache : _nullStaticCache; }
}
/// <summary>
/// Returns the current Runtime cache
/// </summary>
public IRuntimeCacheProvider RuntimeCache
{
get { return _enableCache ? _httpCache : _nullHttpCache; }
}
public ICacheProvider RequestCache { get; internal set; }
#region Legacy Runtime/Http Cache accessors
/// <summary>
/// Returns the current Runtime cache
/// </summary>
public ICacheProvider StaticCache { get; internal set; }
/// <summary>
/// Returns the current Runtime cache
/// </summary>
public IRuntimeCacheProvider RuntimeCache { get; internal set; }
/// <summary>
/// Returns the current Isolated Runtime cache manager
/// </summary>
public IsolatedRuntimeCache IsolatedRuntimeCache { get; internal set; }
#region Legacy Runtime/Http Cache accessors
/// <summary>
/// Clears the item in umbraco's runtime cache
/// </summary>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void ClearAllCache()
{
if (_enableCache == false)
{
_nullHttpCache.ClearAllCache();
}
else
{
_httpCache.ClearAllCache();
}
RuntimeCache.ClearAllCache();
IsolatedRuntimeCache.ClearAllCaches();
}
/// <summary>
@@ -150,16 +130,10 @@ namespace Umbraco.Core
/// </summary>
/// <param name="key">Key</param>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void ClearCacheItem(string key)
{
if (_enableCache == false)
{
_nullHttpCache.ClearCacheItem(key);
}
else
{
_httpCache.ClearCacheItem(key);
}
RuntimeCache.ClearCacheItem(key);
}
@@ -171,30 +145,17 @@ namespace Umbraco.Core
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
public void ClearCacheObjectTypes(string typeName)
{
if (_enableCache == false)
{
_nullHttpCache.ClearCacheObjectTypes(typeName);
}
else
{
_httpCache.ClearCacheObjectTypes(typeName);
}
RuntimeCache.ClearCacheObjectTypes(typeName);
}
/// <summary>
/// Clears all objects in the System.Web.Cache with the System.Type specified
/// </summary>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void ClearCacheObjectTypes<T>()
{
if (_enableCache == false)
{
_nullHttpCache.ClearCacheObjectTypes<T>();
}
else
{
_httpCache.ClearCacheObjectTypes<T>();
}
RuntimeCache.ClearCacheObjectTypes<T>();
}
/// <summary>
@@ -202,16 +163,10 @@ namespace Umbraco.Core
/// </summary>
/// <param name="keyStartsWith">The start of the key</param>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void ClearCacheByKeySearch(string keyStartsWith)
{
if (_enableCache == false)
{
_nullHttpCache.ClearCacheByKeySearch(keyStartsWith);
}
else
{
_httpCache.ClearCacheByKeySearch(keyStartsWith);
}
RuntimeCache.ClearCacheByKeySearch(keyStartsWith);
}
/// <summary>
@@ -219,29 +174,17 @@ namespace Umbraco.Core
/// </summary>
/// <param name="regexString"></param>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void ClearCacheByKeyExpression(string regexString)
{
if (_enableCache == false)
{
_nullHttpCache.ClearCacheByKeyExpression(regexString);
}
else
{
_httpCache.ClearCacheByKeyExpression(regexString);
}
RuntimeCache.ClearCacheByKeyExpression(regexString);
}
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public IEnumerable<T> GetCacheItemsByKeySearch<T>(string keyStartsWith)
{
if (_enableCache == false)
{
return _nullHttpCache.GetCacheItemsByKeySearch<T>(keyStartsWith);
}
else
{
return _httpCache.GetCacheItemsByKeySearch<T>(keyStartsWith);
}
return RuntimeCache.GetCacheItemsByKeySearch<T>(keyStartsWith);
}
/// <summary>
@@ -251,16 +194,10 @@ namespace Umbraco.Core
/// <param name="cacheKey"></param>
/// <returns></returns>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public TT GetCacheItem<TT>(string cacheKey)
{
if (_enableCache == false)
{
return _nullHttpCache.GetCacheItem<TT>(cacheKey);
}
else
{
return _httpCache.GetCacheItem<TT>(cacheKey);
}
return RuntimeCache.GetCacheItem<TT>(cacheKey);
}
/// <summary>
@@ -271,16 +208,11 @@ namespace Umbraco.Core
/// <param name="getCacheItem"></param>
/// <returns></returns>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public TT GetCacheItem<TT>(string cacheKey, Func<TT> getCacheItem)
{
if (_enableCache == false)
{
return _nullHttpCache.GetCacheItem<TT>(cacheKey, getCacheItem);
}
else
{
return _httpCache.GetCacheItem<TT>(cacheKey, getCacheItem);
}
return RuntimeCache.GetCacheItem<TT>(cacheKey, getCacheItem);
}
/// <summary>
@@ -292,17 +224,12 @@ namespace Umbraco.Core
/// <param name="getCacheItem"></param>
/// <returns></returns>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public TT GetCacheItem<TT>(string cacheKey,
TimeSpan timeout, Func<TT> getCacheItem)
{
if (_enableCache == false)
{
return _nullHttpCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout);
}
else
{
return _httpCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout);
}
return RuntimeCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout);
}
/// <summary>
@@ -315,18 +242,13 @@ namespace Umbraco.Core
/// <param name="getCacheItem"></param>
/// <returns></returns>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public TT GetCacheItem<TT>(string cacheKey,
CacheItemRemovedCallback refreshAction, TimeSpan timeout,
Func<TT> getCacheItem)
{
if (!_enableCache)
{
return _nullHttpCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout, removedCallback: refreshAction);
}
else
{
return _httpCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout, removedCallback: refreshAction);
}
return RuntimeCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout, removedCallback: refreshAction);
}
/// <summary>
@@ -340,18 +262,13 @@ namespace Umbraco.Core
/// <param name="getCacheItem"></param>
/// <returns></returns>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public TT GetCacheItem<TT>(string cacheKey,
CacheItemPriority priority, CacheItemRemovedCallback refreshAction, TimeSpan timeout,
Func<TT> getCacheItem)
{
if (_enableCache == false)
{
return _nullHttpCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout, false, priority, refreshAction);
}
else
{
return _httpCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout, false, priority, refreshAction);
}
return RuntimeCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout, false, priority, refreshAction);
}
/// <summary>
@@ -373,20 +290,13 @@ namespace Umbraco.Core
TimeSpan timeout,
Func<TT> getCacheItem)
{
if (_enableCache == false)
var cache = RuntimeCache as HttpRuntimeCacheProvider;
if (cache != null)
{
return _nullHttpCache.GetCacheItem<TT>(cacheKey, getCacheItem, timeout, false, priority, refreshAction, null);
}
else
{
var cache = _httpCache as HttpRuntimeCacheProvider;
if (cache != null)
{
var result = cache.GetCacheItem(cacheKey, () => getCacheItem(), timeout, false, priority, refreshAction, cacheDependency);
return result == null ? default(TT) : result.TryConvertTo<TT>().Result;
}
throw new InvalidOperationException("Cannot use this obsoleted overload when the current provider is not of type " + typeof(HttpRuntimeCacheProvider));
var result = cache.GetCacheItem(cacheKey, () => getCacheItem(), timeout, false, priority, refreshAction, cacheDependency);
return result == null ? default(TT) : result.TryConvertTo<TT>().Result;
}
throw new InvalidOperationException("Cannot use this obsoleted overload when the current provider is not of type " + typeof(HttpRuntimeCacheProvider));
}
/// <summary>
@@ -404,20 +314,13 @@ namespace Umbraco.Core
CacheDependency cacheDependency,
Func<TT> getCacheItem)
{
if (!_enableCache)
var cache = RuntimeCache as HttpRuntimeCacheProvider;
if (cache != null)
{
return _nullHttpCache.GetCacheItem<TT>(cacheKey, getCacheItem, null, false, priority, null, null);
}
else
{
var cache = _httpCache as HttpRuntimeCacheProvider;
if (cache != null)
{
var result = cache.GetCacheItem(cacheKey, () => getCacheItem(), null, false, priority, null, cacheDependency);
return result == null ? default(TT) : result.TryConvertTo<TT>().Result;
}
throw new InvalidOperationException("Cannot use this obsoleted overload when the current provider is not of type " + typeof(HttpRuntimeCacheProvider));
var result = cache.GetCacheItem(cacheKey, () => getCacheItem(), null, false, priority, null, cacheDependency);
return result == null ? default(TT) : result.TryConvertTo<TT>().Result;
}
throw new InvalidOperationException("Cannot use this obsoleted overload when the current provider is not of type " + typeof(HttpRuntimeCacheProvider));
}
/// <summary>
@@ -427,18 +330,14 @@ namespace Umbraco.Core
/// <param name="cacheKey"></param>
/// <param name="priority"></param>
/// <param name="getCacheItem"></param>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void InsertCacheItem<T>(string cacheKey,
CacheItemPriority priority,
Func<T> getCacheItem)
{
if (_enableCache == false)
{
_nullHttpCache.InsertCacheItem<T>(cacheKey, getCacheItem, priority: priority);
}
else
{
_httpCache.InsertCacheItem<T>(cacheKey, getCacheItem, priority: priority);
}
RuntimeCache.InsertCacheItem<T>(cacheKey, getCacheItem, priority: priority);
}
/// <summary>
@@ -449,19 +348,14 @@ namespace Umbraco.Core
/// <param name="priority"></param>
/// <param name="timeout">This will set an absolute expiration from now until the timeout</param>
/// <param name="getCacheItem"></param>
[Obsolete("Do not use this method, access the runtime cache from the RuntimeCache property")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void InsertCacheItem<T>(string cacheKey,
CacheItemPriority priority,
TimeSpan timeout,
Func<T> getCacheItem)
{
if (_enableCache == false)
{
_nullHttpCache.InsertCacheItem<T>(cacheKey, getCacheItem, timeout, priority: priority);
}
else
{
_httpCache.InsertCacheItem<T>(cacheKey, getCacheItem, timeout, priority: priority);
}
RuntimeCache.InsertCacheItem<T>(cacheKey, getCacheItem, timeout, priority: priority);
}
/// <summary>
@@ -480,19 +374,12 @@ namespace Umbraco.Core
TimeSpan timeout,
Func<T> getCacheItem)
{
if (_enableCache == false)
var cache = RuntimeCache as HttpRuntimeCacheProvider;
if (cache != null)
{
_nullHttpCache.InsertCacheItem<T>(cacheKey, getCacheItem, timeout, priority: priority, dependentFiles:null);
}
else
{
var cache = _httpCache as HttpRuntimeCacheProvider;
if (cache != null)
{
cache.InsertCacheItem(cacheKey, () => getCacheItem(), timeout, false, priority, null, cacheDependency);
}
throw new InvalidOperationException("Cannot use this obsoleted overload when the current provider is not of type " + typeof(HttpRuntimeCacheProvider));
cache.InsertCacheItem(cacheKey, () => getCacheItem(), timeout, false, priority, null, cacheDependency);
}
throw new InvalidOperationException("Cannot use this obsoleted overload when the current provider is not of type " + typeof(HttpRuntimeCacheProvider));
}
/// <summary>
@@ -513,19 +400,12 @@ namespace Umbraco.Core
TimeSpan? timeout,
Func<T> getCacheItem)
{
if (_enableCache == false)
var cache = RuntimeCache as HttpRuntimeCacheProvider;
if (cache != null)
{
_nullHttpCache.InsertCacheItem<T>(cacheKey, getCacheItem, timeout, false, priority, refreshAction, null);
}
else
{
var cache = _httpCache as HttpRuntimeCacheProvider;
if (cache != null)
{
cache.InsertCacheItem(cacheKey, () => getCacheItem(), timeout, false, priority, refreshAction, cacheDependency);
}
throw new InvalidOperationException("Cannot use this obsoleted overload when the current provider is not of type " + typeof(HttpRuntimeCacheProvider));
cache.InsertCacheItem(cacheKey, () => getCacheItem(), timeout, false, priority, refreshAction, cacheDependency);
}
throw new InvalidOperationException("Cannot use this obsoleted overload when the current provider is not of type " + typeof(HttpRuntimeCacheProvider));
}
#endregion
@@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
namespace Umbraco.Core.Collections
{
/// <summary>
/// A List that can be deep cloned with deep cloned elements and can reset the collection's items dirty flags
/// </summary>
/// <typeparam name="T"></typeparam>
internal class DeepCloneableList<T> : List<T>, IDeepCloneable, IRememberBeingDirty
{
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Collections.Generic.List`1"/> class that is empty and has the default initial capacity.
/// </summary>
public DeepCloneableList()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="T:System.Collections.Generic.List`1"/> class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.
/// </summary>
/// <param name="collection">The collection whose elements are copied to the new list.</param><exception cref="T:System.ArgumentNullException"><paramref name="collection"/> is null.</exception>
public DeepCloneableList(IEnumerable<T> collection) : base(collection)
{
}
/// <summary>
/// Creates a new list and adds each element as a deep cloned element if it is of type IDeepCloneable
/// </summary>
/// <returns></returns>
public object DeepClone()
{
var newList = new DeepCloneableList<T>();
foreach (var item in this)
{
var dc = item as IDeepCloneable;
if (dc != null)
{
newList.Add((T) dc.DeepClone());
}
else
{
newList.Add(item);
}
}
return newList;
}
public bool IsDirty()
{
return this.OfType<IRememberBeingDirty>().Any(x => x.IsDirty());
}
public bool WasDirty()
{
return this.OfType<IRememberBeingDirty>().Any(x => x.WasDirty());
}
/// <summary>
/// Always returns false, the list has no properties we need to report
/// </summary>
/// <param name="propName"></param>
/// <returns></returns>
public bool IsPropertyDirty(string propName)
{
return false;
}
/// <summary>
/// Always returns false, the list has no properties we need to report
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public bool WasPropertyDirty(string propertyName)
{
return false;
}
public void ResetDirtyProperties()
{
foreach (var dc in this.OfType<IRememberBeingDirty>())
{
dc.ResetDirtyProperties();
}
}
public void ForgetPreviouslyDirtyProperties()
{
foreach (var dc in this.OfType<IRememberBeingDirty>())
{
dc.ForgetPreviouslyDirtyProperties();
}
}
public void ResetDirtyProperties(bool rememberPreviouslyChangedProperties)
{
foreach (var dc in this.OfType<IRememberBeingDirty>())
{
dc.ResetDirtyProperties(rememberPreviouslyChangedProperties);
}
}
}
}
@@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration
{
public class UmbracoVersion
{
private static readonly Version Version = new Version("7.3.4");
private static readonly Version Version = new Version("7.3.6");
/// <summary>
/// Gets the current version of Umbraco.
+1 -1
View File
@@ -206,7 +206,7 @@ namespace Umbraco.Core
/// </summary>
internal const string StandardPropertiesGroupName = "Membership";
internal static Dictionary<string, PropertyType> GetStandardPropertyTypeStubs()
public static Dictionary<string, PropertyType> GetStandardPropertyTypeStubs()
{
return new Dictionary<string, PropertyType>
{
+20 -5
View File
@@ -136,7 +136,10 @@ namespace Umbraco.Core
{
try
{
x.OnApplicationInitialized(UmbracoApplication, ApplicationContext);
using (ProfilingLogger.DebugDuration<CoreBootManager>(string.Format("Executing {0} in ApplicationInitialized", x.GetType())))
{
x.OnApplicationInitialized(UmbracoApplication, ApplicationContext);
}
}
catch (Exception ex)
{
@@ -188,10 +191,16 @@ namespace Umbraco.Core
protected virtual CacheHelper CreateApplicationCache()
{
var cacheHelper = new CacheHelper(
new ObjectCacheRuntimeCacheProvider(),
//we need to have the dep clone runtime cache provider to ensure
//all entities are cached properly (cloned in and cloned out)
new DeepCloneRuntimeCacheProvider(new ObjectCacheRuntimeCacheProvider()),
new StaticCacheProvider(),
//we have no request based cache when not running in web-based context
new NullCacheProvider());
new NullCacheProvider(),
new IsolatedRuntimeCache(type =>
//we need to have the dep clone runtime cache provider to ensure
//all entities are cached properly (cloned in and cloned out)
new DeepCloneRuntimeCacheProvider(new ObjectCacheRuntimeCacheProvider())));
return cacheHelper;
}
@@ -293,7 +302,10 @@ namespace Umbraco.Core
{
try
{
x.OnApplicationStarting(UmbracoApplication, ApplicationContext);
using (ProfilingLogger.DebugDuration<CoreBootManager>(string.Format("Executing {0} in ApplicationStarting", x.GetType())))
{
x.OnApplicationStarting(UmbracoApplication, ApplicationContext);
}
}
catch (Exception ex)
{
@@ -344,7 +356,10 @@ namespace Umbraco.Core
{
try
{
x.OnApplicationStarted(UmbracoApplication, ApplicationContext);
using (ProfilingLogger.DebugDuration<CoreBootManager>(string.Format("Executing {0} in ApplicationStarted", x.GetType())))
{
x.OnApplicationStarted(UmbracoApplication, ApplicationContext);
}
}
catch (Exception ex)
{
+44 -21
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Web;
@@ -12,6 +13,12 @@ namespace Umbraco.Core
/// </summary>
public class DisposableTimer : DisposableObject
{
private readonly ILogger _logger;
private readonly LogType? _logType;
private readonly IProfiler _profiler;
private readonly Type _loggerType;
private readonly string _endMessage;
private readonly IDisposable _profilerStep;
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
private readonly Action<long> _callback;
@@ -25,25 +32,12 @@ namespace Umbraco.Core
if (logger == null) throw new ArgumentNullException("logger");
if (loggerType == null) throw new ArgumentNullException("loggerType");
_callback = x =>
{
if (profiler != null)
{
profiler.DisposeIfDisposable();
}
switch (logType)
{
case LogType.Debug:
logger.Debug(loggerType, () => endMessage + " (took " + x + "ms)");
break;
case LogType.Info:
logger.Info(loggerType, () => endMessage + " (took " + x + "ms)");
break;
default:
throw new ArgumentOutOfRangeException("logType");
}
};
_logger = logger;
_logType = logType;
_profiler = profiler;
_loggerType = loggerType;
_endMessage = endMessage;
switch (logType)
{
case LogType.Debug:
@@ -58,7 +52,7 @@ namespace Umbraco.Core
if (profiler != null)
{
profiler.Step(loggerType, startMessage);
_profilerStep = profiler.Step(loggerType, startMessage);
}
}
@@ -223,7 +217,36 @@ namespace Umbraco.Core
/// </summary>
protected override void DisposeResources()
{
_callback.Invoke(Stopwatch.ElapsedMilliseconds);
if (_profiler != null)
{
_profiler.DisposeIfDisposable();
}
if (_profilerStep != null)
{
_profilerStep.Dispose();
}
if (_logType.HasValue && _endMessage.IsNullOrWhiteSpace() == false && _loggerType != null && _logger != null)
{
switch (_logType)
{
case LogType.Debug:
_logger.Debug(_loggerType, () => _endMessage + " (took " + Stopwatch.ElapsedMilliseconds + "ms)");
break;
case LogType.Info:
_logger.Info(_loggerType, () => _endMessage + " (took " + Stopwatch.ElapsedMilliseconds + "ms)");
break;
default:
throw new ArgumentOutOfRangeException("logType");
}
}
if (_callback != null)
{
_callback.Invoke(Stopwatch.ElapsedMilliseconds);
}
}
}
+2 -2
View File
@@ -199,8 +199,8 @@ namespace Umbraco.Core.IO
using (var image = Image.FromStream(fs))
{
var fileNameThumb = string.IsNullOrWhiteSpace(fileNameAddition)
? string.Format("{0}_UMBRACOSYSTHUMBNAIL.jpg", Path.Substring(0, Path.LastIndexOf(".", StringComparison.Ordinal)))
: string.Format("{0}_{1}.jpg", Path.Substring(0, Path.LastIndexOf(".", StringComparison.Ordinal)), fileNameAddition);
? string.Format("{0}_UMBRACOSYSTHUMBNAIL." + Extension, Path.Substring(0, Path.LastIndexOf(".", StringComparison.Ordinal)))
: string.Format("{0}_{1}." + Extension, Path.Substring(0, Path.LastIndexOf(".", StringComparison.Ordinal)), fileNameAddition);
var thumbnail = maxWidthHeight == -1
? ImageHelper.GenerateThumbnail(image, width, height, fileNameThumb, Extension, _fs)
+6 -2
View File
@@ -11,8 +11,12 @@ namespace Umbraco.Core.Macros
/// </summary>
internal class MacroTagParser
{
private static readonly Regex MacroRteContent = new Regex(@"(<!--\s*?)(<\?UMBRACO_MACRO.*?/>)(\s*?-->)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
private static readonly Regex MacroPersistedFormat = new Regex(@"(<\?UMBRACO_MACRO (?:.+?)?macroAlias=[""']([^""\'\n\r]+?)[""'].+?)(?:/>|>.*?</\?UMBRACO_MACRO>)", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex MacroRteContent = new Regex(@"(<!--\s*?)(<\?UMBRACO_MACRO.*?/>)(\s*?-->)",
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Singleline);
private static readonly Regex MacroPersistedFormat =
new Regex(@"(<\?UMBRACO_MACRO (?:.+?)??macroAlias=[""']([^""\'\n\r]+?)[""'].+?)(?:/>|>.*?</\?UMBRACO_MACRO>)",
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Singleline);
/// <summary>
/// This formats the persisted string to something useful for the rte so that the macro renders properly since we
@@ -75,7 +75,7 @@ namespace Umbraco.Core.Media.Exif
{
if (items.ContainsKey (key))
items.Remove (key);
if (key == ExifTag.WindowsTitle || key == ExifTag.WindowsTitle || key == ExifTag.WindowsComment || key == ExifTag.WindowsAuthor || key == ExifTag.WindowsKeywords || key == ExifTag.WindowsSubject) {
if (key == ExifTag.WindowsTitle || key == ExifTag.WindowsComment || key == ExifTag.WindowsAuthor || key == ExifTag.WindowsKeywords || key == ExifTag.WindowsSubject) {
items.Add (key, new WindowsByteString (key, value));
} else {
items.Add (key, new ExifAscii (key, value, parent.Encoding));
+37 -16
View File
@@ -59,7 +59,7 @@ namespace Umbraco.Core.Media
var fileHeight = image.Height;
return new Size(fileWidth, fileHeight);
}
}
public static string GetMimeType(this Image image)
@@ -79,22 +79,22 @@ namespace Umbraco.Core.Media
/// <param name="additionalThumbSizes"></param>
/// <returns></returns>
internal static IEnumerable<ResizedImage> GenerateMediaThumbnails(
IFileSystem fs,
string fileName,
string extension,
IFileSystem fs,
string fileName,
string extension,
Image originalImage,
IEnumerable<int> additionalThumbSizes)
{
var result = new List<ResizedImage>();
var allSizesDictionary = new Dictionary<int,string> {{100,"thumb"}, {500,"big-thumb"}};
var allSizesDictionary = new Dictionary<int, string> { { 100, "thumb" }, { 500, "big-thumb" } };
//combine the static dictionary with the additional sizes with only unique values
var allSizes = allSizesDictionary.Select(kv => kv.Key)
.Union(additionalThumbSizes.Where(x => x > 0).Distinct());
var sizesDictionary = allSizes.ToDictionary(s => s, s => allSizesDictionary.ContainsKey(s) ? allSizesDictionary[s]: "");
var sizesDictionary = allSizes.ToDictionary(s => s, s => allSizesDictionary.ContainsKey(s) ? allSizesDictionary[s] : "");
foreach (var s in sizesDictionary)
{
@@ -121,9 +121,9 @@ namespace Umbraco.Core.Media
/// <returns></returns>
private static ResizedImage Resize(IFileSystem fileSystem, string path, string extension, int maxWidthHeight, string fileNameAddition, Image originalImage)
{
var fileNameThumb = String.IsNullOrEmpty(fileNameAddition)
? string.Format("{0}_UMBRACOSYSTHUMBNAIL.jpg", path.Substring(0, path.LastIndexOf(".")))
: string.Format("{0}_{1}.jpg", path.Substring(0, path.LastIndexOf(".")), fileNameAddition);
var fileNameThumb = string.IsNullOrWhiteSpace(fileNameAddition)
? string.Format("{0}_UMBRACOSYSTHUMBNAIL." + extension, path.Substring(0, path.LastIndexOf(".", StringComparison.Ordinal)))
: string.Format("{0}_{1}." + extension, path.Substring(0, path.LastIndexOf(".", StringComparison.Ordinal)), fileNameAddition);
var thumb = GenerateThumbnail(
originalImage,
@@ -190,9 +190,9 @@ namespace Umbraco.Core.Media
//use best quality
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
}
g.SmoothingMode = SmoothingMode.HighQuality;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
@@ -202,10 +202,29 @@ namespace Umbraco.Core.Media
// Copy metadata
var imageEncoders = ImageCodecInfo.GetImageEncoders();
var codec = extension.ToLower() == "png" || extension.ToLower() == "gif"
? imageEncoders.Single(t => t.MimeType.Equals("image/png"))
: imageEncoders.Single(t => t.MimeType.Equals("image/jpeg"));
ImageCodecInfo codec;
switch (extension.ToLower())
{
case "png":
codec = imageEncoders.Single(t => t.MimeType.Equals("image/png"));
break;
case "gif":
codec = imageEncoders.Single(t => t.MimeType.Equals("image/gif"));
break;
case "tif":
case "tiff":
codec = imageEncoders.Single(t => t.MimeType.Equals("image/tiff"));
break;
case "bmp":
codec = imageEncoders.Single(t => t.MimeType.Equals("image/bmp"));
break;
// TODO: this is dirty, defaulting to jpg but the return value of this thing is used all over the
// place so left it here, but it needs to not set a codec if it doesn't know which one to pick
// Note: when fixing this: both .jpg and .jpeg should be handled as extensions
default:
codec = imageEncoders.Single(t => t.MimeType.Equals("image/jpeg"));
break;
}
// Set compresion ratio to 90%
var ep = new EncoderParameters();
@@ -213,12 +232,14 @@ namespace Umbraco.Core.Media
// Save the new image using the dimensions of the image
var predictableThumbnailName = thumbnailFileName.Replace("UMBRACOSYSTHUMBNAIL", maxWidthHeight.ToString(CultureInfo.InvariantCulture));
var predictableThumbnailNameJpg = predictableThumbnailName.Substring(0, predictableThumbnailName.LastIndexOf(".", StringComparison.Ordinal)) + ".jpg";
using (var ms = new MemoryStream())
{
bp.Save(ms, codec, ep);
ms.Seek(0, 0);
fs.AddFile(predictableThumbnailName, ms);
fs.AddFile(predictableThumbnailNameJpg, ms);
}
// TODO: Remove this, this is ONLY here for backwards compatibility but it is essentially completely unusable see U4-5385
+6
View File
@@ -53,6 +53,9 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets or sets the alias of the default Template.
/// TODO: This should be ignored from cloning!!!!!!!!!!!!!!
/// - but to do that we have to implement callback hacks, this needs to be fixed in v8,
/// we should not store direct entity
/// </summary>
[IgnoreDataMember]
public ITemplate DefaultTemplate
@@ -79,6 +82,9 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets or Sets a list of Templates which are allowed for the ContentType
/// TODO: This should be ignored from cloning!!!!!!!!!!!!!!
/// - but to do that we have to implement callback hacks, this needs to be fixed in v8,
/// we should not store direct entity
/// </summary>
[DataMember]
public IEnumerable<ITemplate> AllowedTemplates
@@ -78,6 +78,12 @@ namespace Umbraco.Core.Models
}
else
{
//skip instead of trying to create instance of abstract or interface
if (propertyInfo.PropertyType.IsAbstract || propertyInfo.PropertyType.IsInterface)
{
continue;
}
//its a custom IEnumerable, we'll try to create it
try
{
+12 -1
View File
@@ -14,6 +14,7 @@ namespace Umbraco.Core.Models
[DataContract(IsReference = true)]
public class DictionaryItem : Entity, IDictionaryItem
{
public Func<int, ILanguage> GetLanguage { get; set; }
private Guid? _parentId;
private string _itemKey;
private IEnumerable<IDictionaryTranslation> _translations;
@@ -78,7 +79,17 @@ namespace Umbraco.Core.Models
{
SetPropertyValueAndDetectChanges(o =>
{
_translations = value;
var asArray = value.ToArray();
//ensure the language callback is set on each translation
if (GetLanguage != null)
{
foreach (var translation in asArray.OfType<DictionaryTranslation>())
{
translation.GetLanguage = GetLanguage;
}
}
_translations = asArray;
return _translations;
}, _translations, TranslationsSelector,
//Custom comparer for enumerable
@@ -13,13 +13,18 @@ namespace Umbraco.Core.Models
[DataContract(IsReference = true)]
public class DictionaryTranslation : Entity, IDictionaryTranslation
{
internal Func<int, ILanguage> GetLanguage { get; set; }
private ILanguage _language;
private string _value;
//note: this will be memberwise cloned
private int _languageId;
public DictionaryTranslation(ILanguage language, string value)
{
if (language == null) throw new ArgumentNullException("language");
_language = language;
_languageId = _language.Id;
_value = value;
}
@@ -27,6 +32,20 @@ namespace Umbraco.Core.Models
{
if (language == null) throw new ArgumentNullException("language");
_language = language;
_languageId = _language.Id;
_value = value;
Key = uniqueId;
}
internal DictionaryTranslation(int languageId, string value)
{
_languageId = languageId;
_value = value;
}
internal DictionaryTranslation(int languageId, string value, Guid uniqueId)
{
_languageId = languageId;
_value = value;
Key = uniqueId;
}
@@ -37,20 +56,43 @@ namespace Umbraco.Core.Models
/// <summary>
/// Gets or sets the <see cref="Language"/> for the translation
/// </summary>
/// <remarks>
/// Marked as DoNotClone - TODO: this member shouldn't really exist here in the first place, the DictionaryItem
/// class will have a deep hierarchy of objects which all get deep cloned which we don't want. This should have simply
/// just referenced a language ID not the actual language object. In v8 we need to fix this.
/// We're going to have to do the same hacky stuff we had to do with the Template/File contents so that this is returned
/// on a callback.
/// </remarks>
[DataMember]
[DoNotClone]
public ILanguage Language
{
get { return _language; }
get
{
if (_language != null)
return _language;
// else, must lazy-load
if (GetLanguage != null && _languageId > 0)
_language = GetLanguage(_languageId);
return _language;
}
set
{
SetPropertyValueAndDetectChanges(o =>
{
_language = value;
_languageId = _language == null ? -1 : _language.Id;
return _language;
}, _language, LanguageSelector);
}
}
public int LanguageId
{
get { return _languageId; }
}
/// <summary>
/// Gets or sets the translated text
/// </summary>
@@ -68,5 +110,23 @@ namespace Umbraco.Core.Models
}
}
public override object DeepClone()
{
var clone = (DictionaryTranslation)base.DeepClone();
// clear fields that were memberwise-cloned and that we don't want to clone
clone._language = null;
// turn off change tracking
clone.DisableChangeTracking();
// this shouldn't really be needed since we're not tracking
clone.ResetDirtyProperties(false);
// re-enable tracking
clone.EnableChangeTracking();
return clone;
}
}
}
@@ -12,6 +12,8 @@ namespace Umbraco.Core.Models
[DataMember]
ILanguage Language { get; set; }
int LanguageId { get; }
/// <summary>
/// Gets or sets the translated text
/// </summary>
@@ -98,45 +98,10 @@ namespace Umbraco.Core.Models.PublishedContent
#endregion
#region Cache
// these methods are called by ContentTypeCacheRefresher and DataTypeCacheRefresher
internal static void ClearAll()
{
Logging.LogHelper.Debug<PublishedContentType>("Clear all.");
// ok and faster to do it by types, assuming noone else caches PublishedContentType instances
//ApplicationContext.Current.ApplicationCache.ClearStaticCacheByKeySearch("PublishedContentType_");
ApplicationContext.Current.ApplicationCache.StaticCache.ClearCacheObjectTypes<PublishedContentType>();
}
internal static void ClearContentType(int id)
{
Logging.LogHelper.Debug<PublishedContentType>("Clear content type w/id {0}.", () => id);
// requires a predicate because the key does not contain the ID
// faster than key strings comparisons anyway
ApplicationContext.Current.ApplicationCache.StaticCache.ClearCacheObjectTypes<PublishedContentType>(
(key, value) => value.Id == id);
}
internal static void ClearDataType(int id)
{
Logging.LogHelper.Debug<PublishedContentType>("Clear data type w/id {0}.", () => id);
// there is no recursion to handle here because a PublishedContentType contains *all* its
// properties ie both its own properties and those that were inherited (it's based upon an
// IContentTypeComposition) and so every PublishedContentType having a property based upon
// the cleared data type, be it local or inherited, will be cleared.
ApplicationContext.Current.ApplicationCache.StaticCache.ClearCacheObjectTypes<PublishedContentType>(
(key, value) => value.PropertyTypes.Any(x => x.DataTypeId == id));
}
public static PublishedContentType Get(PublishedItemType itemType, string alias)
{
var key = string.Format("PublishedContentType_{0}_{1}",
itemType.ToString().ToLowerInvariant(), alias.ToLowerInvariant());
var type = ApplicationContext.Current.ApplicationCache.StaticCache.GetCacheItem<PublishedContentType>(key,
() => CreatePublishedContentType(itemType, alias));
var type = CreatePublishedContentType(itemType, alias);
return type;
}
@@ -169,21 +134,8 @@ namespace Umbraco.Core.Models.PublishedContent
return new PublishedContentType(contentType);
}
// for unit tests - changing the callback must reset the cache obviously
private static Func<string, PublishedContentType> _getPublishedContentTypeCallBack;
internal static Func<string, PublishedContentType> GetPublishedContentTypeCallback
{
get { return _getPublishedContentTypeCallBack; }
set
{
// see note above
//ClearAll();
ApplicationContext.Current.ApplicationCache.StaticCache.ClearCacheByKeySearch("PublishedContentType_");
_getPublishedContentTypeCallBack = value;
}
}
#endregion
// for unit tests
internal static Func<string, PublishedContentType> GetPublishedContentTypeCallback { get; set; }
}
}
+11 -16
View File
@@ -1,15 +1,10 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security;
using System.Xml;
namespace Umbraco.Core
@@ -51,7 +46,7 @@ namespace Umbraco.Core
public static Attempt<T> TryConvertTo<T>(this object input)
{
var result = TryConvertTo(input, typeof(T));
if (!result.Success)
if (result.Success == false)
{
//just try a straight up conversion
try
@@ -64,7 +59,7 @@ namespace Umbraco.Core
return Attempt<T>.Fail(e);
}
}
return !result.Success ? Attempt<T>.Fail() : Attempt<T>.Succeed((T)result.Result);
return result.Success == false ? Attempt<T>.Fail() : Attempt<T>.Succeed((T)result.Result);
}
/// <summary>
@@ -117,7 +112,7 @@ namespace Umbraco.Core
}
// we've already dealed with nullables, so any other generic types need to fall through
if (!destinationType.IsGenericType)
if (destinationType.IsGenericType == false)
{
if (input is string)
{
@@ -335,11 +330,11 @@ namespace Umbraco.Core
return null; // we can't decide...
}
private readonly static char[] NumberDecimalSeparatorsToNormalize = new[] {'.', ','};
private static readonly char[] NumberDecimalSeparatorsToNormalize = new[] {'.', ','};
private static string NormalizeNumberDecimalSeparator(string s)
{
var normalized = System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator[0];
var normalized = System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator[0];
return s.ReplaceMany(NumberDecimalSeparatorsToNormalize, normalized);
}
@@ -442,7 +437,7 @@ namespace Umbraco.Core
{
var props = TypeDescriptor.GetProperties(o);
var d = new Dictionary<string, TVal>();
foreach (var prop in props.Cast<PropertyDescriptor>().Where(x => !ignoreProperties.Contains(x.Name)))
foreach (var prop in props.Cast<PropertyDescriptor>().Where(x => ignoreProperties.Contains(x.Name) == false))
{
var val = prop.GetValue(o);
if (val != null)
@@ -478,13 +473,13 @@ namespace Umbraco.Core
var items = (from object enumItem in enumerable let value = GetEnumPropertyDebugString(enumItem, levels) where value != null select value).Take(10).ToList();
return items.Count() > 0
return items.Any()
? "{{ {0} }}".InvariantFormat(String.Join(", ", items))
: null;
}
var props = obj.GetType().GetProperties();
if ((props.Count() == 2) && props[0].Name == "Key" && props[1].Name == "Value" && levels > -2)
if ((props.Length == 2) && props[0].Name == "Key" && props[1].Name == "Value" && levels > -2)
{
try
{
@@ -500,12 +495,12 @@ namespace Umbraco.Core
if (levels > -1)
{
var items =
from propertyInfo in props
(from propertyInfo in props
let value = GetPropertyDebugString(propertyInfo, obj, levels)
where value != null
select "{0}={1}".InvariantFormat(propertyInfo.Name, value);
select "{0}={1}".InvariantFormat(propertyInfo.Name, value)).ToArray();
return items.Count() > 0
return items.Any()
? "[{0}]:{{ {1} }}".InvariantFormat(obj.GetType().Name, String.Join(", ", items))
: null;
}
@@ -42,7 +42,7 @@ namespace Umbraco.Core.Persistence.Factories
{
var text = new LanguageTextDto
{
LanguageId = translation.Language.Id,
LanguageId = translation.LanguageId,
UniqueId = translation.Key,
Value = translation.Value
};
@@ -7,20 +7,19 @@ namespace Umbraco.Core.Persistence.Factories
internal class DictionaryTranslationFactory
{
private readonly Guid _uniqueId;
private ILanguage _language;
public DictionaryTranslationFactory(Guid uniqueId, ILanguage language)
public DictionaryTranslationFactory(Guid uniqueId)
{
_uniqueId = uniqueId;
_language = language;
}
#region Implementation of IEntityFactory<DictionaryTranslation,LanguageTextDto>
public IDictionaryTranslation BuildEntity(LanguageTextDto dto)
{
var item = new DictionaryTranslation(_language, dto.Value, _uniqueId)
var item = new DictionaryTranslation(dto.LanguageId, dto.Value, _uniqueId)
{Id = dto.PrimaryKey};
//on initial construction we don't want to have dirty properties tracked
// http://issues.umbraco.org/issue/U4-1946
item.ResetDirtyProperties(false);
@@ -31,7 +30,7 @@ namespace Umbraco.Core.Persistence.Factories
{
var text = new LanguageTextDto
{
LanguageId = entity.Language.Id,
LanguageId = entity.LanguageId,
UniqueId = _uniqueId,
Value = entity.Value
};
@@ -129,11 +129,7 @@ namespace Umbraco.Core.Persistence.Factories
Name = propertyType.Name,
SortOrder = propertyType.SortOrder,
ValidationRegExp = propertyType.ValidationRegExp,
UniqueId = propertyType.HasIdentity
? propertyType.Key == Guid.Empty
? Guid.NewGuid()
: propertyType.Key
: Guid.NewGuid()
UniqueId = propertyType.Key == Guid.Empty ? Guid.NewGuid() : propertyType.Key
};
if (tabId != default(int))
@@ -18,8 +18,11 @@ namespace Umbraco.Core.Persistence.Relators
// Is this the same DictionaryItem as the current one we're processing
if (Current != null && Current.Id == a.Id)
{
// Yes, just add this User2AppDto to the current item's collection
Current.User2AppDtos.Add(p);
if (p.AppAlias.IsNullOrWhiteSpace() == false)
{
// Yes, just add this User2AppDto to the current item's collection
Current.User2AppDtos.Add(p);
}
// Return null to indicate we're not done with this User yet
return null;
@@ -35,7 +38,7 @@ namespace Umbraco.Core.Persistence.Relators
Current = a;
Current.User2AppDtos = new List<User2AppDto>();
//this can be null since we are doing a left join
if (p.AppAlias != null)
if (p.AppAlias.IsNullOrWhiteSpace() == false)
{
Current.User2AppDtos.Add(p);
}
@@ -155,8 +155,8 @@ namespace Umbraco.Core.Persistence.Repositories
"DELETE FROM cmsContentVersion WHERE ContentId = @Id",
"DELETE FROM cmsContentXml WHERE nodeId = @Id",
"DELETE FROM cmsContent WHERE nodeId = @Id",
"DELETE FROM umbracoNode WHERE id = @Id",
"DELETE FROM umbracoAccess WHERE nodeId = @Id"
"DELETE FROM umbracoAccess WHERE nodeId = @Id",
"DELETE FROM umbracoNode WHERE id = @Id"
};
return list;
}
@@ -234,8 +234,15 @@ namespace Umbraco.Core.Persistence.Repositories
var processed = 0;
do
{
var descendants = GetPagedResultsByQuery(query, pageIndex, pageSize, out total, "Path", Direction.Ascending);
//NOTE: This is an important call, we cannot simply make a call to:
// GetPagedResultsByQuery(query, pageIndex, pageSize, out total, "Path", Direction.Ascending);
// because that method is used to query 'latest' content items where in this case we don't necessarily
// want latest content items because a pulished content item might not actually be the latest.
// see: http://issues.umbraco.org/issue/U4-6322 & http://issues.umbraco.org/issue/U4-5982
var descendants = GetPagedResultsByQuery<DocumentDto, Content>(query, pageIndex, pageSize, out total,
new Tuple<string, string>("cmsDocument", "nodeId"),
ProcessQuery, "Path", Direction.Ascending);
var xmlItems = (from descendant in descendants
let xml = serializer(descendant)
select new ContentXmlDto { NodeId = descendant.Id, Xml = xml.ToDataString() }).ToArray();
@@ -728,7 +735,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// <param name="content"></param>
/// <param name="xml"></param>
public void AddOrUpdateContentXml(IContent content, Func<IContent, XElement> xml)
{
{
_contentXmlRepository.AddOrUpdate(new ContentXmlEntity<IContent>(content, xml));
}
@@ -826,11 +833,11 @@ namespace Umbraco.Core.Persistence.Repositories
var contentTypes = _contentTypeRepository.GetAll(dtos.Select(x => x.ContentVersionDto.ContentDto.ContentTypeId).ToArray())
.ToArray();
var ids = dtos
.Where(dto => dto.TemplateId.HasValue && dto.TemplateId.Value > 0)
.Select(x => x.TemplateId.Value).ToArray();
//NOTE: This should be ok for an SQL 'IN' statement, there shouldn't be an insane amount of content types
var templates = ids.Length == 0 ? Enumerable.Empty<ITemplate>() : _templateRepository.GetAll(ids).ToArray();
@@ -972,4 +979,4 @@ namespace Umbraco.Core.Persistence.Repositories
_contentXmlRepository.Dispose();
}
}
}
}
@@ -30,12 +30,9 @@ namespace Umbraco.Core.Persistence.Repositories
protected ContentTypeBaseRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
: base(work, cache, logger, sqlSyntax)
{
_guidRepo = new GuidReadOnlyContentTypeBaseRepository(this, work, cache, logger, sqlSyntax);
{
}
private readonly GuidReadOnlyContentTypeBaseRepository _guidRepo;
/// <summary>
/// Returns the content type ids that match the query
/// </summary>
@@ -454,6 +451,7 @@ AND umbracoNode.id <> @id",
propType.DataTypeDefinitionId = dto.DataTypeId;
propType.Description = dto.Description;
propType.Id = dto.Id;
propType.Key = dto.UniqueId;
propType.Name = dto.Name;
propType.Mandatory = dto.Mandatory;
propType.SortOrder = dto.SortOrder;
@@ -564,14 +562,13 @@ AND umbracoNode.id <> @id",
}
}
public static IEnumerable<IMediaType> GetMediaTypes<TRepo, TId>(
TId[] mediaTypeIds, Database db, ISqlSyntaxProvider sqlSyntax,
public static IEnumerable<IMediaType> GetMediaTypes<TRepo>(
Database db, ISqlSyntaxProvider sqlSyntax,
TRepo contentTypeRepository)
where TRepo : IReadRepository<TId, TEntity>
where TId: struct
where TRepo : IReadRepository<int, TEntity>
{
IDictionary<TId, IEnumerable<TId>> allParentMediaTypeIds;
var mediaTypes = MapMediaTypes(mediaTypeIds, db, sqlSyntax, out allParentMediaTypeIds)
IDictionary<int, List<int>> allParentMediaTypeIds;
var mediaTypes = MapMediaTypes(db, sqlSyntax, out allParentMediaTypeIds)
.ToArray();
MapContentTypeChildren(mediaTypes, db, sqlSyntax, contentTypeRepository, allParentMediaTypeIds);
@@ -579,16 +576,15 @@ AND umbracoNode.id <> @id",
return mediaTypes;
}
public static IEnumerable<IContentType> GetContentTypes<TRepo, TId>(
TId[] contentTypeIds, Database db, ISqlSyntaxProvider sqlSyntax,
public static IEnumerable<IContentType> GetContentTypes<TRepo>(
Database db, ISqlSyntaxProvider sqlSyntax,
TRepo contentTypeRepository,
ITemplateRepository templateRepository)
where TRepo : IReadRepository<TId, TEntity>
where TId : struct
where TRepo : IReadRepository<int, TEntity>
{
IDictionary<TId, IEnumerable<AssociatedTemplate>> allAssociatedTemplates;
IDictionary<TId, IEnumerable<TId>> allParentContentTypeIds;
var contentTypes = MapContentTypes(contentTypeIds, db, sqlSyntax, out allAssociatedTemplates, out allParentContentTypeIds)
IDictionary<int, List<AssociatedTemplate>> allAssociatedTemplates;
IDictionary<int, List<int>> allParentContentTypeIds;
var contentTypes = MapContentTypes(db, sqlSyntax, out allAssociatedTemplates, out allParentContentTypeIds)
.ToArray();
if (contentTypes.Any())
@@ -603,12 +599,11 @@ AND umbracoNode.id <> @id",
return contentTypes;
}
internal static void MapContentTypeChildren<TRepo, TId>(IContentTypeComposition[] contentTypes,
internal static void MapContentTypeChildren<TRepo>(IContentTypeComposition[] contentTypes,
Database db, ISqlSyntaxProvider sqlSyntax,
TRepo contentTypeRepository,
IDictionary<TId, IEnumerable<TId>> allParentContentTypeIds)
where TRepo : IReadRepository<TId, TEntity>
where TId : struct
IDictionary<int, List<int>> allParentContentTypeIds)
where TRepo : IReadRepository<int, TEntity>
{
//NOTE: SQL call #2
@@ -630,20 +625,17 @@ AND umbracoNode.id <> @id",
var allParentIdsAsArray = allParentContentTypeIds.SelectMany(x => x.Value).Distinct().ToArray();
if (allParentIdsAsArray.Any())
{
var allParentContentTypes = contentTypeRepository.GetAll(allParentIdsAsArray).ToArray();
var allParentContentTypes = contentTypes.Where(x => allParentIdsAsArray.Contains(x.Id)).ToArray();
foreach (var contentType in contentTypes)
{
//TODO: this is pretty hacky right now but i don't have time to refactor/fix running queries based on ints and Guids
// (i.e. for v8) but we need queries by GUIDs now so this is how it's gonna have to be
var entityId = typeof(TId) == typeof(int) ? contentType.Id : (object)contentType.Key;
{
var entityId = contentType.Id;
var parentContentTypes = allParentContentTypes.Where(x =>
{
//TODO: this is pretty hacky right now but i don't have time to refactor/fix running queries based on ints and Guids
// (i.e. for v8) but we need queries by GUIDs now so this is how it's gonna have to be
var parentEntityId = typeof(TId) == typeof(int) ? x.Id : (object)x.Key;
var parentEntityId = x.Id;
return allParentContentTypeIds[(TId)entityId].Contains((TId)parentEntityId);
return allParentContentTypeIds[entityId].Contains(parentEntityId);
});
foreach (var parentContentType in parentContentTypes)
{
@@ -661,13 +653,12 @@ AND umbracoNode.id <> @id",
}
internal static void MapContentTypeTemplates<TRepo, TId>(IContentType[] contentTypes,
internal static void MapContentTypeTemplates<TRepo>(IContentType[] contentTypes,
Database db,
TRepo contentTypeRepository,
ITemplateRepository templateRepository,
IDictionary<TId, IEnumerable<AssociatedTemplate>> associatedTemplates)
where TRepo : IReadRepository<TId, TEntity>
where TId: struct
IDictionary<int, List<AssociatedTemplate>> associatedTemplates)
where TRepo : IReadRepository<int, TEntity>
{
if (associatedTemplates == null || associatedTemplates.Any() == false) return;
@@ -684,11 +675,9 @@ AND umbracoNode.id <> @id",
foreach (var contentType in contentTypes)
{
//TODO: this is pretty hacky right now but i don't have time to refactor/fix running queries based on ints and Guids
// (i.e. for v8) but we need queries by GUIDs now so this is how it's gonna have to be
var entityId = typeof(TId) == typeof(int) ? contentType.Id : (object)contentType.Key;
var associatedTemplateIds = associatedTemplates[(TId)entityId].Select(x => x.TemplateId)
var entityId = contentType.Id;
var associatedTemplateIds = associatedTemplates[entityId].Select(x => x.TemplateId)
.Distinct()
.ToArray();
@@ -700,19 +689,14 @@ AND umbracoNode.id <> @id",
}
internal static IEnumerable<IMediaType> MapMediaTypes<TId>(TId[] mediaTypeIds, Database db, ISqlSyntaxProvider sqlSyntax,
out IDictionary<TId, IEnumerable<TId>> parentMediaTypeIds)
where TId : struct
internal static IEnumerable<IMediaType> MapMediaTypes(Database db, ISqlSyntaxProvider sqlSyntax,
out IDictionary<int, List<int>> parentMediaTypeIds)
{
Mandate.That(mediaTypeIds.Any(), () => new InvalidOperationException("must be at least one content type id specified"));
Mandate.ParameterNotNull(db, "db");
//ensure they are unique
mediaTypeIds = mediaTypeIds.Distinct().ToArray();
var sql = @"SELECT cmsContentType.pk as ctPk, cmsContentType.alias as ctAlias, cmsContentType.allowAtRoot as ctAllowAtRoot, cmsContentType.description as ctDesc,
cmsContentType.icon as ctIcon, cmsContentType.isContainer as ctIsContainer, cmsContentType.nodeId as ctId, cmsContentType.thumbnail as ctThumb,
AllowedTypes.allowedId as ctaAllowedId, AllowedTypes.SortOrder as ctaSortOrder, AllowedTypes.alias as ctaAlias,
AllowedTypes.AllowedId as ctaAllowedId, AllowedTypes.SortOrder as ctaSortOrder, AllowedTypes.alias as ctaAlias,
ParentTypes.parentContentTypeId as chtParentId, ParentTypes.parentContentTypeKey as chtParentKey,
umbracoNode.createDate as nCreateDate, umbracoNode." + sqlSyntax.GetQuotedColumnName("level") + @" as nLevel, umbracoNode.nodeObjectType as nObjectType, umbracoNode.nodeUser as nUser,
umbracoNode.parentID as nParentId, umbracoNode." + sqlSyntax.GetQuotedColumnName("path") + @" as nPath, umbracoNode.sortOrder as nSortOrder, umbracoNode." + sqlSyntax.GetQuotedColumnName("text") + @" as nName, umbracoNode.trashed as nTrashed,
@@ -734,27 +718,10 @@ AND umbracoNode.id <> @id",
ON cmsContentType2ContentType.parentContentTypeId = umbracoNode." + sqlSyntax.GetQuotedColumnName("id") + @"
) ParentTypes
ON ParentTypes.childContentTypeId = cmsContentType.nodeId
WHERE (umbracoNode.nodeObjectType = @nodeObjectType)";
if (mediaTypeIds.Any())
{
//TODO: This is all sorts of hacky but i don't have time to refactor a lot to get both ints and guids working nicely... this will
// work for the time being.
if (typeof(TId) == typeof(int))
{
sql = sql + " AND (umbracoNode.id IN (@contentTypeIds))";
}
else if (typeof(TId) == typeof(Guid))
{
sql = sql + " AND (umbracoNode.uniqueID IN (@contentTypeIds))";
}
}
//NOTE: we are going to assume there's not going to be more than 2100 content type ids since that is the max SQL param count!
if ((mediaTypeIds.Length - 1) > 2000)
throw new InvalidOperationException("Cannot perform this lookup, too many sql parameters");
var result = db.Fetch<dynamic>(sql, new { nodeObjectType = new Guid(Constants.ObjectTypes.MediaType), contentTypeIds = mediaTypeIds });
WHERE (umbracoNode.nodeObjectType = @nodeObjectType)
ORDER BY ctId";
var result = db.Fetch<dynamic>(sql, new { nodeObjectType = new Guid(Constants.ObjectTypes.MediaType) });
if (result.Any() == false)
{
@@ -762,91 +729,114 @@ AND umbracoNode.id <> @id",
return Enumerable.Empty<IMediaType>();
}
parentMediaTypeIds = new Dictionary<TId, IEnumerable<TId>>();
parentMediaTypeIds = new Dictionary<int, List<int>>();
var mappedMediaTypes = new List<IMediaType>();
foreach (var contentTypeId in mediaTypeIds)
//loop through each result and fill in our required values, each row will contain different requried data than the rest.
// it is much quicker to iterate each result and populate instead of looking up the values over and over in the result like
// we used to do.
var queue = new Queue<dynamic>(result);
var currAllowedContentTypes = new List<ContentTypeSort>();
while (queue.Count > 0)
{
//the current content type id that we're working with
var ct = queue.Dequeue();
var currentCtId = contentTypeId;
//first we want to get the main content type data this is 1 : 1 with umbraco node data
var ct = result
.Where(x =>
{
//TODO: This is a bit hacky right now but don't have time to do a nice refactor to support both GUID and Int queries, so this is
// how it is for now.
return (typeof (TId) == typeof (int))
? x.ctId == currentCtId
: x.nUniqueId == currentCtId;
})
.Select(x => new { x.ctPk, x.ctId, x.ctAlias, x.ctAllowAtRoot, x.ctDesc, x.ctIcon, x.ctIsContainer, x.ctThumb, x.nName, x.nCreateDate, x.nLevel, x.nObjectType, x.nUser, x.nParentId, x.nPath, x.nSortOrder, x.nTrashed, x.nUniqueId })
.DistinctBy(x => (int)x.ctId)
.FirstOrDefault();
if (ct == null)
//check for allowed content types
int? allowedCtId = ct.ctaAllowedId;
int? allowedCtSort = ct.ctaSortOrder;
string allowedCtAlias = ct.ctaAlias;
if (allowedCtId.HasValue && allowedCtSort.HasValue && allowedCtAlias != null)
{
continue;
var ctSort = new ContentTypeSort(new Lazy<int>(() => allowedCtId.Value), allowedCtSort.Value, allowedCtAlias);
if (currAllowedContentTypes.Contains(ctSort) == false)
{
currAllowedContentTypes.Add(ctSort);
}
}
var contentTypeDto = new ContentTypeDto
//always ensure there's a list for this content type
if (parentMediaTypeIds.ContainsKey(ct.ctId) == false)
parentMediaTypeIds[ct.ctId] = new List<int>();
//check for parent ids and assign to the outgoing collection
int? parentId = ct.chtParentId;
if (parentId.HasValue)
{
Alias = ct.ctAlias,
AllowAtRoot = ct.ctAllowAtRoot,
Description = ct.ctDesc,
Icon = ct.ctIcon,
IsContainer = ct.ctIsContainer,
NodeId = ct.ctId,
PrimaryKey = ct.ctPk,
Thumbnail = ct.ctThumb,
//map the underlying node dto
NodeDto = new NodeDto
{
CreateDate = ct.nCreateDate,
Level = (short)ct.nLevel,
NodeId = ct.ctId,
NodeObjectType = ct.nObjectType,
ParentId = ct.nParentId,
Path = ct.nPath,
SortOrder = ct.nSortOrder,
Text = ct.nName,
Trashed = ct.nTrashed,
UniqueId = ct.nUniqueId,
UserId = ct.nUser
}
};
var associatedParentIds = parentMediaTypeIds[ct.ctId];
if (associatedParentIds.Contains(parentId.Value) == false)
associatedParentIds.Add(parentId.Value);
}
//now create the media type object
if (queue.Count == 0 || queue.Peek().ctId != ct.ctId)
{
//it's the last in the queue or the content type is changing (moving to the next one)
var mediaType = CreateForMapping(ct, currAllowedContentTypes);
mappedMediaTypes.Add(mediaType);
var factory = new MediaTypeFactory(new Guid(Constants.ObjectTypes.MediaType));
var mediaType = factory.BuildEntity(contentTypeDto);
//map the allowed content types
//map the child content type ids
MapCommonContentTypeObjects(mediaType, currentCtId, result, parentMediaTypeIds);
mappedMediaTypes.Add(mediaType);
//Here we need to reset the current variables, we're now collecting data for a different content type
currAllowedContentTypes = new List<ContentTypeSort>();
}
}
return mappedMediaTypes;
}
internal static IEnumerable<IContentType> MapContentTypes<TId>(TId[] contentTypeIds, Database db, ISqlSyntaxProvider sqlSyntax,
out IDictionary<TId, IEnumerable<AssociatedTemplate>> associatedTemplates,
out IDictionary<TId, IEnumerable<TId>> parentContentTypeIds)
where TId : struct
private static IMediaType CreateForMapping(dynamic currCt, List<ContentTypeSort> currAllowedContentTypes)
{
// * create the DTO object
// * create the content type object
// * map the allowed content types
// * add to the outgoing list
var contentTypeDto = new ContentTypeDto
{
Alias = currCt.ctAlias,
AllowAtRoot = currCt.ctAllowAtRoot,
Description = currCt.ctDesc,
Icon = currCt.ctIcon,
IsContainer = currCt.ctIsContainer,
NodeId = currCt.ctId,
PrimaryKey = currCt.ctPk,
Thumbnail = currCt.ctThumb,
//map the underlying node dto
NodeDto = new NodeDto
{
CreateDate = currCt.nCreateDate,
Level = (short)currCt.nLevel,
NodeId = currCt.ctId,
NodeObjectType = currCt.nObjectType,
ParentId = currCt.nParentId,
Path = currCt.nPath,
SortOrder = currCt.nSortOrder,
Text = currCt.nName,
Trashed = currCt.nTrashed,
UniqueId = currCt.nUniqueId,
UserId = currCt.nUser
}
};
//now create the content type object
var factory = new MediaTypeFactory(new Guid(Constants.ObjectTypes.MediaType));
var mediaType = factory.BuildEntity(contentTypeDto);
//map the allowed content types
mediaType.AllowedContentTypes = currAllowedContentTypes;
return mediaType;
}
internal static IEnumerable<IContentType> MapContentTypes(Database db, ISqlSyntaxProvider sqlSyntax,
out IDictionary<int, List<AssociatedTemplate>> associatedTemplates,
out IDictionary<int, List<int>> parentContentTypeIds)
{
Mandate.ParameterNotNull(db, "db");
//ensure they are unique
contentTypeIds = contentTypeIds.Distinct().ToArray();
var sql = @"SELECT cmsDocumentType.IsDefault as dtIsDefault, cmsDocumentType.templateNodeId as dtTemplateId,
cmsContentType.pk as ctPk, cmsContentType.alias as ctAlias, cmsContentType.allowAtRoot as ctAllowAtRoot, cmsContentType.description as ctDesc,
cmsContentType.icon as ctIcon, cmsContentType.isContainer as ctIsContainer, cmsContentType.nodeId as ctId, cmsContentType.thumbnail as ctThumb,
AllowedTypes.allowedId as ctaAllowedId, AllowedTypes.SortOrder as ctaSortOrder, AllowedTypes.alias as ctaAlias,
AllowedTypes.AllowedId as ctaAllowedId, AllowedTypes.SortOrder as ctaSortOrder, AllowedTypes.alias as ctaAlias,
ParentTypes.parentContentTypeId as chtParentId,ParentTypes.parentContentTypeKey as chtParentKey,
umbracoNode.createDate as nCreateDate, umbracoNode." + sqlSyntax.GetQuotedColumnName("level") + @" as nLevel, umbracoNode.nodeObjectType as nObjectType, umbracoNode.nodeUser as nUser,
umbracoNode.parentID as nParentId, umbracoNode." + sqlSyntax.GetQuotedColumnName("path") + @" as nPath, umbracoNode.sortOrder as nSortOrder, umbracoNode." + sqlSyntax.GetQuotedColumnName("text") + @" as nName, umbracoNode.trashed as nTrashed,
@@ -877,28 +867,10 @@ AND umbracoNode.id <> @id",
ON cmsContentType2ContentType.parentContentTypeId = umbracoNode." + sqlSyntax.GetQuotedColumnName("id") + @"
) ParentTypes
ON ParentTypes.childContentTypeId = cmsContentType.nodeId
WHERE (umbracoNode.nodeObjectType = @nodeObjectType)";
if (contentTypeIds.Any())
{
//TODO: This is all sorts of hacky but i don't have time to refactor a lot to get both ints and guids working nicely... this will
// work for the time being.
if (typeof(TId) == typeof(int))
{
sql = sql + " AND (umbracoNode.id IN (@contentTypeIds))";
}
else if (typeof(TId) == typeof(Guid))
{
sql = sql + " AND (umbracoNode.uniqueID IN (@contentTypeIds))";
}
}
//NOTE: we are going to assume there's not going to be more than 2100 content type ids since that is the max SQL param count!
if ((contentTypeIds.Length - 1) > 2000)
throw new InvalidOperationException("Cannot perform this lookup, too many sql parameters");
var result = db.Fetch<dynamic>(sql, new { nodeObjectType = new Guid(Constants.ObjectTypes.DocumentType), contentTypeIds = contentTypeIds });
WHERE (umbracoNode.nodeObjectType = @nodeObjectType)
ORDER BY ctId";
var result = db.Fetch<dynamic>(sql, new { nodeObjectType = new Guid(Constants.ObjectTypes.DocumentType)});
if (result.Any() == false)
{
@@ -907,121 +879,141 @@ AND umbracoNode.id <> @id",
return Enumerable.Empty<IContentType>();
}
parentContentTypeIds = new Dictionary<TId, IEnumerable<TId>>();
associatedTemplates = new Dictionary<TId, IEnumerable<AssociatedTemplate>>();
parentContentTypeIds = new Dictionary<int, List<int>>();
associatedTemplates = new Dictionary<int, List<AssociatedTemplate>>();
var mappedContentTypes = new List<IContentType>();
foreach (var contentTypeId in contentTypeIds)
var queue = new Queue<dynamic>(result);
var currDefaultTemplate = -1;
var currAllowedContentTypes = new List<ContentTypeSort>();
while (queue.Count > 0)
{
//the current content type id that we're working with
var ct = queue.Dequeue();
var currentCtId = contentTypeId;
//first we want to get the main content type data this is 1 : 1 with umbraco node data
var ct = result
.Where(x =>
{
//TODO: This is a bit hacky right now but don't have time to do a nice refactor to support both GUID and Int queries, so this is
// how it is for now.
return (typeof(TId) == typeof(int))
? x.ctId == currentCtId
: x.nUniqueId == currentCtId;
})
.Select(x => new { x.ctPk, x.ctId, x.ctAlias, x.ctAllowAtRoot, x.ctDesc, x.ctIcon, x.ctIsContainer, x.ctThumb, x.nName, x.nCreateDate, x.nLevel, x.nObjectType, x.nUser, x.nParentId, x.nPath, x.nSortOrder, x.nTrashed, x.nUniqueId })
.DistinctBy(x => (int)x.ctId)
.FirstOrDefault();
if (ct == null)
//check for default templates
bool? isDefaultTemplate = Convert.ToBoolean(ct.dtIsDefault);
int? templateId = ct.dtTemplateId;
if (currDefaultTemplate == -1 && isDefaultTemplate.HasValue && templateId.HasValue)
{
continue;
currDefaultTemplate = templateId.Value;
}
//get the unique list of associated templates
var defaultTemplates = result
.Where(x =>
{
//TODO: This is a bit hacky right now but don't have time to do a nice refactor to support both GUID and Int queries, so this is
// how it is for now.
return (typeof(TId) == typeof(int))
? x.ctId == currentCtId
: x.nUniqueId == currentCtId;
})
//use a tuple so that distinct checks both values (in some rare cases the dtIsDefault will not compute as bool?, so we force it with Convert.ToBoolean)
.Select(x => new Tuple<bool?, int?>(Convert.ToBoolean(x.dtIsDefault), x.dtTemplateId))
.Where(x => x.Item1.HasValue && x.Item2.HasValue)
.Distinct()
.OrderByDescending(x => x.Item1.Value)
.ToArray();
//if there isn't one set to default explicitly, we'll pick the first one
var defaultTemplate = defaultTemplates.FirstOrDefault(x => x.Item1.Value)
?? defaultTemplates.FirstOrDefault();
//always ensure there's a list for this content type
if (associatedTemplates.ContainsKey(ct.ctId) == false)
associatedTemplates[ct.ctId] = new List<AssociatedTemplate>();
var dtDto = new DocumentTypeDto
//check for associated templates and assign to the outgoing collection
if (ct.tId != null)
{
//create the content type dto
ContentTypeDto = new ContentTypeDto
var associatedTemplate = new AssociatedTemplate(ct.tId, ct.tAlias, ct.tText);
var associatedList = associatedTemplates[ct.ctId];
if (associatedList.Contains(associatedTemplate) == false)
associatedList.Add(associatedTemplate);
}
//check for allowed content types
int? allowedCtId = ct.ctaAllowedId;
int? allowedCtSort = ct.ctaSortOrder;
string allowedCtAlias = ct.ctaAlias;
if (allowedCtId.HasValue && allowedCtSort.HasValue && allowedCtAlias != null)
{
var ctSort = new ContentTypeSort(new Lazy<int>(() => allowedCtId.Value), allowedCtSort.Value, allowedCtAlias);
if (currAllowedContentTypes.Contains(ctSort) == false)
{
Alias = ct.ctAlias,
AllowAtRoot = ct.ctAllowAtRoot,
Description = ct.ctDesc,
Icon = ct.ctIcon,
IsContainer = ct.ctIsContainer,
NodeId = ct.ctId,
PrimaryKey = ct.ctPk,
Thumbnail = ct.ctThumb,
//map the underlying node dto
NodeDto = new NodeDto
{
CreateDate = ct.nCreateDate,
Level = (short)ct.nLevel,
NodeId = ct.ctId,
NodeObjectType = ct.nObjectType,
ParentId = ct.nParentId,
Path = ct.nPath,
SortOrder = ct.nSortOrder,
Text = ct.nName,
Trashed = ct.nTrashed,
UniqueId = ct.nUniqueId,
UserId = ct.nUser
}
},
ContentTypeNodeId = ct.ctId,
IsDefault = defaultTemplate != null,
TemplateNodeId = defaultTemplate != null ? defaultTemplate.Item2.Value : 0,
};
currAllowedContentTypes.Add(ctSort);
}
}
// We will map a subset of the associated template - alias, id, name
//always ensure there's a list for this content type
if (parentContentTypeIds.ContainsKey(ct.ctId) == false)
parentContentTypeIds[ct.ctId] = new List<int>();
associatedTemplates.Add(currentCtId, result
.Where(x =>
{
//TODO: This is a bit hacky right now but don't have time to do a nice refactor to support both GUID and Int queries, so this is
// how it is for now.
return (typeof(TId) == typeof(int))
? x.ctId == currentCtId
: x.nUniqueId == currentCtId;
})
.Where(x => x.tId != null)
.Select(x => new AssociatedTemplate(x.tId, x.tAlias, x.tText))
.Distinct()
.ToArray());
//check for parent ids and assign to the outgoing collection
int? parentId = ct.chtParentId;
if (parentId.HasValue)
{
var associatedParentIds = parentContentTypeIds[ct.ctId];
//now create the content type object
if (associatedParentIds.Contains(parentId.Value) == false)
associatedParentIds.Add(parentId.Value);
}
var factory = new ContentTypeFactory(new Guid(Constants.ObjectTypes.DocumentType));
var contentType = factory.BuildEntity(dtDto);
if (queue.Count == 0 || queue.Peek().ctId != ct.ctId)
{
//it's the last in the queue or the content type is changing (moving to the next one)
var contentType = CreateForMapping(ct, currAllowedContentTypes, currDefaultTemplate);
mappedContentTypes.Add(contentType);
//map the allowed content types
//map the child content type ids
MapCommonContentTypeObjects(contentType, currentCtId, result, parentContentTypeIds);
mappedContentTypes.Add(contentType);
//Here we need to reset the current variables, we're now collecting data for a different content type
currDefaultTemplate = -1;
currAllowedContentTypes = new List<ContentTypeSort>();
}
}
return mappedContentTypes;
}
private static IContentType CreateForMapping(dynamic currCt, List<ContentTypeSort> currAllowedContentTypes, int currDefaultTemplate)
{
// * set the default template to the first one if a default isn't found
// * create the DTO object
// * create the content type object
// * map the allowed content types
// * add to the outgoing list
var dtDto = new DocumentTypeDto
{
//create the content type dto
ContentTypeDto = new ContentTypeDto
{
Alias = currCt.ctAlias,
AllowAtRoot = currCt.ctAllowAtRoot,
Description = currCt.ctDesc,
Icon = currCt.ctIcon,
IsContainer = currCt.ctIsContainer,
NodeId = currCt.ctId,
PrimaryKey = currCt.ctPk,
Thumbnail = currCt.ctThumb,
//map the underlying node dto
NodeDto = new NodeDto
{
CreateDate = currCt.nCreateDate,
Level = (short)currCt.nLevel,
NodeId = currCt.ctId,
NodeObjectType = currCt.nObjectType,
ParentId = currCt.nParentId,
Path = currCt.nPath,
SortOrder = currCt.nSortOrder,
Text = currCt.nName,
Trashed = currCt.nTrashed,
UniqueId = currCt.nUniqueId,
UserId = currCt.nUser
}
},
ContentTypeNodeId = currCt.ctId,
IsDefault = currDefaultTemplate != -1,
TemplateNodeId = currDefaultTemplate != -1 ? currDefaultTemplate : 0,
};
//now create the content type object
var factory = new ContentTypeFactory(new Guid(Constants.ObjectTypes.DocumentType));
var contentType = factory.BuildEntity(dtDto);
// NOTE
// that was done by the factory but makes little sense, moved here, so
// now we have to reset dirty props again (as the factory does it) and yet,
// we are not managing allowed templates... the whole thing is weird.
((ContentType)contentType).DefaultTemplateId = dtDto.TemplateNodeId;
contentType.ResetDirtyProperties(false);
//map the allowed content types
contentType.AllowedContentTypes = currAllowedContentTypes;
return contentType;
}
private static void MapCommonContentTypeObjects<T, TId>(T contentType, TId currentCtId, List<dynamic> result, IDictionary<TId, IEnumerable<TId>> parentContentTypeIds)
where T : IContentTypeBase
where TId : struct
@@ -1196,71 +1188,20 @@ AND umbracoNode.id <> @id",
}
/// <summary>
/// Inner repository to support the GUID lookups and keep the caching consistent
/// </summary>
internal class GuidReadOnlyContentTypeBaseRepository : PetaPocoRepositoryBase<Guid, TEntity>
{
private readonly ContentTypeBaseRepository<TEntity> _parentRepo;
public GuidReadOnlyContentTypeBaseRepository(
ContentTypeBaseRepository<TEntity> parentRepo,
IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
: base(work, cache, logger, sqlSyntax)
{
_parentRepo = parentRepo;
}
protected override TEntity PerformGet(Guid id)
{
return _parentRepo.PerformGet(id);
}
protected override IEnumerable<TEntity> PerformGetAll(params Guid[] ids)
{
return _parentRepo.PerformGetAll(ids);
}
protected override Sql GetBaseQuery(bool isCount)
{
return _parentRepo.GetBaseQuery(isCount);
}
protected override string GetBaseWhereClause()
{
return "umbracoNode.uniqueID = @Id";
}
#region No implementation required
protected override IEnumerable<TEntity> PerformGetByQuery(IQuery<TEntity> query)
{
throw new NotImplementedException();
}
protected override IEnumerable<string> GetDeleteClauses()
{
throw new NotImplementedException();
}
protected override Guid NodeObjectTypeId
{
get { throw new NotImplementedException(); }
}
protected override void PersistNewItem(TEntity entity)
{
throw new NotImplementedException();
}
protected override void PersistUpdatedItem(TEntity entity)
{
throw new NotImplementedException();
}
#endregion
}
protected abstract TEntity PerformGet(Guid id);
protected abstract TEntity PerformGet(string alias);
protected abstract IEnumerable<TEntity> PerformGetAll(params Guid[] ids);
protected abstract bool PerformExists(Guid id);
/// <summary>
/// Gets an Entity by alias
/// </summary>
/// <param name="alias"></param>
/// <returns></returns>
public TEntity Get(string alias)
{
return PerformGet(alias);
}
/// <summary>
/// Gets an Entity by Id
@@ -1269,7 +1210,7 @@ AND umbracoNode.id <> @id",
/// <returns></returns>
public TEntity Get(Guid id)
{
return _guidRepo.Get(id);
return PerformGet(id);
}
/// <summary>
@@ -1277,9 +1218,12 @@ AND umbracoNode.id <> @id",
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public IEnumerable<TEntity> GetAll(params Guid[] ids)
/// <remarks>
/// Ensure explicit implementation, we don't want to have any accidental calls to this since it is essentially the same signature as the main GetAll when there are no parameters
/// </remarks>
IEnumerable<TEntity> IReadRepository<Guid, TEntity>.GetAll(params Guid[] ids)
{
return _guidRepo.GetAll(ids);
return PerformGetAll(ids);
}
/// <summary>
@@ -1289,7 +1233,7 @@ AND umbracoNode.id <> @id",
/// <returns></returns>
public bool Exists(Guid id)
{
return _guidRepo.Exists(id);
return PerformExists(id);
}
}
}
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
@@ -27,29 +28,32 @@ namespace Umbraco.Core.Persistence.Repositories
_templateRepository = templateRepository;
}
#region Overrides of RepositoryBase<int,IContentType>
private FullDataSetRepositoryCachePolicyFactory<IContentType, int> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<IContentType, int> CachePolicyFactory
{
get
{
//Use a FullDataSet cache policy - this will cache the entire GetAll result in a single collection
return _cachePolicyFactory ?? (_cachePolicyFactory = new FullDataSetRepositoryCachePolicyFactory<IContentType, int>(RuntimeCache, GetEntityId));
}
}
protected override IContentType PerformGet(int id)
{
var contentTypes = ContentTypeQueryMapper.GetContentTypes(
new[] {id}, Database, SqlSyntax, this, _templateRepository);
var contentType = contentTypes.SingleOrDefault();
return contentType;
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Id == id);
}
protected override IEnumerable<IContentType> PerformGetAll(params int[] ids)
{
if (ids.Any())
{
return ContentTypeQueryMapper.GetContentTypes(ids, Database, SqlSyntax, this, _templateRepository);
}
else
{
var sql = new Sql().Select("id").From<NodeDto>().Where<NodeDto>(dto => dto.NodeObjectType == NodeObjectTypeId);
var allIds = Database.Fetch<int>(sql).ToArray();
return ContentTypeQueryMapper.GetContentTypes(allIds, Database, SqlSyntax, this, _templateRepository);
//NOTE: This logic should never be executed according to our cache policy
return ContentTypeQueryMapper.GetContentTypes(Database, SqlSyntax, this, _templateRepository)
.Where(x => ids.Contains(x.Id));
}
return ContentTypeQueryMapper.GetContentTypes(Database, SqlSyntax, this, _templateRepository);
}
protected override IEnumerable<IContentType> PerformGetByQuery(IQuery<IContentType> query)
@@ -64,9 +68,7 @@ namespace Umbraco.Core.Persistence.Repositories
? GetAll(dtos.DistinctBy(x => x.ContentTypeDto.NodeId).Select(x => x.ContentTypeDto.NodeId).ToArray())
: Enumerable.Empty<IContentType>();
}
#endregion
/// <summary>
/// Gets all entities of the specified <see cref="PropertyType"/> query
/// </summary>
@@ -244,25 +246,33 @@ namespace Umbraco.Core.Persistence.Repositories
protected override IContentType PerformGet(Guid id)
{
var contentTypes = ContentTypeQueryMapper.GetContentTypes(
new[] { id }, Database, SqlSyntax, this, _templateRepository);
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Key == id);
}
var contentType = contentTypes.SingleOrDefault();
return contentType;
protected override IContentType PerformGet(string alias)
{
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Alias.InvariantEquals(alias));
}
protected override IEnumerable<IContentType> PerformGetAll(params Guid[] ids)
{
//use the underlying GetAll which will force cache all content types
if (ids.Any())
{
return ContentTypeQueryMapper.GetContentTypes(ids, Database, SqlSyntax, this, _templateRepository);
return GetAll().Where(x => ids.Contains(x.Key));
}
else
{
var sql = new Sql().Select("id").From<NodeDto>(SqlSyntax).Where<NodeDto>(dto => dto.NodeObjectType == NodeObjectTypeId);
var allIds = Database.Fetch<int>(sql).ToArray();
return ContentTypeQueryMapper.GetContentTypes(allIds, Database, SqlSyntax, this, _templateRepository);
return GetAll();
}
}
protected override bool PerformExists(Guid id)
{
return GetAll().FirstOrDefault(x => x.Key == id) != null;
}
}
}
@@ -24,17 +24,15 @@ namespace Umbraco.Core.Persistence.Repositories
/// </summary>
internal class DataTypeDefinitionRepository : PetaPocoRepositoryBase<int, IDataTypeDefinition>, IDataTypeDefinitionRepository
{
private readonly CacheHelper _cacheHelper;
private readonly IContentTypeRepository _contentTypeRepository;
private readonly DataTypePreValueRepository _preValRepository;
public DataTypeDefinitionRepository(IDatabaseUnitOfWork work, CacheHelper cache, CacheHelper cacheHelper, ILogger logger, ISqlSyntaxProvider sqlSyntax,
public DataTypeDefinitionRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax,
IContentTypeRepository contentTypeRepository)
: base(work, cache, logger, sqlSyntax)
{
_cacheHelper = cacheHelper;
_contentTypeRepository = contentTypeRepository;
_preValRepository = new DataTypePreValueRepository(work, CacheHelper.CreateDisabledCacheHelper(), logger, sqlSyntax);
_preValRepository = new DataTypePreValueRepository(work, CacheHelper.CreateDisabledCacheHelper(), logger, sqlSyntax);
}
#region Overrides of RepositoryBase<int,DataTypeDefinition>
@@ -231,7 +229,7 @@ AND umbracoNode.id <> @id",
//NOTE: This is a special case, we need to clear the custom cache for pre-values here so they are not stale if devs
// are querying for them in the Saved event (before the distributed call cache is clearing it)
_cacheHelper.RuntimeCache.ClearCacheItem(GetPrefixedCacheKey(entity.Id));
RuntimeCache.ClearCacheItem(GetPrefixedCacheKey(entity.Id));
entity.ResetDirtyProperties();
}
@@ -270,7 +268,7 @@ AND umbracoNode.id <> @id",
public PreValueCollection GetPreValuesCollectionByDataTypeId(int dataTypeId)
{
var cached = _cacheHelper.RuntimeCache.GetCacheItemsByKeySearch<PreValueCollection>(GetPrefixedCacheKey(dataTypeId));
var cached = RuntimeCache.GetCacheItemsByKeySearch<PreValueCollection>(GetPrefixedCacheKey(dataTypeId));
if (cached != null && cached.Any())
{
//return from the cache, ensure it's a cloned result
@@ -289,7 +287,7 @@ AND umbracoNode.id <> @id",
{
//We need to see if we can find the cached PreValueCollection based on the cache key above
var cached = _cacheHelper.RuntimeCache.GetCacheItemsByKeyExpression<PreValueCollection>(GetCacheKeyRegex(preValueId));
var cached = RuntimeCache.GetCacheItemsByKeyExpression<PreValueCollection>(GetCacheKeyRegex(preValueId));
if (cached != null && cached.Any())
{
//return from the cache
@@ -408,7 +406,7 @@ AND umbracoNode.id <> @id",
+ string.Join(",", collection.FormatAsDictionary().Select(x => x.Value.Id).ToArray());
//store into cache
_cacheHelper.RuntimeCache.InsertCacheItem(key, () => collection,
RuntimeCache.InsertCacheItem(key, () => collection,
//30 mins
new TimeSpan(0, 0, 30),
//sliding is true
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
@@ -19,30 +20,40 @@ namespace Umbraco.Core.Persistence.Repositories
/// </summary>
internal class DictionaryRepository : PetaPocoRepositoryBase<int, IDictionaryItem>, IDictionaryRepository
{
private readonly ILanguageRepository _languageRepository;
public DictionaryRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider syntax, ILanguageRepository languageRepository)
public DictionaryRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider syntax)
: base(work, cache, logger, syntax)
{
_languageRepository = languageRepository;
}
{
}
private IRepositoryCachePolicyFactory<IDictionaryItem, int> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<IDictionaryItem, int> CachePolicyFactory
{
get
{
//custom cache policy which will not cache any results for GetAll
return _cachePolicyFactory ?? (_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, int>(
RuntimeCache,
new RepositoryCachePolicyOptions
{
//allow zero to be cached
GetAllCacheAllowZeroCount = true
}));
}
}
#region Overrides of RepositoryBase<int,DictionaryItem>
protected override IDictionaryItem PerformGet(int id)
{
var sql = GetBaseQuery(false)
.Where(GetBaseWhereClause(), new {Id = id})
.Where(GetBaseWhereClause(), new { Id = id })
.OrderBy<DictionaryDto>(x => x.UniqueId, SqlSyntax);
var dto = Database.Fetch<DictionaryDto, LanguageTextDto, DictionaryDto>(new DictionaryLanguageTextRelator().Map, sql).FirstOrDefault();
if (dto == null)
return null;
//This will be cached
var allLanguages = _languageRepository.GetAll().ToArray();
var entity = ConvertFromDto(dto, allLanguages);
var entity = ConvertFromDto(dto);
//on initial construction we don't want to have dirty properties tracked
// http://issues.umbraco.org/issue/U4-1946
@@ -56,14 +67,11 @@ namespace Umbraco.Core.Persistence.Repositories
var sql = GetBaseQuery(false).Where("cmsDictionary.pk > 0");
if (ids.Any())
{
sql.Where("cmsDictionary.pk in (@ids)", new { ids = ids });
sql.Where("cmsDictionary.pk in (@ids)", new { ids = ids });
}
//This will be cached
var allLanguages = _languageRepository.GetAll().ToArray();
return Database.Fetch<DictionaryDto, LanguageTextDto, DictionaryDto>(new DictionaryLanguageTextRelator().Map, sql)
.Select(dto => ConvertFromDto(dto, allLanguages));
.Select(dto => ConvertFromDto(dto));
}
protected override IEnumerable<IDictionaryItem> PerformGetByQuery(IQuery<IDictionaryItem> query)
@@ -72,12 +80,9 @@ namespace Umbraco.Core.Persistence.Repositories
var translator = new SqlTranslator<IDictionaryItem>(sqlClause, query);
var sql = translator.Translate();
sql.OrderBy<DictionaryDto>(x => x.UniqueId, SqlSyntax);
//This will be cached
var allLanguages = _languageRepository.GetAll().ToArray();
return Database.Fetch<DictionaryDto, LanguageTextDto, DictionaryDto>(new DictionaryLanguageTextRelator().Map, sql)
.Select(x => ConvertFromDto(x, allLanguages));
.Select(x => ConvertFromDto(x));
}
#endregion
@@ -87,7 +92,7 @@ namespace Umbraco.Core.Persistence.Repositories
protected override Sql GetBaseQuery(bool isCount)
{
var sql = new Sql();
if(isCount)
if (isCount)
{
sql.Select("COUNT(*)")
.From<DictionaryDto>(SqlSyntax);
@@ -123,26 +128,28 @@ namespace Umbraco.Core.Persistence.Repositories
protected override void PersistNewItem(IDictionaryItem entity)
{
((DictionaryItem)entity).AddingEntity();
var dictionaryItem = ((DictionaryItem) entity);
foreach (var translation in entity.Translations)
dictionaryItem.AddingEntity();
foreach (var translation in dictionaryItem.Translations)
translation.Value = translation.Value.ToValidXmlString();
var factory = new DictionaryItemFactory();
var dto = factory.BuildDto(entity);
var dto = factory.BuildDto(dictionaryItem);
var id = Convert.ToInt32(Database.Insert(dto));
entity.Id = id;
dictionaryItem.Id = id;
var translationFactory = new DictionaryTranslationFactory(entity.Key, null);
foreach (var translation in entity.Translations)
var translationFactory = new DictionaryTranslationFactory(dictionaryItem.Key);
foreach (var translation in dictionaryItem.Translations)
{
var textDto = translationFactory.BuildDto(translation);
translation.Id = Convert.ToInt32(Database.Insert(textDto));
translation.Key = entity.Key;
translation.Key = dictionaryItem.Key;
}
entity.ResetDirtyProperties();
dictionaryItem.ResetDirtyProperties();
}
protected override void PersistUpdatedItem(IDictionaryItem entity)
@@ -157,11 +164,11 @@ namespace Umbraco.Core.Persistence.Repositories
Database.Update(dto);
var translationFactory = new DictionaryTranslationFactory(entity.Key, null);
var translationFactory = new DictionaryTranslationFactory(entity.Key);
foreach (var translation in entity.Translations)
{
var textDto = translationFactory.BuildDto(translation);
if(translation.HasIdentity)
if (translation.HasIdentity)
{
Database.Update(textDto);
}
@@ -183,7 +190,7 @@ namespace Umbraco.Core.Persistence.Repositories
{
RecursiveDelete(entity.Key);
Database.Delete<LanguageTextDto>("WHERE UniqueId = @Id", new { Id = entity.Key});
Database.Delete<LanguageTextDto>("WHERE UniqueId = @Id", new { Id = entity.Key });
Database.Delete<DictionaryDto>("WHERE id = @Id", new { Id = entity.Key });
//Clear the cache entries that exist by uniqueid/item key
@@ -193,7 +200,7 @@ namespace Umbraco.Core.Persistence.Repositories
private void RecursiveDelete(Guid parentId)
{
var list = Database.Fetch<DictionaryDto>("WHERE parent = @ParentId", new {ParentId = parentId});
var list = Database.Fetch<DictionaryDto>("WHERE parent = @ParentId", new { ParentId = parentId });
foreach (var dto in list)
{
RecursiveDelete(dto.UniqueId);
@@ -209,20 +216,18 @@ namespace Umbraco.Core.Persistence.Repositories
#endregion
protected IDictionaryItem ConvertFromDto(DictionaryDto dto, ILanguage[] allLanguages)
protected IDictionaryItem ConvertFromDto(DictionaryDto dto)
{
var factory = new DictionaryItemFactory();
var entity = factory.BuildEntity(dto);
var list = new List<IDictionaryTranslation>();
foreach (var textDto in dto.LanguageTextDtos)
{
//Assuming this is cached!
var language = allLanguages.FirstOrDefault(x => x.Id == textDto.LanguageId);
if (language == null)
{
if (textDto.LanguageId <= 0)
continue;
var translationFactory = new DictionaryTranslationFactory(dto.UniqueId, language);
var translationFactory = new DictionaryTranslationFactory(dto.UniqueId);
list.Add(translationFactory.BuildEntity(textDto));
}
entity.Translations = list;
@@ -234,7 +239,7 @@ namespace Umbraco.Core.Persistence.Repositories
{
using (var uniqueIdRepo = new DictionaryByUniqueIdRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
{
return uniqueIdRepo.Get(uniqueId);
return uniqueIdRepo.Get(uniqueId);
}
}
@@ -242,10 +247,10 @@ namespace Umbraco.Core.Persistence.Repositories
{
using (var keyRepo = new DictionaryByKeyRepository(this, UnitOfWork, RepositoryCache, Logger, SqlSyntax))
{
return keyRepo.Get(key);
return keyRepo.Get(key);
}
}
private IEnumerable<IDictionaryItem> GetRootDictionaryItems()
{
var query = Query<IDictionaryItem>.Builder.Where(x => x.ParentId == null);
@@ -254,9 +259,6 @@ namespace Umbraco.Core.Persistence.Repositories
public IEnumerable<IDictionaryItem> GetDictionaryItemDescendants(Guid? parentId)
{
//This will be cached
var allLanguages = _languageRepository.GetAll().ToArray();
//This methods will look up children at each level, since we do not store a path for dictionary (ATM), we need to do a recursive
// lookup to get descendants. Currently this is the most efficient way to do it
@@ -275,7 +277,7 @@ namespace Umbraco.Core.Persistence.Repositories
sql.OrderBy<DictionaryDto>(x => x.UniqueId, SqlSyntax);
return Database.Fetch<DictionaryDto, LanguageTextDto, DictionaryDto>(new DictionaryLanguageTextRelator().Map, sql)
.Select(x => ConvertFromDto(x, allLanguages));
.Select(x => ConvertFromDto(x));
});
};
@@ -284,7 +286,7 @@ namespace Umbraco.Core.Persistence.Repositories
: getItemsFromParents(new[] { parentId.Value });
return childItems.SelectRecursive(items => getItemsFromParents(items.Select(x => x.Key).ToArray())).SelectMany(items => items);
}
private class DictionaryByUniqueIdRepository : SimpleGetRepository<Guid, IDictionaryItem, DictionaryDto>
@@ -314,20 +316,34 @@ namespace Umbraco.Core.Persistence.Repositories
protected override IDictionaryItem ConvertToEntity(DictionaryDto dto)
{
//This will be cached
var allLanguages = _dictionaryRepository._languageRepository.GetAll().ToArray();
return _dictionaryRepository.ConvertFromDto(dto, allLanguages);
return _dictionaryRepository.ConvertFromDto(dto);
}
protected override object GetBaseWhereClauseArguments(Guid id)
{
return new {Id = id};
return new { Id = id };
}
protected override string GetWhereInClauseForGetAll()
{
return "cmsDictionary." + SqlSyntax.GetQuotedColumnName("id") + " in (@ids)";
}
private IRepositoryCachePolicyFactory<IDictionaryItem, Guid> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<IDictionaryItem, Guid> CachePolicyFactory
{
get
{
//custom cache policy which will not cache any results for GetAll
return _cachePolicyFactory ?? (_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, Guid>(
RuntimeCache,
new RepositoryCachePolicyOptions
{
//allow zero to be cached
GetAllCacheAllowZeroCount = true
}));
}
}
}
private class DictionaryByKeyRepository : SimpleGetRepository<string, IDictionaryItem, DictionaryDto>
@@ -357,9 +373,7 @@ namespace Umbraco.Core.Persistence.Repositories
protected override IDictionaryItem ConvertToEntity(DictionaryDto dto)
{
//This will be cached
var allLanguages = _dictionaryRepository._languageRepository.GetAll().ToArray();
return _dictionaryRepository.ConvertFromDto(dto, allLanguages);
return _dictionaryRepository.ConvertFromDto(dto);
}
protected override object GetBaseWhereClauseArguments(string id)
@@ -371,17 +385,24 @@ namespace Umbraco.Core.Persistence.Repositories
{
return "cmsDictionary." + SqlSyntax.GetQuotedColumnName("key") + " in (@ids)";
}
private IRepositoryCachePolicyFactory<IDictionaryItem, string> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<IDictionaryItem, string> CachePolicyFactory
{
get
{
//custom cache policy which will not cache any results for GetAll
return _cachePolicyFactory ?? (_cachePolicyFactory = new OnlySingleItemsRepositoryCachePolicyFactory<IDictionaryItem, string>(
RuntimeCache,
new RepositoryCachePolicyOptions
{
//allow zero to be cached
GetAllCacheAllowZeroCount = true
}));
}
}
}
/// <summary>
/// Dispose disposable properties
/// </summary>
/// <remarks>
/// Ensure the unit of work is disposed
/// </remarks>
protected override void DisposeResources()
{
_languageRepository.Dispose();
}
}
}
@@ -18,25 +18,19 @@ namespace Umbraco.Core.Persistence.Repositories
internal class DomainRepository : PetaPocoRepositoryBase<int, IDomain>, IDomainRepository
{
private readonly RepositoryCacheOptions _cacheOptions;
public DomainRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
: base(work, cache, logger, sqlSyntax)
{
//Custom cache options for better performance
_cacheOptions = new RepositoryCacheOptions
{
GetAllCacheAllowZeroCount = true,
GetAllCacheValidateCount = false
};
{
}
/// <summary>
/// Returns the repository cache options
/// </summary>
protected override RepositoryCacheOptions RepositoryCacheOptions
private FullDataSetRepositoryCachePolicyFactory<IDomain, int> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<IDomain, int> CachePolicyFactory
{
get { return _cacheOptions; }
get
{
//Use a FullDataSet cache policy - this will cache the entire GetAll result in a single collection
return _cachePolicyFactory ?? (_cachePolicyFactory = new FullDataSetRepositoryCachePolicyFactory<IDomain, int>(RuntimeCache, GetEntityId));
}
}
protected override IDomain PerformGet(int id)
@@ -0,0 +1,11 @@
using System;
using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
{
public interface IContentTypeCompositionRepository<TEntity> : IRepositoryQueryable<int, TEntity>, IReadRepository<Guid, TEntity>
where TEntity : IContentTypeComposition
{
TEntity Get(string alias);
}
}
@@ -5,7 +5,7 @@ using Umbraco.Core.Persistence.Querying;
namespace Umbraco.Core.Persistence.Repositories
{
public interface IContentTypeRepository : IRepositoryQueryable<int, IContentType>, IReadRepository<Guid, IContentType>
public interface IContentTypeRepository : IContentTypeCompositionRepository<IContentType>
{
/// <summary>
/// Gets all entities of the specified <see cref="PropertyType"/> query
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Querying;
namespace Umbraco.Core.Persistence.Repositories
{
public interface IMediaTypeRepository : IRepositoryQueryable<int, IMediaType>, IReadRepository<Guid, IMediaType>
public interface IMediaTypeRepository : IContentTypeCompositionRepository<IMediaType>
{
/// <summary>
/// Gets all entities of the specified <see cref="PropertyType"/> query
@@ -3,7 +3,7 @@ using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
{
public interface IMemberTypeRepository : IRepositoryQueryable<int, IMemberType>, IReadRepository<Guid, IMemberType>
public interface IMemberTypeRepository : IContentTypeCompositionRepository<IMemberType>
{
}
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
@@ -22,6 +23,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// <param name="alias"></param>
/// <returns></returns>
[Obsolete("Use GetDescendants instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
TemplateNode GetTemplateNode(string alias);
/// <summary>
@@ -31,6 +33,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// <param name="alias"></param>
/// <returns></returns>
[Obsolete("Use GetDescendants instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
TemplateNode FindTemplateInTree(TemplateNode anyNode, string alias);
/// <summary>
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
@@ -20,23 +21,17 @@ namespace Umbraco.Core.Persistence.Repositories
{
public LanguageRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
: base(work, cache, logger, sqlSyntax)
{
//Custom cache options for better performance
_cacheOptions = new RepositoryCacheOptions
{
GetAllCacheAllowZeroCount = true,
GetAllCacheValidateCount = false
};
{
}
private readonly RepositoryCacheOptions _cacheOptions;
/// <summary>
/// Returns the repository cache options
/// </summary>
protected override RepositoryCacheOptions RepositoryCacheOptions
private FullDataSetRepositoryCachePolicyFactory<ILanguage, int> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<ILanguage, int> CachePolicyFactory
{
get { return _cacheOptions; }
get
{
//Use a FullDataSet cache policy - this will cache the entire GetAll result in a single collection
return _cachePolicyFactory ?? (_cachePolicyFactory = new FullDataSetRepositoryCachePolicyFactory<ILanguage, int>(RuntimeCache, GetEntityId));
}
}
#region Overrides of RepositoryBase<int,Language>
@@ -159,13 +154,13 @@ namespace Umbraco.Core.Persistence.Repositories
public ILanguage GetByCultureName(string cultureName)
{
//use the underlying GetAll which will force cache all domains
//use the underlying GetAll which will force cache all languages
return GetAll().FirstOrDefault(x => x.CultureName.InvariantEquals(cultureName));
}
public ILanguage GetByIsoCode(string isoCode)
{
//use the underlying GetAll which will force cache all domains
//use the underlying GetAll which will force cache all languages
return GetAll().FirstOrDefault(x => x.IsoCode.InvariantEquals(isoCode));
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
@@ -24,29 +25,32 @@ namespace Umbraco.Core.Persistence.Repositories
{
}
#region Overrides of RepositoryBase<int,IMedia>
private FullDataSetRepositoryCachePolicyFactory<IMediaType, int> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<IMediaType, int> CachePolicyFactory
{
get
{
//Use a FullDataSet cache policy - this will cache the entire GetAll result in a single collection
return _cachePolicyFactory ?? (_cachePolicyFactory = new FullDataSetRepositoryCachePolicyFactory<IMediaType, int>(RuntimeCache, GetEntityId));
}
}
protected override IMediaType PerformGet(int id)
{
var contentTypes = ContentTypeQueryMapper.GetMediaTypes(
new[] { id }, Database, SqlSyntax, this);
var contentType = contentTypes.SingleOrDefault();
return contentType;
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Id == id);
}
protected override IEnumerable<IMediaType> PerformGetAll(params int[] ids)
{
if (ids.Any())
{
return ContentTypeQueryMapper.GetMediaTypes(ids, Database, SqlSyntax, this);
}
else
{
var sql = new Sql().Select("id").From<NodeDto>().Where<NodeDto>(dto => dto.NodeObjectType == NodeObjectTypeId);
var allIds = Database.Fetch<int>(sql).ToArray();
return ContentTypeQueryMapper.GetMediaTypes(allIds, Database, SqlSyntax, this);
//NOTE: This logic should never be executed according to our cache policy
return ContentTypeQueryMapper.GetMediaTypes(Database, SqlSyntax, this)
.Where(x => ids.Contains(x.Id));
}
return ContentTypeQueryMapper.GetMediaTypes(Database, SqlSyntax, this);
}
protected override IEnumerable<IMediaType> PerformGetByQuery(IQuery<IMediaType> query)
@@ -61,9 +65,7 @@ namespace Umbraco.Core.Persistence.Repositories
? GetAll(dtos.DistinctBy(x => x.NodeId).Select(x => x.NodeId).ToArray())
: Enumerable.Empty<IMediaType>();
}
#endregion
/// <summary>
/// Gets all entities of the specified <see cref="PropertyType"/> query
@@ -168,25 +170,33 @@ namespace Umbraco.Core.Persistence.Repositories
protected override IMediaType PerformGet(Guid id)
{
var contentTypes = ContentTypeQueryMapper.GetMediaTypes(
new[] { id }, Database, SqlSyntax, this);
var contentType = contentTypes.SingleOrDefault();
return contentType;
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Key == id);
}
protected override IEnumerable<IMediaType> PerformGetAll(params Guid[] ids)
{
//use the underlying GetAll which will force cache all content types
if (ids.Any())
{
return ContentTypeQueryMapper.GetMediaTypes(ids, Database, SqlSyntax, this);
return GetAll().Where(x => ids.Contains(x.Key));
}
else
{
var sql = new Sql().Select("id").From<NodeDto>(SqlSyntax).Where<NodeDto>(dto => dto.NodeObjectType == NodeObjectTypeId);
var allIds = Database.Fetch<int>(sql).ToArray();
return ContentTypeQueryMapper.GetMediaTypes(allIds, Database, SqlSyntax, this);
return GetAll();
}
}
protected override bool PerformExists(Guid id)
{
return GetAll().FirstOrDefault(x => x.Key == id) != null;
}
protected override IMediaType PerformGet(string alias)
{
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Alias.InvariantEquals(alias));
}
}
}
@@ -20,13 +20,9 @@ namespace Umbraco.Core.Persistence.Repositories
internal class MemberGroupRepository : PetaPocoRepositoryBase<int, IMemberGroup>, IMemberGroupRepository
{
private readonly CacheHelper _cacheHelper;
public MemberGroupRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax, CacheHelper cacheHelper)
public MemberGroupRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
: base(work, cache, logger, sqlSyntax)
{
if (cacheHelper == null) throw new ArgumentNullException("cacheHelper");
_cacheHelper = cacheHelper;
}
private readonly MemberGroupFactory _modelFactory = new MemberGroupFactory();
@@ -135,7 +131,7 @@ namespace Umbraco.Core.Persistence.Repositories
public IMemberGroup GetByName(string name)
{
return _cacheHelper.RuntimeCache.GetCacheItem<IMemberGroup>(
return RuntimeCache.GetCacheItem<IMemberGroup>(
string.Format("{0}.{1}", typeof (IMemberGroup).FullName, name),
() =>
{
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using log4net;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Models;
@@ -26,25 +27,20 @@ namespace Umbraco.Core.Persistence.Repositories
{
}
#region Overrides of RepositoryBase<int, IMemberType>
private FullDataSetRepositoryCachePolicyFactory<IMemberType, int> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<IMemberType, int> CachePolicyFactory
{
get
{
//Use a FullDataSet cache policy - this will cache the entire GetAll result in a single collection
return _cachePolicyFactory ?? (_cachePolicyFactory = new FullDataSetRepositoryCachePolicyFactory<IMemberType, int>(RuntimeCache, GetEntityId));
}
}
protected override IMemberType PerformGet(int id)
{
var sql = GetBaseQuery(false);
sql.Where(GetBaseWhereClause(), new { Id = id });
sql.OrderByDescending<NodeDto>(x => x.NodeId);
var dtos =
Database.Fetch<MemberTypeReadOnlyDto, PropertyTypeReadOnlyDto, PropertyTypeGroupReadOnlyDto, MemberTypeReadOnlyDto>(
new PropertyTypePropertyGroupRelator().Map, sql);
if (dtos == null || dtos.Any() == false)
return null;
var factory = new MemberTypeReadOnlyFactory();
var member = factory.BuildEntity(dtos.First());
return member;
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Id == id);
}
protected override IEnumerable<IMemberType> PerformGetAll(params int[] ids)
@@ -52,10 +48,11 @@ namespace Umbraco.Core.Persistence.Repositories
var sql = GetBaseQuery(false);
if (ids.Any())
{
//NOTE: This logic should never be executed according to our cache policy
var statement = string.Join(" OR ", ids.Select(x => string.Format("umbracoNode.id='{0}'", x)));
sql.Where(statement);
}
sql.OrderByDescending<NodeDto>(x => x.NodeId);
sql.OrderByDescending<NodeDto>(x => x.NodeId, SqlSyntax);
var dtos =
Database.Fetch<MemberTypeReadOnlyDto, PropertyTypeReadOnlyDto, PropertyTypeGroupReadOnlyDto, MemberTypeReadOnlyDto>(
@@ -71,7 +68,7 @@ namespace Umbraco.Core.Persistence.Repositories
var subquery = translator.Translate();
var sql = GetBaseQuery(false)
.Append(new Sql("WHERE umbracoNode.id IN (" + subquery.SQL + ")", subquery.Arguments))
.OrderBy<NodeDto>(x => x.SortOrder);
.OrderBy<NodeDto>(x => x.SortOrder, SqlSyntax);
var dtos =
Database.Fetch<MemberTypeReadOnlyDto, PropertyTypeReadOnlyDto, PropertyTypeGroupReadOnlyDto, MemberTypeReadOnlyDto>(
@@ -79,11 +76,7 @@ namespace Umbraco.Core.Persistence.Repositories
return BuildFromDtos(dtos);
}
#endregion
#region Overrides of PetaPocoRepositoryBase<int, IMemberType>
protected override Sql GetBaseQuery(bool isCount)
{
var sql = new Sql();
@@ -157,11 +150,7 @@ namespace Umbraco.Core.Persistence.Repositories
{
get { return new Guid(Constants.ObjectTypes.MemberType); }
}
#endregion
#region Unit of Work Implementation
protected override void PersistNewItem(IMemberType entity)
{
ValidateAlias(entity);
@@ -238,8 +227,7 @@ namespace Umbraco.Core.Persistence.Repositories
entity.ResetDirtyProperties();
}
#endregion
/// <summary>
/// Override so we can specify explicit db type's on any property types that are built-in.
@@ -262,38 +250,33 @@ namespace Umbraco.Core.Persistence.Repositories
protected override IMemberType PerformGet(Guid id)
{
var sql = GetBaseQuery(false);
sql.Where("umbracoNode.uniqueID = @Id", new { Id = id });
sql.OrderByDescending<NodeDto>(x => x.NodeId);
var dtos =
Database.Fetch<MemberTypeReadOnlyDto, PropertyTypeReadOnlyDto, PropertyTypeGroupReadOnlyDto, MemberTypeReadOnlyDto>(
new PropertyTypePropertyGroupRelator().Map, sql);
if (dtos == null || dtos.Any() == false)
return null;
var factory = new MemberTypeReadOnlyFactory();
var member = factory.BuildEntity(dtos.First());
return member;
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Key == id);
}
protected override IEnumerable<IMemberType> PerformGetAll(params Guid[] ids)
{
var sql = GetBaseQuery(false);
//use the underlying GetAll which will force cache all content types
if (ids.Any())
{
var statement = string.Join(" OR ", ids.Select(x => string.Format("umbracoNode.uniqueID='{0}'", x)));
sql.Where(statement);
return GetAll().Where(x => ids.Contains(x.Key));
}
sql.OrderByDescending<NodeDto>(x => x.NodeId, SqlSyntax);
else
{
return GetAll();
}
}
var dtos =
Database.Fetch<MemberTypeReadOnlyDto, PropertyTypeReadOnlyDto, PropertyTypeGroupReadOnlyDto, MemberTypeReadOnlyDto>(
new PropertyTypePropertyGroupRelator().Map, sql);
protected override bool PerformExists(Guid id)
{
return GetAll().FirstOrDefault(x => x.Key == id) != null;
}
return BuildFromDtos(dtos);
protected override IMemberType PerformGet(string alias)
{
//use the underlying GetAll which will force cache all content types
return GetAll().FirstOrDefault(x => x.Alias.InvariantEquals(alias));
}
/// <summary>
@@ -26,13 +26,14 @@ namespace Umbraco.Core.Persistence.Repositories
where TEntity : class, IAggregateRoot
{
private readonly IDatabaseUnitOfWork _unitOfWork;
private readonly CacheHelper _cache;
private readonly IRuntimeCacheProvider _runtimeCache;
private readonly ISqlSyntaxProvider _sqlSyntax;
internal PermissionRepository(IDatabaseUnitOfWork unitOfWork, CacheHelper cache, ISqlSyntaxProvider sqlSyntax)
{
_unitOfWork = unitOfWork;
_cache = cache;
//Make this repository use an isolated cache
_runtimeCache = cache.IsolatedRuntimeCache.GetOrCreateCache<EntityPermission>();
_sqlSyntax = sqlSyntax;
}
@@ -45,7 +46,7 @@ namespace Umbraco.Core.Persistence.Repositories
public IEnumerable<EntityPermission> GetUserPermissionsForEntities(int userId, params int[] entityIds)
{
var entityIdKey = string.Join(",", entityIds.Select(x => x.ToString(CultureInfo.InvariantCulture)));
return _cache.RuntimeCache.GetCacheItem<IEnumerable<EntityPermission>>(
return _runtimeCache.GetCacheItem<IEnumerable<EntityPermission>>(
string.Format("{0}{1}{2}", CacheKeys.UserPermissionsCacheKey, userId, entityIdKey),
() =>
{
@@ -17,33 +17,23 @@ namespace Umbraco.Core.Persistence.Repositories
{
public PublicAccessRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax)
: base(work, cache, logger, sqlSyntax)
{
_options = new RepositoryCacheOptions
{
//We want to ensure that a zero count gets cached, even if there is nothing in the db we don't want it to lookup nothing each time
GetAllCacheAllowZeroCount = true,
//Set to 1000 just to ensure that all of them are cached, The GetAll on this repository gets called *A lot*, we want max performance
GetAllCacheThresholdLimit = 1000,
//Override to false so that a Count check against the db is NOT performed when doing a GetAll without params, we just want to
// return the raw cache without validation. The GetAll on this repository gets called *A lot*, we want max performance
GetAllCacheValidateCount = false
};
{
}
private readonly RepositoryCacheOptions _options;
private FullDataSetRepositoryCachePolicyFactory<PublicAccessEntry, Guid> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<PublicAccessEntry, Guid> CachePolicyFactory
{
get
{
//Use a FullDataSet cache policy - this will cache the entire GetAll result in a single collection
return _cachePolicyFactory ?? (_cachePolicyFactory = new FullDataSetRepositoryCachePolicyFactory<PublicAccessEntry, Guid>(RuntimeCache, GetEntityId));
}
}
protected override PublicAccessEntry PerformGet(Guid id)
{
var sql = GetBaseQuery(false);
sql.Where(GetBaseWhereClause(), new { Id = id });
var taskDto = Database.Fetch<AccessDto, AccessRuleDto, AccessDto>(new AccessRulesRelator().Map, sql).FirstOrDefault();
if (taskDto == null)
return null;
var factory = new PublicAccessEntryFactory();
var entity = factory.BuildEntity(taskDto);
return entity;
//return from GetAll - this will be cached as a collection
return GetAll().FirstOrDefault(x => x.Key == id);
}
protected override IEnumerable<PublicAccessEntry> PerformGetAll(params Guid[] ids)
@@ -102,15 +92,6 @@ namespace Umbraco.Core.Persistence.Repositories
get { throw new NotImplementedException(); }
}
/// <summary>
/// Returns the repository cache options
/// </summary>
protected override RepositoryCacheOptions RepositoryCacheOptions
{
get { return _options; }
}
protected override void PersistNewItem(PublicAccessEntry entity)
{
entity.AddingEntity();
@@ -1,7 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Cache;
using Umbraco.Core.Collections;
using Umbraco.Core.Logging;
using Umbraco.Core.Models.EntityBase;
@@ -22,11 +24,7 @@ namespace Umbraco.Core.Persistence.Repositories
if (logger == null) throw new ArgumentNullException("logger");
Logger = logger;
_work = work;
//IMPORTANT: We will force the DeepCloneRuntimeCacheProvider to be used here which is a wrapper for the underlying
// runtime cache to ensure that anything that can be deep cloned in/out is done so, this also ensures that our tracks
// changes entities are reset.
_cache = new CacheHelper(new DeepCloneRuntimeCacheProvider(cache.RuntimeCache), cache.StaticCache, cache.RequestCache);
_cache = cache;
}
/// <summary>
@@ -84,9 +82,41 @@ namespace Umbraco.Core.Persistence.Repositories
{
}
private readonly RepositoryCacheOptions _cacheOptions = new RepositoryCacheOptions();
#region IRepository<TEntity> Members
protected virtual TId GetEntityId(TEntity entity)
{
return (TId)(object)entity.Id;
}
/// <summary>
/// The runtime cache used for this repo by default is the isolated cache for this type
/// </summary>
protected override IRuntimeCacheProvider RuntimeCache
{
get { return RepositoryCache.IsolatedRuntimeCache.GetOrCreateCache<TEntity>(); }
}
private IRepositoryCachePolicyFactory<TEntity, TId> _cachePolicyFactory;
/// <summary>
/// Returns the Cache Policy for the repository
/// </summary>
/// <remarks>
/// The Cache Policy determines how each entity or entity collection is cached
/// </remarks>
protected virtual IRepositoryCachePolicyFactory<TEntity, TId> CachePolicyFactory
{
get
{
return _cachePolicyFactory ?? (_cachePolicyFactory = new DefaultRepositoryCachePolicyFactory<TEntity, TId>(
RuntimeCache,
new RepositoryCachePolicyOptions(() =>
{
//Get count of all entities of current type (TEntity) to ensure cached result is correct
var query = Query<TEntity>.Builder.Where(x => x.Id != 0);
return PerformCount(query);
})));
}
}
/// <summary>
/// Adds or Updates an entity of type TEntity
@@ -119,23 +149,16 @@ namespace Umbraco.Core.Persistence.Repositories
protected abstract TEntity PerformGet(TId id);
/// <summary>
/// Gets an entity by the passed in Id utilizing the repository's runtime cache
/// Gets an entity by the passed in Id utilizing the repository's cache policy
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public TEntity Get(TId id)
{
var cacheKey = GetCacheIdKey<TEntity>(id);
var fromCache = RuntimeCache.GetCacheItem<TEntity>(cacheKey);
if (fromCache != null) return fromCache;
var entity = PerformGet(id);
if (entity == null) return null;
RuntimeCache.InsertCacheItem(cacheKey, () => entity);
return entity;
using (var p = CachePolicyFactory.CreatePolicy())
{
return p.Get(id, PerformGet);
}
}
protected abstract IEnumerable<TEntity> PerformGetAll(params TId[] ids);
@@ -158,88 +181,13 @@ namespace Umbraco.Core.Persistence.Repositories
throw new InvalidOperationException("Cannot perform a query with more than 2000 parameters");
}
if (ids.Any())
using (var p = CachePolicyFactory.CreatePolicy())
{
var entities = ids.Select(x => RuntimeCache.GetCacheItem<TEntity>(GetCacheIdKey<TEntity>(x))).ToArray();
if (ids.Count().Equals(entities.Count()) && entities.Any(x => x == null) == false)
return entities;
}
else
{
var allEntities = RuntimeCache.GetCacheItemsByKeySearch<TEntity>(GetCacheTypeKey<TEntity>())
.WhereNotNull()
.ToArray();
if (allEntities.Any())
{
if (RepositoryCacheOptions.GetAllCacheValidateCount)
{
//Get count of all entities of current type (TEntity) to ensure cached result is correct
var query = Query<TEntity>.Builder.Where(x => x.Id != 0);
int totalCount = PerformCount(query);
if (allEntities.Count() == totalCount)
return allEntities;
}
else
{
return allEntities;
}
}
else if (RepositoryCacheOptions.GetAllCacheAllowZeroCount)
{
//if the repository allows caching a zero count, then check the zero count cache
var zeroCount = RuntimeCache.GetCacheItem<TEntity[]>(GetCacheTypeKey<TEntity>());
if (zeroCount != null && zeroCount.Any() == false)
{
//there is a zero count cache so return an empty list
return Enumerable.Empty<TEntity>();
}
}
}
var entityCollection = PerformGetAll(ids)
//ensure we don't include any null refs in the returned collection!
.WhereNotNull()
.ToArray();
//We need to put a threshold here! IF there's an insane amount of items
// coming back here we don't want to chuck it all into memory, this added cache here
// is more for convenience when paging stuff temporarily
if (entityCollection.Length > RepositoryCacheOptions.GetAllCacheThresholdLimit)
return entityCollection;
if (entityCollection.Length == 0 && RepositoryCacheOptions.GetAllCacheAllowZeroCount)
{
//there was nothing returned but we want to cache a zero count result so add an TEntity[] to the cache
// to signify that there is a zero count cache
RuntimeCache.InsertCacheItem(GetCacheTypeKey<TEntity>(), () => new TEntity[] {});
}
foreach (var entity in entityCollection)
{
if (entity != null)
{
var localCopy = entity;
RuntimeCache.InsertCacheItem(GetCacheIdKey<TEntity>(entity.Id), () => localCopy);
}
}
return entityCollection;
var result = p.GetAll(ids, PerformGetAll);
return result;
}
}
/// <summary>
/// Returns the repository cache options
/// </summary>
protected virtual RepositoryCacheOptions RepositoryCacheOptions
{
get { return _cacheOptions; }
}
protected abstract IEnumerable<TEntity> PerformGetByQuery(IQuery<TEntity> query);
/// <summary>
/// Gets a list of entities by the passed in query
@@ -261,12 +209,10 @@ namespace Umbraco.Core.Persistence.Repositories
/// <returns></returns>
public bool Exists(TId id)
{
var fromCache = RuntimeCache.GetCacheItem<TEntity>(GetCacheIdKey<TEntity>(id));
if (fromCache != null)
using (var p = CachePolicyFactory.CreatePolicy())
{
return true;
return p.Exists(id, PerformExists);
}
return PerformExists(id);
}
protected abstract int PerformCount(IQuery<TEntity> query);
@@ -279,34 +225,19 @@ namespace Umbraco.Core.Persistence.Repositories
{
return PerformCount(query);
}
#endregion
#region IUnitOfWorkRepository Members
/// <summary>
/// Unit of work method that tells the repository to persist the new entity
/// </summary>
/// <param name="entity"></param>
public virtual void PersistNewItem(IEntity entity)
{
try
{
PersistNewItem((TEntity)entity);
RuntimeCache.InsertCacheItem(GetCacheIdKey<TEntity>(entity.Id), () => entity);
//If there's a GetAll zero count cache, ensure it is cleared
RuntimeCache.ClearCacheItem(GetCacheTypeKey<TEntity>());
}
catch (Exception ex)
{
//if an exception is thrown we need to remove the entry from cache, this is ONLY a work around because of the way
// that we cache entities: http://issues.umbraco.org/issue/U4-4259
RuntimeCache.ClearCacheItem(GetCacheIdKey<TEntity>(entity.Id));
//If there's a GetAll zero count cache, ensure it is cleared
RuntimeCache.ClearCacheItem(GetCacheTypeKey<TEntity>());
throw;
}
var casted = (TEntity)entity;
using (var p = CachePolicyFactory.CreatePolicy())
{
p.CreateOrUpdate(casted, PersistNewItem);
}
}
/// <summary>
@@ -315,23 +246,12 @@ namespace Umbraco.Core.Persistence.Repositories
/// <param name="entity"></param>
public virtual void PersistUpdatedItem(IEntity entity)
{
try
{
PersistUpdatedItem((TEntity)entity);
RuntimeCache.InsertCacheItem(GetCacheIdKey<TEntity>(entity.Id), () => entity);
//If there's a GetAll zero count cache, ensure it is cleared
RuntimeCache.ClearCacheItem(GetCacheTypeKey<TEntity>());
}
catch (Exception)
{
//if an exception is thrown we need to remove the entry from cache, this is ONLY a work around because of the way
// that we cache entities: http://issues.umbraco.org/issue/U4-4259
RuntimeCache.ClearCacheItem(GetCacheIdKey<TEntity>(entity.Id));
//If there's a GetAll zero count cache, ensure it is cleared
RuntimeCache.ClearCacheItem(GetCacheTypeKey<TEntity>());
throw;
}
var casted = (TEntity)entity;
using (var p = CachePolicyFactory.CreatePolicy())
{
p.CreateOrUpdate(casted, PersistUpdatedItem);
}
}
/// <summary>
@@ -340,21 +260,19 @@ namespace Umbraco.Core.Persistence.Repositories
/// <param name="entity"></param>
public virtual void PersistDeletedItem(IEntity entity)
{
PersistDeletedItem((TEntity)entity);
RuntimeCache.ClearCacheItem(GetCacheIdKey<TEntity>(entity.Id));
//If there's a GetAll zero count cache, ensure it is cleared
RuntimeCache.ClearCacheItem(GetCacheTypeKey<TEntity>());
var casted = (TEntity)entity;
using (var p = CachePolicyFactory.CreatePolicy())
{
p.Remove(casted, PersistDeletedItem);
}
}
#endregion
#region Abstract IUnitOfWorkRepository Methods
protected abstract void PersistNewItem(TEntity item);
protected abstract void PersistUpdatedItem(TEntity item);
protected abstract void PersistDeletedItem(TEntity item);
#endregion
/// <summary>
/// Dispose disposable properties
@@ -4,6 +4,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
@@ -32,7 +33,6 @@ namespace Umbraco.Core.Persistence.Repositories
private readonly ITemplatesSection _templateConfig;
private readonly ViewHelper _viewHelper;
private readonly MasterPageHelper _masterPageHelper;
private readonly RepositoryCacheOptions _cacheOptions;
internal TemplateRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, ISqlSyntaxProvider sqlSyntax, IFileSystem masterpageFileSystem, IFileSystem viewFileSystem, ITemplatesSection templateConfig)
: base(work, cache, logger, sqlSyntax)
@@ -41,41 +41,26 @@ namespace Umbraco.Core.Persistence.Repositories
_viewsFileSystem = viewFileSystem;
_templateConfig = templateConfig;
_viewHelper = new ViewHelper(_viewsFileSystem);
_masterPageHelper = new MasterPageHelper(_masterpagesFileSystem);
_cacheOptions = new RepositoryCacheOptions
{
//Allow a zero count cache entry because GetAll() gets used quite a lot and we want to ensure
// if there are no templates, that it doesn't keep going to the db.
GetAllCacheAllowZeroCount = true,
//GetAll gets called a lot, we want to ensure that all templates are in the cache, default is 100 which
// would normally be fine but we'll increase it in case people have a ton of templates.
GetAllCacheThresholdLimit = 500
};
_masterPageHelper = new MasterPageHelper(_masterpagesFileSystem);
}
/// <summary>
/// Returns the repository cache options
/// </summary>
protected override RepositoryCacheOptions RepositoryCacheOptions
private FullDataSetRepositoryCachePolicyFactory<ITemplate, int> _cachePolicyFactory;
protected override IRepositoryCachePolicyFactory<ITemplate, int> CachePolicyFactory
{
get { return _cacheOptions; }
get
{
//Use a FullDataSet cache policy - this will cache the entire GetAll result in a single collection
return _cachePolicyFactory ?? (_cachePolicyFactory = new FullDataSetRepositoryCachePolicyFactory<ITemplate, int>(RuntimeCache, GetEntityId));
}
}
#region Overrides of RepositoryBase<int,ITemplate>
protected override ITemplate PerformGet(int id)
{
var sql = GetBaseQuery(false).Where<TemplateDto>(x => x.NodeId == id);
var result = Database.Fetch<TemplateDto, NodeDto>(sql).FirstOrDefault();
if (result == null) return null;
//look up the simple template definitions that have a master template assigned, this is used
// later to populate the template item's properties
var childIds = GetAxisDefinitions(result).ToArray();
return MapFromDto(result, childIds);
//use the underlying GetAll which will force cache all templates
return base.GetAll().FirstOrDefault(x => x.Id == id);
}
protected override IEnumerable<ITemplate> PerformGetAll(params int[] ids)
@@ -479,126 +464,102 @@ namespace Umbraco.Core.Persistence.Repositories
public ITemplate Get(string alias)
{
var sql = GetBaseQuery(false).Where<TemplateDto>(x => x.Alias == alias);
var dto = Database.Fetch<TemplateDto, NodeDto>(sql).FirstOrDefault();
if (dto == null)
return null;
return MapFromDto(dto, GetAxisDefinitions(dto).ToArray());
return GetAll(alias).FirstOrDefault();
}
public IEnumerable<ITemplate> GetAll(params string[] aliases)
{
var sql = GetBaseQuery(false);
//We must call the base (normal) GetAll method
// which is cached. This is a specialized method and unfortunatley with the params[] it
// overlaps with the normal GetAll method.
if (aliases.Any() == false) return base.GetAll();
if (aliases.Any())
{
sql.Where("cmsTemplate.alias IN (@aliases)", new {aliases = aliases});
}
var dtos = Database.Fetch<TemplateDto, NodeDto>(sql).ToArray();
if (dtos.Length == 0) return Enumerable.Empty<ITemplate>();
var axisDefos = GetAxisDefinitions(dtos).ToArray();
return dtos.Select(x => MapFromDto(x, axisDefos));
//return from base.GetAll, this is all cached
return base.GetAll().Where(x => aliases.InvariantContains(x.Alias));
}
public IEnumerable<ITemplate> GetChildren(int masterTemplateId)
{
var sql = GetBaseQuery(false);
if (masterTemplateId <= 0)
{
sql.Where<NodeDto>(x => x.ParentId <= 0);
}
else
{
sql.Where<NodeDto>(x => x.ParentId == masterTemplateId);
}
//return from base.GetAll, this is all cached
var all = base.GetAll().ToArray();
var dtos = Database.Fetch<TemplateDto, NodeDto>(sql).ToArray();
if (dtos.Length == 0) return Enumerable.Empty<ITemplate>();
if (masterTemplateId <= 0) return all.Where(x => x.MasterTemplateAlias.IsNullOrWhiteSpace());
var axisDefos = GetAxisDefinitions(dtos).ToArray();
return dtos.Select(x => MapFromDto(x, axisDefos));
var parent = all.FirstOrDefault(x => x.Id == masterTemplateId);
if (parent == null) return Enumerable.Empty<ITemplate>();
var children = all.Where(x => x.MasterTemplateAlias.InvariantEquals(parent.Alias));
return children;
}
public IEnumerable<ITemplate> GetChildren(string alias)
{
var sql = GetBaseQuery(false);
if (alias.IsNullOrWhiteSpace())
{
sql.Where<NodeDto>(x => x.ParentId <= 0);
}
else
{
//unfortunately SQLCE doesn't support scalar subqueries in the where clause, otherwise we could have done this
// in a single query, now we have to lookup the path to acheive the same thing
var parent = Database.ExecuteScalar<int?>(new Sql().Select("nodeId").From<TemplateDto>(SqlSyntax).Where<TemplateDto>(dto => dto.Alias == alias));
if (parent.HasValue == false) return Enumerable.Empty<ITemplate>();
sql.Where<NodeDto>(x => x.ParentId == parent.Value);
}
var dtos = Database.Fetch<TemplateDto, NodeDto>(sql).ToArray();
if (dtos.Length == 0) return Enumerable.Empty<ITemplate>();
var axisDefos = GetAxisDefinitions(dtos).ToArray();
return dtos.Select(x => MapFromDto(x, axisDefos));
//return from base.GetAll, this is all cached
return base.GetAll().Where(x => alias.IsNullOrWhiteSpace()
? x.MasterTemplateAlias.IsNullOrWhiteSpace()
: x.MasterTemplateAlias.InvariantEquals(alias));
}
public IEnumerable<ITemplate> GetDescendants(int masterTemplateId)
{
var sql = GetBaseQuery(false);
//return from base.GetAll, this is all cached
var all = base.GetAll().ToArray();
var descendants = new List<ITemplate>();
if (masterTemplateId > 0)
{
//unfortunately SQLCE doesn't support scalar subqueries in the where clause, otherwise we could have done this
// in a single query, now we have to lookup the path to acheive the same thing
var path = Database.ExecuteScalar<string>(
new Sql().Select(SqlSyntax.GetQuotedColumnName("path"))
.From<TemplateDto>(SqlSyntax)
.InnerJoin<NodeDto>(SqlSyntax)
.On<TemplateDto, NodeDto>(SqlSyntax, dto => dto.NodeId, dto => dto.NodeId)
.Where<NodeDto>(dto => dto.NodeId == masterTemplateId));
if (path.IsNullOrWhiteSpace()) return Enumerable.Empty<ITemplate>();
sql.Where(@"(umbracoNode." + SqlSyntax.GetQuotedColumnName("path") + @" LIKE @query)", new { query = path + ",%" });
var parent = all.FirstOrDefault(x => x.Id == masterTemplateId);
if (parent == null) return Enumerable.Empty<ITemplate>();
//recursively add all children with a level
AddChildren(all, descendants, parent.Alias);
}
else
{
descendants.AddRange(all.Where(x => x.MasterTemplateAlias.IsNullOrWhiteSpace()));
foreach (var parent in descendants)
{
//recursively add all children with a level
AddChildren(all, descendants, parent.Alias);
}
}
sql.OrderBy("umbracoNode." + SqlSyntax.GetQuotedColumnName("level"));
var dtos = Database.Fetch<TemplateDto, NodeDto>(sql).ToArray();
if (dtos.Length == 0) return Enumerable.Empty<ITemplate>();
var axisDefos = GetAxisDefinitions(dtos).ToArray();
return dtos.Select(x => MapFromDto(x, axisDefos));
//return the list - it will be naturally ordered by level
return descendants;
}
public IEnumerable<ITemplate> GetDescendants(string alias)
{
var sql = GetBaseQuery(false);
var all = base.GetAll().ToArray();
var descendants = new List<ITemplate>();
if (alias.IsNullOrWhiteSpace() == false)
{
//unfortunately SQLCE doesn't support scalar subqueries in the where clause, otherwise we could have done this
// in a single query, now we have to lookup the path to acheive the same thing
var path = Database.ExecuteScalar<string>(
"SELECT umbracoNode.path FROM cmsTemplate INNER JOIN umbracoNode ON cmsTemplate.nodeId = umbracoNode.id WHERE cmsTemplate.alias = @alias", new { alias = alias });
if (path.IsNullOrWhiteSpace()) return Enumerable.Empty<ITemplate>();
sql.Where(@"(umbracoNode." + SqlSyntax.GetQuotedColumnName("path") + @" LIKE @query)", new {query = path + ",%" });
var parent = all.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
if (parent == null) return Enumerable.Empty<ITemplate>();
//recursively add all children
AddChildren(all, descendants, parent.Alias);
}
else
{
descendants.AddRange(all.Where(x => x.MasterTemplateAlias.IsNullOrWhiteSpace()));
foreach (var parent in descendants)
{
//recursively add all children with a level
AddChildren(all, descendants, parent.Alias);
}
}
//return the list - it will be naturally ordered by level
return descendants;
}
sql.OrderBy("umbracoNode." + SqlSyntax.GetQuotedColumnName("level"));
var dtos = Database.Fetch<TemplateDto, NodeDto>(sql).ToArray();
if (dtos.Length == 0) return Enumerable.Empty<ITemplate>();
var axisDefos = GetAxisDefinitions(dtos).ToArray();
return dtos.Select(x => MapFromDto(x, axisDefos));
private void AddChildren(ITemplate[] all, List<ITemplate> descendants, string masterAlias)
{
var c = all.Where(x => x.MasterTemplateAlias.InvariantEquals(masterAlias)).ToArray();
descendants.AddRange(c);
if (c.Any() == false) return;
//recurse through all children
foreach (var child in c)
{
AddChildren(all, descendants, child.Alias);
}
}
/// <summary>
@@ -610,9 +571,9 @@ namespace Umbraco.Core.Persistence.Repositories
public TemplateNode GetTemplateNode(string alias)
{
//first get all template objects
var allTemplates = GetAll().ToArray();
var allTemplates = base.GetAll().ToArray();
var selfTemplate = allTemplates.SingleOrDefault(x => x.Alias == alias);
var selfTemplate = allTemplates.SingleOrDefault(x => x.Alias.InvariantEquals(alias));
if (selfTemplate == null)
{
return null;
@@ -621,11 +582,11 @@ namespace Umbraco.Core.Persistence.Repositories
var top = selfTemplate;
while (top.MasterTemplateAlias.IsNullOrWhiteSpace() == false)
{
top = allTemplates.Single(x => x.Alias == top.MasterTemplateAlias);
top = allTemplates.Single(x => x.Alias.InvariantEquals(top.MasterTemplateAlias));
}
var topNode = new TemplateNode(allTemplates.Single(x => x.Id == top.Id));
var childTemplates = allTemplates.Where(x => x.MasterTemplateAlias == top.Alias);
var childTemplates = allTemplates.Where(x => x.MasterTemplateAlias.InvariantEquals(top.Alias));
//This now creates the hierarchy recursively
topNode.Children = CreateChildren(topNode, childTemplates, allTemplates);
@@ -633,10 +594,11 @@ namespace Umbraco.Core.Persistence.Repositories
return FindTemplateInTree(topNode, alias);
}
[Obsolete("Only used by obsolete code")]
private static TemplateNode WalkTree(TemplateNode current, string alias)
{
//now walk the tree to find the node
if (current.Template.Alias == alias)
if (current.Template.Alias.InvariantEquals(alias))
{
return current;
}
@@ -683,7 +645,7 @@ namespace Umbraco.Core.Persistence.Repositories
{
var engine = _templateConfig.DefaultRenderingEngine;
var viewHelper = new ViewHelper(_viewsFileSystem);
if (!viewHelper.ViewExists(template))
if (viewHelper.ViewExists(template) == false)
{
if (template.Content.IsNullOrWhiteSpace() == false && MasterPageHelper.IsMasterPageSyntax(template.Content))
{
@@ -768,7 +730,7 @@ namespace Umbraco.Core.Persistence.Repositories
//get this node's children
var local = childTemplate;
var kids = allTemplates.Where(x => x.MasterTemplateAlias == local.Alias);
var kids = allTemplates.Where(x => x.MasterTemplateAlias.InvariantEquals(local.Alias));
//recurse
child.Children = CreateChildren(child, kids, allTemplates);
@@ -798,7 +760,7 @@ namespace Umbraco.Core.Persistence.Repositories
private bool AliasAlreadExists(ITemplate template)
{
var sql = GetBaseQuery(true).Where<TemplateDto>(x => x.Alias == template.Alias && x.NodeId != template.Id);
var sql = GetBaseQuery(true).Where<TemplateDto>(x => x.Alias.InvariantEquals(template.Alias) && x.NodeId != template.Id);
var count = Database.ExecuteScalar<int>(sql);
return count > 0;
}
@@ -1,5 +1,6 @@
using Umbraco.Core.Configuration;
using System;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
@@ -18,6 +19,7 @@ namespace Umbraco.Core.Persistence
private readonly ILogger _logger;
private readonly ISqlSyntaxProvider _sqlSyntax;
private readonly CacheHelper _cacheHelper;
private readonly CacheHelper _noCache;
private readonly IUmbracoSettingsSection _settings;
#region Ctors
@@ -29,7 +31,28 @@ namespace Umbraco.Core.Persistence
//if (sqlSyntax == null) throw new ArgumentNullException("sqlSyntax");
if (settings == null) throw new ArgumentNullException("settings");
_cacheHelper = cacheHelper;
_cacheHelper = cacheHelper;
//IMPORTANT: We will force the DeepCloneRuntimeCacheProvider to be used here which is a wrapper for the underlying
// runtime cache to ensure that anything that can be deep cloned in/out is done so, this also ensures that our tracks
// changes entities are reset.
if ((_cacheHelper.RuntimeCache is DeepCloneRuntimeCacheProvider) == false)
{
var origRuntimeCache = cacheHelper.RuntimeCache;
_cacheHelper.RuntimeCache = new DeepCloneRuntimeCacheProvider(origRuntimeCache);
}
//If the factory for isolated cache doesn't return DeepCloneRuntimeCacheProvider, then ensure it does
if (_cacheHelper.IsolatedRuntimeCache.CacheFactory.Method.ReturnType != typeof (DeepCloneRuntimeCacheProvider))
{
var origFactory = cacheHelper.IsolatedRuntimeCache.CacheFactory;
_cacheHelper.IsolatedRuntimeCache.CacheFactory = type =>
{
var cache = origFactory(type);
return new DeepCloneRuntimeCacheProvider(cache);
};
}
_noCache = CacheHelper.CreateDisabledCacheHelper();
_logger = logger;
_sqlSyntax = sqlSyntax;
_settings = settings;
@@ -53,6 +76,7 @@ namespace Umbraco.Core.Persistence
{
if (cacheHelper == null) throw new ArgumentNullException("cacheHelper");
_cacheHelper = cacheHelper;
_noCache = CacheHelper.CreateDisabledCacheHelper();
}
[Obsolete("Use the ctor specifying all dependencies instead")]
@@ -80,15 +104,15 @@ namespace Umbraco.Core.Persistence
public virtual ITaskRepository CreateTaskRepository(IDatabaseUnitOfWork uow)
{
return new TaskRepository(uow,
CacheHelper.CreateDisabledCacheHelper(), //never cache
return new TaskRepository(uow,
_noCache, //never cache
_logger, _sqlSyntax);
}
public virtual IAuditRepository CreateAuditRepository(IDatabaseUnitOfWork uow)
{
return new AuditRepository(uow,
CacheHelper.CreateDisabledCacheHelper(), //never cache
_noCache, //never cache
_logger, _sqlSyntax);
}
@@ -128,7 +152,6 @@ namespace Umbraco.Core.Persistence
{
return new DataTypeDefinitionRepository(
uow,
_cacheHelper,
_cacheHelper,
_logger, _sqlSyntax,
CreateContentTypeRepository(uow));
@@ -140,8 +163,7 @@ namespace Umbraco.Core.Persistence
uow,
_cacheHelper,
_logger,
_sqlSyntax,
CreateLanguageRepository(uow));
_sqlSyntax);
}
public virtual ILanguageRepository CreateLanguageRepository(IDatabaseUnitOfWork uow)
@@ -175,7 +197,7 @@ namespace Umbraco.Core.Persistence
{
return new RelationRepository(
uow,
CacheHelper.CreateDisabledCacheHelper(), //never cache
_noCache, //never cache
_logger, _sqlSyntax,
CreateRelationTypeRepository(uow));
}
@@ -184,7 +206,7 @@ namespace Umbraco.Core.Persistence
{
return new RelationTypeRepository(
uow,
CacheHelper.CreateDisabledCacheHelper(), //never cache
_noCache, //never cache
_logger, _sqlSyntax);
}
@@ -222,7 +244,7 @@ namespace Umbraco.Core.Persistence
{
return new MigrationEntryRepository(
uow,
CacheHelper.CreateDisabledCacheHelper(), //never cache
_noCache, //never cache
_logger, _sqlSyntax);
}
@@ -283,8 +305,7 @@ namespace Umbraco.Core.Persistence
{
return new MemberGroupRepository(uow,
_cacheHelper,
_logger, _sqlSyntax,
_cacheHelper);
_logger, _sqlSyntax);
}
public virtual IEntityRepository CreateEntityRepository(IDatabaseUnitOfWork uow)
@@ -292,15 +313,15 @@ namespace Umbraco.Core.Persistence
return new EntityRepository(uow);
}
public IDomainRepository CreateDomainRepository(IDatabaseUnitOfWork uow)
public virtual IDomainRepository CreateDomainRepository(IDatabaseUnitOfWork uow)
{
return new DomainRepository(uow, _cacheHelper, _logger, _sqlSyntax);
}
public ITaskTypeRepository CreateTaskTypeRepository(IDatabaseUnitOfWork uow)
{
return new TaskTypeRepository(uow,
CacheHelper.CreateDisabledCacheHelper(), //never cache
return new TaskTypeRepository(uow,
_noCache, //never cache
_logger, _sqlSyntax);
}
}
@@ -357,7 +357,9 @@ namespace Umbraco.Core.Security
{
//TODO: Do we need to do more here?? need to make sure that the forms cookie is gone, but is that
// taken care of in our custom middleware somehow?
ctx.Authentication.SignOut();
ctx.Authentication.SignOut(
Core.Constants.Security.BackOfficeAuthenticationType,
Core.Constants.Security.BackOfficeExternalAuthenticationType);
return null;
}
}
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Security;
@@ -97,6 +99,8 @@ namespace Umbraco.Core.Security
}
_userService.Save(member);
if (member.Id == 0) throw new DataException("Could not create the user, check logs for details");
//re-assign id
user.Id = member.Id;
@@ -315,7 +315,7 @@ namespace Umbraco.Core.Services
//remove the cache now that it has changed SD: I'm leaving this here even though it
// is taken care of by events as well, I think unit tests may rely on it being cleared here.
_cache.ClearCacheItem(CacheKeys.ApplicationTreeCacheKey);
_cache.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationTreeCacheKey);
}
}
}
@@ -1227,6 +1227,13 @@ namespace Umbraco.Core.Services
/// <param name="userId">Optional Id of the user issueing the delete operation</param>
public void DeleteContentOfType(int contentTypeId, int userId = 0)
{
//TODO: This currently this is called from the ContentTypeService but that needs to change,
// if we are deleting a content type, we should just delete the data and do this operation slightly differently.
// This method will recursively go lookup every content item, check if any of it's descendants are
// of a different type, move them to the recycle bin, then permanently delete the content items.
// The main problem with this is that for every content item being deleted, events are raised...
// which we need for many things like keeping caches in sync, but we can surely do this MUCH better.
using (new WriteLock(Locker))
{
using (var uow = UowProvider.GetUnitOfWork())
@@ -1977,6 +1984,10 @@ namespace Umbraco.Core.Services
var uow = UowProvider.GetUnitOfWork();
using (var repository = RepositoryFactory.CreateContentRepository(uow))
{
if (published == false)
{
content.ChangePublishedState(PublishedState.Saved);
}
//Since this is the Save and Publish method, the content should be saved even though the publish fails or isn't allowed
if (content.HasIdentity == false)
{
@@ -2119,6 +2130,22 @@ namespace Umbraco.Core.Services
content.Name, content.Id));
return PublishStatusType.FailedPathNotPublished;
}
else if (content.ExpireDate.HasValue && content.ExpireDate.Value > DateTime.MinValue && DateTime.Now > content.ExpireDate.Value)
{
Logger.Info<ContentService>(
string.Format(
"Content '{0}' with Id '{1}' has expired and could not be published.",
content.Name, content.Id));
return PublishStatusType.FailedHasExpired;
}
else if (content.ReleaseDate.HasValue && content.ReleaseDate.Value > DateTime.MinValue && content.ReleaseDate.Value > DateTime.Now)
{
Logger.Info<ContentService>(
string.Format(
"Content '{0}' with Id '{1}' is awaiting release and could not be published.",
content.Name, content.Id));
return PublishStatusType.FailedAwaitingRelease;
}
return PublishStatusType.Success;
}
@@ -158,10 +158,7 @@ namespace Umbraco.Core.Services
{
using (var repository = RepositoryFactory.CreateContentTypeRepository(UowProvider.GetUnitOfWork()))
{
var query = Query<IContentType>.Builder.Where(x => x.Alias == alias);
var contentTypes = repository.GetByQuery(query);
return contentTypes.FirstOrDefault();
return repository.Get(alias);
}
}
@@ -455,6 +452,13 @@ namespace Umbraco.Core.Services
using (new WriteLock(Locker))
{
//TODO: This needs to change, if we are deleting a content type, we should just delete the data,
// this method will recursively go lookup every content item, check if any of it's descendants are
// of a different type, move them to the recycle bin, then permanently delete the content items.
// The main problem with this is that for every content item being deleted, events are raised...
// which we need for many things like keeping caches in sync, but we can surely do this MUCH better.
_contentService.DeleteContentOfType(contentType.Id);
var uow = UowProvider.GetUnitOfWork();
@@ -531,10 +535,7 @@ namespace Umbraco.Core.Services
{
using (var repository = RepositoryFactory.CreateMediaTypeRepository(UowProvider.GetUnitOfWork()))
{
var query = Query<IMediaType>.Builder.Where(x => x.Alias == alias);
var contentTypes = repository.GetByQuery(query);
return contentTypes.FirstOrDefault();
return repository.Get(alias);
}
}
@@ -379,6 +379,7 @@ namespace Umbraco.Core.Services
new XElement("Type", propertyType.PropertyEditorAlias),
new XElement("Definition", definition.Key),
new XElement("Tab", propertyGroup == null ? "" : propertyGroup.Name),
new XElement("SortOrder", propertyType.SortOrder),
new XElement("Mandatory", propertyType.Mandatory.ToString()),
new XElement("Validation", propertyType.ValidationRegExp),
new XElement("Description", new XCData(propertyType.Description)));
+5
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Messaging;
@@ -371,6 +372,8 @@ namespace Umbraco.Core.Services
/// </summary>
/// <param name="alias"></param>
/// <returns></returns>
[Obsolete("Use GetDescendants instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public TemplateNode GetTemplateNode(string alias)
{
using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork()))
@@ -385,6 +388,8 @@ namespace Umbraco.Core.Services
/// <param name="anyNode"></param>
/// <param name="alias"></param>
/// <returns></returns>
[Obsolete("Use GetDescendants instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public TemplateNode FindTemplateInTree(TemplateNode anyNode, string alias)
{
using (var repository = _repositoryFactory.CreateTemplateRepository(_dataUowProvider.GetUnitOfWork()))
@@ -94,6 +94,9 @@ namespace Umbraco.Core.Services
repository.AddOrUpdate(item);
uow.Commit();
//ensure the lazy Language callback is assigned
EnsureDictionaryItemLanguageCallback(item);
SavedDictionaryItem.RaiseEvent(new SaveEventArgs<IDictionaryItem>(item), this);
return item;
@@ -109,7 +112,10 @@ namespace Umbraco.Core.Services
{
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
{
return repository.Get(id);
var item = repository.Get(id);
//ensure the lazy Language callback is assigned
EnsureDictionaryItemLanguageCallback(item);
return item;
}
}
@@ -122,7 +128,10 @@ namespace Umbraco.Core.Services
{
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
{
return repository.Get(id);
var item = repository.Get(id);
//ensure the lazy Language callback is assigned
EnsureDictionaryItemLanguageCallback(item);
return item;
}
}
@@ -135,7 +144,10 @@ namespace Umbraco.Core.Services
{
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
{
return repository.Get(key);
var item = repository.Get(key);
//ensure the lazy Language callback is assigned
EnsureDictionaryItemLanguageCallback(item);
return item;
}
}
@@ -149,8 +161,9 @@ namespace Umbraco.Core.Services
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
{
var query = Query<IDictionaryItem>.Builder.Where(x => x.ParentId == parentId);
var items = repository.GetByQuery(query);
var items = repository.GetByQuery(query).ToArray();
//ensure the lazy Language callback is assigned
items.ForEach(EnsureDictionaryItemLanguageCallback);
return items;
}
}
@@ -164,7 +177,10 @@ namespace Umbraco.Core.Services
{
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
{
return repository.GetDictionaryItemDescendants(parentId);
var items = repository.GetDictionaryItemDescendants(parentId).ToArray();
//ensure the lazy Language callback is assigned
items.ForEach(EnsureDictionaryItemLanguageCallback);
return items;
}
}
@@ -177,8 +193,9 @@ namespace Umbraco.Core.Services
using (var repository = RepositoryFactory.CreateDictionaryRepository(UowProvider.GetUnitOfWork()))
{
var query = Query<IDictionaryItem>.Builder.Where(x => x.ParentId == null);
var items = repository.GetByQuery(query);
var items = repository.GetByQuery(query).ToArray();
//ensure the lazy Language callback is assigned
items.ForEach(EnsureDictionaryItemLanguageCallback);
return items;
}
}
@@ -211,6 +228,8 @@ namespace Umbraco.Core.Services
{
repository.AddOrUpdate(dictionaryItem);
uow.Commit();
//ensure the lazy Language callback is assigned
EnsureDictionaryItemLanguageCallback(dictionaryItem);
}
SavedDictionaryItem.RaiseEvent(new SaveEventArgs<IDictionaryItem>(dictionaryItem, false), this);
@@ -265,10 +284,6 @@ namespace Umbraco.Core.Services
using (var repository = RepositoryFactory.CreateLanguageRepository(UowProvider.GetUnitOfWork()))
{
return repository.GetByCultureName(cultureName);
//var query = Query<ILanguage>.Builder.Where(x => x.CultureName == cultureName);
//var items = repository.GetByQuery(query);
//return items.FirstOrDefault();
}
}
@@ -282,10 +297,6 @@ namespace Umbraco.Core.Services
using (var repository = RepositoryFactory.CreateLanguageRepository(UowProvider.GetUnitOfWork()))
{
return repository.GetByIsoCode(isoCode);
//var query = Query<ILanguage>.Builder.Where(x => x.IsoCode == isoCode);
//var items = repository.GetByQuery(query);
//return items.FirstOrDefault();
}
}
@@ -357,6 +368,24 @@ namespace Umbraco.Core.Services
}
}
/// <summary>
/// This is here to take care of a hack - the DictionaryTranslation model contains an ILanguage reference which we don't want but
/// we cannot remove it because it would be a large breaking change, so we need to make sure it's resolved lazily. This is because
/// if developers have a lot of dictionary items and translations, the caching and cloning size gets much much larger because of
/// the large object graphs. So now we don't cache or clone the attached ILanguage
/// </summary>
private void EnsureDictionaryItemLanguageCallback(IDictionaryItem d)
{
var item = d as DictionaryItem;
if (item == null) return;
item.GetLanguage = GetLanguageById;
foreach (var trans in item.Translations.OfType<DictionaryTranslation>())
{
trans.GetLanguage = GetLanguageById;
}
}
#region Event Handlers
/// <summary>
/// Occurs before Delete
@@ -112,19 +112,15 @@ namespace Umbraco.Core.Services
}
//convert all areas + keys to a single key with a '/'
var areas = xmlSource[culture].Value.XPathSelectElements("//area");
foreach (var area in areas)
result = GetStoredTranslations(xmlSource, culture);
//merge with the english file in case there's keys in there that don't exist in the local file
var englishCulture = new CultureInfo("en-US");
if (culture.Equals(englishCulture) == false)
{
var keys = area.XPathSelectElements("./key");
foreach (var key in keys)
{
var dictionaryKey = string.Format("{0}/{1}", (string) area.Attribute("alias"), (string) key.Attribute("alias"));
//there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files
if (result.ContainsKey(dictionaryKey) == false)
{
result.Add(dictionaryKey, key.Value);
}
}
var englishResults = GetStoredTranslations(xmlSource, englishCulture);
foreach (var englishResult in englishResults.Where(englishResult => result.ContainsKey(englishResult.Key) == false))
result.Add(englishResult.Key, englishResult.Value);
}
}
else
@@ -153,6 +149,25 @@ namespace Umbraco.Core.Services
return result;
}
private Dictionary<string, string> GetStoredTranslations(IDictionary<CultureInfo, Lazy<XDocument>> xmlSource, CultureInfo cult)
{
var result = new Dictionary<string, string>();
var areas = xmlSource[cult].Value.XPathSelectElements("//area");
foreach (var area in areas)
{
var keys = area.XPathSelectElements("./key");
foreach (var key in keys)
{
var dictionaryKey = string.Format("{0}/{1}", (string)area.Attribute("alias"),
(string)key.Attribute("alias"));
//there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files
if (result.ContainsKey(dictionaryKey) == false)
result.Add(dictionaryKey, key.Value);
}
}
return result;
}
/// <summary>
/// Returns a list of all currently supported cultures
/// </summary>
@@ -254,23 +269,35 @@ namespace Umbraco.Core.Services
return "[" + key + "]";
}
var cultureSource = xmlSource[culture].Value;
var xpath = area.IsNullOrWhiteSpace()
? string.Format("//key [@alias = '{0}']", key)
: string.Format("//area [@alias = '{0}']/key [@alias = '{1}']", area, key);
var found = cultureSource.XPathSelectElement(xpath);
var found = FindTranslation(xmlSource, culture, area, key);
if (found != null)
{
return ParseTokens(found.Value, tokens);
}
// Fall back to English by default if we can't find the key
found = FindTranslation(xmlSource, new CultureInfo("en-US"), area, key);
if (found != null)
return ParseTokens(found.Value, tokens);
//NOTE: Based on how legacy works, the default text does not contain the area, just the key
// If it can't be found in either file, fall back to the default, showing just the key in square brackets
// NOTE: Based on how legacy works, the default text does not contain the area, just the key
return "[" + key + "]";
}
private XElement FindTranslation(IDictionary<CultureInfo, Lazy<XDocument>> xmlSource, CultureInfo culture, string area, string key)
{
var cultureSource = xmlSource[culture].Value;
var xpath = area.IsNullOrWhiteSpace()
? string.Format("//key [@alias = '{0}']", key)
: string.Format("//area [@alias = '{0}']/key [@alias = '{1}']", area, key);
var found = cultureSource.XPathSelectElement(xpath);
return found;
}
/// <summary>
/// Parses the tokens in the value
/// </summary>
@@ -2,10 +2,10 @@
using System.Globalization;
using System.Linq;
using System.Threading;
using Umbraco.Core.Dictionary;
namespace Umbraco.Core.Services
{
/// <summary>
/// Extension methods for ILocalizedTextService
/// </summary>
@@ -61,5 +61,43 @@ namespace Umbraco.Core.Services
return variables.Select((s, i) => new { index = i.ToString(CultureInfo.InvariantCulture), value = s })
.ToDictionary(keyvals => keyvals.index, keyvals => keyvals.value);
}
private static ICultureDictionary _cultureDictionary;
/// <summary>
/// TODO: We need to refactor how we work with ICultureDictionary - this is supposed to be the 'fast' way to
/// do readonly access to the Dictionary without using the ILocalizationService. See TODO Notes in `DefaultCultureDictionary`
/// Also NOTE that the ICultureDictionary is based on the ILocalizationService not the ILocalizedTextService (which is used
/// only for the localization files - not the dictionary)
/// </summary>
/// <param name="manager"></param>
/// <param name="text"></param>
/// <returns></returns>
internal static string UmbracoDictionaryTranslate(this ILocalizedTextService manager, string text)
{
var cultureDictionary = CultureDictionary;
return UmbracoDictionaryTranslate(text, cultureDictionary);
}
private static string UmbracoDictionaryTranslate(string text, ICultureDictionary cultureDictionary)
{
if (text == null)
return null;
if (text.StartsWith("#") == false)
return text;
text = text.Substring(1);
return cultureDictionary[text].IfNullOrWhiteSpace(text);
}
private static ICultureDictionary CultureDictionary
{
get
{
return _cultureDictionary
?? (_cultureDictionary = CultureDictionaryFactoryResolver.Current.Factory.CreateDictionary());
}
}
}
}
+1 -1
View File
@@ -111,7 +111,7 @@ namespace Umbraco.Core.Services
member.RawPasswordValue = result.RawPasswordValue;
member.LastPasswordChangeDate = result.LastPasswordChangeDate;
member.UpdateDate = member.UpdateDate;
member.UpdateDate = result.UpdateDate;
}
/// <summary>
@@ -69,10 +69,7 @@ namespace Umbraco.Core.Services
{
using (var repository = RepositoryFactory.CreateMemberTypeRepository(UowProvider.GetUnitOfWork()))
{
var query = Query<IMemberType>.Builder.Where(x => x.Alias == alias);
var contentTypes = repository.GetByQuery(query);
return contentTypes.FirstOrDefault();
return repository.Get(alias);
}
}
@@ -652,12 +652,17 @@ namespace Umbraco.Core.Services
if (dataTypeDefinition == null) continue;
}
var sortOrder = 0;
var sortOrderElement = property.Element("SortOrder");
if (sortOrderElement != null)
int.TryParse(sortOrderElement.Value, out sortOrder);
var propertyType = new PropertyType(dataTypeDefinition, property.Element("Alias").Value)
{
Name = property.Element("Name").Value,
Description = property.Element("Description").Value,
Mandatory = property.Element("Mandatory").Value.ToLowerInvariant().Equals("true"),
ValidationRegExp = property.Element("Validation").Value,
SortOrder = sortOrder
};
var tab = property.Element("Tab").Value;
+1 -1
View File
@@ -171,7 +171,7 @@ namespace Umbraco.Core.Services
//remove the cache so it gets re-read ... SD: I'm leaving this here even though it
// is taken care of by events as well, I think unit tests may rely on it being cleared here.
_cache.ClearCacheItem(CacheKeys.ApplicationsCacheKey);
_cache.RuntimeCache.ClearCacheItem(CacheKeys.ApplicationsCacheKey);
}
}
}
@@ -286,6 +286,7 @@ namespace Umbraco.Core.Services
_entityService = new Lazy<IEntityService>(() => new EntityService(
provider, repositoryFactory, logger, eventMessagesFactory,
_contentService.Value, _contentTypeService.Value, _mediaService.Value, _dataTypeService.Value, _memberService.Value, _memberTypeService.Value,
//TODO: Consider making this an isolated cache instead of using the global one
cache.RuntimeCache));
if (_relationService == null)
+1 -1
View File
@@ -266,7 +266,7 @@ namespace Umbraco.Core.Services
//should never be null but it could have been deleted by another thread.
user.RawPasswordValue = result.RawPasswordValue;
user.LastPasswordChangeDate = result.LastPasswordChangeDate;
user.UpdateDate = user.UpdateDate;
user.UpdateDate = result.UpdateDate;
}
}
@@ -14,6 +14,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Models.Rdbms;
using Umbraco.Core.Persistence;
using umbraco.interfaces;
using Umbraco.Core.Persistence.SqlSyntax;
namespace Umbraco.Core.Sync
{
@@ -59,7 +60,7 @@ namespace Umbraco.Core.Sync
protected override bool RequiresDistributed(IEnumerable<IServerAddress> servers, ICacheRefresher refresher, MessageType dispatchType)
{
// we don't care if there's servers listed or not,
// we don't care if there's servers listed or not,
// if distributed call is enabled we will make the call
return _initialized && DistributedEnabled;
}
@@ -138,12 +139,35 @@ namespace Umbraco.Core.Sync
{
if (_released) return;
var coldboot = false;
if (_lastId < 0) // never synced before
{
// we haven't synced - in this case we aren't going to sync the whole thing, we will assume this is a new
// we haven't synced - in this case we aren't going to sync the whole thing, we will assume this is a new
// server and it will need to rebuild it's own caches, eg Lucene or the xml cache file.
_logger.Warn<DatabaseServerMessenger>("No last synced Id found, this generally means this is a new server/install. The server will rebuild its caches and indexes and then adjust it's last synced id to the latest found in the database and will start maintaining cache updates based on that id");
_logger.Warn<DatabaseServerMessenger>("No last synced Id found, this generally means this is a new server/install."
+ " The server will build its caches and indexes, and then adjust its last synced Id to the latest found in"
+ " the database and maintain cache updates based on that Id.");
coldboot = true;
}
else
{
//check for how many instructions there are to process
var count = _appContext.DatabaseContext.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM umbracoCacheInstruction WHERE id > @lastId", new {lastId = _lastId});
if (count > _options.MaxProcessingInstructionCount)
{
//too many instructions, proceed to cold boot
_logger.Warn<DatabaseServerMessenger>("The instruction count ({0}) exceeds the specified MaxProcessingInstructionCount ({1})."
+ " The server will skip existing instructions, rebuild its caches and indexes entirely, adjust its last synced Id"
+ " to the latest found in the database and maintain cache updates based on that Id.",
() => count, () => _options.MaxProcessingInstructionCount);
coldboot = true;
}
}
if (coldboot)
{
// go get the last id in the db and store it
// note: do it BEFORE initializing otherwise some instructions might get lost
// when doing it before, some instructions might run twice - not an issue
@@ -168,7 +192,7 @@ namespace Umbraco.Core.Sync
{
lock (_locko)
{
if (_syncing)
if (_syncing)
return;
if (_released)
@@ -212,9 +236,9 @@ namespace Umbraco.Core.Sync
private void ProcessDatabaseInstructions()
{
// NOTE
// we 'could' recurse to ensure that no remaining instructions are pending in the table before proceeding but I don't think that
// we 'could' recurse to ensure that no remaining instructions are pending in the table before proceeding but I don't think that
// would be a good idea since instructions could keep getting added and then all other threads will probably get stuck from serving requests
// (depending on what the cache refreshers are doing). I think it's best we do the one time check, process them and continue, if there are
// (depending on what the cache refreshers are doing). I think it's best we do the one time check, process them and continue, if there are
// pending requests after being processed, they'll just be processed on the next poll.
//
// FIXME not true if we're running on a background thread, assuming we can?
@@ -277,12 +301,42 @@ namespace Umbraco.Core.Sync
}
/// <summary>
/// Remove old instructions from the database.
/// Remove old instructions from the database
/// </summary>
/// <remarks>
/// Always leave the last (most recent) record in the db table, this is so that not all instructions are removed which would cause
/// the site to cold boot if there's been no instruction activity for more than DaysToRetainInstructions.
/// See: http://issues.umbraco.org/issue/U4-7643#comment=67-25085
/// </remarks>
private void PruneOldInstructions()
{
_appContext.DatabaseContext.Database.Delete<CacheInstructionDto>("WHERE utcStamp < @pruneDate",
new { pruneDate = DateTime.UtcNow.AddDays(-_options.DaysToRetainInstructions) });
var pruneDate = DateTime.UtcNow.AddDays(-_options.DaysToRetainInstructions);
var sqlSyntax = _appContext.DatabaseContext.SqlSyntax;
//NOTE: this query could work on SQL server and MySQL:
/*
SELECT id
FROM umbracoCacheInstruction
WHERE utcStamp < getdate()
AND id <> (SELECT MAX(id) FROM umbracoCacheInstruction)
*/
// However, this will not work on SQLCE and in fact it will be slower than the query we are
// using if the SQL server doesn't perform it's own query optimizations (i.e. since the above
// query could actually execute a sub query for every row found). So we've had to go with an
// inner join which is faster and works on SQLCE but it's uglier to read.
var deleteQuery = new Sql().Select("cacheIns.id")
.From("umbracoCacheInstruction cacheIns")
.InnerJoin("(SELECT MAX(id) id FROM umbracoCacheInstruction) tMax")
.On("cacheIns.id <> tMax.id")
.Where("cacheIns.utcStamp < @pruneDate", new {pruneDate = pruneDate});
var deleteSql = sqlSyntax.GetDeleteSubquery(
"umbracoCacheInstruction",
"id",
deleteQuery);
_appContext.DatabaseContext.Database.Execute(deleteSql);
}
/// <summary>
@@ -298,10 +352,11 @@ namespace Umbraco.Core.Sync
.Where<CacheInstructionDto>(dto => dto.Id == _lastId);
var dtos = _appContext.DatabaseContext.Database.Fetch<CacheInstructionDto>(sql);
if (dtos.Count == 0)
_lastId = -1;
}
/// <summary>
/// Reads the last-synced id from file into memory.
/// </summary>
@@ -469,4 +524,4 @@ namespace Umbraco.Core.Sync
#endregion
}
}
}
@@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
namespace Umbraco.Core.Sync
{
{
/// <summary>
/// Provides options to the <see cref="DatabaseServerMessenger"/>.
/// </summary>
@@ -14,9 +14,15 @@ namespace Umbraco.Core.Sync
public DatabaseServerMessengerOptions()
{
DaysToRetainInstructions = 2; // 2 days
ThrottleSeconds = 5; // 5 seconds
ThrottleSeconds = 5; // 5 second
MaxProcessingInstructionCount = 1000;
}
/// <summary>
/// The maximum number of instructions that can be processed at startup; otherwise the server cold-boots (rebuilds its caches).
/// </summary>
public int MaxProcessingInstructionCount { get; set; }
/// <summary>
/// A list of callbacks that will be invoked if the lastsynced.txt file does not exist.
/// </summary>
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
namespace Umbraco.Core.Sync
{
@@ -14,13 +15,18 @@ namespace Umbraco.Core.Sync
{
StaleServerTimeout = TimeSpan.FromMinutes(2); // 2 minutes
ThrottleSeconds = 30; // 30 seconds
RecurringSeconds = 60; // do it every minute
}
/// <summary>
/// The number of seconds to wait between each updates to the database.
/// </summary>
[Obsolete("This is no longer used")]
[EditorBrowsable(EditorBrowsableState.Never)]
public int ThrottleSeconds { get; set; }
/// <summary>
/// The amount of seconds to wait between calls to the database on the background thread
/// </summary>
public int RecurringSeconds { get; set; }
/// <summary>
/// The time span to wait before considering a server stale, after it has last been accessed.
/// </summary>
+13 -2
View File
@@ -156,19 +156,29 @@
<Compile Include="CacheHelper.cs" />
<Compile Include="Cache\CacheKeys.cs" />
<Compile Include="Cache\CacheProviderExtensions.cs" />
<Compile Include="Cache\DefaultRepositoryCachePolicy.cs" />
<Compile Include="Cache\DefaultRepositoryCachePolicyFactory.cs" />
<Compile Include="Cache\FullDataSetRepositoryCachePolicy.cs" />
<Compile Include="Cache\FullDataSetRepositoryCachePolicyFactory.cs" />
<Compile Include="Cache\ICacheProvider.cs" />
<Compile Include="Cache\CacheRefresherBase.cs" />
<Compile Include="Cache\CacheRefresherEventArgs.cs" />
<Compile Include="Cache\DictionaryCacheProviderBase.cs" />
<Compile Include="Cache\HttpRequestCacheProvider.cs" />
<Compile Include="Cache\IRepositoryCachePolicy.cs" />
<Compile Include="Cache\IPayloadCacheRefresher.cs" />
<Compile Include="Cache\IRepositoryCachePolicyFactory.cs" />
<Compile Include="Cache\IsolatedRuntimeCache.cs" />
<Compile Include="Cache\ObjectCacheRuntimeCacheProvider.cs" />
<Compile Include="Cache\IRuntimeCacheProvider.cs" />
<Compile Include="Cache\HttpRuntimeCacheProvider.cs" />
<Compile Include="Cache\IJsonCacheRefresher.cs" />
<Compile Include="Cache\JsonCacheRefresherBase.cs" />
<Compile Include="Cache\NullCacheProvider.cs" />
<Compile Include="Cache\SingleItemsOnlyRepositoryCachePolicy.cs" />
<Compile Include="Cache\OnlySingleItemsRepositoryCachePolicyFactory.cs" />
<Compile Include="Cache\PayloadCacheRefresherBase.cs" />
<Compile Include="Cache\RepositoryCachePolicyOptions.cs" />
<Compile Include="Cache\StaticCacheProvider.cs" />
<Compile Include="Cache\TypedCacheRefresherBase.cs" />
<Compile Include="CodeAnnotations\FriendlyNameAttribute.cs" />
@@ -176,6 +186,7 @@
<Compile Include="CodeAnnotations\UmbracoWillObsoleteAttribute.cs" />
<Compile Include="CodeAnnotations\UmbracoExperimentalFeatureAttribute.cs" />
<Compile Include="CodeAnnotations\UmbracoProposedPublicAttribute.cs" />
<Compile Include="Collections\DeepCloneableList.cs" />
<Compile Include="ConcurrentHashSet.cs" />
<Compile Include="Configuration\BaseRest\IBaseRestSection.cs" />
<Compile Include="Configuration\BaseRest\IExtension.cs" />
@@ -441,10 +452,11 @@
<Compile Include="Persistence\RecordPersistenceType.cs" />
<Compile Include="Persistence\Relators\AccessRulesRelator.cs" />
<Compile Include="Persistence\Repositories\AuditRepository.cs" />
<Compile Include="Persistence\Repositories\DeepCloneRuntimeCacheProvider.cs" />
<Compile Include="Cache\DeepCloneRuntimeCacheProvider.cs" />
<Compile Include="Persistence\Repositories\DomainRepository.cs" />
<Compile Include="Persistence\Repositories\ExternalLoginRepository.cs" />
<Compile Include="Persistence\Repositories\Interfaces\IAuditRepository.cs" />
<Compile Include="Persistence\Repositories\Interfaces\IContentTypeCompositionRepository.cs" />
<Compile Include="Persistence\Repositories\Interfaces\IDomainRepository.cs" />
<Compile Include="Persistence\Repositories\Interfaces\IExternalLoginRepository.cs" />
<Compile Include="Persistence\Repositories\Interfaces\IMigrationEntryRepository.cs" />
@@ -455,7 +467,6 @@
<Compile Include="Persistence\Repositories\Interfaces\ITaskTypeRepository.cs" />
<Compile Include="Persistence\Repositories\MigrationEntryRepository.cs" />
<Compile Include="Persistence\Repositories\PublicAccessRepository.cs" />
<Compile Include="Persistence\Repositories\RepositoryCacheOptions.cs" />
<Compile Include="Persistence\Repositories\TaskRepository.cs" />
<Compile Include="Persistence\Repositories\TaskTypeRepository.cs" />
<Compile Include="PropertyEditors\ValueConverters\GridValueConverter.cs" />
@@ -4,9 +4,11 @@ using System.Web;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Collections;
using Umbraco.Core.Models;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Tests.Collections;
namespace Umbraco.Tests.Cache
{
@@ -36,6 +38,23 @@ namespace Umbraco.Tests.Cache
get { return _provider; }
}
[Test]
public void Clones_List()
{
var original = new DeepCloneableList<DeepCloneableListTests.TestClone>();
original.Add(new DeepCloneableListTests.TestClone());
original.Add(new DeepCloneableListTests.TestClone());
original.Add(new DeepCloneableListTests.TestClone());
var val = _provider.GetCacheItem<DeepCloneableList<DeepCloneableListTests.TestClone>>("test", () => original);
Assert.AreEqual(original.Count, val.Count);
foreach (var item in val)
{
Assert.IsTrue(item.IsClone);
}
}
[Test]
public void Ensures_Cloned_And_Reset()
{
@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using System.Web.Caching;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class DefaultCachePolicyTests
{
[Test]
public void Caches_Single()
{
var isCached = false;
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.InsertCacheItem(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback(() =>
{
isCached = true;
});
var defaultPolicy = new DefaultRepositoryCachePolicy<AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions());
using (defaultPolicy)
{
var found = defaultPolicy.Get(1, o => new AuditItem(1, "blah", AuditType.Copy, 123));
}
Assert.IsTrue(isCached);
}
[Test]
public void Get_Single_From_Cache()
{
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.GetCacheItem(It.IsAny<string>())).Returns(new AuditItem(1, "blah", AuditType.Copy, 123));
var defaultPolicy = new DefaultRepositoryCachePolicy<AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions());
using (defaultPolicy)
{
var found = defaultPolicy.Get(1, o => (AuditItem) null);
Assert.IsNotNull(found);
}
}
[Test]
public void Caches_Per_Id_For_Get_All()
{
var cached = new List<string>();
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.InsertCacheItem(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) =>
{
cached.Add(cacheKey);
});
cache.Setup(x => x.GetCacheItemsByKeySearch(It.IsAny<string>())).Returns(new AuditItem[] {});
var defaultPolicy = new DefaultRepositoryCachePolicy<AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions());
using (defaultPolicy)
{
var found = defaultPolicy.GetAll(new object[] {}, o => new[]
{
new AuditItem(1, "blah", AuditType.Copy, 123),
new AuditItem(2, "blah2", AuditType.Copy, 123)
});
}
Assert.AreEqual(2, cached.Count);
}
[Test]
public void Get_All_Without_Ids_From_Cache()
{
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.GetCacheItemsByKeySearch(It.IsAny<string>())).Returns(new[]
{
new AuditItem(1, "blah", AuditType.Copy, 123),
new AuditItem(2, "blah2", AuditType.Copy, 123)
});
var defaultPolicy = new DefaultRepositoryCachePolicy<AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions());
using (defaultPolicy)
{
var found = defaultPolicy.GetAll(new object[] {}, o => new[] {(AuditItem) null});
Assert.AreEqual(2, found.Length);
}
}
[Test]
public void If_CreateOrUpdate_Throws_Cache_Is_Removed()
{
var cacheCleared = false;
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.ClearCacheItem(It.IsAny<string>()))
.Callback(() =>
{
cacheCleared = true;
});
var defaultPolicy = new DefaultRepositoryCachePolicy<AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions());
try
{
using (defaultPolicy)
{
defaultPolicy.CreateOrUpdate(new AuditItem(1, "blah", AuditType.Copy, 123), item =>
{
throw new Exception("blah!");
});
}
}
catch
{
//we need this catch or nunit throw up
}
finally
{
Assert.IsTrue(cacheCleared);
}
}
}
}
@@ -0,0 +1,109 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.Caching;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Cache;
using Umbraco.Core.Collections;
using Umbraco.Core.Models;
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class FullDataSetCachePolicyTests
{
[Test]
public void Get_All_Caches_Empty_List()
{
var cached = new List<string>();
IList list = null;
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.InsertCacheItem(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) =>
{
cached.Add(cacheKey);
list = o() as IList;
});
cache.Setup(x => x.GetCacheItem(It.IsAny<string>())).Returns(() =>
{
//return null if this is the first pass
return cached.Any() ? new DeepCloneableList<AuditItem>() : null;
});
var defaultPolicy = new FullDataSetRepositoryCachePolicy<AuditItem, object>(cache.Object, item => item.Id);
using (defaultPolicy)
{
var found = defaultPolicy.GetAll(new object[] {}, o => new AuditItem[] {});
}
Assert.AreEqual(1, cached.Count);
Assert.IsNotNull(list);
//Do it again, ensure that its coming from the cache!
defaultPolicy = new FullDataSetRepositoryCachePolicy<AuditItem, object>(cache.Object, item => item.Id);
using (defaultPolicy)
{
var found = defaultPolicy.GetAll(new object[] { }, o => new AuditItem[] { });
}
Assert.AreEqual(1, cached.Count);
Assert.IsNotNull(list);
}
[Test]
public void Get_All_Caches_As_Single_List()
{
var cached = new List<string>();
IList list = null;
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.InsertCacheItem(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) =>
{
cached.Add(cacheKey);
list = o() as IList;
});
cache.Setup(x => x.GetCacheItem(It.IsAny<string>())).Returns(new AuditItem[] { });
var defaultPolicy = new FullDataSetRepositoryCachePolicy<AuditItem, object>(cache.Object, item => item.Id);
using (defaultPolicy)
{
var found = defaultPolicy.GetAll(new object[] { }, o => new[]
{
new AuditItem(1, "blah", AuditType.Copy, 123),
new AuditItem(2, "blah2", AuditType.Copy, 123)
});
}
Assert.AreEqual(1, cached.Count);
Assert.IsNotNull(list);
}
[Test]
public void Get_All_Without_Ids_From_Cache()
{
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.GetCacheItem(It.IsAny<string>())).Returns(() => new DeepCloneableList<AuditItem>
{
new AuditItem(1, "blah", AuditType.Copy, 123),
new AuditItem(2, "blah2", AuditType.Copy, 123)
});
var defaultPolicy = new FullDataSetRepositoryCachePolicy<AuditItem, object>(cache.Object, item => item.Id);
using (defaultPolicy)
{
var found = defaultPolicy.GetAll(new object[] { }, o => new[] { (AuditItem)null });
Assert.AreEqual(2, found.Length);
}
}
}
}
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Web.Caching;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
namespace Umbraco.Tests.Cache
{
[TestFixture]
public class SingleItemsOnlyCachePolicyTests
{
[Test]
public void Get_All_Doesnt_Cache()
{
var cached = new List<string>();
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.InsertCacheItem(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback((string cacheKey, Func<object> o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) =>
{
cached.Add(cacheKey);
});
cache.Setup(x => x.GetCacheItemsByKeySearch(It.IsAny<string>())).Returns(new AuditItem[] { });
var defaultPolicy = new SingleItemsOnlyRepositoryCachePolicy<AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions());
using (defaultPolicy)
{
var found = defaultPolicy.GetAll(new object[] { }, o => new[]
{
new AuditItem(1, "blah", AuditType.Copy, 123),
new AuditItem(2, "blah2", AuditType.Copy, 123)
});
}
Assert.AreEqual(0, cached.Count);
}
[Test]
public void Caches_Single()
{
var isCached = false;
var cache = new Mock<IRuntimeCacheProvider>();
cache.Setup(x => x.InsertCacheItem(It.IsAny<string>(), It.IsAny<Func<object>>(), It.IsAny<TimeSpan?>(), It.IsAny<bool>(),
It.IsAny<CacheItemPriority>(), It.IsAny<CacheItemRemovedCallback>(), It.IsAny<string[]>()))
.Callback(() =>
{
isCached = true;
});
var defaultPolicy = new SingleItemsOnlyRepositoryCachePolicy<AuditItem, object>(cache.Object, new RepositoryCachePolicyOptions());
using (defaultPolicy)
{
var found = defaultPolicy.Get(1, o => new AuditItem(1, "blah", AuditType.Copy, 123));
}
Assert.IsTrue(isCached);
}
}
}
@@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using Umbraco.Core.Collections;
using Umbraco.Core.Models;
namespace Umbraco.Tests.Collections
{
[TestFixture]
public class DeepCloneableListTests
{
[Test]
public void Deep_Clones_All_Elements()
{
var list = new DeepCloneableList<TestClone>();
list.Add(new TestClone());
list.Add(new TestClone());
list.Add(new TestClone());
var cloned = list.DeepClone() as DeepCloneableList<TestClone>;
Assert.IsNotNull(cloned);
Assert.AreNotSame(list, cloned);
Assert.AreEqual(list.Count, cloned.Count);
}
[Test]
public void Clones_Each_Item()
{
var list = new DeepCloneableList<TestClone>();
list.Add(new TestClone());
list.Add(new TestClone());
list.Add(new TestClone());
var cloned = (DeepCloneableList<TestClone>) list.DeepClone();
foreach (var item in cloned)
{
Assert.IsTrue(item.IsClone);
}
}
[Test]
public void Cloned_Sequence_Equals()
{
var list = new DeepCloneableList<TestClone>();
list.Add(new TestClone());
list.Add(new TestClone());
list.Add(new TestClone());
var cloned = (DeepCloneableList<TestClone>)list.DeepClone();
//Test that each item in the sequence is equal - based on the equality comparer of TestClone (i.e. it's ID)
Assert.IsTrue(list.SequenceEqual(cloned));
//Test that each instance in the list is not the same one
foreach (var item in list)
{
var clone = cloned.Single(x => x.Id == item.Id);
Assert.AreNotSame(item, clone);
}
}
public class TestClone : IDeepCloneable, IEquatable<TestClone>
{
public TestClone(Guid id)
{
Id = id;
IsClone = true;
}
public TestClone()
{
Id = Guid.NewGuid();
}
public Guid Id { get; private set; }
public bool IsClone { get; private set; }
public object DeepClone()
{
return new TestClone(Id);
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <returns>
/// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
public bool Equals(TestClone other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Id.Equals(other.Id);
}
/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <returns>
/// true if the specified object is equal to the current object; otherwise, false.
/// </returns>
/// <param name="obj">The object to compare with the current object. </param>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((TestClone)obj);
}
/// <summary>
/// Serves as the default hash function.
/// </summary>
/// <returns>
/// A hash code for the current object.
/// </returns>
public override int GetHashCode()
{
return Id.GetHashCode();
}
public static bool operator ==(TestClone left, TestClone right)
{
return Equals(left, right);
}
public static bool operator !=(TestClone left, TestClone right)
{
return Equals(left, right) == false;
}
}
}
}
@@ -223,6 +223,41 @@ namespace Umbraco.Tests.Macros
<p> </p>".Replace(Environment.NewLine, string.Empty), result.Replace(Environment.NewLine, string.Empty));
}
[Test]
public void Format_RTE_Data_For_Persistence_Multiline_Parameters()
{
var content = @"<html>
<body>
<h1>asdfasdf</h1>
<div class='umb-macro-holder mceNonEditable' att1='asdf' att2='asdfasdfasdf' att3=""sdfsdfd"">
<!-- <?UMBRACO_MACRO macroAlias=""myMacro"" param1=""test1"" param2=""test2
dfdsfds"" /> -->
asdfasdf
asdfas
<span>asdfasdfasdf</span>
<p>asdfasdf</p>
</div>
<span>asdfdasf</span>
<div>
asdfsdf
</div>
</body>
</html>";
var result = MacroTagParser.FormatRichTextContentForPersistence(content);
Assert.AreEqual(@"<html>
<body>
<h1>asdfasdf</h1>
<?UMBRACO_MACRO macroAlias=""myMacro"" param1=""test1"" param2=""test2
dfdsfds"" />
<span>asdfdasf</span>
<div>
asdfsdf
</div>
</body>
</html>".Replace(Environment.NewLine, string.Empty), result.Replace(Environment.NewLine, string.Empty));
}
[Test]
public void Format_RTE_Data_For_Editor_With_Params_Closing_Tag()
{
@@ -269,6 +304,28 @@ namespace Umbraco.Tests.Macros
<p>asdfasdf</p>".Replace(Environment.NewLine, string.Empty), result.Replace(Environment.NewLine, string.Empty));
}
[Test]
public void Format_RTE_Data_For_Editor_With_Multiline_Parameters()
{
var content = @"<p>asdfasdf</p>
<p>asdfsadf</p>
<?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2
test"" />
<p>asdfasdf</p>";
var result = MacroTagParser.FormatRichTextPersistedDataForEditor(content, new Dictionary<string, string>() { { "test1", "value1" }, { "test2", "value2\r\ntest" } });
Assert.AreEqual(@"<p>asdfasdf</p>
<p>asdfsadf</p>
<div class=""umb-macro-holder mceNonEditable"" test1=""value1"" test2=""value2
test"">
<!-- <?UMBRACO_MACRO macroAlias=""Map"" test1=""value1"" test2=""value2
test"" /> -->
<ins>Macro alias: <strong>Map</strong></ins></div>
<p>asdfasdf</p>".Replace(Environment.NewLine, string.Empty), result.Replace(Environment.NewLine, string.Empty));
}
[Test]
public void Format_RTE_Data_For_Persistence()
{
+7 -6
View File
@@ -27,7 +27,8 @@ namespace Umbraco.Tests.Macros
var cacheHelper = new CacheHelper(
new ObjectCacheRuntimeCacheProvider(),
new StaticCacheProvider(),
new NullCacheProvider());
new NullCacheProvider(),
new IsolatedRuntimeCache(type => new ObjectCacheRuntimeCacheProvider()));
ApplicationContext.Current = new ApplicationContext(cacheHelper, new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>()));
UmbracoConfig.For.SetUmbracoSettings(SettingsForTests.GetDefault());
@@ -36,7 +37,7 @@ namespace Umbraco.Tests.Macros
[TearDown]
public void TearDown()
{
ApplicationContext.Current.ApplicationCache.ClearAllCache();
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearAllCache();
ApplicationContext.Current.DisposeIfDisposable();
ApplicationContext.Current = null;
}
@@ -136,11 +137,11 @@ namespace Umbraco.Tests.Macros
public void Macro_Needs_Removing_Based_On_Macro_File(int minutesToNow, bool expectedResult)
{
var now = DateTime.Now;
ApplicationContext.Current.ApplicationCache.InsertCacheItem(
ApplicationContext.Current.ApplicationCache.RuntimeCache.InsertCacheItem(
"TestDate",
CacheItemPriority.NotRemovable,
new TimeSpan(0, 0, 60),
() => now.AddMinutes(minutesToNow)); //add a datetime value of 'now' with the minutes offset
priority: CacheItemPriority.NotRemovable,
timeout: new TimeSpan(0, 0, 60),
getCacheItem: () => now.AddMinutes(minutesToNow)); //add a datetime value of 'now' with the minutes offset
//now we need to update a file's date to 'now' to compare
var path = Path.Combine(TestHelpers.TestHelper.CurrentAssemblyDirectory, "temp.txt");
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Serialization;
@@ -36,12 +37,15 @@ namespace Umbraco.Tests.Models
Assert.AreEqual(clone.Key, item.Key);
Assert.AreEqual(clone.UpdateDate, item.UpdateDate);
Assert.AreNotSame(clone.Language, item.Language);
Assert.AreEqual(clone.Language, item.Language);
//This is null because we are ignoring it from cloning due to caching/cloning issues - we don't really want
// this entity attached to this item but we're stuck with it for now
Assert.IsNull(clone.Language);
Assert.AreEqual(clone.LanguageId, item.LanguageId);
Assert.AreEqual(clone.Value, item.Value);
//This double verifies by reflection
var allProps = clone.GetType().GetProperties();
foreach (var propertyInfo in allProps)
foreach (var propertyInfo in allProps.Where(x => x.Name != "Language"))
{
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
}
@@ -55,10 +55,11 @@ namespace Umbraco.Tests.Persistence.Querying
transaction.Complete();
}
IDictionary<int, IEnumerable<ContentTypeRepository.ContentTypeQueryMapper.AssociatedTemplate>> allAssociatedTemplates;
IDictionary<int, IEnumerable<int>> allParentContentTypeIds;
IDictionary<int, List<ContentTypeRepository.ContentTypeQueryMapper.AssociatedTemplate>> allAssociatedTemplates;
IDictionary<int, List<int>> allParentContentTypeIds;
var contentTypes = ContentTypeRepository.ContentTypeQueryMapper.MapContentTypes(
new[] {99997, 99998}, DatabaseContext.Database, SqlSyntax, out allAssociatedTemplates, out allParentContentTypeIds)
DatabaseContext.Database, SqlSyntax, out allAssociatedTemplates, out allParentContentTypeIds)
.Where(x => (new[] {99997, 99998}).Contains(x.Id))
.ToArray();
var contentType1 = contentTypes.SingleOrDefault(x => x.Id == 99997);
@@ -109,9 +110,10 @@ namespace Umbraco.Tests.Persistence.Querying
transaction.Complete();
}
IDictionary<int, IEnumerable<int>> allParentContentTypeIds;
IDictionary<int, List<int>> allParentContentTypeIds;
var contentTypes = ContentTypeRepository.ContentTypeQueryMapper.MapMediaTypes(
new[] { 99997, 99998 }, DatabaseContext.Database, SqlSyntax, out allParentContentTypeIds)
DatabaseContext.Database, SqlSyntax, out allParentContentTypeIds)
.Where(x => (new[] { 99997, 99998 }).Contains(x.Id))
.ToArray();
var contentType1 = contentTypes.SingleOrDefault(x => x.Id == 99997);
@@ -57,6 +57,58 @@ namespace Umbraco.Tests.Persistence.Repositories
return repository;
}
[Test]
public void Rebuild_Xml_Structures_With_Non_Latest_Version()
{
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
ContentTypeRepository contentTypeRepository;
using (var repository = CreateRepository(unitOfWork, out contentTypeRepository))
{
var contentType1 = MockedContentTypes.CreateSimpleContentType("Textpage1", "Textpage1");
contentTypeRepository.AddOrUpdate(contentType1);
var allCreated = new List<IContent>();
//create 100 non published
for (var i = 0; i < 100; i++)
{
var c1 = MockedContent.CreateSimpleContent(contentType1);
repository.AddOrUpdate(c1);
allCreated.Add(c1);
}
//create 100 published
for (var i = 0; i < 100; i++)
{
var c1 = MockedContent.CreateSimpleContent(contentType1);
c1.ChangePublishedState(PublishedState.Published);
repository.AddOrUpdate(c1);
allCreated.Add(c1);
}
unitOfWork.Commit();
//now create some versions of this content - this shouldn't affect the xml structures saved
for (int i = 0; i < allCreated.Count; i++)
{
allCreated[i].Name = "blah" + i;
//IMPORTANT testing note here: We need to changed the published state here so that
// it doesn't automatically think this is simply publishing again - this forces the latest
// version to be Saved and not published
allCreated[i].ChangePublishedState(PublishedState.Saved);
repository.AddOrUpdate(allCreated[i]);
}
unitOfWork.Commit();
//delete all xml
unitOfWork.Database.Execute("DELETE FROM cmsContentXml");
Assert.AreEqual(0, unitOfWork.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsContentXml"));
repository.RebuildXmlStructures(media => new XElement("test"), 10);
Assert.AreEqual(100, unitOfWork.Database.ExecuteScalar<int>("SELECT COUNT(*) FROM cmsContentXml"));
}
}
[Test]
public void Rebuild_All_Xml_Structures()
{
@@ -297,7 +297,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var allGuidIds = repository.GetAll().Select(x => x.Key).ToArray();
// Act
var contentTypes = repository.GetAll(allGuidIds);
var contentTypes = ((IReadRepository<Guid, IContentType>)repository).GetAll(allGuidIds);
int count =
DatabaseContext.Database.ExecuteScalar<int>(
"SELECT COUNT(*) FROM umbracoNode WHERE nodeObjectType = @NodeObjectType",
@@ -34,7 +34,6 @@ namespace Umbraco.Tests.Persistence.Repositories
{
var dataTypeDefinitionRepository = new DataTypeDefinitionRepository(
unitOfWork, CacheHelper.CreateDisabledCacheHelper(),
CacheHelper.CreateDisabledCacheHelper(),
Mock.Of<ILogger>(), SqlSyntax,
new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax,
new TemplateRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax, Mock.Of<IFileSystem>(), Mock.Of<IFileSystem>(), Mock.Of<ITemplatesSection>())));
@@ -376,10 +375,14 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
var cache = new CacheHelper(new ObjectCacheRuntimeCacheProvider(), new StaticCacheProvider(), new StaticCacheProvider());
var cache = new CacheHelper(
new ObjectCacheRuntimeCacheProvider(),
new StaticCacheProvider(),
new StaticCacheProvider(),
new IsolatedRuntimeCache(type => new ObjectCacheRuntimeCacheProvider()));
Func<DataTypeDefinitionRepository> creator = () => new DataTypeDefinitionRepository(
unitOfWork, CacheHelper.CreateDisabledCacheHelper(),
unitOfWork,
cache,
Mock.Of<ILogger>(), SqlSyntax,
new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax,
@@ -402,7 +405,8 @@ namespace Umbraco.Tests.Persistence.Repositories
var collection = repository.GetPreValuesCollectionByDataTypeId(dtd.Id);
}
var cached = cache.RuntimeCache.GetCacheItemsByKeySearch<PreValueCollection>(CacheKeys.DataTypePreValuesCacheKey + dtd.Id + "-");
var cached = cache.IsolatedRuntimeCache.GetCache<IDataTypeDefinition>().Result
.GetCacheItemsByKeySearch<PreValueCollection>(CacheKeys.DataTypePreValuesCacheKey + dtd.Id + "-");
Assert.IsNotNull(cached);
Assert.AreEqual(1, cached.Count());
@@ -415,10 +419,14 @@ namespace Umbraco.Tests.Persistence.Repositories
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
var cache = new CacheHelper(new ObjectCacheRuntimeCacheProvider(), new StaticCacheProvider(), new StaticCacheProvider());
var cache = new CacheHelper(
new ObjectCacheRuntimeCacheProvider(),
new StaticCacheProvider(),
new StaticCacheProvider(),
new IsolatedRuntimeCache(type => new ObjectCacheRuntimeCacheProvider()));
Func<DataTypeDefinitionRepository> creator = () => new DataTypeDefinitionRepository(
unitOfWork, CacheHelper.CreateDisabledCacheHelper(),
unitOfWork,
cache,
Mock.Of<ILogger>(), SqlSyntax,
new ContentTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax,
@@ -441,7 +449,8 @@ namespace Umbraco.Tests.Persistence.Repositories
var val = repository.GetPreValueAsString(Convert.ToInt32(id));
}
var cached = cache.RuntimeCache.GetCacheItemsByKeySearch<PreValueCollection>(CacheKeys.DataTypePreValuesCacheKey + dtd.Id + "-");
var cached = cache.IsolatedRuntimeCache.GetCache<IDataTypeDefinition>().Result
.GetCacheItemsByKeySearch<PreValueCollection>(CacheKeys.DataTypePreValuesCacheKey + dtd.Id + "-");
Assert.IsNotNull(cached);
Assert.AreEqual(1, cached.Count());
@@ -27,10 +27,9 @@ namespace Umbraco.Tests.Persistence.Repositories
CreateTestData();
}
private DictionaryRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out LanguageRepository languageRepository)
private DictionaryRepository CreateRepository(IDatabaseUnitOfWork unitOfWork)
{
languageRepository = new LanguageRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax);
var dictionaryRepository = new DictionaryRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), new SqlCeSyntaxProvider(), languageRepository);
var dictionaryRepository = new DictionaryRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), new SqlCeSyntaxProvider());
return dictionaryRepository;
}
@@ -41,8 +40,8 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
var dictionaryItem = (IDictionaryItem)new DictionaryItem("Testing1235")
{
@@ -74,8 +73,8 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
var dictionaryItem = (IDictionaryItem)new DictionaryItem("Testing1235")
{
@@ -107,8 +106,8 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
var dictionaryItem = (IDictionaryItem)new DictionaryItem("Testing1235")
{
@@ -141,8 +140,8 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
var dictionaryItem = (IDictionaryItem) new DictionaryItem("Testing1235");
@@ -168,8 +167,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
// Act
@@ -190,8 +188,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
// Act
@@ -211,8 +208,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
// Act
@@ -232,8 +228,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
// Act
@@ -251,8 +246,8 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var languageRepository = new LanguageRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax))
using (var repository = CreateRepository(unitOfWork))
{
var language = languageRepository.Get(1);
@@ -282,8 +277,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
// Act
@@ -310,8 +304,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
var languageRepository = new LanguageRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax);
var repository = new DictionaryRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), new SqlCeSyntaxProvider(), languageRepository);
var repository = new DictionaryRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), new SqlCeSyntaxProvider());
var languageNo = new Language("nb-NO") { CultureName = "nb-NO" };
ServiceContext.LocalizationService.Save(languageNo);
@@ -325,12 +318,12 @@ namespace Umbraco.Tests.Persistence.Repositories
repository.AddOrUpdate(item);
unitOfWork.Commit();
var dictionaryItem = repository.Get(1);
var dictionaryItem = (DictionaryItem)repository.Get(1);
// Assert
Assert.That(dictionaryItem, Is.Not.Null);
Assert.That(dictionaryItem.Translations.Count(), Is.EqualTo(3));
Assert.That(dictionaryItem.Translations.Single(t => t.Language.IsoCode == "nb-NO").Value, Is.EqualTo("Les mer"));
Assert.That(dictionaryItem.Translations.Single(t => t.LanguageId == languageNo.Id).Value, Is.EqualTo("Les mer"));
}
[Test]
@@ -339,8 +332,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
// Act
@@ -361,8 +353,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Arrange
var provider = new PetaPocoUnitOfWorkProvider(Logger);
var unitOfWork = provider.GetUnitOfWork();
LanguageRepository languageRepository;
using (var repository = CreateRepository(unitOfWork, out languageRepository))
using (var repository = CreateRepository(unitOfWork))
{
// Act
@@ -188,7 +188,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
var mediaTypes = repository.GetAll(allGuidIds);
var mediaTypes = ((IReadRepository<Guid, IMediaType>)repository).GetAll(allGuidIds);
int count =
DatabaseContext.Database.ExecuteScalar<int>(
@@ -37,7 +37,7 @@ namespace Umbraco.Tests.Persistence.Repositories
private MemberRepository CreateRepository(IDatabaseUnitOfWork unitOfWork, out MemberTypeRepository memberTypeRepository, out MemberGroupRepository memberGroupRepository)
{
memberTypeRepository = new MemberTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax);
memberGroupRepository = new MemberGroupRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax, CacheHelper.CreateDisabledCacheHelper());
memberGroupRepository = new MemberGroupRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax);
var tagRepo = new TagRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax);
var repository = new MemberRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Mock.Of<ILogger>(), SqlSyntax, memberTypeRepository, memberGroupRepository, tagRepo, Mock.Of<IContentSection>());
return repository;
@@ -115,7 +115,7 @@ namespace Umbraco.Tests.Persistence.Repositories
repository.AddOrUpdate(memberType2);
unitOfWork.Commit();
var result = repository.GetAll(memberType1.Key, memberType2.Key);
var result = ((IReadRepository<Guid, IMemberType>)repository).GetAll(memberType1.Key, memberType2.Key);
//there are 3 because of the Member type created for init data
Assert.AreEqual(2, result.Count());
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
@@ -11,6 +12,13 @@ namespace Umbraco.Tests.PropertyEditors
[TestFixture]
public class PropertyEditorValueEditorTests
{
[SetUp]
public void Setup()
{
//normalize culture
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
}
[TestCase("{prop1: 'val1', prop2: 'val2'}", true)]
[TestCase("{1,2,3,4}", false)]
[TestCase("[1,2,3,4]", true)]
@@ -74,6 +74,31 @@ namespace Umbraco.Tests.Services.Importing
Assert.That(uBlogsyLanding.CompositionPropertyGroups.Count(), Is.EqualTo(5));
}
[Test]
public void PackagingService_Can_Import_Inherited_ContentTypes_And_Verify_PropertyTypes_UniqueIds()
{
// Arrange
string strXml = ImportResources.InheritedDocTypes_Package;
var xml = XElement.Parse(strXml);
var dataTypeElement = xml.Descendants("DataTypes").First();
var templateElement = xml.Descendants("Templates").First();
var docTypeElement = xml.Descendants("DocumentTypes").First();
var packagingService = ServiceContext.PackagingService;
// Act
var dataTypes = packagingService.ImportDataTypeDefinitions(dataTypeElement);
var templates = packagingService.ImportTemplates(templateElement);
var contentTypes = packagingService.ImportContentTypes(docTypeElement);
// Assert
var mRBasePage = contentTypes.First(x => x.Alias == "MRBasePage");
foreach (var propertyType in mRBasePage.PropertyTypes)
{
var propertyTypeDto = this.DatabaseContext.Database.First<PropertyTypeDto>("WHERE id = @id", new { id = propertyType.Id });
Assert.AreEqual(propertyTypeDto.UniqueId, propertyType.Key);
}
}
[Test]
public void PackagingService_Can_Import_Inherited_ContentTypes_And_Verify_PropertyGroups_And_PropertyTypes()
{
+4
View File
@@ -175,6 +175,10 @@
<Compile Include="AttemptTests.cs" />
<Compile Include="Cache\CacheRefresherTests.cs" />
<Compile Include="Cache\DeepCloneRuntimeCacheProviderTests.cs" />
<Compile Include="Cache\DefaultCachePolicyTests.cs" />
<Compile Include="Cache\FullDataSetCachePolicyTests.cs" />
<Compile Include="Cache\SingleItemsOnlyCachePolicyTests.cs" />
<Compile Include="Collections\DeepCloneableListTests.cs" />
<Compile Include="Controllers\BackOfficeControllerUnitTests.cs" />
<Compile Include="DelegateExtensionsTests.cs" />
<Compile Include="Logging\AsyncRollingFileAppenderTest.cs" />

Some files were not shown because too many files have changed in this diff Show More