Saturday, March 27, 2010

Join List objects LINQ C#

 
public List getCustomerSpecials(int StoreID, int customerID)
        {
            Table<CategoryItem> specialsTable = customersTable.Context.GetTable<CategoryItem>();
            Table<CustomerCoupon> customerCouponsTable = customersTable.Context.GetTable<CustomerCoupon>();
            List<CategoryItem> specials = new List<CategoryItem>();
            List<CustomerCoupon> coupons = new List<CustomerCoupon>();
            coupons = customerCouponsTable.Where(coupon => coupon.Customer.CustomerID == customerID).ToList();
            specials = specialsTable.Where(cItem => cItem.StoreCategory.CategoryName == cItem.Item.Store.StoreCategorys[0].CategoryName && cItem.Item.Store.StoreID == StoreID).ToList();

            var query = from c in coupons
                        join s in specials on c.ItemID equals s.ItemID
                        select new { c.Item };
            return query.ToList();

        }

Wednesday, March 24, 2010

Write Files directly on Response ASP.Net C#


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

///
/// Summary description for Util
///
namespace Utility
{
    public class FileUtil
    {
        public FileUtil()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        static public void writeFileToResponse(string filePath,HttpResponse Response)
        {
            try
            {
           
            string FileName = Path.GetFileName(filePath);
            Response.Clear();

            Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);

            //Response.ContentType = sContentType;

            Response.WriteFile(filePath);

            Response.Flush();

            File.Delete(filePath);
            Response.End();

            }
            catch (System.Exception ex)
            {

            }

        }
    }
}

Monday, March 22, 2010

Verify DSSS/DS3 ASM ASClinent connectivity



1)      Run DSSS/DS3 Virtual Machine

2)      Run vmwaregateway.exe/t

3)      telnet localhost 55178
4)      paste following line into telnet session (keystore location must be  correct)

openConnection;d:/DS3/ASClient/ASClient/Java/lib/asadclient.keystore;123456;192.168.1.85;false


Tuesday, March 16, 2010

LINQ to Object : Querying Non- IEnumerable collections


Below is an example of accessing EventlofEntityCollection, if I need to filter EventlogEntityCollect using LINQ I just need to mention object type in my collect after from clause in LINQ statement.

Instead of:

var ev = from e in elog.Entries where e.Source == "MsiInstaller" && e.Message.Contains(megString) select e;

Use:
var ev = from EventLogEntry e in elog.Entries where e.Source == "MsiInstaller" && e.Message.Contains(megString) select e;


Example:
EventLog elog = new EventLog();
            /* Tell Which type of log we need to access
            1. System
            2. Security
            3. Application
            */
            elog.Log = "Application";
           //Filter and Select Eventlog Entries Using LINQ
            var ev = from EventLogEntry e in elog.Entries where e.Source == "MsiInstaller" && e.Message.Contains(megString) select e;

Read Eventlog using C# and LINQ


using System;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
namespace EventUtils
{
    class EventViewer
    {
        static void Main(string[] args)
        {
            string megString = "Product: MySQL Tools for 5.0";
            /* Create an object for event log */
            EventLog elog = new EventLog();
            /* Tell Which type of log we need to access
            1. System
            2. Security
            3. Application
            */
            elog.Log = "Application";
           //Filter and Select Eventlog Entries Using LINQ
            var ev = from EventLogEntry e in elog.Entries where e.Source == "MsiInstaller" && e.Message.Contains(megString) select e;
            foreach (var eventEntity in ev)
            {
                Console.WriteLine("Message: " + eventEntity.Message + "\n" +
                "App: " + eventEntity.Source + "\n" +
                "Entry type: " + eventEntity.EntryType + "\n" +
                "User Name: " + eventEntity.UserName);
                Console.WriteLine();
            }
            Console.ReadLine();
           
        }
    }
}

Followers

Search This Blog