Trikks

The digital adventures of Eric Herlitz

This blog is under migration

Posted by trikks on November 17, 2014

Hi you!

All content has been moved and all new posts are now posted on http://www.herlitz.nu

Cheers

Posted in Uncategorized | Leave a Comment »

Updating Visual Studio 2013 Premium to Ultimate

Posted by trikks on December 27, 2013

I decided to try an upgrade from Visual Studio 2013 Premium to Ultimate but was a bit skeptical to the procedure. Last time I performed such a thing I had to first uninstall the Premium and perform a clean setup of Ultimate consuming lots of time.

What is the state of upgrading now?

Well it shows that if you have Premium installed and also install Ultimate the Premium installation is mainly replaced by Ultimate as expected unless you choose to install it in a separate folder. The most successful way of doing this is to

  1. Install Ultimate on top of Premium or Professional
  2. Remove the Premium or Professional edition through Add/Remove Programs

Before upgrading

1. HD1

I installed Ultimate with the same features as Premium had, the install was very quick and as you can see the suggested size is only 424 MB that took less than a minute to install.

2. Installing Ultimate with defaults

When done have a look in Programs and Features (Control Panel\Programs\Programs and Features)

3. Done installing

Modify the Premium/Professional edition and uninstall it. This process is pretty quick, just a minute or so.

4. Uninstallation

When done ensure it was removed

5. Done uninstalling

After the upgrade and remove of the previous edition

For some reason the total size of my VM actually shrunk a bit after replacing Premium

6. HD2

Enjoy!

Posted in Uncategorized | Leave a Comment »

Resolving “Sorry, this site hasn’t been shared with you” when accessing Central Admin in SharePoint 2013

Posted by trikks on December 26, 2013

Let me guess

  • you are trying to access Central Admin with an account that you know have admin of even farm admin access
  • you can access certain pages in Central Admin but not some of them that you should be able to reach
  • you have verified your accounts by running the Get-SPManagedAccount command
  • you have verified that all services and so on are running with the right credentials
  • you may even have restarted everything connected to the farm including the farm

I had this error and several advices told me to restart the “Microsoft SharePoint Foundation Web Application” that can be found in Application Management > Manage Services on Server (_admin/Server.aspx). If you are able to reach this page try to stop and start the service from here.

This didn’t to the trick for me, I had to resort to much more violent methods

This command may take a while

stsadm -o provisionservice -action stop -servicetype spwebservice
iisreset /noforce

When done, go to Central Admin and verify that the service have stopped. Then run the same command but replace the action with “start”.

stsadm -o provisionservice -action start -servicetype spwebservice
iisreset /noforce

Most guides on the net tells you to only run the start command, that didn’t work in my environment.

Posted in Sharepoint, SharePoint 2013 | Tagged: , | Leave a Comment »

Overriding the default window.prompt using Apprise

Posted by trikks on November 3, 2013

I’ve been using Apprise for quite a long time now, the V2 actually made it harder working with callbacks and similar, hence this post.

Replacing methods in Javascript

Replacing methods in Javascript is simple

// Replace the prompt with an alert
window.prompt = function(text) {
    alert(text);
}

Replacing the window.prompt with an apprise call

// Define new prompt method
window.prompt = function(text, callback) {
    // Setup Apprise
    var options = {
        buttons: {
            confirm: {
                text: 'Send',
                action: function(e) {
                    callback(e.input);
                    Apprise('close');
                }
            },
        },
        input: true
    };

    // Call Apprise
    Apprise(text, options);
};

// Call the prompt method
prompt("Say something", function(returnValue) {
    // Handle the returnValue here
    console.log(returnValue);
});

The dialog

Screen Shot 2013-11-03 at 20.43.46

 

The call and result in a console

Screen Shot 2013-11-03 at 20.44.05

 

Have fun!

 

Posted in Javascript | Tagged: , | Leave a Comment »

Administering a Synology MySQL Server

Posted by trikks on July 31, 2013

So I bought one of those fancy Synology NAS devices. Since i often to build quite complex environments it seemed as a nice thing to place my iSCSI shares on a central NAS station instead of hosting them on Windows, then I noticed that the device also had support to run MySQL natively, oh the joy.

So I hit google to find out how to administer the MySQL Server and nope… deploy phpMyAdmin everything said. Now, there is nothing wrong with phpMyAdmin except that I don’t like it for numerous reasons. It has one of those interfaces and a usability flow as you expect a russian tank from the early 20′s would – and that my friends is none.

To administer this MySQL Server the real (and easy) way let’s hit the console. I’m on a Mac, if you are on “a Windows” download putty or similar tool to get access to SSH.

Enable SSH on the device

Go to your disk station web interface and open the Control Panel, click in the terminal Icon

Screen Shot 2013-07-31 at 22.41.45

When the terminal settings are loaded simply enable the SSH Service.

Screen Shot 2013-07-31 at 22.41.57

Click Apply

Navigate to the device using SSH

I have called my device ds01 and it is located on my trikks.com domain. Hence I write this to connect

ssh admin@ds01.trikks.com

I use my default admin user, enter the password and click enter. You may get a certificate warning, if so simply write yes and continue.

Administering MySQL

Since you are in the device you have passed the hard part. The rest is actually to play around a bit with the MySQL binaries that are located in the folder /usr/syno/mysql/bin/.

First connect to MySQL

./usr/syno/mysql/bin/mysql -u root

You should be welcomed with something like this

Screen Shot 2013-07-31 at 22.52.19

Set a root password

Even though it’s not required, I really recommend you to set a mysql root password on the device. All users are stored in a database named “mysql”

mysql> USE mysql;
mysql> SELECT User, Host, Password FROM user;        
+------+-----------+----------+
| User | Host      | Password |
+------+-----------+----------+
| root | localhost |          |
| root | DS01      |          |
| root | 127.0.0.1 |          |
|      | localhost |          |
|      | DS01      |          |
+------+-----------+----------+

As can be seen above I switched to the database mysql and printed all users available in the user table. In MySQL users are separated by host, this means you can have multiple root users with different passwords, all depending on which host they are connecting from.

To set a password for all root users

mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH privileges;

Replace the phrase NEWPASSWORD with your desired password, to verify that it happened run the select SQL query again

mysql> SELECT User, Host, Password FROM user;
+------+-----------+-------------------------------------------+
| User | Host      | Password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *97D6E45C0D981055B8CF1BA88CE69338CDD3F45D |
| root | DS01      | *97D6E45C0D981055B8CF1BA88CE69338CDD3F45D |
| root | 127.0.0.1 | *97D6E45C0D981055B8CF1BA88CE69338CDD3F45D |
|      | localhost |                                           |
|      | DS01      |                                           |
+------+-----------+-------------------------------------------+

The root user password have been updated.

Adding a new external user

This is so very often required, you may either have a service outside the NAS that need access or simply a user for an administration program.

Ensure that you are in the mysql database (use mysql;) and run the following command

mysql> GRANT ALL privileges ON *.* TO 'admin'@'192.168.1.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
mysql> FLUSH privileges;

What this command does is to give the user ‘admin’ coming from the network 192.168.1.xxx full access.

Screen Shot 2013-07-31 at 23.05.25

And simple like that I can use my beloved interface Navicat again!

Backing up?

There are a lot of backup agents for MySQL, I’d recommend using something. But while we are at it here is how you do a backup from the ssh command line in the Synology world.

./usr/syno/mysql/bin/mysqldump --user root --password=xxxx --database my_blog > /volume1/BackupShare/my_blog.sql

Keep it simple!

Posted in MySQL, Synology | Leave a Comment »

Having the error “Verification of outbound replication failed” when adding a new DC?

Posted by trikks on July 25, 2013

So I had plans to create some redundancy for my domain by adding a slave domain controller. The primary domain controller was however somewhat obnoxious and returned an error when I tried to let my new domain controller join it.

“Verification of outbound replication failed. Outbound replication is not enabled on replication source domain controller: dc01.corp.com”

The setup

Primary domain controller

  • dc01.corp.com
  • Windows 2012 Server (standard)

Secondary domain controller

  • dc02.corp.com
  • Windows 2012 Server (standard)

To solve my issues I had to rely on the good old repadmin, http://technet.microsoft.com/en-us/library/cc770963(v=WS.10).aspx

Begin by checking the current options

repadmin /options dc01.corp.com
Current DSA Options: IS_GC DISABLE_INBOUND_REPL DISABLE_OUTBOUND_REPL

Aha! DISABLE_OUTBOUND_REPL, this shouldn’t be there. Remove it like this

repadmin /options dc01.corp.com -DISABLE_OUTBOUND_REPL
Current DSA Options: IS_GC DISABLE_INBOUND_REPL DISABLE_OUTBOUND_REPL
New DSA Options: IS_GC DISABLE_INBOUND_REPL

There, all good. Just go again and hopefully you’ll do fine.

Or get another error. :)

Posted in Active Directory | Leave a Comment »

Enabling a missing “Save site as template” using PowerShell

Posted by trikks on July 23, 2013

This blog post presents a great way to do this by using SPD, which I quite often tend to not have installed. Instead I rely on PowerShell, now if this feature is missing there is a property (SaveSiteAsTemplateEnabled) that is set on the Web.

Simply

Add-PSSnapin Microsoft.SharePoint.PowerShell
$site = Get-SPSite -Identity "http://sharepointsite.com/sites/collection"
$web = $site.RootWeb;
$web.SaveSiteAsTemplateEnabled = $true;
$web.Update();

And voila, the save site option is once again available

Save site as template

Posted in SharePoint 2013 | Tagged: | Leave a Comment »

How to return data after ajax call success

Posted by trikks on June 27, 2013

There are some misunderstandings on the web how to work with asynchronous methods and data when using ajax. There are some great efforts in usage scenarios on stackoverflow but they don’t really get there do they?

What the developers are asking for is a way to store the result from a success method in a variable. The fact that the variable is ‘undefined’ right after the call is completely irrelevant.

Code

This is one way of doing it

// Example object with ajax method
var Example = (function () {
    // ctor
    function self() { }

    // Ajax request method
    self.Request = function (params) {
        $.ajax({
            dataType: params.datatype || "json",
            type: params.verb || 'GET',
            contentType: params.contentType || "application/json",
            data: params.data || {},
            async: params.async || true,
            processData: params.processData || true,
            url: params.url || '/api/default',
            error: function (xhr, textStatus, errorThrown) {
                params.error(xhr, textStatus, errorThrown);
            },
            success: function (data, textStatus, xhr) {
                params.success(data);
            }
        });

    };

    // Return object
    return self;

})($);

// Usage
var locale = Example.Request({
    async: true, // Set to false to enable synchronized calls
    url: '/api/locale/getlocale',
    success: function (data) {
        // Send data back to the locale variable
        locale = data;

        // ...or 
        // use the 'data' inside of this callback if you are concerned about async failures
    }
});

Noteworthy

  • The data sent back in the ‘data’ parameter is stored in the variable ‘locale’ but will only be available (not undefined) when the ajax call is done
  • Example.Request({…}); any parameter seen inside the $.ajax method can be placed for the call. I just placed the async, url and success parameters for demonstration. It is highly customizable
  • Good practice is to handle your async operations within the callback of success: function (data) { … }, this way of doing it however allows you not to, go wild :)

Enjoy

Posted in Ajax, Javascript | Leave a Comment »

Get or construct a HttpContextWrapper inside a Web API Controller

Posted by trikks on June 27, 2013

The HttpContextWrapper is an essential part of the ASP.NET Web API since you will be able to not only use the common HttpContext data but also lots of other useful properties and methods. It is not in general recommended to use the HttpContextWrapper in testing and mocking, in such cases you should instad use the HttpContextBase from which the HttpContextWrapper inherits.

private HttpContextWrapper GetHttpContext(HttpRequestMessage request = null)
{
    request = request ?? Request;
 
    if (request.Properties.ContainsKey("MS_HttpContext"))
    {
        return ((HttpContextWrapper)request.Properties["MS_HttpContext"]);
    }
    else if (HttpContext.Current != null)
    {
        return new HttpContextWrapper(HttpContext.Current);
    }
    else
    {
        return null;
    }
}

Enjoy

Posted in C#, Web API | Leave a Comment »

Getting the client locale using ASP.NET Web API

Posted by trikks on June 27, 2013

I think it is very neat to automatically help the user fill out some forms, adapt date and time formats and so on. Small things like this keeps visitors satisfied which is rather important!

Using ASP.NET Web API for this is simple

The query address will be something like http://yoursite/api/locale depending on your routing.

using System.Net.Http;
using System.Web;
using System.Web.Http;
 
namespace Trikks.Controllers.Api
{
    public class LocaleController : ApiController
    {
        public string[] GetLocale()
        {
            return GetClientLocale();
        }
 
        private string[] GetClientLocale(HttpRequestMessage request = null)
        {
            request = request ?? Request;
 
            if (request.Properties.ContainsKey("MS_HttpContext"))
            {
                return ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserLanguages;
            }
            else if (HttpContext.Current != null)
            {
                return HttpContext.Current.Request.UserLanguages;
            }
            else
            {
                return null;
            }
        }
    }
}

The returns will look something like this

["sv-SE","sv;q=0.8","en-US;q=0.6","en;q=0.4"]

Store the response in a javascript variable

var locales = ["sv-SE","sv;q=0.8","en-US;q=0.6","en;q=0.4"];
var primaryLocale = locales[0];

primaryLocale will contain the first locale, in this case “sv-SE”

Enjoy

Posted in C#, Web API | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.