Thursday, June 4, 2009

CodeRush plugins for Xaf

To download sources see DxCore plugins for Xaf are moving

Updates

(10/6/09) (see Xaf Exception Stack Explorer)
(17/6/09) (see Coderush plugins for Xaf update1)
(19/6/09) (see Coderush plugins for Xaf update2)

ProjectConverter

Browsing and downloading from Devexpress support center often I find old projects with broken references

solutionexplorer

Old days when i see broken references at my solution due to version changes I had to go to my C:\Program files\pathToYourProjectConverter executable. Open it, browse to find my solution folder and convert it

Nowadays I am using a small CodeRush addin I wrote and I can convert any solution from with in Visual Studio By pressing a shortcut. You have to configure it by setting its path as shown in the image bellow

options1

if you use a recompile version of the assemblies you can also set at the PublicToken field

Then you go to shortcuts and assign a shortcut key for the convertProject command

shortcut 

now every time i need to convert a solution i just hit Ctrl+Shift+Alt+C and voila

solutionexplorerFixed

ModelEditor

Tired of seeing Visual studio errors like

Bug Report Details: XAF Model Designer issue: Possible reason: the assembly 'abc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d70b2af257f40453' has been loaded twice.

me and my friend John were tired also so one day in a half of our 5 hours long skype meeting we decide to write an CodeRush addin that will use the ModelEditor executable provided by Devexpress. So any time i want to use model editor at design time I use that addin

What it does ? It searches your solution for all projects that have a model.xafml file and shows them in a list where by pressing enter or double click will open the modified Model Editor (source included for this one also)

xafmodels

You should configure it using the same approach as project converter .

To install the addin download from here XafAddins(source,binary)  copy the assemblies to your community plugins folder or build the sources

comufol

the first time you will run it you have to configure it with an approach same to ProjectConverters

see video bellow

Enjoy!!!

Update 5/6/2009

After try to use it with a more complex solution like this one

complexsolution

i noticed that the plugin enumerates only root project

rootModels

Lets fix that. First i though that this is too basic and maybe i am missing something so lets ask DevExpress support .

List of Projects in a solution not a good answer eh? Maybe they didn’t understand me well or maybe they were too busy.

This shouldn’t be too hard to find so i search a little more on support center and i find this Find in Solution Explorer and also Enumerating projects in a Visual Studio solution

Now we know how to enumerate through all items in a solution and the type of each item !!! the next part is easy. Just write the code and adding it as an extension to EnvDTE.Solution class cause i think its an appropriate place to find there

public static class SolutionExtension
{
public static List<Project> GetAllProjects(this Solution solution)
{
var DTE = CodeRush.ApplicationObject;
var UIHSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object as UIHierarchy;
var projects = new List<Project>();
if (UIHSolutionExplorer != null && UIHSolutionExplorer.UIHierarchyItems.Count > 0)
ProcessSolutionExplorerItem(UIHSolutionExplorer.UIHierarchyItems.Item(1),projects);
return projects;
}

private static void ProcessSolutionExplorerItem(UIHierarchyItem item, List<Project> projects)
{
if (item.UIHierarchyItems.Count > 0)
for (int i = 1; i <= item.UIHierarchyItems.Count; i++)
{
UIHierarchyItem hierarchyItem = item.UIHierarchyItems.Item(i);
object o = hierarchyItem.Object;
if (o is Project && !isSolutionFolder(o))
projects.Add((Project) o);
else if (o is ProjectItem)
{
Project project = ((ProjectItem) o).SubProject;
if (project != null && !isSolutionFolder(project))
projects.Add(project);
}
ProcessSolutionExplorerItem(hierarchyItem, projects);
}
}

private static bool isSolutionFolder(object o)
{
return ((Project)o).Kind == "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}";
}


}


Limitation: if one assembly references another assembly in the project, you need to set 'Copy Local' = true for the referenced assemly otherwise a 'FileNotFound' error pops up when you try to view the model
thnks Steven :)




Collapse all items in solution Explorer



Since all my application are now heavily based on modularization i tend to have a solution template that i use to start a new solution. That solution project count is now roughly about 80 project and I often find myself lost in solution explorer.



bigsolution



So i decided to write a command for CodeRush to help me collapse all items by pressing a shortcut. The command name is collapseAllItemsInSolutionExplorer



collapseall



public static void CollapseAllFolders(this Solution solution)
{
var DTE = CodeRush.ApplicationObject;
var UIHSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object as UIHierarchy;
if (UIHSolutionExplorer== null||UIHSolutionExplorer.UIHierarchyItems.Count == 0)
return;
UIHierarchyItem rootItem = UIHSolutionExplorer.UIHierarchyItems.Item(1);
rootItem.DTE.SuppressUI = true;
Collapse(rootItem,UIHSolutionExplorer);
// Select the solution node, or else when you click
// on the solution window
// scrollbar, it will synchronize the open document
rootItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
rootItem.DTE.SuppressUI = false;
}

private static void Collapse(UIHierarchyItem item, UIHierarchy solutionExplorer)
{
foreach (UIHierarchyItem hierarchyItem in item.UIHierarchyItems)
{
if (hierarchyItem.UIHierarchyItems.Count>0)
{
Collapse(hierarchyItem, solutionExplorer);
if (hierarchyItem.UIHierarchyItems.Expanded)
hierarchyItem.UIHierarchyItems.Expanded = false;
}
}
}




Enjoy!!!



Subscribe to XAF feed
Subscribe to community feed

DiggIt!

17 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Your friend John feels a bit left behind... I will catch up as soon as I get tied off my deadlines. That models-in-a-tool-window thing is pretty amazing. Does it refresh itself if I add a new module in my solution?

    And btw... great piece of work mate! Whole loads of grats.

    ReplyDelete
  3. @John

    Thnks for your comments . Yes it does refresh when you add or remove a module from a solution

    ReplyDelete
  4. Thanks!!! The ModelEditor plugin is a life saver!! It was so frustrating to get that message before. Anyway, I did notice that it's not able to handle project directories that contain spaces in them. I'm not sure how hard it would be to update it to handle this. Once I figured this out I simply put an underscore where the space was. Anyway, great work!!!

    ReplyDelete
  5. @Steve

    thnks for your comments . I have tested the added with your scenario but it still works look here
    spaces
    do I miss somthing?

    ReplyDelete
  6. @ Apostolis
    The plugin was able to find the models just fine but it ran in to issues when I tried to open the model. Did you try opening the model? I think it has to do with the args passed to the ModelEditor.exe program. I believe that when trying to retrieve the args, because there is a space in the folder name the argument is thought to be everything up until the space occurs. Does that make sense? For example, if I had a model file located in 'D:\FolderTemp\Sub Folder\Model.xafml' - Because there is a space in '\Sub Folder\' when you try to get the args[1] value that gets passed to the ModelEditor.exe it thinks that the args[1] value is 'D:\FolderTemp\Sub' instead of the whole name. Anyway, all I know is that it was able to open up the model when I placed an underscore where the space was in the folder name.

    Another small issue I ran into was that if one assembly references another assembly in the project, you need to set 'Copy Local' = true for the referenced assemly otherwise a 'FileNotFound' error pops up when you try to view the model.

    Anyway, Thanks again for your hard work!!

    ReplyDelete
  7. @Steve
    thnks for the debugging :). 1st bug is now fixed. If you want you can download again and now your folders will not need any renaming. But for the 2nd bug I can not do much or it involves much work to fix it, because that is the default behaviour of standalone ModelEditor.

    ReplyDelete
  8. Hi Apostolis,

    Is there something else that I need to do in order to get the model editor to persist the changes that I make? The editor opens but when I make changes to the model the 'save' button remains in the disabled state and none of the changes are persisted upon closing.

    Thanks,
    Steve

    ReplyDelete
  9. Hi Steve

    I m very sorry I have overllooked the code and when trying to fix the last bug you reported I created a new one. They are both fixed now.
    The bug was in modeleditor

    ReplyDelete
  10. @Apostolis,
    No problem. I would never have thought to come up with this solution in the first place so I am just thrilled that you created this and have shared it with the community. It has been and will be a huge time saver and will help me keep my sanity by not running into that error any more. Thanks again for sharing!!

    ReplyDelete
  11. Hello,

    >>Collapse all items in solution Explorer
    Very useful feature.

    BTW, all XAF Team members use a similar macros in their IDEs:
    =============
    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports System.Diagnostics

    Public Module Expand_Collapse
    Sub CollapseItem(ByVal Item As UIHierarchyItem)
    If Item.UIHierarchyItems.Expanded Then
    Dim UIHItem As UIHierarchyItem
    For Each UIHItem In Item.UIHierarchyItems
    CollapseItem(UIHItem)
    Next
    Item.UIHierarchyItems.Expanded = False
    If Item.UIHierarchyItems.Expanded = True Then
    ' Bug in VS 2005
    Item.Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object().DoDefaultAction()
    End If
    End If
    End Sub
    Sub CollapseAll()
    ' Get the the Solution Explorer tree
    Dim UIHSolutionExplorer As UIHierarchy
    UIHSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
    ' Check if there is any open solution
    If (UIHSolutionExplorer.UIHierarchyItems.Count = 0) Then
    MsgBox("Nothing to collapse. You must have an open solution.")
    Return
    End If
    ' Get the top node (the name of the solution)
    Dim UIHSolutionRootNode As UIHierarchyItem
    UIHSolutionRootNode = UIHSolutionExplorer.UIHierarchyItems.Item(1)
    Dim UIHItem As UIHierarchyItem
    For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems
    CollapseItem(UIHItem)
    Next
    ' Collapse each project node
    ' Select the solution node, or else when you click on the solution window
    ' scrollbar, it will synchronize the open document with the tree and pop
    ' out the corresponding node which is probably not what you want.
    UIHSolutionRootNode.Select(vsUISelectionType.vsUISelectionTypeSelect)
    End Sub
    Sub SetRerefencePaths()
    Dim i As Integer
    For i = 1 To DTE.Solution.Count
    Dim Project As Project
    Project = DTE.Solution.Item(i)
    Project.Properties.Item("ReferencePath").Value = "D:\2008.1\XAF\_Out;D:\2008.2\XAF\_Out;D:\2008.3\XAF\_Out;D:\2009.1\XAF\_Out;D:\2009.2\XAF\_Out;D:\2009.3\XAF\_Out;D:\2010.1\XAF\_Out"
    Next
    End Sub
    End Module
    =============
    Of course, your solution is more suitable.

    ReplyDelete
  12. Hi Apostolis,

    DevExpress.ExpressApp.ModelEditor.v9.1.exe from your download crashes when I try to open a module. I tried to run it directly and it does crash. Tried admin mode same results.
    If I use the one from DevExpress it says "Usage
    DevExpress.ExpressApp.ModelEditor.v9.1.exe Path_to_app_config_file". I am using 9.1.4, Vista, VS 2008. Thanks

    ReplyDelete
  13. model editor uses a log file in the same path as it. please check that

    ReplyDelete
  14. Hi Apostolis,

    Thanks for the tip. Unfortunately the program crashes even before it has a chance to log anything (I think). I get Vista message "Model Editor has stopped working... Check online... Close the program... Debug the program...". Any other tips? I tried it also under XP and it also crashes. I'm using 32-but Vista and XP.

    I get "loaded twice" error a lot and DevExpress pointed me to your solution, although I've visited your site and watched your videos before. Thanks for sharing btw.

    I also noticed that your supplied ModelEditor is 9.1.4 and is 36k. The one from DevExpress is also 9.1.4.0 but is only 23k in size.
    Thanks.

    ReplyDelete
  15. My model editor contains initialization code thats why size differs. What i would do in your situation since source code is avaliable as well why not run it from there and see exactly why it fails? but for sure smells like some kind of versioning problem

    ReplyDelete
  16. Where the heck is the download for these..

    ReplyDelete
  17. see <a href=&apos;http://apobekiaris.blogspot.com/2009/10/how-to-get-expand-latest-version.html&apos;>How to get eXpand latest version</a>

    ReplyDelete