Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Page History: SSRS Extender Cache Class

Compare Page Revisions



« Older Revision - Back to Page History - Newer Revision »


Page Revision: Thu, Mar 11, 2010, 9:36 AM


This page is a Draft. Its content is not complete and might contain errors.

This page is part of the Class Library Pages collection.
Click the icon to see the index.

Overview

The SsrsExtender.Cache class is used within a SQL Server Reporting Services report to place field values in a Page Header or Page Footer section.

Walkthrough

Source Code

VB.NET

{copytext|VbSource}
Imports System.Data.SqlClient
Imports System.Security.Permissions

Public Class Cache

    Private Shared _dict As Dictionary(Of String, String)
    '==============================================================================================
    Shared Sub New()

        Dim p As SqlClientPermission = New SqlClientPermission(PermissionState.Unrestricted)
        p.Assert()
        _dict = New Dictionary(Of String, String)

    End Sub
    '==============================================================================================
    Public Shared Function [Set](ByVal name As String, ByVal value As String) As Boolean

        Dim p As SqlClientPermission = New SqlClientPermission(PermissionState.Unrestricted)
        p.Assert()
        Dim result As Boolean = False
        name = name.ToUpper()
        Try
            If value IsNot Nothing Then
                If _dict.ContainsKey(name) Then
                    _dict.Item(name) = value
                    result = True
                Else
                    _dict.Add(name, value)
                End If
            End If
        Catch ex As Exception
            'ignore exceptions
        End Try

        Return result

    End Function
    '==============================================================================================
    Public Shared Function [Get](ByVal name As String) As String

        Dim p As SqlClientPermission = New SqlClientPermission(PermissionState.Unrestricted)
        p.Assert()
        Dim result As String = ""
        name = name.ToUpper()
        Try

            If _dict.ContainsKey(name) Then
                result = _dict.Item(name)
            End If

        Catch ex As Exception
            'ignore exceptions
        End Try

        Return result

    End Function

End Class

C#

{copytext|CsSource}
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Permissions;
using System.Data.SqlClient;

namespace MyNamespace
{
    public static class Cache
    {
        private static Dictionary<string, string> _dict;

        //-----------------------------------------------------------------------------------------
        static Cache()
        {
            new SqlClientPermission(PermissionState.Unrestricted).Assert();
            _dict = new Dictionary<string, string>();
        }
        //-----------------------------------------------------------------------------------------
        public static bool Set(string name, string value)
        {
            new SqlClientPermission(PermissionState.Unrestricted).Assert();
            bool result = false;
            name = name.ToUpper();
            try
            {
                if (value != null)
                {
                    if (_dict.ContainsKey(name))
                    {
                        _dict[name] = value;
                        result = true;
                    }
                    else
                    {
                        _dict.Add(name, value);
                        result = true;
                    }
                }
            }
            catch {/* ignore exceptions */}

            return result;
        }
        //-----------------------------------------------------------------------------------------
        public static string Get(string name)
        {
            new SqlClientPermission(PermissionState.Unrestricted).Assert();
            name = name.ToUpper();
            string result = "";
            try
            {
                if (_dict.ContainsKey(name))
                    result = _dict[name];
            }
            catch {/* ignore exceptions */}

            return result;
        }
    }
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.