Monthly Archives: August 2015

Modern UI for WPF

In this post, i will try to tell you about how to create WPF applications using Modern UI Theme.

There may be several ways to include Modern UI to a project but i will concentrate on much a simpler way without using NuGET or something else. In this context, Visual Studio 2015 Community Edition is used as IDE and codes are generated using C# with Net Framework 4.5.

1. Create Project

Create a new WPF using File > New > Project dialog and select WPF Application template under Visual C# > Windows category. Give your project a name and click OK to create your demo project. Then we need to add an assembly reference to the FirstFloor.ModernUI.dll which is the main library file for the Modern UI.

2. Modify MainWindow

Open MainWindow.xaml file and replace all of the page content with the following definition.

<mui:ModernWindow x:Class="MuiTest.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mui="http://firstfloorsoftware.com/ModernUI"
  Title="MainWindow" Height="350" Width="525">
</mui:ModernWindow>

Open MainWindow.xaml.cs, add the ModernUI using clause and replace the Window base class with ModernWindow.

using FirstFloor.ModernUI.Windows.Controls;
public partial class MainWindow : ModernWindow { }

3. Modify App.xaml

Open App.xaml file and replace the <Application.Resources> part as shown below:

<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=”/FirstFloor.ModernUI;component/Assets/ModernUI.xaml” />
<ResourceDictionary Source=”/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml”/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>

Choose ModernUI.Light.xaml for the light theme and ModernUI.Dark.xaml for the dark theme. Don’t supply both at the same time!

Important: If you are using the WPF 4.0 version of ModernUI you need to add an empty Rectangle style to work around a bug in WPF, as shown below. The workaround is not needed for WPF 4.5.

<Application.Resources>
 <ResourceDictionary>
 <!-- WPF 4.0 workaround -->
 <Style TargetType="{x:Type Rectangle}" />
 <!-- end of workaround -->
 <ResourceDictionary.MergedDictionaries>
 <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
 <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
 </ResourceDictionary.MergedDictionaries>
 </ResourceDictionary>
</Application.Resources>

For Net Framework 4.0 you need to add Microsoft.Windows.Shell.dll library reference to the project.

4. Add navigation

Open MainWindow.xaml and remove the Grid content if exists. Important: the ModernWindow.Content property is ignored, all content is rendered by specifying page links as is demonstrated below.

Define the main menu by adding the following menu link groups:

<mui:ModernWindow.MenuLinkGroups>
<mui:LinkGroup DisplayName=”group 1″ >
<mui:LinkGroup.Links>
<mui:Link DisplayName=”link 1″ />
<mui:Link DisplayName=”link 2″ />
<mui:Link DisplayName=”link 3″ />
</mui:LinkGroup.Links>
</mui:LinkGroup>
</mui:ModernWindow.MenuLinkGroups>

5. Add page

Add a WPF UserControl named Page1. Open Page1.xaml and add the following content:

<Grid Style=”{StaticResource ContentRoot}”>
<TextBlock Text=”Hello Modern UI!” />
</Grid>

The ContentRoot style ensures the content is correctly positioned on screen. Go back to MainWindow.xaml and modify the first link so that it refers to Page1.xaml.

<mui:Link DisplayName=”link 1″ Source=”/Page1.xaml” />

Additionally add a ContentSource attribute to the ModernWindow element. The ContentSource defines the page that is loaded on start. In above case, /Page1.xaml will be loaded upon startup.

<mui:ModernWindow …
ContentSource=”/Page1.xaml” />

6. Run

Compile and run the application.

Click to download: Demo Project

References:

https://github.com/firstfloorsoftware/mui

https://github.com/firstfloorsoftware/mui/wiki/Getting-started-without-templates

Hide Drive Letters in Windows 7

If you want to hide some drive letters from the windows explorer then you can use registry to achieve this.

1.

Open registry editor (regedit.exe) and navigate to the following location:

HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionPoliciesExplorer

If the key Explorer is not present under the Policies key, you can simply create a new key and give the name Explorer.

2.

Under the Explorer key, create a new 32-bit DWORD and name it NoDrives.

3.

The important thing is the value to be given to that parameter. Below is a table showing the list drive letters in reverse order. To hide a drive letter, you must put 1 for that letter (or 0 to unhide/show). The resulting binary number is the value for NoDrives parameter.

Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1

If you want to hide drive letters A,B,D,E and F for example (as shown above) binary value will be : 111011 (remaining zeros not used since no drive letter left to hide, you must go until covering all drive letters considered to be hide).

You need to convert 110111 binary to decimal (http://www.binaryhexconverter.com/binary-to-decimal-converter may be used) which is equal to 55.

Then modify the previously created NoDrives parameter to 59.

Be careful to select Decimal as Base.

Note

Table shown in the below has values for some common drive letters. You may sum decimal values for which drive letters you want to hide.

Drive Letter Decimal Hex
A 1 1
B 2 2
C 4 4
D 8 8
E 16 10
F 32 20
G 64 40
H 128 80

For the example given above, if we sum 1+2+8+16+32 we reach 59 for hiding: A,B,D,E and F.

 

4.

Restart the computer. Thats all done!

 

References

http://www.howtogeek.com/howto/windows-vista/hide-drives-from-your-computer-in-windows-vista/

WPF

When creating a WPF application, the first thing you will meet is the Window class. It serves as the root of a window and provides you with the standard border, title bar and maximize, minimize and close buttons. A WPF window is a combination of a XAML (.xaml) file, where the element is the root, and a CodeBehind (.cs) file. A default structure od a XAMP (eXtended Application Markup Language) file will be like the following:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
         ...
        </Grid>
</Window>

The x:class attribute tells the XAML file which class to use.
There is a Grid control inside the Window element. The Grid is one of the WPF panels, and while it could be any panel or control, the Window can only have only ONE child control, so a Panel, which in turn can contain multiple child controls, is usually a good choice.

App.xaml, including a Code-behind file called App.xaml.cs, is the declarative starting point of the application.  App.xaml.cs extends the Application class, which is a central class in a WPF Windows application. .NET will go to this class for starting instructions and then start the desired Window or Page from there. This is also the place to subscribe to important application events, like application start, unhandled exceptions and so on. One of the most commonly used features of the App.xaml file is to define global resources that may be used and accessed from all over an application, for instance global styles.

 

App.xaml structure

When creating a new application, the automatically generated App.xaml will look something like this:

<Application x:Class="WpfTutorialSamples.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>

The main thing to notice here is the StartupUri property. This is actually the part that instructs which Window or Page to start up when the application is launched. In this case, MainWindow.xaml will be started, but if you would like to use another window as the starting point, you can simply change this.

In some situations, you want more control over how and when the first window is displayed. In that case, you can remove the StartupUri property and value and then do it all from Code-Behind instead. This will be demonstrated below.

App.xaml.cs structure

The matching App.xaml.cs will usually look like this for a new project:

using System;
using System.Collections.Generic;
using System.Windows;

namespace WpfTutorialSamples
{
        public partial class App : Application
        {

        }
}

You will see how this class extends the Application class, allowing us to do stuff on the application level. For instance, you can subscribe to the Startup event, where you can manually create your starting window.

 

Here’s an example:

<Application x:Class="WpfTutorialSamples.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                         Startup="Application_Startup">
    <Application.Resources></Application.Resources>
</Application>

Notice how the StartupUri has been replaced with a subscription to the Startup event (subscribing to events through XAML is explained in another chapter). In Code-Behind, you can use the event like this:

using System;
using System.Collections.Generic;
using System.Windows;

namespace WpfTutorialSamples
{
        public partial class App : Application
        {

                private void Application_Startup(object sender, StartupEventArgs e)
                {
                        // Create the startup window
                        MainWindow wnd = new MainWindow();
                        // Do stuff here, e.g. to the window
                        wnd.Title = "Something else";
                        // Show the window
                        wnd.Show();
                }
        }
}

The cool thing in this example, compared to just using the StartupUri property, is that we get to manipulate the startup window before showing it. In this, we change the title of it, which is not terribly useful, but you could also subscribe to events or perhaps show a splash screen. When you have all the control, there are many possibilities. We will look deeper into several of them in the next articles of this tutorial.

 

WPF Resources

 

WPF introduces a very handy concept: The ability to store data as a resource, either locally for a control, locally for the entire window or globally for the entire application. The data can be pretty much whatever you want, from actual information to a hierarchy of WPF controls. This allows you to place data in one place and then use it from or several other places, which is very useful.

 

<Window x:Class="WpfTutorialSamples.WPF_Application.ResourceSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="ResourceSample" Height="150" Width="350">
    <Window.Resources>
        <sys:String x:Key="strHelloWorld">Hello, world!</sys:String>
    </Window.Resources>
    <StackPanel Margin="10">
        <TextBlock Text="{StaticResource strHelloWorld}" FontSize="56" />
        <TextBlock>Just another "<TextBlock Text="{StaticResource strHelloWorld}" />" example, but with resources!</TextBlock>
    </StackPanel>
</Window>



Resources are given a key, using the x:Key attribute, which allows you to reference it from other parts of the application by using this key, in combination with the StaticResource markup extension. In this example, I just store a simple string, which I then use from two different TextBlock controls.

StaticResource vs. DynamicResource

In the examples so far, I have used the StaticResource markup extension to reference a resource. However, an alternative exists, in form of the DynamicResource.

The main difference is that a static resource is resolved only once, which is at the point where the XAML is loaded. If the resource is then changed later on, this change will not be reflected where you have used the StaticResource.

 

A DynamicResource on the other hand, is resolved once it’s actually needed, and then again if the resource changes. Think of it as binding to a static value vs. binding to a function that monitors this value and sends it to you each time it’s changed – it’s not exactly how it works, but it should give you a better idea of when to use what. Dynamic resources also allows you to use resources which are not even there during design time, e.g. if you add them from Code-behind during the startup of the application.

More resource types

Sharing a simple string was easy, but you can do much more. In the next example, I’ll also store a complete array of strings, along with a gradient brush to be used for the background. This should give you a pretty good idea of just how much you can do with resources:

 

<Window x:Class="WpfTutorialSamples.WPF_Application.ExtendedResourceSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="ExtendedResourceSample" Height="160" Width="300"
        Background="{DynamicResource WindowBackgroundBrush}">
    <Window.Resources>
        <sys:String x:Key="ComboBoxTitle">Items:</sys:String>

        <x:Array x:Key="ComboBoxItems" Type="sys:String">
            <sys:String>Item #1</sys:String>
            <sys:String>Item #2</sys:String>
            <sys:String>Item #3</sys:String>
        </x:Array>

        <LinearGradientBrush x:Key="WindowBackgroundBrush">
            <GradientStop Offset="0" Color="Silver"/>
            <GradientStop Offset="1" Color="Gray"/>
        </LinearGradientBrush>
    </Window.Resources>
    <StackPanel Margin="10">
        <Label Content="{StaticResource ComboBoxTitle}" />
        <ComboBox ItemsSource="{StaticResource ComboBoxItems}" />
    </StackPanel>
</Window>



HTTP, HTTP GET and HTTP POST

HTTP (Hyper Text Transfer Protocol) is a stateless, text based network protocol that is designed for enabling communications between clients and servers by using request and response cycles. A client opens a connection and submits a request message to a server; then the server returns a response to that client. Because of the stateless nature, after delivering the response, the server closes the connection and does not maintain any information about connection.

The requests and responses are text based messages including some basic information about the request or response and some HTTP headers as well as application specific information requested or responded.

 

Sample HTTP Request:

The first line of the HTTP request is called the request line and consists of 3 parts:

 method path protocol
 GET  /index.html HTTP/1.1
  • The first part is called as the “method” that indicates what kind of request this is. Most common methods are GET, POST and HEAD.
  • The second part is called as the “path” that is generally the part of the url that comes after the host (domain).
  • The third part is called as the “protocol” that part contains “HTTP” and the version number.

The remainder of the request contains HTTP headers as “Name: Value” pairs on each line. These contain various information about the HTTP request and your browser. For example, the “User-Agent” line provides information on the browser version and the Operating System you are using. “Accept-Encoding” tells the server if your browser can accept compressed output like gzip.

You may have noticed that the cookie data is also transmitted inside an HTTP header. And if there was a referring url, that would have been in the header too. Most of these headers are optional. This HTTP request could have been as small as this:

GET /index.html HTTP/1.1
Host: http://www.example.com

Sample HTTP Response:

Upon receiving a request, server generates a response and transmits it to the client. A basic response as a sample is given below:

HTTP/1.1 200 OK
Date: Mon, 30 May 2015 01:01:01 GMT
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 100
Accept-Ranges: bytes
Connection: close

<html>
<head>
<title>Sample Page</title>
</head>
<body>
Hello World, this is a very simple HTML document.
</body>
</html>

 

Request Methods:

GET: Requests data from a specified resource

This is the main method used for retrieving data like html, images, JavaScript, CSS, etc. If request includes some data, it is included in query string and sent to the server in the URL of the request as name/value pairs. The amount of data that can be sent by GET requests is limited. Below is the list of some properties about GET:

  • Data are restricted to ASCII codes
  • All data is visible in the URL
  • GET requests can be cached
  • GET requests remain in the browser history
  • GET requests can be bookmarked
  • GET requests should never be used when dealing with sensitive data
  • GET requests have length restrictions since URL lengths are limited depending on both client and server (max URL length is 2048 characters)
  • GET requests should be used only to retrieve data
  • Encoding type is “application/x-www-form-urlencoded”

 

POST: Submits data to be processed to a specified resource

Request data is sent in the HTTP message body of a POST request.

Binary data can be transmitted
POST requests are never cached
POST requests do not remain in the browser history
POST requests cannot be bookmarked
POST requests have no restrictions on data length

Encoding type is “application/x-www-form-urlencoded” or “multipart/form-data” for binary data

 

Other HTTP Request Methods

HEAD Same as GET but returns only HTTP headers and no document body
PUT Uploads a representation of the specified URI
DELETE Deletes the specified resource
OPTIONS Returns the HTTP methods that the server supports
CONNECT Converts the request connection to a transparent TCP/IP tunnel

References:

https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

http://www.w3schools.com/tags/ref_httpmethods.asp

http://www.jmarshall.com/easy/http/

http://code.tutsplus.com/tutorials/http-headers-for-dummies–net-8039

OBIEE – Variables

Oracle Business Intelligence Enterprise Edition (OBIEE) allows us to use several types of variables in the different places of components like analyses, dashboards, KPI’s, conditions… etc.

There are four main types of variables each having a different use area and syntax. These are:

  • Session Variables
  • Repository Variables
  • Presentation Variables
  • Request Variable

 

Session Variables

A session variable is a variable as its name implies, that is initialized at the time of user login for each user. When a new user logins to the BI Server, a new instance of session variables are created, initialized and assigned to that user.

There are two types of session variables:

  • System Session Variable: A session variable that the Oracle BI Server and Oracle BI Presentation Services use for specific purposes. System session variables have reserved names that CAN NOT be used for other kinds of variables.
  • Non-System Session Variables: A session variable that the administrator user creates and names in the repository us,ng the Administration tool.

Syntax:

@{biServer.variables[‘NQ_SESSION.variablename‘]}

Sample:

@{biServer.variables[‘NQ_SESSION.USER’]}

 

 

Repository Variables

Repository variables are created by the BI Administration Tool in the repository by the admin user. There are two types of repository variables:

  • Static Repository Variable: Static repository variables are constant and they do not change until the administrator user changes them in the repository.
  • Dynamic Repository Variable: Dynamic repository variables values are refreshed by data returned from queries.

Syntax:

@{biServer.variables.variablename} or @{biServer.variables[‘variablename‘]}

Sample:

@{biServer.variables.country} or @{biServer.variables[‘country’]}

 

 

Presentation Variables

A presentation variable is a variable that users in the BI Answer can create as creating dashboard prompts as:

  • Column prompt: A presentation variable created as part of a column prompt is associated with a column, and the values that it can take come from the column values. To create a presentation variable as part of a column prompt, in the “New Prompt dialog” (or Edit Prompt dialog), you have to select Presentation Variable in the Set a variable field and then enter a name for the variable in the Variable Name field.
  • Variable prompt: A presentation variable created as part of a variable prompt is not associated with any column, and you define the values that it can take. To create a presentation variable as part of a variable prompt, in the “New Prompt dialog” (or Edit Prompt dialog), you have to select Presentation Variable in the Prompt for field and then enter a name for the variable in the Variable Name field.

The value of a presentation variable is populated by the column or variable prompt with which it was created. That is, each time a user selects a value in the column or variable prompt, the value of the presentation variable is set to the value that the user selects.

Syntax:

@{[variables.]variablename}[format]{defaultvalue} or @{scope.variables[‘variablename‘]}

Sample:

@{[variables.]Country}{COUNTRY NOT SELECTED} or @{dashboard.variables[‘Country’]}

  • variablename is the name of the presentation or request variable
  • (optional) format is any valid format mask dependent on the data type of the variable (#,##0, MM/DD/YY hh:mm:ss.) Note that the format is not applied to the default value
  • (optional) defaultvalue is a constant or variable reference indicating a value to be used if the variable referenced by variablename is not set
  • scope identifies the qualifiers for the variable. You must specify the scope when a variable is used at multiple levels (analyses, dashboard pages, and dashboards) and you want to access a specific value. (If you do not specify the scope, then the order of precedence is analyses, dashboard pages, and dashboards.)

 

Request Variables

A request variable lets you override the value of a session variable but only for the duration of a database request initiated from a column prompt. You can create a request variable as part of the process of creating a column prompt.
A request variable that is created as part of a column prompt is associated with a column, and the values that it can take come from the column values.

To create a request variable as part of a column prompt, in the “New Prompt dialog” (or Edit Prompt dialog), you have to select Request Variable in the Set a variable field and then enter the name of the session variable to override in the Variable Name field.

The value of a request variable is populated by the column prompt with which it was created. That is, each time a user selects a value in the column prompt, the value of the request variable is set to the value that the user selects. The value, however, is in effect only from the time the user presses the Go button for the prompt until the analysis results are returned to the dashboard.

Syntax:

@{[variables.]variablename}[format]{defaultvalue} or @{scope.variables[‘variablename‘]}

Sample:

@{[variables.]Country}{COUNTRY NOT SELECTED} or @{dashboard.variables[‘Country’]}

  • variablename is the name of the presentation or request variable
  • (optional) format is any valid format mask dependent on the data type of the variable (#,##0, MM/DD/YY hh:mm:ss.) Note that the format is not applied to the default value
  • (optional) defaultvalue is a constant or variable reference indicating a value to be used if the variable referenced by variablename is not set
  • scope identifies the qualifiers for the variable. You must specify the scope when a variable is used at multiple levels (analyses, dashboard pages, and dashboards) and you want to access a specific value. (If you do not specify the scope, then the order of precedence is analyses, dashboard pages, and dashboards.)

 

 

 

 

References:

http://obieetutorialguide.blogspot.com.tr/2012/02/using-variables-in-obiee.html

http://docs.oracle.com/cd/E12096_01/books/AnyUser/AnyUser_Format8.html

OBIEE – Direct Database Request: Using Presentation Variables

In the previous post, we have mentioned about direct database requests (DDR), and positive and negative properties of them. If you are interested in those topics please take some time and read corresponding post:

OBIEE – Direct Database Requests

In this article, we will try to explain how to use presentation variables in these requests.

 

OBIEE – Direct Database Request: User Permissions

In the previous post, we have mentioned about direct database requests (DDR), and positive and negative properties of them. If you are interested in those topics please take some time and read corresponding post:

OBIEE – Direct Database Requests

In this article, we will try to explain which permissions are required for DDR’s and how to assign then to a specific user.

First of all, we need to configure some settings in the repository part using Administration tool:

  • Open the Administration Tool and go to Manage -> Identity
  • Select BI Repository and on the right side, select Users or Application Roles tab
  • Under the selected tab, select the desired user or application role name and double click
  • Select the permissions button on the Application Role popup window
  • In the Query Limits tabs, change Execute Direct Database Requests from Ignore to Allow
  • Save and close windows.

Then we need to configure some settings in the BI Server:

  • Using your web browser, open BI Server (analytics) and login as an administrator (weblogic user)
  • Click on the Administration link placed at the right side of the top most part of the page
  • Click on the Manage Privileges link located under Security part
  • In the Answers section (list is not alphabetically sorted), for Edit Direct Database Analysis and Execute Direct Database Analysis sections click on the default value to include desired users and groups to allow these features.