Tuesday, 22 September 2015

Wireless Nomad

I am constantly moving between cities and countries. Working as software dev, sometimes all you need is Internet connection.
Wireless Nomad series is about best short- and long-term offers for mobile Internet (and sometimes calls too), that I could find.
Mobile offers change often, so everything is up to date only on time of writing.

Monday, 10 August 2015

Customize Office365 suite bar links

You want to be able to disable some of those links?
1.       Go to Office 365 Home screen (https://portal.office.com/Home)
 
2.       Go to Admin > SharePoint
 
3.       Go to Settings
(or skip steps 1-3 and just type https://{your company name}-admin.sharepoint.com/_layouts/15/online/TenantSettings.aspx)
 
4.       You can now show or hide some of those links

Monday, 25 May 2015

[Review] Duel Decks: Elspeth vs Kiora

I got myself the Duel Decks: Elspeth vs. Kiora. I have already played few games with them. This is my review of the decks that come with this purchase.

Elspeth is much better deck.
Don't even think, that you're going to pull that Planeswalker card every single game. I ain't gonna calculate the probabilities, but in my 7 games, only once Kiora, the Crashing Wave was played. You must rely on the other cards.

Also, Kiora has only 4 Loyalty counter, so she can be dealt with quickly.

Elspeth has Dictate of Heliod. This card is a game changer. It literally turns the tables. It can turn your weak 1/1 tokens into descent 3/3 creatures, and your 3/2 descent creatures into some nasty 5/4s. Then add some Veterans and Kiora can go home.

Kiora may have some mighty creatures (7/11 Inkwell Leviathan and 6/6 Simic Sky Swallower), but those are expensive to cast. Compare it with many Soldiers in Elspeth's deck, that can be cast for 3-4 white mana and then +1/+1-upped.

True, that Kiora has many spells, that can return opponents' creatures to his hand, but it takes only 2-3 turns to cast them all back.

Duel Decks are supposed to be two ready-to-play decks, that can be played against each other. In theory, Elspeth vs Kiora is fast vs strong deck. But only 2 out of 7 times, since I started playing it, has Kiora managed to win. And only because the hand was very favorable to her. 

Wednesday, 5 November 2014

How to fetch more than 5000 entities from CRM

Let's start with simple example to get all entities from CRM

public EntityCollection GetEntities(string entityName)
{
    var config = ServerConnection.GetServerConfiguration();
    var proxy = ServerConnection.GetOrganizationProxy(config);

    string request = string.Format(@"<fetch mapping ='logical'>
               <entity name = '{0}'></entity></fetch>", entityName);
    FetchExpression expression = new FetchExpression(request);
    var mult = proxy.RetrieveMultiple(expression);

    return mult;           
}
This will work, but will return maximum of 5000 elements in mult.Entities.
Let's add paging now and put that in loop until mult.MoreRecords is false.

string request = string.Format(@"<fetch
                count='5000' page='{1}' mapping ='logical'>
                <entity name = '{0}'></entity></fetch>"
, entityName, page++);
But now Paging cookie is required when trying to retrieve a set of records on any high pages.
Paging cookie is returned in EntityCollection.PagingCookie property. Also, XML tags must be encoded, because this is xml-in-xml.

pagingCookie = string.Format("paging-cookie='{0}'",
    System.Web.
HttpUtility.HtmlEncode(mult.PagingCookie));

Now, complete method looks like this:

public IList<Entity> GetEntitiesNoLimit(string entityName)
{
    var config = ServerConnection.GetServerConfiguration();
    IOrganizationService proxy = ServerConnection.GetOrganizationProxy(config);

    var entities = new List<Entity>();
    int page = 1;
    string pagingCookie = string.Empty;
    while (true)
    {
        string request = string.Format(@"<fetch {2} count='5000' page='{1}'
                         mapping ='logical'><entity name = '{0}'></entity></fetch>",
                         entityName, page++, pagingCookie);
        FetchExpression expression = new FetchExpression(request);
        var mult = proxy.RetrieveMultiple(expression);
        entities.AddRange(mult.Entities);
        if (mult.MoreRecords)
        {
            pagingCookie = string.Format("paging-cookie='{0}'",
                        System.Web.HttpUtility.HtmlEncode(mult.PagingCookie));
        }
        else
        {
            break;
        }
    }

    return entities;
}

Tuesday, 4 November 2014

Tuesday, 28 October 2014

SSIS - find element in table, use its key and insert to another table

I have database with following 3 tables:
·         Customers.CustomerId is integer and PK
·         Addresses.AddressId is integer and PK
·         CustomerAddresses.Customer_CustomerId is integer and FK to Customers
·         CustomerAddresses.Address_AddressId is integer and FK to Addresses
·         Customers.EntityId is GUID
·         Addresses.EntityId is GUID

I use SQL Server Integration Services.
I have also XML file with pairs of addressEntityID and customerEntityId. These are are EntityIDs (GUID), that need to be mapped to IDs (integer) and inserted into CustomerAddresses.

How to map this relationship and import to CustomerAddresses?
1.  In Data Flow drop XML source
2.  Add Derived column, map values from XML (from string to GUID)

3.  Add Lookup, connect to Addresses table, create JOIN from derived AddressGuid to EntityId. AddressId is output.
4.  Add another Lookup and do the same for Customers table
On "Specify how to handle rows with no matching entries" choose "Redirect rows to error output".
5.  Add DB destination, map values from Lookup to AddressId and CustomerId

Complete Data Flow

Monday, 27 October 2014

Drop all foreign keys

DECLARE @SQL varchar(4000)=''
SELECT @SQL = @SQL + 'ALTER TABLE ' + FK.TABLE_NAME + ' DROP CONSTRAINT [' + RTRIM(C.CONSTRAINT_NAME) +'];' + CHAR(13)
  FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK
    ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK
    ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU
    ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
INNER JOIN (
            SELECT i1.TABLE_NAME, i2.COLUMN_NAME
              FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
             INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2
                ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
            WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY'
           ) PT
    ON PT.TABLE_NAME = PK.TABLE_NAME

EXEC (@SQL)

PRINT @SQL

Friday, 24 October 2014

Search within range with LINQ and DbGeography

    var myLocation = DbGeography.FromText(string.Format("POINT({0} {1})", lon, lat)); 
    var result = (from u in _db.Restaurants
           orderby u.Location.Distance(myLocation)
           where u.Location.Distance(myLocation) < distance
           select u).Take(limit).ToList();
distance is a double and its value is in meters.

Thursday, 23 October 2014

Mobile site - device channel configuration

1.       Go to Site collection features and activate SharePoint Server Publishing Infrastructure


2.       Go to Device Channels

3.       Create new device channel, give it alias "mobile". Under Device Inclusion Rules enter user agent substrings for devices, that should use mobile view. Check as active.

Wednesday, 22 October 2014

Przechowywanie datasource pomiędzy PostBack

        private string _countriesList = "countries";
        private List<CountryInfo> _countries;
        private List<CountryInfo> Countries
        {
            get
            {
                if (ViewState[_countriesList] == null)
                    return new List<CountryInfo>();
                return (List<CountryInfo>)ViewState[_countriesList];
            }
            set
            {
                ViewState[_countriesList] = value;
                _countries = value;
            }

        }