示例#1
0
        public static Bitmap GetEmployeePhoto(Guid employeeId)
        {
            byte[] photoData = null;

            // Attempt to retrieve from cache
            ICacheManager cache = EnterpriseLibraryContainer.Current.GetInstance <ICacheManager>();

            photoData = (byte[])cache[employeeId.ToString()];

            // Retrieve from dataProvider if not in Cache and Online
            if (photoData == null && ConnectionManager.IsOnline)
            {
                EmployeeDataProvider dataProvider = new EmployeeDataProvider();
                photoData = dataProvider.GetEmployeePhotoData(employeeId);

                cache.Add(employeeId.ToString(), photoData);
            }

            // No data found.
            if (photoData == null)
            {
                return(null);
            }

            // Convert bytes to Bitmap
            using (MemoryStream ms = new MemoryStream(photoData))
            {
                return(new Bitmap(ms));
            }
        }
示例#2
0
        public static EmployeesDataSet GetContactDetails()
        {
            EmployeesDataSet dsEmployees = null;

            // Attempt to retrieve from cache
            ICacheManager cache = EnterpriseLibraryContainer.Current.GetInstance <ICacheManager>();

            dsEmployees = (EmployeesDataSet)cache[CACHE_KEY];

            // Retrieve from dataProvider if not in Cache and Online
            if (dsEmployees == null && ConnectionManager.IsOnline)
            {
                EmployeeDataProvider dataProvider = new EmployeeDataProvider();
                dsEmployees = dataProvider.GetEmployees();

                // Expire in 2 days
                AbsoluteTime expiry = new AbsoluteTime(new TimeSpan(2, 0, 0, 0));
                cache.Add(
                    CACHE_KEY,
                    dsEmployees,
                    CacheItemPriority.High,
                    null,
                    new ICacheItemExpiration[] { expiry });
            }

            return(dsEmployees);
        }
示例#3
0
        public static Bitmap GetEmployeePhoto(Guid employeeId)
        {
            byte[] photoData = null;

            // TODO: Add Caching of Photo
            //EmployeeDataProvider dataProvider = new EmployeeDataProvider();
            //photoData = dataProvider.GetEmployeePhotoData(employeeId);
            ICacheManager cache = EnterpriseLibraryContainer.Current.GetInstance <ICacheManager>();

            photoData = (byte[])cache[employeeId.ToString()];

            // No data found.
            if (photoData == null)
            {
                EmployeeDataProvider dataProvider = new EmployeeDataProvider();
                photoData = dataProvider.GetEmployeePhotoData(employeeId);
                cache.Add(employeeId.ToString(), photoData);
            }

            // Convert bytes to Bitmap
            using (MemoryStream ms = new MemoryStream(photoData))
            {
                return(new Bitmap(ms));
            }
        }
示例#4
0
        public static EmployeesDataSet GetContactDetails()
        {
            EmployeesDataSet dsEmployees = null;

            EmployeeDataProvider dataProvider = new EmployeeDataProvider();

            dsEmployees = dataProvider.GetEmployees();

            return(dsEmployees);
        }
示例#5
0
        public static EmployeesDataSet GetContactDetails()
        {
            EmployeesDataSet dsEmployees = null;

            // TODO: Add persistent caching with time-out

            EmployeeDataProvider dataProvider = new EmployeeDataProvider();

            dsEmployees = dataProvider.GetEmployees();

            return(dsEmployees);
        }
示例#6
0
        public static Bitmap GetEmployeePhoto(Guid employeeId)
        {
            byte[] photoData = null;

            // TODO: Add Caching of Photo
            EmployeeDataProvider dataProvider = new EmployeeDataProvider();

            photoData = dataProvider.GetEmployeePhotoData(employeeId);

            // No data found.
            if (photoData == null)
            {
                return(null);
            }

            // Convert bytes to Bitmap
            using (MemoryStream ms = new MemoryStream(photoData))
            {
                return(new Bitmap(ms));
            }
        }
示例#7
0
        // TODO: PopulateCache & BeginBackgroundLoad

        private static void PopulateCache()
        {
            byte[] photoData = null;

            EmployeesDataSet dsEmployees = GetContactDetails();

            if (dsEmployees == null)
            {
                return;
            }

            ICacheManager cache = EnterpriseLibraryContainer.Current.GetInstance <ICacheManager>();

            foreach (EmployeesDataSet.EmployeesRow employee in dsEmployees.Employees)
            {
                if (!cache.Contains(employee.EmployeeID.ToString()))
                {
                    EmployeeDataProvider dataProvider = new EmployeeDataProvider();
                    photoData = dataProvider.GetEmployeePhotoData(employee.EmployeeID);
                    cache.Add(employee.EmployeeID.ToString(), photoData);
                }
            }
        }