Tip number 1
Problem: The fallback is disabled by default in the item:save events.Tip: You can use the following code:
using(new FallbackDisabler(FallbackStates.Default)) { db.GetItem() ... }
using(new FallbackDisabler(FallbackStates.Default)) { db.GetItem() ... }
param ( [string]$assemblyVersion, [string]$fileAssemblyVersion, [string]$nugetVersion ) #Update the AssemblyInfo.cs and the .nuspec file to replace the X.X.J.B version number by the correct one depending of the number from TFS function Update-SourceVersion { param ( [string]$SrcPath, [string]$assemblyVersion, [string]$fileAssemblyVersion, [string]$nugetVersion ) $buildNumber = $env:TF_BUILD_BUILDNUMBER Write-Host "env:TF_BUILD_BUILDNUMBER: $buildNumber" if ($buildNumber -eq $null) { $buildIncrementalNumber = 0 } else { $splitted = $buildNumber.Split('.') $buildIncrementalNumber = $splitted[$splitted.Length - 1] } if ($fileAssemblyVersion -eq "") { $fileAssemblyVersion = $assemblyVersion } Write-Host "Executing Update-SourceVersion in path $SrcPath, Version is $assemblyVersion and File Version is $fileAssemblyVersion" $AllVersionFiles = Get-ChildItem $SrcPath AssemblyInfo.cs -recurse $jdate = Get-Date -format 1MMdd Write-Host "Infos: jdate: $jdate, buildIncrementalNumber: $buildIncrementalNumber" $assemblyVersion = $assemblyVersion.Replace("J", $jdate).Replace("B", $buildIncrementalNumber) $fileAssemblyVersion = $fileAssemblyVersion.Replace("J", $jdate).Replace("B", $buildIncrementalNumber) Write-Host "Transformed Assembly Version is $assemblyVersion and Transformed File Version is $fileAssemblyVersion" foreach ($file in $AllVersionFiles) { Write-Host "Modifying file " + $file.FullName #save the file for restore $backFile = $file.FullName + "._ORI" $tempFile = $file.FullName + ".tmp" Copy-Item $file.FullName $backFile #now load all content of the original file and rewrite modified to the same file Get-Content $file.FullName | %{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', "AssemblyVersion(""$assemblyVersion"")" } | %{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', "AssemblyFileVersion(""$fileAssemblyVersion"")" } > $tempFile Move-Item $tempFile $file.FullName -force } $nugetVersion = $nugetVersion.Replace("J", $jdate).Replace("B", $buildIncrementalNumber) Write-Host "Transformed Nuspec Version is $nugetVersion" $AllNugetFiles = Get-ChildItem $SrcPath *.nuspec -recurse $replaceExp = '<file src="$1" target="$2.' + $nugetVersion + '.update" />' foreach ($file in $AllNugetFiles) { Write-Host "Modifying file " + $file.FullName #save the file for restore $backFile = $file.FullName + "._ORI" $tempFile = $file.FullName + ".tmp" Copy-Item $file.FullName $backFile #now load all content of the original file and rewrite modified to the same file Get-Content $file.FullName | %{$_ -replace '<version>[0-9]+(\.([0-9]+|\*)){1,3}</version>', "<version>$nugetVersion</version>" } | %{$_ -replace '<file src="(.*NationalLottery\.DeHub\..*)" target="(.*)\.[0-9]+(\.([0-9]+|\*|J|B)){1,3}.update" />', $replaceExp } > $tempFile Move-Item $tempFile $file.FullName -force } } Write-Host "Running Pre Build Scripts" $scriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition $scriptRootBuildFunctions = "$scriptRoot\TFSUtils.psm1" Write-Host "Script root: $scriptRootBuildFunctions" if ($assemblyVersion -eq "") { $assemblyVersion = "1.1.0.0" $fileAssemblyVersion = "1.1.J.B" } $srcPath = "$scriptRoot/../" Update-SourceVersion $srcPath $assemblyVersion $fileAssemblyVersion $nugetVersion
#RootFolder : the root folder of the project (we should be able to get it from the environment) $rootFolder = "E:\Websites\XXX\Website" function Remove-Item-If-Exist { param ( [string]$pathToDelete, [switch]$force, [switch]$recurse ) If (Test-Path $pathToDelete){ Remove-Item $pathToDelete -Force:$force -Recurse:$recurse } } #Cleanup the old files Remove-Item-If-Exist "$rootFolder\Design" -Force -Recurse Remove-Item-If-Exist "$rootFolder\layouts\Layouts" -Force -Recurse Remove-Item-If-Exist "$rootFolder\layouts\Sublayouts" -Force -Recurse Remove-Item-If-Exist "$rootFolder\layouts\UserControls" -Force -Recurse Remove-Item-If-Exist "$rootFolder\bin\PROJECTNAMESPACE.*.dll" -Force Remove-Item-If-Exist "$rootFolder\App_Config\Include\PROJECTNAMESPACE.*.config" -Force
param ( [string]$releaseVersion ) #Constants $octopusApiUrl = "http://10.0.2.50:8088/api" $octopusApiKey = "API-RX6UIIWTB2ZBUWU0TRIYXXXXXXX" $projectName = "XXX" $scriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition #Functions # Get the formated TFS version number. Replace the tokens J and B by the current build number function Format-TFS-Version { param ( [string]$versionToFormat ) $buildNumber = $env:TF_BUILD_BUILDNUMBER Write-Host "env:TF_BUILD_BUILDNUMBER: $buildNumber" if ($buildNumber -eq $null) { $buildIncrementalNumber = 0 } else { $splitted = $buildNumber.Split('.') $buildIncrementalNumber = $splitted[$splitted.Length - 1] } $jdate = Get-Date -format 1MMdd return $versionToFormat.Replace("J", $jdate).Replace("B", $buildIncrementalNumber) } #Create a release in Octopus with the specifiic version of the nuget packages function Octopus-Create-Release { param ( [string]$releaseVersion ) $releaseVersion = Format-TFS-Version $releaseVersion $corePackage = "--package=XXX.Core:$releaseVersion" $corporatePackage = "--package=XXX.Corporate:$releaseVersion" $scriptPackage = "--package=XXX.Tools.SqlScriptsUpdate:$releaseVersion" Write-Host "Create the octopus release by calling $scriptRoot\Octopus\octo.exe create-release --project=$projectName --server=$octopusApiUrl --apiKey=$octopusApiKey --version $releaseVersion $corePackage $corporatePackage $scriptPackage" &$scriptRoot\Octopus\octo.exe create-release --project=$projectName --server=$octopusApiUrl --apiKey=$octopusApiKey --version $releaseVersion $corePackage $corporatePackage $scriptPackage } #Deploy a release in Octopus function Octopus-Deploy-Release { param ( [string]$releaseVersion, [string]$deployToEnvironment ) Write-Host "Deploy the octopus release by calling $scriptRoot\Octopus\octo.exe deploy-release --project=$projectName --version=$releaseVersion --deployto=$deployToEnvironment --server=$octopusApiUrl --apiKey=$octopusApiKey" &$scriptRoot\Octopus\octo.exe deploy-release --project=$projectName --version=$releaseVersion --deployto=$deployToEnvironment --server=$octopusApiUrl --apiKey=$octopusApiKey } #Main program $releaseVersion = Format-TFS-Version $releaseVersion Write-Host "Release version: $releaseVersion" Octopus-Create-Release $releaseVersion Octopus-Deploy-Release $releaseVersion Integration
<?xml version="1.0"?> <package > <metadata> <id>XXX.TDSDeploy</id> <version>1.0.0</version> <authors>Vangansewinkel Benjamin</authors> <owners>Vangansewinkel Benjamin</owners> <projectUrl>http://www.xxx.be</projectUrl> <iconUrl>http://www.xxx.be/design/images/generalImages/favicon.ico</iconUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>XXX TDS package</description> <releaseNotes></releaseNotes> <copyright>Copyright 2014</copyright> </metadata> <files> <file src="..\..\..\..\..\bin\_Packages\XXX.CoreTDS\XXX.CoreTDS.scitems.update" target="content\TdsPackages\XXX.CoreTDS.1.1.J.B.update" /> <file src="..\..\..\..\..\bin\_Packages\XXX.LayoutsTDS\XXX.LayoutsTDS.scitems.update" target="content\TdsPackages\XXX.LayoutsTDS.1.1.J.B.update" /> <file src="..\..\..\..\..\bin\_Packages\XXX.TemplatesTDS\XXX.TemplatesTDS.scitems.update" target="content\TdsPackages\XXX.TemplatesTDS.1.1.J.B.update" /> </files> </package>
<x:Property Name="Octopus_OctoPackPublishApiKey" Type="InArgument(x:String)" /> <x:Property Name="Octopus_OctoPackPublishPackageToHttp" Type="InArgument(x:String)" /> <x:Property Name="Octopus_RunOctoPack" Type="InArgument(x:Boolean)" /> <x:Property Name="TDS_IsDesktopBuild" Type="InArgument(x:Boolean)" /> <x:Property Name="TDS_GeneratePackage" Type="InArgument(x:Boolean)" />
<mtbw:ProcessParameterMetadata BrowsableWhen="Always" Category="#500 Octopus" Description="Set this to true to run OctoPack" DisplayName="OctoPack : Run OctoPack" ParameterName="Octopus_RunOctoPack" /> <mtbw:ProcessParameterMetadata BrowsableWhen="Always" Category="#500 Octopus" Description="Url where the octopack need to be published" DisplayName="OctoPack : Publish package to http" ParameterName="Octopus_OctoPackPublishPackageToHttp" /> <mtbw:ProcessParameterMetadata BrowsableWhen="Always" Category="#500 Octopus" Description="API Key of the nuget server for the publish" DisplayName="OctoPack : API Key of the nuget server" ParameterName="Octopus_OctoPackPublishApiKey" /> <mtbw:ProcessParameterMetadata BrowsableWhen="Always" Category="#600 TDS" Description="Set this to true if it is a desktop build" DisplayName="TDS : IsDesktopBuild" ParameterName="TDS_IsDesktopBuild" /> <mtbw:ProcessParameterMetadata BrowsableWhen="Always" Category="#600 TDS" Description="Set this to true to generate the packages" DisplayName="TDS : Generate packages" ParameterName="TDS_GeneratePackage" />
String.Format("/p:SkipInvalidConfigurations=true {0} /p:OctoPackPublishPackageToHttp={1} /p:OctoPackPublishApiKey={2} /p:RunOctoPack={3} /p:IsDesktopBuild={4} /p:GeneratePackage={5}", AdvancedBuildSettings.GetValue(Of String)("MSBuildArguments", String.Empty), [Octopus_OctoPackPublishPackageToHttp], [Octopus_OctoPackPublishApiKey], [Octopus_RunOctoPack], [TDS_IsDesktopBuild], [TDS_GeneratePackage])If you prefer to do that in notepad, don't forget to escape the characters.
cd C:\Program Files\MongoDB 2.6 Standard\bin mongod.exe --dbpath "C:\Program Files\MongoDB 2.6 Standard\data\db"Two things here:
logpath="C:\Program Files\MongoDB 2.6 Standard\logs\mongo.log" dbpath="C:\Program Files\MongoDB 2.6 Standard\data\db"
sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"
sc.exe start MongoDBIf you have the message: "The service did not respond to the start or control request in a timely fashion." this probably mean that your cfg file is not correctly
<add name="analytics" connectionString="mongodb://localhost/analytics" /> <add name="tracking.live" connectionString="mongodb://localhost/tracking_live" /> <add name="tracking.history" connectionString="mongodb://localhost/tracking_history" /> <add name="automation.live" connectionString="mongodb://localhost/automation_live" /> <add name="automation.history" connectionString="mongodb://localhost/automation_history" /> <add name="session" connectionString="mongodb://localhost/session" />For the basic config on my developer's computer this is ok like this. I can run my new instance of sitecore. And.... ok no crash at least :-)
mongoResponse is:
MongoDB shell version: 2.6.0 connecting to: testType:
show dbsResponse is:
admin (empty) analytics (empty) automation_history (empty) automation_live (empty) local 0.078GB mydb 0.078GB tracking_history (empty) tracking_live (empty)
This time the post wll be not directly about Sitecore but for a task I had for a sitecore project: migrate from SVN to TFS
You have of course some tools who allow you to do that but most of the time you need to pay for it and in fact it is really simple to do that in command line.
In TFS 2013, you have two option for the source control:
So I will explain both by using a powershell script. To do that, you just need to create a file with the ps1 extension and then execute it from a powershell command window. If you have the warning who say that the file must be signed you need to execute the following command first:
Set-ExecutionPolicy Unrestricted
$svnPathToMigrate = "http://svn.lbigroup.be:6060/svn/my-project/trunk" $targetGitPath = "c:\Projects\Tests\GitOfMyProject" #Create the folder for the local git md $targetGitPath #Browse into this folder cd $targetGitPath #Create the empty git repository git svn init $svnPathToMigrate --no-metadata #Get the sources from svn into the git repository git svn fetch
$tfsGitTarget = "http://betfs01:8080/tfs/MyProjectCollection/_git/MyProject" #Synch the local git with the TFS collection git remote add TfsGit $tfsGitTarget git push TfsGit master
$tfsTargetCollection = "http://betfs01:8080/tfs/MyProjectCollection" $tfsTargetProject = "$/MyProject" #Push to TFS git tf configure $tfsTargetCollection $tfsTargetProject Git tf checkin --deep --no-lock
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <pipelines> <myCustomPipeline> <processor type="MyNamespace.MyProcessor, MyDll" /> </myCustomPipeline> </pipelines> </sitecore> </configuration>
PipelineArgs args = new PipelineArgs(); CorePipeline.Run("myCustomPipeline", args);
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; namespace BOL.Events { [DataContract] public class ClearCacheEvent { public ClearCacheEvent(string cacheName) { this.CacheName = cacheName; } // Properties [DataMember] public string CacheName { get; protected set; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sitecore.Events; namespace BOL.Events { [Serializable] public class ClearCacheEventArgs : EventArgs, IPassNativeEventArgs { public string CacheName { get; set; } public ClearCacheEventArgs(string cacheName) { this.CacheName = cacheName; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sitecore.Diagnostics; using Sitecore.Events; namespace BOL.Events { public class ClearCacheEventHandler { ////// This methos is used to raise the local event /// /// public static void Run(ClearCacheEvent @event) { Log.Info("ClearCacheEventHandler - Run", typeof(ClearCacheEventHandler)); ClearCacheEventArgs args = new ClearCacheEventArgs(@event.CacheName); Event.RaiseEvent("clearcache:remote", new object[] { args }); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sitecore.Events.Hooks; namespace BOL.Events { public class ClearCacheHook : IHook { public void Initialize() { Sitecore.Eventing.EventManager.Subscribe(new Action { ClearCacheEventHandler.Run }); } } }
public class TriggerEvent { public void Trigger() { ClearCacheEvent inst = new ClearCacheEvent("Navigation"); Sitecore.Eventing.EventManager.QueueEvent(inst); } }
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <hooks> <hook type="BOL.Events.ClearCacheHook, BOL"/> </hooks> <events> <event name="clearcache:remote"> <handler type="Shurgard.Events.ClearStoreCache, Shurgard.Events" method="OnRemoteClearStoreCache"/> </event> <events> </sitecore> </configuration>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <MyCustomSection> <MyCustomElement Name="XXX" MyProperty="YYY" /> <MyCustomElement Name="AAA" MyProperty="BBB" /> </MyCustomSection> </sitecore> </configuration>
using System.Collections.Generic; using Sitecore.Configuration; using System.Xml; using Sitecore.Xml; /// <summary> /// TODO: Update summary. /// </summary> public class MyConfigElement { //The two properties corresponding to the properties into the config public string Name { get; set; } public string MyProperty { get; set; } //The method who return the list of my custom elements public static List<MyConfigElement> GetListMyCustomElements() { List<MyConfigElement> lst = new List<MyConfigElement>(); //Read the configuration nodes foreach (XmlNode node in Factory.GetConfigNodes("MyCustomSection/MyCustomElement")) { //Create a element of this type MyConfigElement elem = new MyConfigElement(); elem.Name = XmlUtil.GetAttribute("Name", node); elem.MyProperty = XmlUtil.GetAttribute("MyProperty", node); lst.Add(elem); } return lst; } }
<%@ Register Assembly="Sitecore.Kernel" Namespace="Sitecore.Web.UI.WebControls" TagPrefix="sc" %>
<?xml version="1.0"?> <configuration> <system.web> <pages validateRequest="false"> <controls> <add tagPrefix="sc" namespace="Sitecore.Web.UI.WebControls" assembly="Sitecore.Kernel" /> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add tagPrefix="sc" namespace="Sitecore.Web.UI.WebControls" assembly="Sitecore.Analytics" /> </controls> </pages> </system.web> </configuration>
<event name="publish:end"> <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache"> <sites hint="list"> <site>website</site> </sites> </handler> </event>
<event name="publish:end"> <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache"> <sites hint="list"> <site>mysite</site> </sites> </handler> </event>
<event name="publish:end"> <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache"> <sites hint="list"> <site>mysite</site> </sites> </handler> </event>
<event name="publish:end"> <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache"> <sites hint="list"> <site name="mysite">mysite</site> </sites> </handler> </event>
<event name="publish:end"> <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache"> <sites hint="list"> <site>website</site> <site name="mysite">mysite</site> </sites> </handler> </event>
When we use SVN or TFS normally we commit some .config file an especially the web.config. The problem happened when all the computers doesn’t have the same path structure. For example I will not use the same data folder as my colleague.
You have multiple solutions to handle including having different build configuration but I think that the easiest way to handle it is by simply using the virtual directories.
To create a virtual directory:<sc.variable name="dataFolder" value="/Data" />
Id | 82480059-8CF4-4D2E-82B1-9C00323F12F2 |
EventType | Sitecore.Eventing.Remote.PublishEndRemoteEvent, Sitecore.Kernel, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null |
InstanceType | Sitecore.Eventing.Remote.PublishEndRemoteEvent, Sitecore.Kernel, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null |
InstanceData | {"CompareRevisions":true,"Deep":false,"FromDate":"\/Date(-5339901827822+0200)\/","LanguageName":"en","Mode":3,"PublishDate":"\/Date(1328532964271+0100)\/","PublishingTargets":["{8E080626-DDC3-4EF4-A1D1-F0BE4A200254}","{8E080626-DDC3-4EF4-A1D1-F0BE4A200254}"],"RepublishAll":false,"RootItemId":"ebff6e2a-9149-4660-9d55-dec34282f856","SourceDatabaseName":"master","TargetDatabaseName":"web"} |
InstanceName | GRNQ6R1-sitecore650up3 |
RaiseLocally | 0 |
RaiseGlobally | 1 |
UserName | sitecore\admin |
Stamp | 0x0000000000079C0F |
Created | 2012-02-06 12:56:07.033 |
Heartbeat 14:22:05 INFO Event started: publish:statusUpdated Heartbeat 14:22:05 INFO Executed: Sitecore.Publishing.RemotePublishingEventHandler.OnStatusUpdated(). Elapsed: 4,23265309264199 Heartbeat 14:22:05 INFO Event ended: publish:statusUpdated. Elapsed: 4,33442834380877
DELETE FROM EventQueue; DELETE FROM [Properties] WHERE [Key] LIKE 'EQStamp%';
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; namespace XXX { [DataContract] public class ClearCacheEvent { public ClearCacheEvent() { } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sitecore.Events; namespace XXX { public class ClearCacheEventArgs : EventArgs, IPassNativeEventArgs { public ClearCacheEventArgs(ClearCacheEvent @event) { } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sitecore.Diagnostics; using Sitecore.Events; namespace XXX { public class ClearCacheEventHandler { /// <summary> /// The methos is the method that you need to implement as you do normally /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public virtual void OnClearCacheRemote(object sender, EventArgs e) { Log.Info("Tadaa", this); } /// <summary> /// This methos is used to raise the local event /// </summary> /// <param name="event"></param> public static void Run(ClearCacheEvent @event) { Log.Info("ClearCacheEventHandler - Run", typeof(ClearCacheEventHandler)); ClearCacheEventArgs args = new ClearCacheEventArgs(@event); Event.RaiseEvent("clearcache:remote", new object[] { args }); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sitecore.Events.Hooks; namespace XXX { public class ClearCacheHook : IHook { public void Initialize() { Sitecore.Eventing.EventManager.Subscribe(new Action (ClearCacheEventHandler.Run)); } } }
ClearCacheEvent inst = new ClearCacheEvent(); Sitecore.Eventing.EventManager.QueueEvent<ClearCacheEvent>(inst);
<hooks> <hook type="XXX.ClearCacheHook, XXX"/> </hooks>The event:
<events> <event name="clearcache:remote"> <handler type="XXX.ClearCacheEventHandler, XXX" method="OnClearCacheRemote"/> </event> </events>
<eventQueue> <processingInterval>00:00:02</processingInterval> </eventQueue>
Log.Info("SH - My message", typeof(MyObject)); Log.Error("SH - My message", typeof(MyObject)); ...
<appender name="MyFileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging"> <file value="$(dataFolder)/logs/mylog.{date}.txt" /> <filter type="log4net.Filter.StringMatchFilter"> <regexToMatch value="^SH .*" /> </filter> <filter type="log4net.Filter.DenyAllFilter" /> <appendToFile value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" /> </layout> </appender>You will need to adapt the regex with your custom prefix of course.
<root> <priority value="DEBUG"/> <appender-ref ref="LogFileAppender"/> <appender-ref ref="MyFileAppender" /> </root>
EDIT: You have an alternative syntaxt and more info about the filters here https://sitecoreblog.blogspot.be/2017/03/log4net-add-stacktrace-in-logs.html