November 29, 2012

Use some asp controls into a XAML control

Here is a small tips to use the standard asp controls in a xaml application.

You just need to add this line into the xamlControls declaration:
xmlns:asp="http://www.sitecore.net/microsoft/webcontrols"

Here is a small example:

<xamlControls
  xmlns:x="http://www.sitecore.net/xaml"
  xmlns:ajax="http://www.sitecore.net/ajax"
  xmlns:rest="http://www.sitecore.net/rest"
  xmlns:r="http://www.sitecore.net/renderings"
  xmlns:xmlcontrol="http://www.sitecore.net/xmlcontrols"
  xmlns:p="http://schemas.sitecore.net/Visual-Studio-Intellisense"
  xmlns:asp="http://www.sitecore.net/microsoft/webcontrols"
  xmlns:html="http://www.sitecore.net/microsoft/htmlcontrols"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:wfm="http://www.sitecore.net/wfm/webcontrols">
   <MyNamespace.MyClass x:inherits="MyNamespace.MyClass, MyNamespace">
  <asp:TextBox ID="tMyTextBox" runat="server" Width="97%"/>
   </MyNamespace.MyClass>
</xamlControls>

November 2, 2012

Install a TDS package into your code

Here is a code snippet to install a TDS package into your code:
public void InstallTDSPackage(string path)
{
    bool hasPostAction;
    string historyPath;

    // Use default logger
    ILog log = LogManager.GetLogger("root");
    XmlConfigurator.Configure((XmlElement)ConfigurationManager.GetSection("log4net"));

    using (new SecurityDisabler())
    {
        DiffInstaller installer = new DiffInstaller(UpgradeAction.Upgrade);
        MetadataView view = UpdateHelper.LoadMetadata(path);

        //Get the package entries
        List<ContingencyEntry> entries = installer.InstallPackage(path, InstallMode.Install, log, out hasPostAction, out historyPath);

        installer.ExecutePostInstallationInstructions(path, historyPath, InstallMode.Install, view, log, ref entries);

        UpdateHelper.SaveInstallationMessages(entries, historyPath);
    }
}

Install a sitecore package in your code

Here is a code snippet to install a sitecore package into your code:
public void InstallPackage(string path)
{
    bool hasPostAction;
    string historyPath;

    // Use default logger
    ILog log = LogManager.GetLogger("root");
    XmlConfigurator.Configure((XmlElement)ConfigurationManager.GetSection("log4net"));

    FileInfo pkgFile = new FileInfo(path);

    if (!pkgFile.Exists)
        throw new ClientAlertException(string.Format("Cannot access path '{0}'. Please check path setting.", path));

    Sitecore.Context.SetActiveSite("shell");
    using (new SecurityDisabler())
    {
        using (new ProxyDisabler())
        {
            using (new SyncOperationContext())
            {
                Sitecore.Install.Framework.IProcessingContext context = new Sitecore.Install.Framework.SimpleProcessingContext(); // 
                Sitecore.Install.Items.IItemInstallerEvents events =
                    new Sitecore.Install.Items.DefaultItemInstallerEvents(new Sitecore.Install.Utils.BehaviourOptions(Sitecore.Install.Utils.InstallMode.Overwrite, Sitecore.Install.Utils.MergeMode.Undefined));
                context.AddAspect(events);
                Sitecore.Install.Files.IFileInstallerEvents events1 = new Sitecore.Install.Files.DefaultFileInstallerEvents(true);
                context.AddAspect(events1);
                var inst = new Sitecore.Install.Installer();
                inst.InstallPackage(Sitecore.MainUtil.MapPath(path), context);
            }
        }
    }            
}