# 23 Kasım 2007 Cuma
A small tidbit. In WCF, service code like this

public string MyServiceMethod()

{

    throw new FaultException<string>("It happened!");

}


will make VS break into debugger. Normally you just throw FaultException's, knowing that the dispatcher hadles it to convert it to a fault contract message. But VS thinks that it's an unhandled user exception (it is, actualy). For a smoother debugging experience, just add System.ServiceModel.FaultException`1 to Debug / Exceptions / Common Language Runtime Exceptions, unchecked.


posted on 23 Kasım 2007 Cuma 07:07:15 UTC  #   
# 29 Ekim 2007 Pazartesi
I have seen Roy's frustration on having a will-expire VPC on the lap, three days before a serious event where he is the speaker planning to use the exact same VPC! Yay.

Here's a quick possible fix to the problem before 1st of November. This is the ninja tactic I have been using for expired VPC's for whatever reason.

  1. Break the date synchronization between the host (your pc) and the VPC image.
    To do this, you should add the following lines (in bold) to the .vmc file (I did this to both Base01 and OrcasBeta2_VSTS vmc files, to be safe):
        <!-- ... other things -->
        <integration>
            <microsoft>
              <!-- ... other things -->
                <components>
                    <host_time_sync>
                        <enabled type="boolean">false</enabled>
                    </host_time_sync>
                </components>

            </microsoft>
        </integration>
  2. Start VPC image. Change date to sometime in the past.
  3. Restart VPC, it won't be in sync with the host anymore.
I tested this by changing my computer's time to 2nd of November, worked for me as shown in the following screenshot:



Based on my past experience it will work forever, but I'm not guaranteeing anything. I don't know if this will work when the actual day comes for this particular VPC image. So, backup your data, don't rely on this for the morning of 1st of November, and take this info AS IS.

Update:
Jeff Beehler says:

"I would strongly advise against changing the system time on the VPC if you're using TFS as TFS counts on time always moving forward.  You cannot make a check in or save a work item with an earlier date than the last one for obvious reasons.  So, if you're using the VPC in production, you could get yourself into a situation where you can't check in which would obviously be problematic."

He has also a solution for the expiration problem if you have a valid 2003 Server media and key.

So, yes, unless you're using TFS on the image, you may use this trick. And this makes it invalid for Roy's case.
posted on 29 Ekim 2007 Pazartesi 12:51:31 UTC  #   
# 29 Ocak 2007 Pazartesi
It sometimes get frustrating when you debug your project through another instance of Visual Studio, especially if you manipulate the "active" DTE within your debug project. I somehow ended up to the following when getting a reference to DTE:

System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0");


It worked most of the time, but "not all the time" means you may add a project to the solution where your code resides (the parent VS instance), rather than where the debugging session is. So, after some research, DTE code turned into this:

[DllImport("ole32.dll")]

public static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);


[DllImport("ole32.dll")]

public static extern int CreateBindCtx(int reserved, out IBindCtx ppbc);


[CLSCompliant(false)]

public static DTE GetDTE(string processID)

{

    IRunningObjectTable prot;

    IEnumMoniker pMonkEnum;

 

    string progID = "!VisualStudio.DTE.8.0:" + processID;

 

    GetRunningObjectTable(0, out prot);

    prot.EnumRunning(out pMonkEnum);

    pMonkEnum.Reset();

 

    IntPtr fetched = IntPtr.Zero;

    IMoniker[] pmon = new IMoniker[1];

    while (pMonkEnum.Next(1, pmon, fetched) == 0)

    {

        IBindCtx pCtx;

        CreateBindCtx(0, out pCtx);

        string str;

        pmon[0].GetDisplayName(pCtx, null, out str);

        if (str == progID)

        {

            object objReturnObject;

            prot.GetObject(pmon[0], out objReturnObject);

            DTE ide = (DTE)objReturnObject;

            return ide;

        }

    }

 

    return null;

}

posted on 29 Ocak 2007 Pazartesi 22:17:43 UTC  #   
# 11 Ekim 2006 Çarşamba
I can't dechiper legal documents even in Turkish, how can I decide if I'm allowed to release the source code or not by looking at the VS DSK license? If Microsoft has a department or something to ask "would you get angry if I release this?", I want to know.

Anyway, you can download the source of ActiveWriter Preview here. I have removed some .tt files copyrighted by Microsoft, but instructions are available in the download to add them from an empty DSL Tools project. Lack of .tt files will prevent any "just extract and open" scenario, sorry about that.

Back to the license adventure. I have asked in DSL Tools forum if it's possible to release the source, and directed to the SDK license. Then I found a post on Interop blog, saying that "It is possible to release extensions to Visual Studio under open source licenses" with an IANAL notice. I have convinced that I can, until I notice copyright notes on all over the .tt files, which are very much the core of the code generation on DSL Tools part. So I followed the next best approach, removed copyrighted stuff.

Having copyright notices in .tt files, for Microsoft, is a bit silly, by the way. They don't include notices in AssemblyInfo or config files (or any other template generated solution files), what's different with .tt's?

Update:

Gareth Jones from DSL Tools team replied, saying that .tt files are considered to be samples and developers may customize them with whatever license statements they have. This is extremely good. I'll re-release the source with all the .tt files included.

And for those who don't know what a .tt file is for; they are input files for the text templating engine of DSL Tools. They have ASP.NET like <# #> syntax to generate output as VS solution files. Very handy, but I prefered a more classic approach in ActiveWriter. CodeGenerationHelper is much nicer in plain C# than .tt syntax.

ActiveWriterReport.tt file:

<#@ template inherits="Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation" debug="true"#>
<#@ output extension=".%EXT%" #>
<#@ ActiveWriter processor="ActiveWriterDirectiveProcessor" requires="fileName='%MODELFILE%'" #>
<#@ import namespace="Altinoren.ActiveWriter.CodeGeneration" #>
<#
    CodeGenerationHelper helper = new CodeGenerationHelper(this.Model, "%NAMESPACE%");
    this.Write(helper.Generate());
#>

and the usage:

protected override byte[] GenerateCode(string inputFileName, string inputFileContent)

{

    ResourceManager manager =

        new ResourceManager("Altinoren.ActiveWriter.VSPackage",

                            typeof (ActiveWriterTemplatedCodeGenerator).Assembly);

    FileInfo fi = new FileInfo(inputFileName);

    inputFileContent =

        manager.GetObject("ActiveWriterReport").ToString().Replace("%MODELFILE%", fi.Name).Replace(

            "%NAMESPACE%", FileNameSpace).Replace("%EXT%", "cs"); // TODO: Get file extension from the project model

 

    byte[] data = base.GenerateCode(inputFileName, inputFileContent);

    return data;

}


posted on 11 Ekim 2006 Çarşamba 09:59:00 UTC  #   
# 30 Eylül 2006 Cumartesi

Help and download available here.

If you missed the announcement, it is a visual designer, an addin for Visual Studio 2005, to design a domain model and to generate code decorated with ActiveRecord attributes.

Please send bugs, suggestions and feature request through the Navigation pane of the site.

Thanks To

ActiveRecord team for the great and well supported library, NHibernate and Hibernate community for making this chain-reaction possible, Microsoft DSL Tools team for making DSL modelling this easy, everyone at DSL Tools forum, and my wife Damla for her patience.

Pluralization code is simplified version of Damian Conway's algorithm in paper An Algorithmic Approach to English Pluralization
Server Explorer integration greatly inspired from Ted Glaza's post here.
posted on 30 Eylül 2006 Cumartesi 18:12:03 UTC  #   
# 15 Eylül 2006 Cuma

Head to the VSIP member site to download. I'm %46 done right now.

Since DSL Tools v1 is bundled with this final release, and since I'll finally be able to include redistributables with ActiveWriter installer, I'm twice excited right now :)

My plan is:

    Compile ActiveWriter against DSL Tools v1
    Fix things broken by the v1
    Add one2one support (Just manual modelling. No heuristics for drag-drop. Will complete that later)
    Test & release.

 And about the current state of the project:

    Handles many-to-one, both in manual design and drag-drop.
    Handles many-to-many, both in manual design and drag-drop.
    Primary keys, properties, fields.
    Composite keys: Writes the attribute as well as a separate composite key class :) Yup.
    Some more model validators (If PrimaryKeyType.Sequence, then sequence name should be defined etc.)
    Versions and Timestamps.
posted on 15 Eylül 2006 Cuma 12:31:35 UTC  #   
# 19 Ağustos 2006 Cumartesi

ActiveWriter is a DLinq designer like addin for Visual Studio 2005 to design a domain model and to generate code decorated with ActiveRecord attributes.

 

 

It supports / will support:

  • Modeling
    Classes (Almost done)
    Class properties (Almost done)
    Setting a property as primary keys (Done)
    Setting more than one property as composite key (TBI)
    Many to One (Done), One to One, Many to Many relations (TBI)
    Nested classes (TBI)
    ... and more (I'm targeting to support the whole ActiveRecord model)
  • Model validation
    Current build validates most common things like classes without names, spaces in class names etc.
  • Drag and drop of table(s) from Server Explorer
    Can place tables, populate properties. I'm working on relations right now.
  • Automatic generation of source code of the model on save.
    Not implemented yet, but I know how to do it. Right now, it goes through .tt file.
  • Multiple database types as drag/drop source.
    Working on SQL Server right now. Oracle and others will follow.

I use the current CTP of DSL Tools to build the base. There are no downloadable bits right now, since I have to get a VSIP licence to make it run without the SDK.

I don't know to what extent I can open the source. I'll sure make the source downloadable but since part of the code is generated by DSL Tools and there's this VSIP licence, I may not be able to licence it under BSD or something. I'll look for it.

Anyway, I believe it will be a nice addin to have for people working with ActiveRecord/NHibernate. I'm doing my best to release a preview in one or two months.

Comments and suggestions are welcome.


posted on 19 Ağustos 2006 Cumartesi 11:02:33 UTC  #   

It's a black hole since its so massive that even a tiny piece of information on it's usage cannot escape out. Start writing an addin for Visual Studio and you'll find lots of information on the net. Enter into realms of Server Explorer, and you'll feel the massive darkness.

I'm coding and addin for Visual Studio 2005 using DSL Tools. Apart from the relatively steep learning curve of DSL Tools, it was going fine. By the very nature of the project, I started thinking on adding drag and drop of tables from Server Explorer. There are some DSRef and UIHierarchy usage examples on the net, so I thought it will be a piece of cake, until I find out there's no simple way of getting the underlying object model for data connections in Server Explorer, thanks to Microsoft's ability to mark everything Server Explorer as Private or Internal.

Long story short, after long nights and hours of Reflector and thousands of evasive maneuvers against the missile fired by my wife, here's how you get the DbConnection instance of Server Explorer holding the tables dropped on your design surface:

        private static DataConnection GetDataConnection(DTE dte, string itemName)

        {

            IntPtr ptr = IntPtr.Zero;

            try

            {

                if (((IServiceProvider)dte).QueryService(ref ServerExplorer, ref IUnknown, out ptr) >= 0)

                {

                    object o = Marshal.GetObjectForIUnknown(ptr);

                    if (o != null)

                    {

                        object dataConnectionsNode = GetField(o, "lastBrowseObjectNodeSite");

                        if (dataConnectionsNode != null)

                        {

                            INodeSite nodeSite =

                                (INodeSite)dataConnectionsNode;

 

                            INodeSite[] nodes = nodeSite.FindChildrenByLabel(itemName);

                            if (nodes != null && nodes.Length > 0)

                            {

                                object expNode = GetField(nodes[0], "expNode");

                                if (expNode != null)

                                {

                                    object nestedHierarchy = GetField(expNode, "nestedHierarchy");

                                    if (nestedHierarchy != null)

                                    {

                                        DataConnection connection =

                                            GetProperty(nestedHierarchy, "DataConnection") as DataConnection;

                                        if (connection != null)

                                        {

                                            return connection;

                                        }

                                    }

                                }

                            }

                        }

                    }

                }

            }

            finally

            {

                Marshal.Release(ptr);

            }

 

            return null;

        }

        private static object GetField(object o, string fieldName)

        {

            if (o != null && !String.IsNullOrEmpty(fieldName))

                return o.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(o);

 

            return null;

        }

 

        private static object GetProperty(object o, string fieldName)

        {

            if (o != null && !String.IsNullOrEmpty(fieldName))

                return o.GetType().GetProperty(fieldName).GetValue(o, null);

 

            return null;

        }

Once you get DataConnection, try ConnectionSupport.ProviderObject property to get the actual DbConnection. Happily, VS loaded addins cannot load new assemblies into AppDomain but at least allowed reflection.

posted on 19 Ağustos 2006 Cumartesi 09:49:55 UTC  #   
# 09 Şubat 2006 Perşembe

Please Note: If you're using VS 2008, you don't need this tool anymore. 2008 has this functionality built-in, look for the dropdown on top of the resource editor.

Introduction

In Visual Studio 2005, strongly-typed code for resource files (.resx files) are automatically generated when you save them. The generated class, however, cannot be accessed externally since the class is marked as internal.

This little add-in just instructs the generation process to build a Public class. To use it, just change the Custom Tool property of any resource file from ResXFileCodeGenerator to ResXFilePublicCodeGenerator.

After you make any changes and save the file, IDE will auto-generate a Public strongly-typed class for your resource.

Licence

The component and source is provided "as is" and there are neither warranties to the quality of the work nor any expressed or implied agreements that the programmer will release any updates. The programmer will release updates and provide any support at his own discretion.

External code mentioned in credits may subject to their own licence terms.

1.0.0.1 Update:
Fixed the issue with VB.Net root namespaces. This is, in fact, reported months ago but I totally forgot to fix it. I apoligize from all VB.Net users for the trouble.

Download

v1.0.0.1

Credits

Includes some code from Daniel Cazzulino’s XSD -> Classes Generator Custom Tool article.

VS Integration classes from http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=4AA14341-24D5-45AB-AB18-B72351D0371C

posted on 09 Şubat 2006 Perşembe 00:10:42 UTC  #