All posts by Eric Bartels

Using a dictionary to create dynamic elasticsearch-queries in .Net 3.5

In a current project a search based solution is required to allow a research against an existing set of records. Of course the search-backend is the elasticsearch.

This projects requires the use of .Net 3.5 which makes it impossible to use NEST as elasticsearch client.

To at least add a little bit of comfort when writing the queries against the search-cluster I make use of RestSharp for easy connecting and JSON handling. Net 3.5 has no ExpandoObject to create dynamic property names. It took me awhile to find out but a simple Dictionary does the trick.

var innerQueries = new List<object>();
 
// Data is a Dictionar<string, string> where the key is the fieldname used in elasticsearch
// and the value the value to search for (e.g. title => foo; description => baz)
foreach(var token in data.Keys)
{
  dataResult.Add(new
  {
    match_phrase = new Dictionary<string, string>;
    {
      { 
        token,
        data[token]
      }
    }
  });
}
 
var final = new
{
  query = new
  {
    @bool = new
    {
      must = innerQueries
    }
  },
  from = 0,
  size = 250
};

Serializing this into JSON and sending it via RestSharp creates a request with multiple must “clauses” each using a match_prase query.

{
  "query":{
    "bool":{
      "must":[
        {
          "match_phrase":{
            "record.title":"foo"
          }
        },
        {
          "match_phrase":{
            "record.description":"baz"
          }
        }
      ]
    }
  },
  "from":0,
  "size":250
}

Solving issue with SharePoint Workspace 2010 when using Forefront TMG

I came accross an issue when using TMG / UAG with SharePoint Workspace 2010. When connecting to a site I got the error

SharePoint Workspace was unable to interpret the SharePoint location.
Please check and ensure the location contains no typing errors.

Of course this error message is misleading. Solutions found in “the internet” like adding “remote differential compression on the server” were not applicable…

So after further tracing I found the culprit. The ULS logs (verbose mode was configured for logging) showed the exact web service calls SharePoint Workspace 2010 did with its full soap body. One call showed an url which I was pretty sure was not inside the AAM of that specific web application. Other calls always show the correct public url of that web application. Just one specific call … So I added it to the configuration and everything is working and synchronizing as expected.

If you encounter this error check your ULS logs and double check your AAM settings!

Bug with Internet Explorer and grid RowEditing-plugin when using scoped-theme

I came across this rare bug in the current development of a project. It makes heavy use of the RowEditing plugin of Extjs‘ grid. Because the Extjs environment is used within SharePoint 2010 I have to use the scoped theme to avoid “damage” to the SharePoint UI.

After inserting a record into the grid via RowEditing and pressing cancel the RowEditings’ editor window is not shown. You guess it right: only when using Internet Explorer (7, 8, 9). After testing it showed that the css itself is not the reason. So debugging the Extjs-source where the setting scopeResetCSS is evaluated…

The final result is a workaround applied via Ext.override to solve the “problem”.

if(Ext.isIE) {
  Ext.AbstractComponent.override({
    onRender: function(container, position) {
      var me = this,
        el = me.el,
        styles = me.initStyles(),
        renderTpl, renderData, i;
 
      position = me.getInsertPosition(position);
 
      if(!el) {
        if(position) {
          el = Ext.DomHelper.insertBefore(position, me.getElConfig(), true);
        }
        else {
          el = Ext.DomHelper.append(container, me.getElConfig(), true);
        }
      }
      else if(me.allowDomMove !== false) {
        if(position) {
          container.dom.insertBefore(el.dom, position);
        } else {
          container.dom.appendChild(el.dom);
        }
      }
 
      if(Ext.scopeResetCSS &amp;&amp; !me.ownerCt) {
 
        if(el.dom == Ext.getBody().dom) {
          el.parent().addCls(Ext.baseCSSPrefix + 'reset');
        }
        else {
          if(me.$className != 'Ext.grid.RowEditor') {
            me.resetEl = el.wrap({
              cls: Ext.baseCSSPrefix + 'reset'
            });
          }
        }
      }
 
      me.setUI(me.ui);
 
      el.addCls(me.initCls());
      el.setStyle(styles);
      me.el = el;
 
      me.initFrame();
 
      renderTpl = me.initRenderTpl();
      if(renderTpl) {
        renderData = me.initRenderData();
        renderTpl.append(me.getTargetEl(), renderData);
      }
 
      me.applyRenderSelectors();
 
      me.rendered = true;
    }
  });
}

The woraround itself is only this:

if(me.$className != 'Ext.grid.RowEditor') {
  me.resetEl = el.wrap({
    cls: Ext.baseCSSPrefix + 'reset'
  });
}

BTW: I “love” IE!

Move the top.links block to another block using only local.xml in Magento

I was trying to move the top.links block (aliased with topLinks) from the header-block to the right-block only using local.xml. Should be easy right?!
I did not found any solution using this way in the wiki or somewhere else.

Simply using unsetChild and simply put the top.links block somewhere else is not working! All default links except the Log in / Log out disappear.

So here is my solution that works. The key is using insert as action…

<?xml version="1.0" encoding="UTF-8"?>
<layout>
  <default>
 
    <reference name="header">
      <remove name="top.search" />
      <action method="unsetChild">
        <alias>topLinks</alias>
      </action>
    </reference>
 
    <reference name="right">
      <action method="insert">
        <blockName>top.links</blockName>
      </action>
    </reference>
  </default>
</layout>

Note: Its important to use the alias when defining action="unsetChild" or the block is not “moving”. Seems buggy to me …

Enable-SPFeature does not trigger the feature receiver

Today I encountered the same problem as stated in a blog post by Christopher Maish. When activating the feature via powershell the associated feature receiver was not called.

Trying the suggested solution in the blog post drove me to the cause of this problem. When using stsadm I got an “access denied” error.
I did run my script via Powershell ISE within Windows Server 2008.

So the real problem is caused, again, by UAC (User Account Control). When starting the Powershell ISE with “Run as administrator” and executing the script the feature receiver is now called as expected. Even when using Enable-SPFeature!