Sunday, May 1, 2016

Json Data format issue /Date() in Asp.net MVC

I struggled bit with getting over to this Json date format issue. I got the lead with Hanselman . Scott tried his best to point to right direction but all he was intended towards web api 2. I was having a issue with asp.net mvc underlying Json.net.


After working on this for an hour I started getting lot of solution via stackoverflow and many other blog post.


We can handle this date issue at client side but I personally want to handle everything at server side.


I liked Bipin Joshi Solution, which is kind of straight forward or straight cut solution.





http://www.developer.com/net/dealing-with-json-dates-in-asp.net-mvc.html

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Xml.Linq;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;

namespace JsonNetExtension
{
    public class JsonNetResult: JsonResult
    {
        public new object Data { get; set; }

        public override void ExecuteResult(ControllerContext context)
        {
            HttpResponseBase response = context.HttpContext.Response;
            response.ContentType = "application/json";
            if (ContentEncoding != null)
                response.ContentEncoding = ContentEncoding;
            if (Data != null)
            {
                JsonTextWriter writer = new JsonTextWriter(response.Output) { Formatting = Newtonsoft.Json.Formatting.Indented };
                JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings());
                serializer.Serialize(writer, Data);
                writer.Flush();
            }
        }
    }
}

Friday, April 22, 2016

C# Cool Code: Convert Enum to List

namespace ConsoleApplication1
{
    class Program
    {
         enum SomeEnum
        {
            RED,
            BLUE,
            WHITE
           
        }
        class KeyValues
        {
            public string Key { get; set; }
            public string Value { get; set; }
        }
        static void Main(string[] args)
        {

            List enums = ((IEnumerable)Enum.GetValues(typeof(SomeEnum)))
                .Select(c => new KeyValues() { Key = ((int)c).ToString(), Value = c.ToString() }).ToList();


            //List Model = new List(){ "1", "2", "3" };
            foreach (var item in enums.Select((value, i) => new { i, value }))
            {

                Console.WriteLine("Collection Object Values : " + item.value.Value);
                Console.WriteLine("Collection Index : "+ item.i);
            }
      }
}

C# Cool Code : Foreach with Index iterator values

namespace PlayWithCollection
{
    class Program
    {
        static void Main(string[] args)
        {
            List Model = new List() { "1", "2", "3" };
            foreach (var item in Model.Select((value, i) => new { i, value }))
            {

                Console.WriteLine("Collection Object Values : " + item.value);
                Console.WriteLine("Collection Index : " + item.i);
            }
        }
    }

Tuesday, March 29, 2016

Sitecore : All about MultiList and Search

 
I was doing bit of R&D around implementing, writing custom multilist with search while doing my bit of research I understand sitecore has not unified the multilist with search in a way so that it can be used widely to solve problem for content author. May be there is less documentation out there where developer ends up writing custom implementation which can very well handled using right query.
 
Below I tried to sum up by putting some of the cool links a kind of reference to begin with.
 
 
 
Simple problem solved
By Raul- Nice explanation
 
Query Bug
 
StartSearchLocation={110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}&TemplateFilter={5E840804-D12E-4D1F-A30F-C1A71F32F63C}

 
 



http://www.sitecore.net/learn/blogs/technical-blogs/sitecore-7-development-team/posts/2013/10/using-the-new-sitecore-7-field-types.aspx

Customize Multilist with search
https://himadritechblog.wordpress.com/2015/03/15/dynamic-multilist-with-search/

http://sitecorenj.blogspot.com.au/2015/11/multilist-with-search-querying-bug.html
StartSearchLocation=query:..&Filter=_latestVersion:*|-_templatename:Saved Query

By Fish Tank
http://getfishtank.ca/blog/using-item-field-as-a-data-source-in-sitecore

Add Selected Item at top in the multilisthttp://www.bugdebugzone.com/2015/07/add-selected-item-in-multilist-at-top.html

http://sitecorefun.baziret.com/2014/08/sitecore-tags-and-multi-site-in-action/

Wednesday, March 2, 2016

Azure Webjobs with some known Facts.

Recently we successfully migrated worker role Queue jobs to Web jobs and below are the set of issues we encountered.

Special thanks to Kanivalan Raju who got this compiled.


When you deploy web jobs in azure cloud, you may come across the following errors.

Error 1
Error :Command cmd was aborted due to no output nor CPU activity for 121 seconds.

Resolution-

add key = "SCM_COMMAND_IDLE_TIMEOUT" value = "100000"

add key = "WEBJOBS_IDLE_TIMEOUT" value = "100000"

http://stackoverflow.com/questions/26596968/azure-webjob-timeout-configuration-settings


Error 2 : Certificate with website_load
Its important to load your certificates with this key appsetting.

WEBSITE_LOAD_CERTIFICATES

Resolution

Add key ‘Add WEBSITE_LOAD_CERTIFICATES’ with thumbprint values as below
X509Certificate2 certificate=null;
X509Store certificateStore =new X509Store(StoreName.My, Storelocation.CurrentUser);


Error 3: Long file name
While publishing the webjob from VS, below error occurred and publish failed


The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resolution :


As mentioned in error, make sure the path and file name of the web job not exceeds 250



Hope these resolution comes handy for folks working on similar problem statement.