Tuesday, 11 September 2018

Easiest way to setup python virtual environments on OSX.

brew install pyenv-virtualenv
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pyenv virtualenv 3.4.8 env
This sets up the virtual env in directory /Users/username/.pyenv/versions/3.4.8/envs/
pyenv activate env
python
Python 3.4.8 (default, May  3 2018, 16:39:36) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
pyenv deactivate


Friday, 11 April 2014

HTTPS Redirect Umbraco Package Infinite Redirect Loop

Sources:
I was having this exact same issue with v1.2.0, and spent some time looking at my IIS set-up and certificates and everything was correct but the redirect kept on happening. What was strange was it worked locally but not on my staging environment.
My solution was to changes the host names set-up in Umbraco.
On my local environment (that worked) I had this set-up in "Manage Host Names":
sub.domain.local/en
But on staging (that wasn't working) I had:
So on staging I change this to:
sub.domain.com/en
This worked! So check your hosts names.

Monday, 31 March 2014

Umbraco css folder always modifying files in background without me touching them

I have a GIT repository and I'm using Umbraco. Once strange thing that was happening to me were my files in the css folder kept on being modified even though I wasn't changing them. So every time I wanted to commit a change I'd have to undo the css file changes.

I thought this was Umbraco and because I had my style sheet linked to the rich text editor datatype, but it turned out to be the uSync package. I was synchronizing Stylesheets so by turning this off in the uSyncSettings.config file this stopped the problem. I don't need uSync to manage these files for me.

Umbraco Relationships Datatype

This is a great Umbraco package that helps manage node relationships in multilingual websites. It's just what I was looking for:

Vizioz Relationships Datatype for Umbraco

Wednesday, 19 March 2014

Umbraco fails to Publish! We get an exception within a load balanced environment.

After a deployment to our live servers which are load balanced we could not Publish. We could Save but not right-click publish or by clicking on the icon.

This was the error:

ERROR Umbraco.Web.UmbracoApplication - [Thread 36] An unhandled exception occurred
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.TypeInitializationException: The type initializer for 'umbraco.presentation.cache.dispatcher' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at umbraco.presentation.cache.dispatcher..cctor()
   --- End of inner exception stack trace ---
   at umbraco.presentation.cache.dispatcher.Refresh(Guid factoryGuid, Int32 Id)
   at umbraco.library.UpdateDocumentCache(Document doc)
   at umbraco.cms.presentation.editContent.Publish(Object sender, EventArgs e)
   at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
   at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

This seemed to be an error with the distributed call from server 1 to server 2 in the load balancer.

  1. First I thought it might be a rewrite rule in \config\UrlRewriting.config - it wasn't
  2. Then I recycled the app pools - this didn't help
  3. I then made sure I could access the Umbraco web service on both servers:
    1. http://serverip1/umbraco/webservices/CacheRefresher.asmx - worked
    2. http://serverip2/umbraco/webservices/CacheRefresher.asmx - worked
  4. I disabled distributed calls and then Publish worked, but this wasn't a solution
  5. Finally the solution was due to incorrect config in \config\umbracoSettings.config. I somehow didn't have the <user>0</usertag:

<distributedCall enable="true">

Friday, 14 March 2014

How do I copy files after Publish to the Publish folder using Visual Studio 2010 with MSBuild?

My web project in Visual Studio 2010 has post-build events that copies files from a folder into the bin directory of the web project. But when I publish my site, MSBuild seems to ignore the post-build events and these files are NOT copied.

The solution is to create a BAT file that executes from a MSBuild Target. I called my BAT file PostBuildEventPublish.bat and it lives in my solution folder. This is the BAT file contents:

xcopy "%1References\UmbracoCourier.lic" "%2" /y
xcopy "%1References\jumps.umbraco.usync.dll" "%2" /y

The parameters %1 and %2 are input from the MSBuild csproj file. In VS2010 unload your web project and edit the project then insert this Target (at the bottom):

<Target Name="AfterPublish" AfterTargets="CopyAllFilesToSingleFolderForPackage">    
    <Exec Command="$(SolutionDir)References\PostBuildEventPublish.bat &quot;$(SolutionDir)&quot; &quot;$(ProjectDir)obj\$(Configuration)\Package\PackageTmp\bin&quot;" />
    <Message Importance="Normal" Text="Finished PostBuildEventPublish.bat" />
 </Target>

Obviously change to the paths you want to use.

As you can see parameter %1 = $(SolutionDir)
and parameter %2 = $(ProjectDir)obj\$(Configuration)\Package\PackageTmp\bin

You will notice that my Target always gets executed before the actual publish files are copied. 

C:\Dev\Puma\Main\References\PostBuildEventPublish.bat "C:\Dev\Main\" "C:\Dev\Puma\Main\Web\obj\Debug\Package\PackageTmp\bin"
C:\Dev\Puma\Main\References\UmbracoCourier.lic
1 File(s) copied
C:\Dev\Puma\Main\References\jumps.umbraco.usync.dll
1 File(s) copied
Finished PostBuildEventPublish.bat
Publish Pipeline Deploy phase Pre-Deploy CopyAllFilesToOneFolder Stage
Deleting existing files...
Publishing folder /...
Publishing folder App_Browsers...
Publishing folder App_Data...
Publishing folder App_Data/packages...
Publishing folder App_Data/packages/created...

Publishing folder App_Data/packages/installed...
...
Publishing folder uSync/Template/ZMag...
Publishing folder Views...
========== Build: 5 succeeded or up-to-date, 0 failed, 0 skipped ==========

========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

So parameter %2 is where the magic happens. Here we copy the files into the temp publish folder and when Publish completes copying the files to the actual Publish folder these post-build files will also be copied.

Friday, 21 February 2014

IIS7 not serving pages (ASPX) but just displays a blank page

I created a new IIS website with ApplicationPoolIdentity as the identity and .NET framework set to v4.0. In my hosts file I set my localhost to point to my test.dev domain (127.0.0.1 test.dev). When I tried viewing the site all I got back as a blank page.

What I tried: 

1. Installing all IIS components as I thought I might have missed some - this didn't help
2. Add full control permissions to my web folder for the ApplicationPoolIdentity (http://stackoverflow.com/questions/7334216/iis7-permissions-overview-applicationpoolidentity) - this didn't help
3. Registered .NET 4 with this command: C:\Windows\Microsoft.NET\Framework\v4.0.30319 C:\Windows\Microsoft.NET\Framework\v4.0.30319> aspnet_regiis.exe -i - This WORKED!!!

Wednesday, 12 February 2014

Umbraco render macro within macro

I wrote this helper method to easily render macros within other macros when using razor (cshtml) views. This also allows the passing in of parameters. This is an alternative to RenderMacroContent which didn't seem to work for me.

public static string RenderMacro(string alias, int nodeId, Dictionary<string string=> parameters)
        {
            var macroEngine = new RazorMacroEngine();
            var macro = new MacroModel();
            macro.ScriptLanguage = "cshtml";
            macro.ScriptName = alias + ".cshtml";

            foreach (var parameter in parameters)
            {
                macro.Properties.Add(new MacroPropertyModel(parameter.Key, parameter.Value));
            }

            return macroEngine.Execute(macro, new umbraco.NodeFactory.Node(nodeId));
        }


This is the code that wasn't working:

umbraco.library.RenderMacroContent(string.Format("</?UMBRACO_MACRO>", alias, args), model.Id)

Friday, 26 July 2013

StyleCop and R# Integration

StyleCop and R# Integration

You can either write your own rule library or use an existing extension like StyleCop+. I’ve used StyleCop+ as it holds common rules and is an open source community project so adding to it is easy. I’ve investigate the StyleCop+ rule SP2101 MethodMustNotContainMoreLinesThan below.

Versions

Visual Studio 2010
R# 5.1.3000.12 and 8.0.14.856
StyleCop 4.7.44.0 and 4.7.45.0
StyleCop+ 1.8

R# 8 and StyleCop with StyleCop+

R#8 will NOT work with StyleCop 4.7.44.0 only 4.7.45.0. If you want to use StyleCop+ 1.8 on top of this you need to change the assembly binding redirects in the Visual Studio 2010 config file (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config).

Make sure VS is closed and the StyleCopPlus.dll in C:\Program Files (x86)\StyleCop 4.7 has been deleted.

Under this XML...

       <runtime>
              <UseSmallInternalThreadStacks enabled="true"/>

              <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

Add this XML...

<dependentAssembly>
          <assemblyIdentity name="StyleCop" publicKeyToken="f904653c63bc2738" />
          <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.7.45.0" />
      </dependentAssembly>
      <dependentAssembly>
          <assemblyIdentity name="StyleCop.CSharp" publicKeyToken="f904653c63bc2738" />
          <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.7.45.0" />
      </dependentAssembly>
      <dependentAssembly>
          <assemblyIdentity name="StyleCop.CSharp.Rules" publicKeyToken="f904653c63bc2738" />
          <bindingRedirect oldVersion="4.5.0.0-4.5.99.99" newVersion="4.7.45.0" />

      </dependentAssembly>

Place the StyleCopPlus.dll back in C:\Program Files (x86)\StyleCop 4.7  and Unblock it.  Now open VS and everything should work!

R# Integration

With these versions installed you can edit the StyleCop+ rule SP2101 to reduce the lines from 120 to 20 to test its working. Open Settings.StyleCop file (Located in folder of project(s) or solution) then go to the StyleCop+ tab and select the rules to edit.



Open the R# options dialog and go to Code Inspection > Inspection Severity and find the StyleCop+ rule to show as an error.



An you’re done!

Build Integration

You can use the MSBuild targets file (e.g. C:\Program Files (x86)\MSBuild\StyleCop\v4.7\StyleCop.Targets) provided with StyleCop to fail the build in Visual Studio for any of the projects you set this up for. The problem with this is all violations are set to error and you can’t target individual rules to break the build.

The solution I think is to use TeamCity to read the XML violations file (e.g. \obj\Debug\StyleCopViolations.xml) generated after the build and then fail the CI build if it finds an individual rule violation. For example if you find this in the file:

<Violation LineNumber="19" Source="C:\DevelopmentSVN\ATMS\Trunk\Isotrak.Zinc\Isotrak.Zinc.ATMS\Common\MapModelHelper.cs" RuleNamespace="StyleCopPlus.StyleCopPlusRules" Rule="MethodMustNotContainMoreLinesThan" RuleId="SP2101">Method body must not contain more than 20 code lines (now 25).</Violation>


Friday, 26 April 2013

Publish in Umbraco 4.11.4 load balanced environment doesn't refresh the umbraco.config file

I has running into this issues when publishing content on my staging site. Nothing would refresh the umbraco.config file except manually deleting it. Until I discovered that our live server settings for load balancing was effecting the publish.

In the /config/umbracoSettings.config file on staging I set:

<distributedcall enabled="true"></distributedcall>

The moment I did this my publish started working as it wasn't attempting the load balance on a non-load balanced environment.

Thursday, 18 April 2013

How to branch/merge with TFS 2010


Below is a simple explanation of TFS branching and merging for one branch and one merge.

Branching
  1. Make sure you have all files check in or shelved
  2. Open Visual Studio 2010 Team Explorer panel
  3. Open your project > Source Control
  4. Make sure your folder structure is like this:
    1. BuildProcessTemplates
    2. Main
      1. All your project source code
  5. If your source code is not in this folder structure above then:
    1. Create a Main folder
    2. Right-click individually on each folder/file and select Move and choose Main as the destination (Can’t multi-select and move for some reason)
    3. Your history will be kept
  6. Check in all your changes
  7. Now right-click on the Main folder and select Branching and Merging > Branch
  8. Now in Target Branch Name type the name of your branch e.g. FeatureBranch1
  9. Click OK (keep default checkbox selections)
  10. Wait until branching has completed and then check in all changes


You will now have a Main branch  e.g. C:\Dev\Project\Main, and a FeatureBranch1 branch e.g. C:\Dev\Project\FeatureBranch1. So open the FeatureBranch1 solution and make all your branch changes there. Then when you ready  you can merge this branch into Main.

As I rule we should label our check-ins for:
  1. The main like this Project: Then the check in description e.g. Puma: Fixed menu layout
  2. The branch like this Project\FeatureBranch1: Then the check in description e.g. Puma\FeatureBranch1: New regions implemented

Merging
  1. Make sure you have all files check in or shelved
  2. Open Visual Studio 2010 Team Explorer panel
  3. Open your project > Source Control
  4. Get latest on the Main branch
  5. Now right-click on the branch folder e.g. FeatureBranch1 and select Branching and Merging > Merge
  6. Source branch should be FeatureBranch1 and Target branch should be Main – Click Next
  7. Version type should be Latest Version – Click Next
  8. Click Finished
  9. The merge will now occur and bring up any conflicts - Resolve the conflicts (easier said than done)
  10. Check in the merge when you confident it works


Shane


Thursday, 28 March 2013

Safari error not showing CSS and images

The Problem

I was getting strange rendering behaviour on Safari 5.1.7 for Windows 7 when viewing my website. The page basically looked like it was not showing CSS or the images. The website rendered fine in all other browsers on Windows 7 like Chrome, IE and Firefox.


Troubleshooting

So what was the problem with Safari? Initially I thought it was due to the Safari browser on Windows, and the fact that Safari was no longer being supported on Windows, but this was not that case as the error was also occurring on OSX Safari 6.0.3.

Then I tried viewing my local development site in Safari on Windows and the site rendered correctly. So the difference between my development site and the staging environment as our staging environment required a IIS username and password to view the site. Hence something was going wrong with the authentication in Safari and this caused the CSS and images to not download correctly.

The developer web inspector network tab showed 302 status codes and undefined types which in turn caused the JavaScript to break and throw console errors.

The Solution

Changing IIS fixed this issue for me.

1. Open IIS
2. Select your web site
3. Open Authentication under the IIS section
4. Make sure you only have Basic Authentication enabled and everything else is disabled

The error was due to a conflict with my Authentication settings:

Challenge-based and login redirect-based authentication cannot be used simultaneously

Hope this helps someone out there!

Wednesday, 20 March 2013

Visual Studio 2010 publish failing with error Unable to add XYZ to the Web site. Access is denied (550).

I started receiving this error when trying to publish through Visual Studio 2010:

Unable to add XYZ to the Web site. Access is denied (550).

The reason being someone had manually FTP-ed files to the website and they had read-only set to true.

Resolution:

Make the folders/files not read-only - easy :)

Wednesday, 6 March 2013

Using EMs for font size

Can you set

body
{
font-size: 62.5%
}

This means that we can use em’s

So 22px will be 2.2ems, 33px will be 3.3px, this is useful for responsive design.

Monday, 4 March 2013

Umbraco 404 custom error page not working on staging/production server

My custom 404 error page in Umbraco was working locally but not when I deployed to staging/production. The reason was explained very nicely here: StackOverflow.

So basically you can add the following to your deployed web.config under :

Thursday, 28 February 2013

Duplicate trees in Umbraco CMS after uninstalling uComponents

I freaked out when I uninstalled uComponents and discovered that all content, media, settings, and developer trees had all been duplicated. After cleaning my solution and removing all dlls in the bin directory the trees returned to normal.

Tuesday, 12 February 2013

Umbraco packages throws error installedPackages.config is denied

This was happening on IIS7.5 and the error message said I should add ASPNET account to the security of the file. Instead (as I was using ApplicationPoolIdentity) I removed the Read-Only flag on the packages folder and this fixed my problem.

Wednesday, 23 January 2013

Umbraco drop down list prevalues using razor

Here is a great link that converts the drop down list datatype prevalues into a Dictionary. Hope this helps someone else out there:

http://blog.dampee.be/post/2012/04/15/Get-a-prevalues-dropdownlist-in-Razor-(umbraco)-for-a-datatype.aspx

Monday, 14 January 2013

Umbraco "Oops...the installer can't connect to the repository!"

I was getting this error on a new Umbraco 4.11.1 installation but only when viewing the site from IIS7 and not when running the site from VS 2010. This also made my packages folder in Umbraco developer tab empty.

I had all the correct permissions on my website folder but it was still failing to display when visiting my dev URL setup in IIS.

The solution was to add the same user/group for the website folder to the C:\Windows\Temp folder. Umbraco was failing permissions trying to access this folder.

Hope this helps someone.

Friday, 28 September 2012

WCF Service Reference Error

I tried updating my WCF service references in my web project and received this strange error:

Error        265          Missing partial modifier on declaration of type 'xyz'; another partial declaration of this type exists   Reference.cs

This mean't I had a class in the service or the web projects that are named the same but are not set as partials. The problem was in the service project the complex object in my EF 4 entities did not generate a partial class when referenced in the References.cs file of the web project.

I had to configure the service reference to reuse the System assembly, then update my reference again and everything worked - strange error :(

This post helped me a bit http://stackoverflow.com/questions/8542514/wcf-reference-cs-suddenly-not-including-classes