0 Comments

A couple of quick extension methods for your amusement that I use a lot.

 

   1:          /// <summary>
   2:          /// Runs action against the specified source.
   3:          /// </summary>
   4:          /// <typeparam name="T">The type of the element.</typeparam>
   5:          /// <param name="source">The source.</param>
   6:          /// <param name="action">The action.</param>
   7:          public static void Run<T>(this IEnumerable<T> source, Function<T> action)
   8:          {
   9:              if (source == null)
  10:              {
  11:                  throw new ArgumentNullException("source");
  12:              }
  13:   
  14:              if (action == null)
  15:              {
  16:                  throw new ArgumentNullException("action");
  17:              }
  18:   
  19:              foreach (var element in source)
  20:              {
  21:                  action(element);
  22:              }
  23:          }
  24:   
  25:          /// <summary>
  26:          /// Does action against the specified source and returns the source.
  27:          /// </summary>
  28:          /// <typeparam name="T">The type of the element.</typeparam>
  29:          /// <param name="source">The source.</param>
  30:          /// <param name="action">The action.</param>
  31:          /// <returns>The source after the action is executed.</returns>
  32:          public static IEnumerable<T> Do<T>(this IEnumerable<T> source, Function<T> action)
  33:          {
  34:              if (source == null)
  35:              {
  36:                  throw new ArgumentNullException("source");
  37:              }
  38:   
  39:              if (action == null)
  40:              {
  41:                  throw new ArgumentNullException("action");
  42:              }
  43:   
  44:              return source.Select(
  45:                  element =>
  46:                  {
  47:                      action(element);
  48:                      return element;
  49:                  });
  50:          }

1 Comments

I’m messing with sync framework and am just posting this as a quick note to self, but it might help others too. When syncing with a custom scope I’m using this code to filter on a column.

   1:  var sqlAzureProvisioning = new SqlSyncScopeProvisioning(sqlAzureConnection, scope);
   2:  if (!sqlAzureProvisioning.ScopeExists(FilteredScopeName))
   3:  {
   4:      sqlAzureProvisioning.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
   5:      sqlAzureProvisioning.SetCreateTrackingTableDefault(DbSyncCreationOption.CreateOrUseExisting);
   6:      sqlAzureProvisioning.SetCreateTriggersDefault(DbSyncCreationOption.CreateOrUseExisting);
   7:      sqlAzureProvisioning.SetCreateProceduresDefault(DbSyncCreationOption.CreateOrUseExisting);
   8:      sqlAzureProvisioning.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.CreateOrUseExisting);
   9:      sqlAzureProvisioning.ObjectSchema = "Sync";
  10:   
  11:      sqlAzureProvisioning.Tables["Contacts"].AddFilterColumn("OwnerContactId");
  12:      sqlAzureProvisioning.Tables["Contacts"].FilterClause =
  13:          string.Format("[side].[OwnerContactId] = '{0}'", Properties.Settings.Default.UserContactId);
  14:   
  15:      sqlAzureProvisioning.Apply();
  16:  }

Technorati Tags: ,

0 Comments

While poking at a recent project with a large stick my script resource handler began coughing and gave me a nasty timeout error. After a little prodding of google I came up with this fix. It works, assuming you don't actually have something wrong with your code that is timing out.

In your master page or page where your script manager lives add the AsyncPostBackTimeout value. The default is 90 seconds in case you're wondering.

<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout ="360000"></asp:ScriptManager>

In your web.config file, add this to your system.web section.

<httpRuntimeexecutionTimeout="360000"/>

That's it. Your pages shouldn't timeout now unless you've broken something else. :)