2017年7月28日 星期五

Populate all Language created on Umbraco Backoffice

Environment: - VS2015 - Umbraco version 7.6.3 assembly: 1.0.6361.21154 Populate all Language created on Umbraco Backoffice
        public List<Library.Models.Language> GetLanguageListItemsModel()
        {
            List<Library.Models.Language> model = new List<Library.Models.Language>();

            IEnumerable<ILanguage> languages = _applicationContext.Services.LocalizationService.GetAllLanguages();

            foreach ( ILanguage l in languages)
            {
                model.Add(new Models.Language(l.CultureInfo.NativeName, l.CultureInfo.Name));
            }            
            
            return model;
        }

Get Umbraco Dictionary Value by CultureInfo Value

Environment: - VS2015 - Umbraco version 7.6.3 assembly: 1.0.6361.21154 Get Umbraco Dictionary Value by CultureInfo Value
public static string GetDictionaryValue(string key, CultureInfo culture , UmbracoContext context)
{
 var dictionaryItem = context.Application.Services.LocalizationService.GetDictionaryItemByKey(key);
 if (dictionaryItem != null)
 {
  var translation = dictionaryItem.Translations.SingleOrDefault(x => x.Language.CultureInfo.Equals(culture));
  if (translation != null)
  {
   return translation.Value;
  }
  else
  {
   return (dictionaryItem.Translations.SingleOrDefault(x => x.Language.CultureInfo.Equals(CultureInfo.GetCultureInfo(DEFAULT_CULTURE)))).Value;
  }
 }
 return key; // if not found, return key
}

2017年7月23日 星期日

TFS Error : The working folder C:\xxx\xxx is already in use by the workspace xxx on computer xxx


tf workspace /delete /server:[tfs server] [workspace name];[owner]


tf workspace /collection:http://tfsserver/tfs/ITD /delete "{workspace name};{workspace owner}"

ref :
- How to: Remove a Workspace
- Workspace Command

2017年7月11日 星期二

Auto generate constructor with properties (No resharper)

Environment:
Visual Studio 2015

Step
1. Select the properties you want included
2. Press Shift-Alt-F10
3. Press Enter





2017年7月5日 星期三

Use local directory instead of thru mail server as receive the email in c#

use local directory instead of thru mail server as receive the email in c#

  <system.net>
    <mailSettings>  
      <smtp deliveryMethod="SpecifiedPickupDirectory">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\temp"/>
      </smtp>
    </mailSettings>
  </system.net>

Ref:

2017年7月4日 星期二

Reset Umbraco First Admin Password


Step 1

Open SQL Server Management Studio
Create a new query using the database for your umbraco project. Copy and paste the following SQL:
UPDATE umbracoUser SET userdisabled = 0, userLogin = 'admin', userPassword = 'default' WHERE id = 0
Run the query. This has now made sure the admin account is enabled and and set the password to 'default'.
This won't work yet though as passwords are stored as hash values, so you need to edit a setting in the web.config file temporarily.

Step 2

In the web.config file, at the root of your web project, use Ctrl+F to find UsersMembershipProvider
The passwordFormat will be set to "Hashed". You need to change it to "Clear" so that you can login. Save the web.config file.

Step 3

Go to the umbraco login page and login with the username of admin and the password of default.
Once you have logged in, you need to change the passwordFormat in the web.config again back to "Hashed" and press Save.

Step 4

Now you can change the password for the admin user to a different one and it will be saved in the database with a hashed value instead of clear text.
To make sure it is storing passwords in the hashed format, run this SQL query after you have changed the password.
SELECT userName, userPassword FROM umbracoUser WHERE id = 0
You should see the admin username and the hashed password.


2017年7月2日 星期日

Expression-bodied members C# 6.0 or above


Before Expression:

private SearchHelper _searchHelper 
{ 
    get { return new SearchHelper(new UmbracoHelper(UmbracoContext.Current)); }
}


After Expression:

private SearchHelper _searchHelper => new SearchHelper(new UmbracoHelper(UmbracoContext.Current));



Reference:
Microsoft Doc. Expression-bodied members (C# programming guide)

HttpContext <=> HttpContextBase



Getting HttpContext from HttpContextBase’s instance:

HttpContext httpContext = httpContextBase.ApplicationInstance.Context;


To get HttpContextBase from HttpContext we have to wrap it in HttpContextWrapper:


HttpContextBase abstractContext = new System.Web.HttpContextWrapper(context);