ClickOnce manual update still asks for update - visual-studio-2017

I disabled update checking in Visual Studio by unchecking the publish property The application should check for updates.
My app checks for updates and the user has to option to decline to update.
The issue is when the user skips the update, the next time he starts the app the default ClickOnce update screen is presented again.
How do I make sure it never shows the default ClickOnce update dialog?
My update code:
private void CheckForUpdates()
{
if (!ApplicationDeployment.IsNetworkDeployed)
{
return;
}
var currentDeployment = ApplicationDeployment.CurrentDeployment;
UpdateCheckInfo info;
try
{
info = currentDeployment.CheckForDetailedUpdate();
}
catch (Exception e)
{
return;
}
if (!info.UpdateAvailable)
{
return;
}
var changelogDialog = new Changelog();
if (changelogDialog.ShowDialog() != true)
{
return;
}
currentDeployment.Update();
Exit();
}
This is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
<assemblyIdentity name="test.ccpl.Desktop.application" version="1.0.0.89" publicKeyToken="7613da056444d824" language="en-CA" processorArchitecture="x86" xmlns="urn:schemas-microsoft-com:asm.v1" />
<description asmv2:publisher="test ccpl" co.v1:suiteName="test" asmv2:product="test ccpl" xmlns="urn:schemas-microsoft-com:asm.v1" />
<deployment install="true" mapFileExtensions="true" co.v1:createDesktopShortcut="true">
<deploymentProvider codebase="https://test-test.test.ca/Installers/test.ccpl.Desktop.application" />
</deployment>
<dependency>
<dependentAssembly dependencyType="install" codebase="Application Files\test.ccpl.Desktop_1_0_0_89\test.ccpl.Desktop.exe.manifest" size="58997">
<assemblyIdentity name="test.ccpl.Desktop.exe" version="1.0.0.89" publicKeyToken="7613da056444d824" language="en-CA" processorArchitecture="x86" type="win32" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>u36JKY4n1mmu2LZC3Ea5uRLheiM=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
<compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
<framework targetVersion="4.7.2" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
<publisherIdentity ...>

I think that everything you are seeing is by design.
As soon as you call currentDeployment.CheckForDetailedUpdate(), clickonce will store that update metadata in the registry. On next startup, clickonce will always look at this information to see if there is a pending deployment and if so, it will also determine if the user has skipped this newer version or not. If you want or not, this is by design.
However, if you really want to get rid of the clickonce Update dialog on startup, then there is an ugly solution available :-) Update: See below for a second workaround.
First, lets have a look at the registry and how everything works:
Navigate to this location:
HKEY_CURRENT_USER\Software\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\SideBySide\2.0\PackageMetadata\{2ec93463-b0c3-45e1-8364-327e96aea856}_{3f471841-eef2-47d6-89c0-d028f03a4ad5}\
You will see 3 sub keys for every clickonce application you have installed.
In my case the application is called WindowsApplication and the public key token is a619d47505395849. So the important key to look for starts with wind..tion_a619d47505395849_
You should see something similar to test..tion_7613da056444d824_xxxxxxxxxx on your side. Just iterate over the keys, look for the public key token and choose the shortest key.
Now comes the important part. Look at the value which name ends with !PendingDeployment. After calling the CheckForDetailedUpdate method, it should look like this:
This is why the Update Dialog is showing up.
And then just replace the value with this and you are done:
The Update Dialog will then not appear anymore. The user can manually check for an update within your application, accept or ignore it again and again.
You can test these steps manually to see if everything works as expected. Putting it in code should become something similar to this:
var changelogDialog = new Changelog();
if (changelogDialog.ShowDialog() != true)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(#"Software\Classes\Software\Microsoft\Windows\CurrentVersion\Deployment\SideBySide\2.0\PackageMetadata\{2ec93463-b0c3-45e1-8364-327e96aea856}_{3f471841-eef2-47d6-89c0-d028f03a4ad5}");
var subkeyName = key.GetSubKeyNames().Where(x => x.Contains("7613da056444d824")).OrderBy(x => x.Length).First();
var subkey = key.OpenSubKey(subkeyName, true);
subkey.SetValue("{2ad613da-6fdb-4671-af9e-18ab2e4df4d8}!PendingDeployment", new byte[] { 00, 00 }, RegistryValueKind.Binary);
return;
}
UPDATE
Another Workaround:
Instead of calling the built-in function CheckForDetailedUpdate(), you can create your own "CheckForUpdate" method. That is not be a big deal:
private CustomUpdateCheckInfo CheckForUpdate()
{
var info = new CustomUpdateCheckInfo();
var currentVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
var manifestUri = ApplicationDeployment.CurrentDeployment.UpdateLocation;
using (XmlTextReader reader = new XmlTextReader(manifestUri.AbsoluteUri))
{
var doc = XDocument.Load(reader);
var version = doc.Descendants().FirstOrDefault(n => n.Name.LocalName == "assemblyIdentity").Attribute("version").Value;
info.NewestVersion = version;
info.IsUpdateAvailable = currentVersion.ToString() != version;
}
return info;
}
It will compare the currently deployed version with the newest version in the manifest file and returns an instance of CustomUpdateCheckInfo:
public class CustomUpdateCheckInfo
{
public bool IsUpdateAvailable { get; set; }
public string NewestVersion { get; set; }
}

Related

Sitecore update field just before publish

I have a need to update a date time field in Sitecore just before the item is published. This will act like a "publish date time" when the item is actually published. I have successfully implemented this in the workflow and that works fine for items in the workflow by adding a custom action.
For items not in workflow and that should be picked up by the Publish agent, I tapped into the pipeline and added a processor just before the PerformAction processor. The field gets updated fine in the master database but it's never published by the publish agent to the web database. The item with all other values before the field update goes through fine.
I have tried to debug the issue and feel like it's happening because the updated item is not reflected as part of the publishqueue. Is there a way I can force the update of the date time field also published in the same process instead of having to force it to publish?
Any suggestions are welcome.
You are right updated item is not part of the publish queue. You need to put your code into publish:itemProcessing event.
You need to follow next steps:
Add a handler class into
<event name="publish:itemProcessing" help="Receives an argument of type ItemProcessingEventArgs (namespace: Sitecore.Publishing.Pipelines.PublishItem)"/>
Your publish:itemProcessing event will look like
<event name="publish:itemProcessing" help="Receives an argument of type ItemProcessingEventArgs (namespace: Sitecore.Publishing.Pipelines.PublishItem)">
<handler type="YourNameSpace.SetPublishDate, YourAssembly" method="UpdatePublishingDate"/>
</event>
Create your own class for processing items on publish:
public class SetPublishDate
{
/// <summary>
/// Gets from date.
/// </summary>
/// <value>From date.</value>
public DateTime FromDate { get; set; }
/// <summary>
/// Gets to date.
/// </summary>
/// <value>To date.</value>
public DateTime ToDate { get; set; }
public void UpdatePublishingDate(object sender, EventArgs args)
{
var arguments = args as Sitecore.Publishing.Pipelines.PublishItem.ItemProcessingEventArgs;
var db = Sitecore.Configuration.Factory.GetDatabase("master");
Item item = db.GetItem(arguments.Context.ItemId);
if (item != null)
{
using (new Sitecore.Data.Events.EventDisabler())
{
using (new EditContext(item))
{
//PublishDateFieldName must be datetime field
item["PublishDateFieldName"] = DateTime.Now;
}
}
}
}
Depending on what you're going to use this date for, perhaps a slight different approach might be better. The previous answer is valid and will probably work just fine. But updating the master database on publish, may let the publishing engine think that the master item has changed and needs re-publishing. (EventDisabler etc will prevent this, as well as trigger a re-index and so on... Things may get very tricky)
Alternatively, you can write the publish date on the item in the web database instead.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<publishItem>
<processor type="Sitecore.Publishing.Pipelines.PublishItem.PerformAction, Sitecore.Kernel">
<patch:attribute name="type">Your.Namespace.PerformAction, Your.Assembly</patch:attribute>
</processor>
</publishItem>
</pipelines>
</sitecore>
</configuration>
And an implementation similar to this:
public class PerformAction : Sitecore.Publishing.Pipelines.PublishItem.PerformAction
{
public override void Process(PublishItemContext context)
{
base.Process(context);
if (context.Aborted || context.VersionToPublish == null || context.VersionToPublish.Source == null)
return;
var target = context.PublishOptions.TargetDatabase.GetItem(context.VersionToPublish.ID, context.VersionToPublish.Language);
if (target == null)
return;
using (new EditContext(target, false /*updateStatistics*/, true /*silent*/))
{
DateField lastPublished = target.Fields["LastPublished"]
lastPublished.Value = Sitecore.DateUtil.IsoNo;
}
}
}
John West have a blog post about this here:
http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2011/08/intercept-item-publishing-with-the-sitecore-aspnet-cms.aspx
Having the publish date stored in the web database, you can either read it from there instead, or create a computed index field for the master db, containing the date from the web db instead.
This can perhaps be a more robust solution, but again, it depends on what you're using the field for and if you're in control of the code reading the value.

Sitecore 8: Sync a bucket item on save

I have seen how we can provide default conditions and default actions to newly created bucket items. I also know that we can create a custom rule for building path based on custom date field.
But, how can we set the item path when the date field is and the is saved.
Consider an example. We have a bucket item template say "News" which has a date field say "Release Date". We have the settings where on item creation, the item path has the creation date like "/News/2015/09/16/item1". Now, we need to have some logic where we can change the path when the "release date" of "item1" is updated and the item is Saved.
How can we update the item path when item's release date is updated and item is Saved !! do i need to implement some logic in OnItemSaved() method ?
I already went through posts on GeekHive
The simplest way to do this would be to hook into the item:saved event and sync the bucket in there. The following code is untested:
public class ItemSavedEventHandler
{
public void Execute(object sender, ItemSavedEventArgs args)
{
Assert.IsNotNull(sender, "sender is null");
Assert.IsNotNull(args, "args is null");
// WARNING: using the events disabler is not recommended in this case.
// If you do this, the path of the item in question will not be updated and will cause issues when you edit the page and try to specify rendering data sources (the locations won't resolve)
using (new EventsDisabler())
{
var parameter = args.Item;
if (!BucketManager.IsItemContainedWithinBucket(paremeter))
{
return;
}
var bucketItem = parameter.GetParentBucketItemOrParent();
if (!bucketItem.IsABucket())
{
return;
}
BucketManager.Sync(bucketItem);
}
}
}
On a bucket with a lot of items, this will considerably slow down the save process tho.
If I understood you right, you want your bucket item path to be based on date updated rather than created? Am I right with that?
If yes, that it is not going to be a straightforward thing to do. I see the following approach to implement that.
Configure your bucket to be organised by update date, not created (you mentioned you already know how to configure that behavior). Every Sitecore item derived from Standard Template should have Statistics section where is __Updated field (with two underscores a the beginning) that automatically updates on each item save by corresponding event. You should use that field.
Once done, sync all existing items to apply that bucketing items paths.
Handle item:saved event
Within item:saved event handler: unbucket that particular item and re-bucket that item again (with item:unbucket and item:bucket commands)
Your that particular item will be bucketed implementing your bucketing path rule.
Hope that helps!
Building on some of the answers, here's the most readable / performant solution for most use cases:
using Sitecore.Buckets.Extensions;
using Sitecore.Buckets.Managers;
using Sitecore.Data.Events;
using Sitecore.Diagnostics;
using System;
using Sitecore.Data.Items;
using Sitecore.Events;
namespace XXXX.Project.Web.Infrastructure.Pipelines
{
public class MoveItemIntoBucketOnSave
{
public void OnItemSaved(object sender, EventArgs args)
{
Assert.IsNotNull(sender, "sender is null");
Assert.IsNotNull(args, "args is null");
var savedItem = Event.ExtractParameter(args, 0) as Item;
if (savedItem == null || savedItem.Database.Name.ToLower() != "master" || !savedItem.IsItemBucketable())
{
return;
}
// WARNING: see update below about EventDisabler
using (new EventDisabler())
{
if (!BucketManager.IsItemContainedWithinBucket(savedItem))
{
return;
}
var bucketItem = savedItem.GetParentBucketItemOrParent();
if (!bucketItem.IsABucket())
{
return;
}
// If you want to sync the entire bucket
// BucketManager.Sync(bucketItem);
BucketManager.MoveItemIntoBucket(savedItem, bucketItem);
}
}
}
}
I'm not worried about there being any empty bucket folders after this operation since they will be cleaned up during a full bucket sync, and content authors would not typically be traversing the bucket tree as they should be using search.
Here's the config:
<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="item:saved">
<handler type="XXXX.Project.Web.Infrastructure.Pipelines.MoveItemIntoBucketOnSave, XXXX.Project.Web" method="OnItemSaved" />
</event>
</events>
</sitecore>
</configuration>
UPDATE: I do not recommend using the EventDisabler. If you add a new page and then try to add a rendering to the page and specify a datasource for it, the datasource locations won't resolve because Sitecore still thinks the path of newly created item is a direct child of the bucket item, rather than wherever the item was moved to within the bucket. See this question for more information.
UPDATE 2:
Note that this method will get called twice when a new bucketed item is created. You should think very carefully about what this means for you, and if you should add any other checks prior to calling any other code within this method.
You can achieve this by programmatically moving the bucketed item to the root of the bucket with the BucketManager. Doing this will force it to reevaluate the bucket rules and reorganize it:
BucketManager.MoveItemIntoBucket(bucketedItem, bucketItem);
Note that this is different from BucketManager.Sync(bucketItem) because it does not sync the whole bucket, but instead handles just the single item that was changed.
In our solutions, we typically create an item:saved event handler to do this automatically:
using Sitecore.Buckets.Managers;
using Sitecore.Buckets.Util;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Events;
using System;
using System.Text.RegularExpressions;
namespace Custom.Events.ItemSaved
{
public class ReorganizeBucketedItemInBucket
{
public void OnItemSaved(object sender, EventArgs args)
{
var bucketedItem = Event.ExtractParameter(args, 0) as Item;
// If we don't have an item or we're not saving in the master DB, ignore this save
if (bucketedItem == null || !"master".Equals(bucketedItem.Database?.Name, StringComparison.OrdinalIgnoreCase))
return;
if (!bucketedItem.TemplateID.Equals(new ID("{bucketed-item-template-id}"))) return;
var itemChanges = Event.ExtractParameter(args, 1) as ItemChanges;
// If there were no changes or the changes didn't include the date field, ignore this save
if (itemChanges == null || !itemChanges.HasFieldsChanged || !itemChanges.IsFieldModified(new ID("{field-id-of-date-field}")))
return;
Item bucketItem = bucketedItem.Axes.SelectSingleItem($"{EscapePath(bucketedItem.Paths.FullPath)}/ancestor-or-self::*[##templateid = '{{bucket-container-template-id}}']");
// If this item isn't in a bucket (or is in a bucket of another, unexpected type), ignore it
if (bucketItem == null) return;
Item parent = bucketedItem.Parent;
BucketManager.MoveItemIntoBucket(bucketedItem, bucketItem);
// Delete empty ancestor bucket folders
while (parent != null && !parent.HasChildren && parent.TemplateID == BucketConfigurationSettings.BucketTemplateId)
{
Item tempParent = parent.Parent;
parent.Delete();
parent = tempParent;
}
}
/// <summary>
/// Wraps each segment of a sitecore path with "#"'s
/// </summary>
public string EscapePath(string path)
{
return Regex.Replace(path, #"([^/]+)", "#$1#").Replace("#*#", "*");
}
}
}
And don't forget your patch config, of course:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<events>
<event name="item:saved">
<handler type="Custom.Events.ItemSaved.ReorganizeBucketedItemInBucket, Custom.Events" method="OnItemSaved"></handler>
</event>
</events>
</sitecore>
</configuration>
You'll need to implement a pipeline processor.
You can do this by adding the following into a .config file in your App_Code/Include folder.
<processors>
<saveUI>
<processor mode="on" type="Namespace.ClassName, Your.Assembly" patch:after="processor[last()]" />
</saveUI>
</processor
You'll also need to implement that class - there's nothing special about it except that it must have a public Process method with a Sitecore.Pipelines.Save.SaveArgs parameter.
namespace CustomFunctions
{
public class SaveAction
{
public void Process(SaveArgs args)
{
// There's a collection of items
// I'm not sure what the situation where there's more than one item is though.
var items = args.SavedItems;
var bucket = SomeFunctionToGetParent(items);
BucketManager.Sync(items);
}
}
}
I've never actually implemented this, but I think my code should give you an idea of how to get started - though this pipeline processor would be called every time an item is saved, so you need efficient checking to make sure that the item needs to have your bucket syncing processor used.

How do I determine if services.msc snap-in is loaded into mmc console?

I need to prompt user to close services.msc snap-in on program uninstall. How do I do that?
You need to write custom action to do that. You can use Process to check whether services.msc is loaded in mmc or not.
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
foreach (Process getProcess in Process.GetProcesses())
{
if (getProcess.ProcessName.Contains("mmc"))
{
if (getProcess.MainWindowTitle == "Services")
{
session["SERVICES_MSC"] = "Running";
break;
}
}
}
return ActionResult.Success;
}
Calls the Custom action in uninstall and stop the uninstallation based on the SERVICES_MSC property.
<Binary Id="Check_Services" SourceFile="..\TestProject\bin\Release\TestProject.CA.dll" />
<CustomAction Id="CHECK_SERVICES" BinaryKey="Check_Services" DllEntry="CustomAction1" Return="check" />
<CustomAction Id="STOP_INSTALLATION" Error="Services.msc is running.Please close that Window before uninstall the setup." />
Inside the Install Execute sequence call the custom actions.
<Custom Action="CHECK_SERVICES" After="InstallValidate">REMOVE ~= "ALL"</Custom>
<Custom Action="STOP_INSTALLATION" After="CHECK_SERVICES">(REMOVE ~= "ALL") AND SERVICES_MSC</Custom>

Change Template of Uploaded File in Media Library in Sitecore

I've done some research into this but not sure I understand all the pieces that need to go into the following problem.
My client needs a special template to be used instead of the auto detected media templates in the Media Library if they upload to a certain Folder. The template has special fields. The template can also house different types of files (PDFs, vendor specific formats, executables).
For development purposes we are currently uploading the file and then doing a template switch afterwards but what really needs to happen is that file be uploaded to that template type in the first place. I was wondering if there was a way to hook into the upload process to make sure the special template is used when underneath a certain path in the Media Library? If so, where should I start?
We recently had to do something similar. Along the same line as techphoria414, I'd tap into the upload save pipeline. Then, to make it a bit more generic and reusable, use the power of Sitecore's configuration parsing to hook everything up to your handler. Here's what we ended up with.
Main class with required "Process" method:
public class ChangeTemplate
{
public string Name { get; set; }
public string Path { get; set; }
public List<ChangedMediaTemplate> Templates { get; set; }
public ChangeTemplate()
{
Templates = new List<ChangedMediaTemplate>();
}
public void Process(UploadArgs args)
{
var db = Sitecore.Context.ContentDatabase;
var uploadPath = db.GetItem(args.Folder).Paths.ContentPath;
if (!uploadPath.StartsWith(Path))
{
// Not uploading to designated folder
return;
}
foreach (var item in args.UploadedItems)
{
// Need to change template for this item?
var changedTemplate = Templates.Where(t => t.Old.Equals(item.Template.FullName)).FirstOrDefault();
if (changedTemplate != null)
{
var newTemplate = db.Templates[changedTemplate.New];
try
{
item.ChangeTemplate(newTemplate);
}
catch (Exception e)
{
Log.Error("Unable to change {0} template on upload of {1} to {2}.".FormatWith(Name, item.Name, uploadPath), e, this);
}
}
}
}
}
Minor supporting class:
public class ChangedMediaTemplate
{
public string Old { get; set; }
public string New { get; set; }
}
And then the config:
<processors>
<uiUpload>
<processor patch:after="*[#type='Sitecore.Pipelines.Upload.Save, Sitecore.Kernel']" mode="on" type="Foo.Project.SitecoreX.Pipelines.Upload.ChangeTemplate, Foo.Project.Classes">
<Name>Product Images</Name>
<Path>/sitecore/media library/Images/Foo/products</Path>
<Templates hint="list">
<Template type="Foo.Project.SitecoreX.Pipelines.Upload.ChangedMediaTemplate, Foo.Project.Classes">
<Old>System/Media/Unversioned/Image</Old>
<New>User Defined/Foo/Product/Image/Unversioned/Product Image</New>
</Template>
<Template type="Foo.Project.SitecoreX.Pipelines.Upload.ChangedMediaTemplate, Foo.Project.Classes">
<Old>System/Media/Unversioned/Jpeg</Old>
<New>User Defined/Foo/Product/Image/Unversioned/Product Jpeg</New>
</Template>
<Template type="Foo.Project.SitecoreX.Pipelines.Upload.ChangedMediaTemplate, Foo.Project.Classes">
<Old>System/Media/Versioned/Image</Old>
<New>User Defined/Foo/Product/Image/Versioned/Product Image</New>
</Template>
<Template type="Foo.Project.SitecoreX.Pipelines.Upload.ChangedMediaTemplate, Foo.Project.Classes">
<Old>System/Media/Versioned/Jpeg</Old>
<New>User Defined/Foo/Product/Image/Versioned/Product Jpeg</New>
</Template>
</Templates>
</processor>
</uiUpload>
</processors>
Modifying or adding new template rules becomes as simple as editing the config as needed.
Hope this helps!
Unfortunately, to my knowledge, the Sitecore.Resources.Media.MediaCreator(handels mediaitem creation) can not be overridden. So the only (easy) way is to change the templates for the entire media library.
Otherwise I think you need to make your own changes to the sheerUI - but i wouldn't recommend it. Anyhow.. the mediaitems Sitecore creates, are defined in web.config under
<mediaLibrary>
<mediaTypes>
<mediaType name="Any" extensions="*">...</mediaType>
<mediaType name="Windows Bitmap image" extensions="bmp">...</mediaType>
....
</mediaTypes>
</mediaLibrary>
There is a version/unversion template for each mediaitem you can change.
If you want to look into SheerUI I recommend you start here:
http://learnsitecore.cmsuniverse.net/en/Developers/Articles/2009/10/My-First-Sitecore-XAML-Application.aspx
I would use an item:saving handler. If the item is a Media Item, and within a configured folder, then you can change its template. As always with item:saving, insert some checks very early in the method and exit quickly if you determine the item is not of concern.
I want to add something to ambrauer's answer above. It is a good solution but the code should be tweaked before use in production.
The following line:
var uploadPath = db.GetItem(args.Folder).Paths.ContentPath;
should be changed to:
if (args.Folder == null) return;
var uploadFolderItem = db.GetItem(args.Folder);
if (uploadFolderItem == null) return;
var uploadPath = uploadFolderItem.Paths.ContentPath;
The reason is that without the null check on args.Folder, the package upload tool in the Sitecore installation wizard breaks.
This is not critical to developers like us but some administrators rely on this tool as part of their workflow if they do not have full access to the site.

Testing nhibernate Castle Windsor mappings in httpModules is not registered

I want to write test that verifies mappings in castle windsor.
I am using ASP MVC2 where i am using castle windsor to map my repositories.
I have read this article:
http://weblogs.asp.net/bsimser/archive/2008/06/04/the-first-spec-you-should-write-when-using-castle.aspx
and based on this i have created my MS Test
[TestMethod()]
public void GetContainerTest()
{
MooseMvc.Infrastructure.DependencyInjectionInitialiser target = new MooseMvc.Infrastructure.DependencyInjectionInitialiser(); // TODO: Initialize to an appropriate value
IWindsorContainer container = target.GetContainer();
foreach (IHandler assignableHandler in container.Kernel.GetAssignableHandlers(typeof(object)))
{
container.Resolve(assignableHandler.ComponentModel.Service);
}
}
The data for target.getcontainer() implements
this._windsorContainer.Register(Component.For<TInterfaceType>()
.ImplementedBy(typeof(TConcreteType)).LifeStyle.PerWebRequest);
I get message as follows:
Looks like you forgot to register the http module
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '<add
name="PerRequestLifestyle"
type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule,
Castle.Windsor" />' to the <httpModules> section on your web.config.
If you're running IIS7 in Integrated Mode you will need to add it to
<modules> section under <system.webServer>
I have had the same problem and I have found a solution: You can define an event in the contructor of the unit test to override the LifestyleType.
void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model)
{
if (model.LifestyleType == LifestyleType.Undefined)
model.LifestyleType = LifestyleType.Transient;
if (model.LifestyleType == LifestyleType.PerWebRequest)
model.LifestyleType = LifestyleType.Transient;
}
public UnitTest1()
{
containerWithControllers = new WindsorContainer();
containerWithControllers.Kernel.ComponentModelCreated += new ComponentModelDelegate(Kernel_ComponentModelCreated);
}
i have found beautifull guide
http://docs.castleproject.org/Windsor.Windsor-tutorial-part-three-a-testing-your-first-installer.ashx
there is not much else to add..