3 Formatted code to prevent horizontal scrolling
source | link
...
EventSystem.Subscribe<Component, CheckInEventArgs>(CheckInPost, 
                                                   EventPhases.TransactionCommitted); 
...

private void CheckInPost(Component component, CheckInEventArgs args, EventPhases phase)
{
    AccessoriesHelper helper = new AccessoriesHelper();
    helper.MoveAccessory(component);
}
public void MoveAccessory(Component component)
{
    Session session = component.Session;
    ItemFields metadata = new ItemFields(component.Metadata, component.Schema);
    KeywordField categoryField = (KeywordField)metadata["Category"];
    Keyword categoryKeyword = categoryField.Value;

    List<Keyword> hierarchy = Utilities.GetKeywordHierarchy(categoryKeyword);

    Folder baseFolder = (Folder)session.GetObject(Utilities.GetSettingFromConfig(
                                                      "AccessoriesCopyBaseFolderUri"));
    Folder saveFolder = GetFolderBasedOnKeywords(baseFolder, hierarchy);

    if (!saveFolder.Id.Equals(component.OrganizationalItem.Id))
    {
        logging.Debug(String.Format(
                      "Accessory needs to move from {0} ({1}) to  {2} ({3})", 
                      component.OrganizationalItem.Title, 
                      component.OrganizationalItem.Id, 
                      saveFolder.Title, saveFolder.Id));
        component.Move(saveFolder);
    }
}
...
EventSystem.Subscribe<Component, CheckInEventArgs>(CheckInPost, EventPhases.TransactionCommitted); 
...

private void CheckInPost(Component component, CheckInEventArgs args, EventPhases phase)
{
    AccessoriesHelper helper = new AccessoriesHelper();
    helper.MoveAccessory(component);
}
public void MoveAccessory(Component component)
{
    Session session = component.Session;
    ItemFields metadata = new ItemFields(component.Metadata, component.Schema);
    KeywordField categoryField = (KeywordField)metadata["Category"];
    Keyword categoryKeyword = categoryField.Value;

    List<Keyword> hierarchy = Utilities.GetKeywordHierarchy(categoryKeyword);

    Folder baseFolder = (Folder)session.GetObject(Utilities.GetSettingFromConfig("AccessoriesCopyBaseFolderUri"));
    Folder saveFolder = GetFolderBasedOnKeywords(baseFolder, hierarchy);

    if (!saveFolder.Id.Equals(component.OrganizationalItem.Id))
    {
        logging.Debug(String.Format("Accessory needs to move from {0} ({1}) to  {2} ({3})", component.OrganizationalItem.Title, component.OrganizationalItem.Id, saveFolder.Title, saveFolder.Id));
        component.Move(saveFolder);
    }
}
...
EventSystem.Subscribe<Component, CheckInEventArgs>(CheckInPost, 
                                                   EventPhases.TransactionCommitted); 
...

private void CheckInPost(Component component, CheckInEventArgs args, EventPhases phase)
{
    AccessoriesHelper helper = new AccessoriesHelper();
    helper.MoveAccessory(component);
}
public void MoveAccessory(Component component)
{
    Session session = component.Session;
    ItemFields metadata = new ItemFields(component.Metadata, component.Schema);
    KeywordField categoryField = (KeywordField)metadata["Category"];
    Keyword categoryKeyword = categoryField.Value;

    List<Keyword> hierarchy = Utilities.GetKeywordHierarchy(categoryKeyword);

    Folder baseFolder = (Folder)session.GetObject(Utilities.GetSettingFromConfig(
                                                      "AccessoriesCopyBaseFolderUri"));
    Folder saveFolder = GetFolderBasedOnKeywords(baseFolder, hierarchy);

    if (!saveFolder.Id.Equals(component.OrganizationalItem.Id))
    {
        logging.Debug(String.Format(
                      "Accessory needs to move from {0} ({1}) to  {2} ({3})", 
                      component.OrganizationalItem.Title, 
                      component.OrganizationalItem.Id, 
                      saveFolder.Title, saveFolder.Id));
        component.Move(saveFolder);
    }
}
2 added 155 characters in body
source | link

I'm trying to move a component using Tridion 2011 Event system.

First I tried to do this using SaveEventArgs in phase processed:

EventSystem.Subscribe<Component, SaveEventArgs>(CompSavePost, EventPhases.Processed); 

But then I got this horrible error:

TransactionScope nested incorrectly

Then I read this article on how to move a component using CheckInEventArgs using phase TransactionCommitted. My code now works fine, no errors, but the component is not moved.

Since my setup is key here, this is the basic version:

...
EventSystem.Subscribe<Component, CheckInEventArgs>(CheckInPost, EventPhases.TransactionCommitted); 
...

private void CheckInPost(Component component, CheckInEventArgs args, EventPhases phase)
{
    AccessoriesHelper helper = new AccessoriesHelper();
    helper.MoveAccessory(component);
}

And then, in my AccessoriesHelper class

public void MoveAccessory(Component component)
{
    Session session = component.Session;
    ItemFields metadata = new ItemFields(component.Metadata, component.Schema);
    KeywordField categoryField = (KeywordField)metadata["Category"];
    Keyword categoryKeyword = categoryField.Value;

    List<Keyword> hierarchy = Utilities.GetKeywordHierarchy(categoryKeyword);

    Folder baseFolder = (Folder)session.GetObject(Utilities.GetSettingFromConfig("AccessoriesCopyBaseFolderUri"));
    Folder saveFolder = GetFolderBasedOnKeywords(baseFolder, hierarchy);

    if (!saveFolder.Id.Equals(component.OrganizationalItem.Id))
    {
        logging.Debug(String.Format("Accessory needs to move from {0} ({1}) to  {2} ({3})", component.OrganizationalItem.Title, component.OrganizationalItem.Id, saveFolder.Title, saveFolder.Id));
        component.Move(saveFolder);
    }
}

The thing is, when I move the component.Move(folder) part to the top of my MoveAccessory method, all works fine. But in the setup as shown above, the component is not moved but no errors too... The 'Accessory needs to move...' part is logged, and seems correct:

Accessory needs to move from 040 Accessories Content Master English (tcm:113-19424-2) to Bags, Cases & Pads (tcm:113-19631-2)

so the Move method should be called...

I'm trying to move a component using Tridion 2011 Event system.

First I tried to do this using SaveEventArgs in phase processed:

EventSystem.Subscribe<Component, SaveEventArgs>(CompSavePost, EventPhases.Processed); 

But then I got this horrible error:

TransactionScope nested incorrectly

Then I read this article on how to move a component using CheckInEventArgs using phase TransactionCommitted. My code now works fine, no errors, but the component is not moved.

Since my setup is key here, this is the basic version:

...
EventSystem.Subscribe<Component, CheckInEventArgs>(CheckInPost, EventPhases.TransactionCommitted); 
...

private void CheckInPost(Component component, CheckInEventArgs args, EventPhases phase)
{
    AccessoriesHelper helper = new AccessoriesHelper();
    helper.MoveAccessory(component);
}

And then, in my AccessoriesHelper class

public void MoveAccessory(Component component)
{
    Session session = component.Session;
    ItemFields metadata = new ItemFields(component.Metadata, component.Schema);
    KeywordField categoryField = (KeywordField)metadata["Category"];
    Keyword categoryKeyword = categoryField.Value;

    List<Keyword> hierarchy = Utilities.GetKeywordHierarchy(categoryKeyword);

    Folder baseFolder = (Folder)session.GetObject(Utilities.GetSettingFromConfig("AccessoriesCopyBaseFolderUri"));
    Folder saveFolder = GetFolderBasedOnKeywords(baseFolder, hierarchy);

    if (!saveFolder.Id.Equals(component.OrganizationalItem.Id))
    {
        logging.Debug(String.Format("Accessory needs to move from {0} ({1}) to  {2} ({3})", component.OrganizationalItem.Title, component.OrganizationalItem.Id, saveFolder.Title, saveFolder.Id));
        component.Move(saveFolder);
    }
}

The thing is, when I move the component.Move(folder) part to the top of my MoveAccessory method, all works fine. But in the setup as shown above, the component is not moved but no errors too... The 'Accessory needs to move...' part is logged, so the Move method should be called...

I'm trying to move a component using Tridion 2011 Event system.

First I tried to do this using SaveEventArgs in phase processed:

EventSystem.Subscribe<Component, SaveEventArgs>(CompSavePost, EventPhases.Processed); 

But then I got this horrible error:

TransactionScope nested incorrectly

Then I read this article on how to move a component using CheckInEventArgs using phase TransactionCommitted. My code now works fine, no errors, but the component is not moved.

Since my setup is key here, this is the basic version:

...
EventSystem.Subscribe<Component, CheckInEventArgs>(CheckInPost, EventPhases.TransactionCommitted); 
...

private void CheckInPost(Component component, CheckInEventArgs args, EventPhases phase)
{
    AccessoriesHelper helper = new AccessoriesHelper();
    helper.MoveAccessory(component);
}

And then, in my AccessoriesHelper class

public void MoveAccessory(Component component)
{
    Session session = component.Session;
    ItemFields metadata = new ItemFields(component.Metadata, component.Schema);
    KeywordField categoryField = (KeywordField)metadata["Category"];
    Keyword categoryKeyword = categoryField.Value;

    List<Keyword> hierarchy = Utilities.GetKeywordHierarchy(categoryKeyword);

    Folder baseFolder = (Folder)session.GetObject(Utilities.GetSettingFromConfig("AccessoriesCopyBaseFolderUri"));
    Folder saveFolder = GetFolderBasedOnKeywords(baseFolder, hierarchy);

    if (!saveFolder.Id.Equals(component.OrganizationalItem.Id))
    {
        logging.Debug(String.Format("Accessory needs to move from {0} ({1}) to  {2} ({3})", component.OrganizationalItem.Title, component.OrganizationalItem.Id, saveFolder.Title, saveFolder.Id));
        component.Move(saveFolder);
    }
}

The thing is, when I move the component.Move(folder) part to the top of my MoveAccessory method, all works fine. But in the setup as shown above, the component is not moved but no errors too... The 'Accessory needs to move...' part is logged and seems correct:

Accessory needs to move from 040 Accessories Content Master English (tcm:113-19424-2) to Bags, Cases & Pads (tcm:113-19631-2)

so the Move method should be called...

1
source | link

2011 Event system Component.Move - component not moved

I'm trying to move a component using Tridion 2011 Event system.

First I tried to do this using SaveEventArgs in phase processed:

EventSystem.Subscribe<Component, SaveEventArgs>(CompSavePost, EventPhases.Processed); 

But then I got this horrible error:

TransactionScope nested incorrectly

Then I read this article on how to move a component using CheckInEventArgs using phase TransactionCommitted. My code now works fine, no errors, but the component is not moved.

Since my setup is key here, this is the basic version:

...
EventSystem.Subscribe<Component, CheckInEventArgs>(CheckInPost, EventPhases.TransactionCommitted); 
...

private void CheckInPost(Component component, CheckInEventArgs args, EventPhases phase)
{
    AccessoriesHelper helper = new AccessoriesHelper();
    helper.MoveAccessory(component);
}

And then, in my AccessoriesHelper class

public void MoveAccessory(Component component)
{
    Session session = component.Session;
    ItemFields metadata = new ItemFields(component.Metadata, component.Schema);
    KeywordField categoryField = (KeywordField)metadata["Category"];
    Keyword categoryKeyword = categoryField.Value;

    List<Keyword> hierarchy = Utilities.GetKeywordHierarchy(categoryKeyword);

    Folder baseFolder = (Folder)session.GetObject(Utilities.GetSettingFromConfig("AccessoriesCopyBaseFolderUri"));
    Folder saveFolder = GetFolderBasedOnKeywords(baseFolder, hierarchy);

    if (!saveFolder.Id.Equals(component.OrganizationalItem.Id))
    {
        logging.Debug(String.Format("Accessory needs to move from {0} ({1}) to  {2} ({3})", component.OrganizationalItem.Title, component.OrganizationalItem.Id, saveFolder.Title, saveFolder.Id));
        component.Move(saveFolder);
    }
}

The thing is, when I move the component.Move(folder) part to the top of my MoveAccessory method, all works fine. But in the setup as shown above, the component is not moved but no errors too... The 'Accessory needs to move...' part is logged, so the Move method should be called...