Wednesday, 19 September 2012

EF edmx error solutions

"If your view is updatable you can simply remove the <DefiningQuery> element from the EntitySet definition for your view inside of the StorageModel section of your .edmx, and the normal update processing will work as with any other table. "


This is the case for me. Simply removing <DefiningQuery> resulted in another error.  I followed the steps of this post except the last one. For your convenience, I copied the 4 steps from the post   that I followed to solve the problem as following:
  1. Right click on the edmx file, select Open with, XML editor
  2. Locate the entity in the edmx:StorageModels element
  3. Remove the DefiningQuery entirely
  4. Rename the store:Schema="dbo" to Schema="dbo" (otherwise, the code will generate an error saying the name is invalid)


original answer: Here



Wednesday, 12 September 2012

Nlogger configuration file example


 I have put together, small sample of configuration file for you to see how you can specify different types of logging.
In this example I have logging into txt file, database, and event log.



here is the example


<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


  <variable name="applicationName" value="Dummmy" />


  <!-- do not change -->
  <variable name="eventLogTaget" value="CompanyName" />

  <targets>
    <!-- NLogViewer logger -->
    <!-- Text file logger
   
<target xsi:type="File" name="log" fileName="${basedir}/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message} ${exception:format=ToString,StackTrace}${newline}" />
-->
    <!--
    working
    <target name="eventlog" xsi:type="EventLog"
            layout="${logger}: ${message} ${exception:format=ToString}"
            log="${eventLogTaget}" source="${applicationName}" />-->

  

    
    
    <target name="databaseLog" type="Database">
      <dbprovider>mssql</dbprovider>
      <dbhost>Server</dbhost>
      <dbdatabase>Database</dbdatabase>
      <dbusername>UserName</dbusername>
      <dbpassword>Password</dbpassword>
      <commandText>
        INSERT INTO dbo.ActivityLog([Level],[Logger],[Message],[Exception],[StackTrace])
        VALUES( @level, @logger, @message, @exception, @stacktrace);
      </commandText>
      <parameter name="@level" layout="${level}" />
      <parameter name="@logger" layout="${logger}" />
      <parameter name="@message" layout="${message}" />
      <parameter name="@exception" layout="${exception:format=ToString,StackTrace}${newline}" />
      <parameter name="@stacktrace" layout="${stacktrace}"/>
    </target>
  </targets>
 
  <rules>
    <logger name="*" writeTo="databaseLog" />
  </rules>

  </targets>
  <rules>
    <logger name="*" levels="Trace, Info, Debug, Warn, Error, Fatal" writeTo="log"/>
    <logger name="*" levels="Trace, Info, Debug, Warn, Error, Fatal" writeTo="eventlog"/>
    <logger name="*" levels="Trace, Info, Debug, Warn, Error, Fatal" writeTo="databaseLog"/>
  </rules>
</nlog>


 Errors with configuration?

Now do you have any problems with configuration of NLog and do not want what is wrong?

add following line into your configuration file:
 throwExceptions="true" internalLogFile="c:\nlog.txt" internalLogLevel="Debug"

The full header:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" internalLogFile="c:\nlog.txt" internalLogLevel="Debug">

TFS select work items for project


Yesterday, I needed to connect to get all work items for project in Team Foundation 
Server. I have seen couple guides, but not easy to find.  
 
 
 
Here is how to get WorkItems Collection: 
 
This is example code and is not fit to be implemented as it is. 
 

 
protected WorkItemCollection ConnectToTFS()
{
 WorkItemCollection workItemCollection = null; 
 try
 {
  // lets define location of tfs server
  var tfsServerUri = new Uri("http://localhost:8080/tfs");
 
  // Account definition
  // var password = "password";
  // var domain = "domain";
  // var userName = "user";
var projectName ="TfsQueryProject";
  Project project = null;  
 
  // needed if you access tfs as user
  // NetworkCredential account = new NetworkCredential(userName, password,domain)
// TeamFoundationServer server = new TeamFoundationServer(tfsServerUri , account);

 
  TeamFoundationServer server = new TeamFoundationServer(tfsServerUri );

  // make sure you can
  server.Authenticate();
 
  // Get access to work items collection for server.
  WorkItemStore store = new WorkItemStore(server); 
 
  // get existing project 
  project = store.Projects[projectName]; 
 
  if (project == null)
   throw new Exception("Project could not found"); 
 
  // now construct query for work items that are in project 
  string querySql = "SELECT [System.Id], [System.Title], [System.Description] " +
     "FROM WorkItems " +
     "WHERE [System.TeamProject] = '" + PROJECT + "' " +; 
 
 //Execute query to get collection with have all the workitems from the project specified. 
 workItemCollection = store.Query(querySql); 
 
 

 }
 catch (Exception ex)
 { 
   // Todo:  handle exception as required.
throw ex;
 }
 
return workItemCollection; 
} 

Wednesday, 29 August 2012

Usefull tools

Do you want to monitor running processes?

You can use :

http://technet.microsoft.com/en-us/sysinternals/bb896645

Sunday, 26 August 2012

VS build commands

Today I needed to copy output from one solution into another.

command to do this is as follows:

copy $(TargetDir) "$(SolutionDir)\PROJECT-NAME\bin"