Synology backup to Azure stuck

My Synology NAS is backing up to Azure for some time now. While troubleshooting our slow internet I noticed the backup was running since June. I would expect a message of concern in my mailbox or in Pushover, but the only message I found are informational.

synology_backup_failed_to_run

I stopped the running Azure backup task. Then I started the Azure backup task again and checked on it the day after to see it completed successful.

To get notified whenever this is happening again I added a notification rule. Whenever the message “Failed to run” appears in the logging I get notified.

synology_log_center_failed_to_run

Posted in Uncategorized | Tagged , | Leave a comment

Ignore integration tests when provider is missing

As an integration test I’ve written some unit tests for my MsAccess Data Access Layer. The provider I’m using is OleDb. It will be installed on every desktop machine, but not on our build server.

The build fails because of the missing provider. So, we decided to ignore the tests when the provider was missing. See the boilerplate code below

static List<string> Providers;
static GMCDatabaseFileUser() {
   Providers = new List<string>();
   var reader = System.Data.OleDb.OleDbEnumerator.GetRootEnumerator();
   while (reader.Read()) {
      for (var i = 0; i < reader.FieldCount; i++) {
         if (reader.GetName(i) == "SOURCES_NAME") {
            Providers.Add(reader.GetValue(i).ToString());
            Trace.WriteLine(reader.GetValue(i).ToString());
         }
      }
   }
   reader.Close();
}
static void EnsureProvider() {
   var provider = "Microsoft.ACE.OLEDB.12.0";
   if (!Providers.Contains(provider)) {
      Assert.Inconclusive("Missing {0}", provider);
   }
}

Now I can simply call the logic in every unit test and have it ignored when the provider is missing.

[TestMethod]
public void MyProviderNeedingTest()
{
   EnsureProvider();
   // provider needing test
}

How will I know this happened on the build server? Check your code coverage, it’ll be less than you expect. Also the ignored tests are in the log.

Posted in Uncategorized | Tagged , , , , | Leave a comment

Week roundup

Last week recap and links:
Image courtesy of kanate / FreeDigitalPhotos.net

Image courtesy of kanate / FreeDigitalPhotos.net

What are your best reads this week? Leave them in the comments below.

Posted in Uncategorized | Tagged , , , , | Leave a comment

SGEN during build and deploy

With sgen you can generate a XML Serializer assembly to ship with your application. This way the .NET framework can load the assembly in stead of generating a temporary type every time you need the XML Serializer.

To generate the XmlSerializers assembly on every build include this in your build/csproj file. This will generate a new assembly in your output folder with the name ASSEMBLY.XmlSerializers.dll. For all types in itemgroup SgenTypes the xmlserializer is included in the assembly.

<Target Name="AfterBuild">
   <ItemGroup>
      <SgenTypes Include="MY.NAMESPACE.TYPE" />
   </ItemGroup>
   <Sgen ShouldGenerateSerializer="true" 
         UseProxyTypes="false" 
         BuildAssemblyName="ASSEMBLY.dll" 
         BuildAssemblyPath="$(TargetDir)" 
         Types="@(SgenTypes)" />
</Target>

When you want the same for website projects but only for deployment, use the code below. It extends the CopyAllFilesToSingleFolderxxxx target to generate the XmlSerializers assembly and to include it in the deploy / package folder.

<PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForPackageDependsOn>
    <CopyAllFilesToSingleFolderForMsDeployDependsOn>
      CustomCollectFiles;
      $(CopyAllFilesToSingleFolderForPackageDependsOn);
    </CopyAllFilesToSingleFolderForMsDeployDependsOn>
  </PropertyGroup>
  <Target Name="CustomCollectFiles">
    <!-- Generate XmlSerializers -->
    <ItemGroup>
      <SgenTypes Include="MY.NAMESPACE.TYPE" />
    </ItemGroup>
    <Sgen ShouldGenerateSerializer="true" UseProxyTypes="false" BuildAssemblyName="ASSEMBLY.dll" BuildAssemblyPath="$(TargetDir)" Types="@(SgenTypes)" />
    <!-- XmlSerializers to publish directory -->
    <ItemGroup>
      <_CustomFiles Include="$(TargetDir)*.XmlSerializers.dll">
        <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </_CustomFiles>
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
    <ItemGroup>
      <_CustomFiles2 Include="Deployment\*">
        <DestinationRelativePath>..\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </_CustomFiles2>
      <FilesForPackagingFromProject Include="%(_CustomFiles2.Identity)">
        <DestinationRelativePath>..\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
Posted in Development | Tagged , , , | Leave a comment

MEF configuration and parallel transactions

aspnetWhile testing my ASP.NET Web API solution single requests are fine, but multiple requests give HTTP500 after a long wait.

A MEF configuration setting caused parallel transactions and the database provider was unable to handle them.

Setup

ASP.NET Web API offers an extension to use your own IoC. I’m using the MEF implementation from stackoverflow. Below the configuration code with my Handler and Context added.

var registration = new RegistrationBuilder();
registration.ForTypesDerivedFrom<Controller>()
            .SetCreationPolicy(CreationPolicy.NonShared)
            .Export();
registration.ForTypesDerivedFrom<ApiController>()
            .SetCreationPolicy(CreationPolicy.NonShared)
            .Export();
registration.ForTypesDerivedFrom<IHandler>()
            .Export<IHandler>();
registration.ForTypesDerivedFrom<IContext>()
            .Export<IContext>();
var catalog = new ApplicationCatalog(registration);
var container = new CompositionContainer(catalog, true);

Exception

Using Fiddler I’m sending multiple requests to the Web API. The result is HTTP500 An error occurred while starting a transaction on the provider connection. See the inner exception for details. with the inner exception on the server SqlConnection does not support parallel transactions.

Solution

The Handler and Context object are shared between the two requests. While creating a record for the first request the second request starts a transaction for creating it’s record. Setting the CreationPolicy for both objects to NonShared solved it.

registration.ForTypesDerivedFrom<IHandler>()
            .SetCreationPolicy(CreationPolicy.NonShared)
            .Export<IHandler>();
registration.ForTypesDerivedFrom<IContext>()
            .SetCreationPolicy(CreationPolicy.NonShared)
            .Export<IContext>();
Posted in Development | Tagged , , | Leave a comment