Tuesday, 15 December 2015

Push notification for android using C#.Net

            // App ID
            string googleAppID = "AIzaSyAYfVEk_C0ATkqbZo6mp2JI1c8bv58wV54";
            // sender key which is generated from Google
            var senderID = "649193597288";
            // Device ID which is used to pull message from android server
            string deviceID = "APA91bFJGvf3zyfVxuTu6WgZKnrSMch6OXUGMqZtean2q9lQ7k-5cibteOgh3wnxME7ex…… ";
            var message = "This is test push notification for android";
           
            WebRequest request;
            request = WebRequest.Create("https://android.googleapis.com/gcm/send");
            request.Method = "post";
            request.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
            request.Headers.Add(string.Format("Authorization: key={0}", googleAppID));

            request.Headers.Add(string.Format("Sender: id={0}", senderID));

            string postData = @"collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + message + "&data.time=" +
            System.DateTime.Now.ToString() + "&registration_id=" + deviceID + "";

            Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            String sResponseFromServer = reader.ReadToEnd();
            reader.Close();
            dataStream.Close();
            response.Close();

Thursday, 3 December 2015

Change order of files in bundling



 
  public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            var JS = new ScriptBundle("~/Content/Dashboard").Include(
                                                  "~/Content/assets/plugins/gridmove/src/underscore-min.js",
                                                  "~/Content/assets/plugins/gridmove/src/knockout-min.js",
                                                  "~/Content/weather/weather.js");
            JS.Orderer = new CustomBundleOrderer();
            bundles.Add(JS);
        }
    }

    class CustomBundleOrderer : IBundleOrderer
    {
        public IEnumerable<FileInfo> OrderFiles(BundleContext context, IEnumerable<FileInfo> files)
        {
            return files; // Do your ordering related stuffs
        }
    }

Wednesday, 18 November 2015

Render PDF from RDLC report in MVC

       public ActionResult Report(string id)
        {
            LocalReport lr = new LocalReport();
            string path = Path.Combine(Server.MapPath("~/Report"), "Report1.rdlc");
            if (System.IO.File.Exists(path))
            {
                lr.ReportPath = path;
            }
            else
            {
                return View("Index");
            }
            List<string> cm = new List<string>();

            // Assign dataset
            ReportDataSource rd = new ReportDataSource("MyDataset", cm);
            lr.DataSources.Add(rd);
            string reportType = id;
            string mimeType;
            string encoding;
            string fileNameExtension;

            lr.EnableExternalImages = true;
            ReportParameter paramLogo = new ReportParameter();
            paramLogo.Name = "rptLogo";
            paramLogo.Values.Add(@"http://xyz.com/PDFS/38201504417635742242574221130.jpg");
            lr.SetParameters(paramLogo);


            string deviceInfo =

            "<DeviceInfo>" +
            "  <OutputFormat>" + id + "</OutputFormat>" +
            "  <PageWidth>8.5in</PageWidth>" +
            "  <PageHeight>11in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>1in</MarginLeft>" +
            "  <MarginRight>1in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            renderedBytes = lr.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);


            return File(renderedBytes, mimeType);
        }