AutoPropertiesToString helper method

I needed in ToString() method for a class to log auto-properties.  Below are two methods that I used

/// <summary>

///

/// </summary>

/// <param name=”obj”></param>

/// <param name=”declaredOnly”></param>

/// <returns></returns>

/// <remarks> Created to log  DeclaredOnly in the current class using GetType().GetProperties(), for full object dump other methods may be more appropriate

/// See  http://stackoverflow.com/questions/4023462/how-do-i-automatically-display-all-properties-of-a-class-and-their-values-in-a-s

/// and  http://stackoverflow.com/questions/852181/c-printing-all-properties-of-an-object?lq=1

///  </remarks>

public static string AutoPropertiesToString( object obj, bool printNulls=false, bool declaredOnly=true)

{

BindingFlags flags = BindingFlags .Public |  BindingFlags.Instance;

if (declaredOnly) flags |= BindingFlags.DeclaredOnly;

var propertyInfos = obj.GetType().GetProperties(flags);

var sb = new StringBuilder();

foreach ( var info in propertyInfos)

{

if (info.IsAutoProperty())

{

var val = info.GetValue(obj, null);

if (printNulls == false && val == null)

continue;

var value = val ?? “(null)”;

sb.AppendLine(info.Name + “: ” + value);

}

}
return sb.ToString();

}
/// <summary>

/// It’s not fool proof, quite brittle

/// </summary>

/// <param name=”info”></param>

/// <returns></returns>

/// <remarks> from http://stackoverflow.com/questions/2210309/how-to-find-out-if-a-property-is-an-auto-implemented-property-with-reflection </remarks>

public static bool IsAutoProperty( this PropertyInfo info)

{

bool mightBe = info.GetGetMethod().GetCustomAttributes(typeof (CompilerGeneratedAttribute ),true ).Any();

if (!mightBe)

{

return false;

}

if (info.DeclaringType == null)

return false;

bool maybe = info.DeclaringType

.GetFields( BindingFlags.NonPublic | BindingFlags.Instance)

.Where(f => f.Name.Contains(info.Name))

.Where(f => f.Name.Contains( “BackingField”))

.Any(f => f.GetCustomAttributes(typeof (CompilerGeneratedAttribute ),true ).Any());
return maybe;

}

#net, #auto-properties, #tostring

Windows Feedback application in Windows 10 is very immature.

Recently I wanted to submit feedback to mIcrosoft and had to use Windows Feedback application in Windows 10. I was surprised how immature it is. They have Connect website  https://connect.microsoft.com that working fine for many applications, including visual studio and SQL server. They also using Uservoice sites, that also have acceptable user interface( apart of stupid limit for number of votes). What was the reason to create new proprietary application, supported only by Windows 10.

Link in MS Feedback is generated as something like

 Windows-Feedback:?contextid=79&feedbackid=b11f8bdf-eaf4-4799-8e65-5161924ad22c&form=1&src=2

As you can expect, browsers do not understand these links. Even when I copied the link into feedback search field, it didn’t find it.

When I upvoted existing feedback, I’ve added a comment. However, when I open the same feedback again, my comments were not visible. They  should show the all discussion, not only initial suggestion.
I am not able to copy text of existing feedback. I opened it but text is not selectable. I tried to share via mail, but the feedback is added as image, not as text. 
It will be much better if MS will create Web client for feedback database to be viewed in normal browser.

#feedback, #windows

I moved my blog from GeeksWithBlogs

This is my first post at WordPress. I  had a http://geekswithblogs.net/mnf/ blog at GeeksWithBlogs for 10 years. But recently I had a big concern, that  GeeksWithBlogs site is not supported at all. The support does not reply to emails, Twitter messages and reports on the support forum.  I will not be surprised, if the GWB site will suddenly shutdown without any warning.

I did a research to find  a blogging platform, and WordPress was recommended in most places. It was a big work to migrate the blog, because there is no out of the box tools ( The  code that I was using is located on https://github.com/MNF/gwb-to-wordpress ).

Now I am thinking how can I achieve the traffic and search engine ranking, that I had in GeeksWithBlogs.

#blog-migration

SqlDependency Notification database Options troubleshooting

For SQL notifications we followed the steps described in http://dimarzionist.wordpress.com/2009/04/01/how-to-make-sql-server-notifications-work.

However it didn’t work for our database. The instructions missed a step to ensure that database options are set for SqlDependency Notification

I’ve created a function to Follow recommendation to always check the notification source, info and type, it returned
 
SqlNotificationEventArgs, Type : Subscribe, Source : Statement, Info : Options 

    //TODO: pass  SQL string
      /// <summary>
               ///
               /// </summary>
               /// <param name=”logger”></param>
               /// <param name=”e”></param>
               public static void LogSqlNotificationEventArgs( Logger logger, SqlNotificationEventArgs e,DbConnection dbConnection=null)
              {
                      LogLevel level = LogLevel .Warn;
                      //You’re supposed to check the values of the SqlNotificationEventArgs argument. Only if Type is Change and Source is Data where you notified for a data change.
                      if ((e.Type == SqlNotificationType .Change) && e.Source == SqlNotificationSource.Data)
                     {
                           level = LogLevel.Info;
                     }
                      if (e.Info == SqlNotificationInfo .Options)
                     {
                            if (dbConnection != null )
                           {
                                   //TODO http://www.mssqltips.com/sqlservertip/1415/determining-set-options-for-a-current-session-in-sql-server/. Make SP
                                   //check DB set options,
                                   // Execute SqlDependencies_CheckDBSetOptions
                                   // Run Alter DB

                           }
                     }
               //http://msdn.microsoft.com/en-us/library/ms189308%28SQL.105%29.aspx Insert/update/delete/truncate are valid
                     logger.Log(level, “SqlNotificationEventArgs, Type : {0}, Source : {1}, Info : {2} “, e.Type, e.Source, e.Info);
                     
              }

Based on TROUBLESHOOTING QUERY NOTIFICATIONS in http://rusanu.com/2006/06/17/the-mysterious-notification/ 

and Troubleshooting Query Notifications I’ve created Stored Procedure


/*
— RUN manually for every DB that required change

ALTER DATABASE MyDB
set ANSI_NULLS ON
       , ANSI_PADDING ON
, ANSI_WARNINGS ON
, CONCAT_NULL_YIELDS_NULL ON
, QUOTED_IDENTIFIER ON
, NUMERIC_ROUNDABORT OFF
,ARITHABORT ON
*/
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
— Drop stored procedure if it already exists
IF EXISTS (  SELECT *     FROM INFORMATION_SCHEMA.ROUTINES     WHERE SPECIFIC_SCHEMA = N’dbo’     AND SPECIFIC_NAME = N’SqlDependencies_CheckDBSetOptions’ )
   DROP PROCEDURE dbo.SqlDependencies_CheckDBSetOptions
GO

— =============================================
— Author:           MNF
— Create date:
— Description:      
— =============================================
CREATE PROCEDURE SqlDependencies_CheckDBSetOptions
       @dbName sysname 
AS
BEGIN
        — SET NOCOUNT ON added to prevent extra result sets from
        — interfering with SELECT statements.
        SET NOCOUNT ON;
select –*
       is_ANSI_NULLS_ON
        ,is_ANSI_PADDING_ON
        ,is_ANSI_WARNINGS_ON
        , is_CONCAT_NULL_YIELDS_NULL_ON
, is_QUOTED_IDENTIFIER_ON
, is_NUMERIC_ROUNDABORT_ON–OFF
,is_ARITHABORT_ON
–select *
From sys .databases where name =@dbName 
and (
       is_ANSI_NULLS_ON =0
        or is_ANSI_PADDING_ON =0
        or is_ANSI_WARNINGS_ON =0
        or is_CONCAT_NULL_YIELDS_NULL_ON =0
or is_QUOTED_IDENTIFIER_ON= 0
or is_NUMERIC_ROUNDABORT_ON = 1–OFF
or is_ARITHABORT_ON= 0)

END
— SqlDependencies_CheckDBSetOptions ‘MyDB’
GO

Links for RazorEngine development.

We are using RazorEngine to generate emails based on .cshtml templates.
 
Below are a few links that I used when develop it



http://weblog.west-wind.com/posts/2010/Dec/27/Hosting-the-Razor-Engine-for-Templating-in-NonWeb-Applications

How to set iOS Pocket to open in Web View.

I prefer to open pages in Web View, because Article View often doesn’t show text (in particular source code) properly.
However option “Open Best View” usually opens Article View and I needed to change it manually.
Pocket support provided me with solution
          To force the app to open all the articles in web view in your iPad you can follow these steps:
  1. Tap the Profile option
  2. Tap Settings, in the top right corner
  3. Under the headline Offline Downloading, disable “Download Best View”, “Always Fetch Article”
  4. Enable “Always Fetch Web View”
However it will be easier for user to have in settings section “select view” with options Web, Article,View.
Also if Pocket would have support forums, they will not need to repeat the same answer for other users and I would not create this post.

Insert new line in multiple xml files using Visual Studio

I needed to insert new line after existing one in multiple similar xml files.
In Visual Studio open “replace in files” dialog and tick “use regular expression”
In “find” escape “/” as “\/”
     <param name=”ExistingKey” value=”(.*)” \/>
In “Replace” repeat original string, then add n and add a new string
     <param name=”ExistingKey” value=”$1″ />\n  <param name=”NewKey” value=”new value” />
Related links: