Attach macro

A visual studio macro to attach to a program to your choice:

Public Sub AttachPRogram()
        Try
            Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
            Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
            Dim compName As String = System.Net.Dns.GetHostName()
            Dim procAll = dbg2.GetProcesses(trans, compName)
            For Each proc2 As Process2 In procAll
                If (proc2.Name.ToLower().Contains("your program name here")) Then

                    proc2.Attach()

                End If
            Next proc2

        Catch ex As System.Exception
            MsgBox(ex.Message)
        End Try
    End Sub

friday links 18

MVC 4 beta was the release of the month : http://www.asp.net/mvc/mvc4 

  1. NETFx3 Samples – Home – dynamic calling WCF services
  2. Alan Turing’s reading list (with readable links) | John Graham-Cumming
  3. Six Whys – Or, Never Trust Your Network Switch – Blog – Stack Exchange
  4. In a New Era for Marketing, Parental Discretion Advised – Leslie Gaines-Ross – Harvard Business Review
  5. Dynamic Proxy and Memory Footprint – Vipul Modi’s Blog – Site Home – MSDN Blogs
  6. A look at ASP.NET MVC 4 | Techdays 2012 the Netherlands | Channel 9
  7. How to: Create Custom Configuration Sections Using ConfigurationSection
  8. RESTful Services with ASP.NET MVC and XHTML
  9. ASP.NET MVC Localization: Generate resource files and localized views using custom templates | Rui Jarimba
  10. ASP.NET: Downloading files from a UNC share | Rui Jarimba
  11. Single Page Application Overview: The Official Microsoft ASP.NET Site
  12. XML Visualizer v.2 – CodeProject®
  13. Calling a WCF service from a client without having the contract interface – CodeProject®
  14. 52 Things People Should Know To Do Cryptography
  15. Must-have Tools on Windows – Part 1 of 2 – Punit Ganshani
  16. Download HelpNDoc Personal Edition | HelpNDoc
  17. HelpNDoc’s feature tour | HelpNDoc
  18. Recruiting: 8 Qualities Your Best Employees Should Have | Inc.com
  19. Ubuntu for Android Effort Takes Flight – InternetNews.
  20. Mark Shuttleworth » Blog Archive » Ubuntu in your pocket
  21. Simple Talk Newsletter
  22. Automated Script-generation with Powershell and SMO
  23. How to Kill a Company in One Step or Save it in Three

Visual Studio Macro – copy from old code

I have a class ( not under my control) and I want to make a shallow copy of his properties.
I was tired to wrote this

newObject.Prop1= this.Prop1;
newObject.Prop2= this.Prop2;
...

And I have not want to use reflection or expression trees ( http://hydrating.codeplex.com/)

So I have made a fast Visual Studio Macro

Public Module TextRelated

    Public Sub CopyOld()
        Dim t As TextSelection = DTE.ActiveDocument.Selection
        Dim text As String = t.Text
        Dim str As String = "newObject." + text + " = this." + text + ";"

'http://svenmaes.blogspot.com/2007/03/access-clipboard-from-visual-studio.html
        modClipboard.ClipboardText = str

    End Sub
End Module

So the work was only to
1. wrote the property
2. click a button
3. CTRL+V

The only part that was difficult was how to put into the clipboard -see the http://svenmaes.blogspot.com/2007/03/access-clipboard-from-visual-studio.html

Simple, but efficient – Enjoy!

friday links 16

  1. Real World: Startup Lifecycle of a Windows Azure Role
  2. Utilizing the Power of Startup Tasks in Your Windows Azure Web Role | Windows Azure Customer Advisory Team (CAT)
  3. Android Development: Do You Know Your Options? » BuildMobile
  4. Fluqi – Ease using jQuery UI with ASP.NET and ASP.NET MVC
  5. SquishIt – The Friendly ASP.NET JavaScript and CSS Squisher | CodeThinked
  6. loads.in – test how fast a webpage loads in a real browser from over 50 locations worldwide
  7. 35 Highly Advanced Yet Simple To Use jQuery Plugins | Free and Useful Online Resources for Designers and Developers
  8. gMap – Google Maps Plugin For jQuery | Download
  9. FullCalendar – Full-sized Calendar jQuery Plugin
  10. 8 Powerful WordPress Plugins You Probably Don’t Use But Should | Free and Useful Online Resources for Designers and Developers
  11. 10 Completely Free Wireframing and Mockup Tools
  12. Scale of the Universe 2012 – OneMoreLevel.com
  13. LayeringPrinciples
  14. svenM: Access the clipboard from a visual studio macro
  15. Using Async for File Access – C# Frequently Asked Questions – Site Home – MSDN Blogs
  16. Microsoft Key Tools and Resources for Microsoft Developers – Developers, Developers Developers – Site Home – MSDN Blogs
  17. Visual Studio 2010 UML Design Pattern Toolbox Items Extension – Microsoft Visual Studio UK Team – Site Home – MSDN Blogs
  18. What is Microdata?
  19. What are Microformats?
  20. ASP.NET MVC DropDownList, MultiSelect and jQuery – Ricka on MVC and related Web Technologies – Site Home – MSDN Blogs
  21. LosTechies | Se Habla Code
  22. Lean Startup: Look Before You Leap — Visual Studio Magazine
  23. Talking to Customers: What a Concept — Visual Studio Magazine
  24. 4 ways to do Mail Merge using Google Apps Script – Google Apps Developer Blog
  25. GUI Architectures
  26. The Build Your Own CAB Series Table of Contents | Jeremy D. Miller
  27. Romcyber | ScrapySharp in english :)
  28. What Level Programmer Are You?
  29. What are your favorite Nuget MVC packages » BuildStarted.com
  30. Jang a server-side/client-side view engine for MVC and javascript » BuildStarted.com
  31. Razor Engine v2.x » BuildStarted.com
  32. Database Performance Transparency – SQLServerCentral
  33. Productive Living
  34. Constraints, expectations and real estate | Jimmy Bogard’s Blog
  35. Linux 2.6.39-rc3 :
    << There really are only two acceptable
    models of development: "think and analyze" or "years and years of
    testing on thousands of machines". Those two really do work.>> Linus Torvalds

Clearer as Nuget package

It was not so difficult to make Clearer as NuGet package. Just analyzing MVC Sitemap package done the trick. So the package looks like:

image

 

You can install from http://nuget.org/packages/Clearer or download a sample application  http://clearer.codeplex.com

( What he does ?

In every application there are some variables that are set by the ASP.NET application( ASP.NET_SessionId cookie ) and some that are set by the programmer( cached data in Application/Session/Cache/Cookies and so on).
I wanted every time to have a page where I can “clear” / delete those – and not found. So it’s the Clearer project.
Possible uses:
For developers – when they want to see what happens when a cache item no longer exists
For developers – to put to site admins some simple tool to reload data from Cache/Application . Just edit the LoadAll function to load only Cache/Application
For developers – to test easily the session. Just delete ASP.NET_SessionId cookie – you will get another one when you refresh the page.

)

So please install Nuget package from http://nuget.org/packages/Clearer and tell me if it works!

Clearer MVC

In every application there are some variables that are set by the ASP.NET  application(  ASP.NET_SessionId  cookie ) and some that are set by the programmer( cached data in Application/Session/Cache/Cookies and so on).

I wanted every time to have a page where I can “clear” / delete those – and not found. So it’s the Clearer project.

It consists of :

  1. ClearerController with 2 Actions:   Index and DeleteItem
  2. 2 Views : Index.cshtml and EditAppData.cshtml
  3. Different Models:
    • SourceData  – enum  – can be  :  None ,        Application ,        Cache ,        Session ,        Cookies
    • AppData –  maintains Key/Value and SourceData pairs
    • ListAppData – loads data from Application , Cache , Session , Cookies  – and deletes.

To make an example, I have put in the Application_Start and Session_Start different values. So the screen is the following:

image

What I learn from the code:

  1. The Cookies, Applications, Session , Cache items can be easily converted to an DictionaryEntry and the code can be like this:
     DictionaryEntry de = new DictionaryEntry(item, sess[item.ToString()]);
     AddNew(de, SourceData.Session);
    
  2. Code must be error prone – what if some item in Session is null ? So , if I have the Key, all is good:
    private void AddNew(DictionaryEntry de, SourceData sd)
            {
                AppData ap = new AppData() { source = sd, Key = de.Key.ToString() };
                try
                {
                    var obj = de.Value;
                    ap.Value = (obj == null) ? Null : obj.ToString();
                }
                catch (Exception ex)
                {
    
                    ap.Value = string.Format(ErrorToString, ex.Message);
                }
                this.Add(ap);
            }
    
  3. The dog-food is good: I have followed my advice from msprogrammer.serviciipeweb… and it works ( used for Remove )
       [HttpPost]
            public JsonResult DeleteItem(string TheKey, int Source)
            {
                try
                {
                    var lad = new ListAppData();
                    lad.DeleteItem(TheKey, (SourceData)Source);
                    return Json(new { ok = true, message = "" });
                }
                catch (Exception ex)
                {
                    return Json(new { ok = false, message = ex.Message });
                }
                
            }
    
  4. When you pass strings in Javascript, there is a simple way to encode: HttpUtility.JavaScriptStringEncode
    <a href="javascript:removeItem('@HttpUtility.JavaScriptStringEncode(Model.Key)','@((int)Model.source)','@id')">Remove</a>
    

Possible uses:

  1. For developers –  when they want to see what happens when a cache item no longer exists
  2. For developers – to put to site admins some simple tool to reload data from Cache/Application . Just edit the LoadAll function to load only Cache/Application Winking smile
  3. For developers  – to test easily the session. Just delete ASP.NET_SessionId  cookie – you will get another one when you refresh the page.

You can view online at http://clearer.apphb.com/Clearer
The project could be found at http://clearer.codeplex.com and have all – source code, downloadable project .

Next week it will be a Nuget item.

For more features , please leave me a comment here or on codeplex at issues
Nuget package at http://nuget.org/packages/Clearer

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.