Wednesday, January 25, 2012

Impliment And/Or multi condition in hbase.

Here  FilterList listOfFiltersA and FilterList listOfFiltersB will impliment AND condition of the filters in the filter list and  FilterList listOfFiltersC will impliment OR Condition on  listOfFiltersA and listOfFiltersB

 public static void multiConditionReturn() throws IOException
    {
        HTable hTable = new HTable("well");
        Scan scan = new Scan();
        FilterList listOfFiltersA = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        FilterList listOfFiltersB = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        FilterList listOfFiltersC = new FilterList(FilterList.Operator.MUST_PASS_ONE);
        SingleColumnValueFilter nodeFilter;
       
        nodeFilter = new SingleColumnValueFilter
                (
                Bytes.toBytes("cf"),
                Bytes.toBytes("well_name"),
                CompareOp.EQUAL,
                Bytes.toBytes("AB Test Well")
                );
        listOfFiltersA.addFilter(nodeFilter);
        nodeFilter = new SingleColumnValueFilter
                (
                Bytes.toBytes("cf"),
                Bytes.toBytes("well_region"),
                CompareOp.EQUAL,
                Bytes.toBytes("Region Name")
                );
        listOfFiltersA.addFilter(nodeFilter);
       
        nodeFilter = new SingleColumnValueFilter
                (
                Bytes.toBytes("cf"),
                Bytes.toBytes("wellDatum_name"),
                CompareOp.EQUAL,
                Bytes.toBytes("Kelly Bushing")
                );
        listOfFiltersB.addFilter(nodeFilter);       
        nodeFilter = new SingleColumnValueFilter
                (
                Bytes.toBytes("cf"),
                Bytes.toBytes("well_uid"),
                CompareOp.EQUAL,
                Bytes.toBytes("BGC_TD")
                );
        listOfFiltersB.addFilter(nodeFilter);      
        listOfFiltersC.addFilter(listOfFiltersA);
        listOfFiltersC.addFilter(listOfFiltersB);
        scan.setFilter(listOfFiltersC);
        ResultScanner scanner = hTable.getScanner(scan);

        for (Result result : scanner) {
        System.out.println(result);           
        }
    }

Tuesday, January 24, 2012

How to delete a specific row or given rows in hbase using java code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package witsml131;

import java.io.IOException;
import java.util.ArrayList;
import javax.security.auth.login.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.Bytes;

/**
 *
 * @author shashwat
 */
public class DeleteFromHbase {

    public static void main(String[] args) throws IOException {

        HTable table = new HTable("well");
        ArrayList<String> rowsToDelete = new ArrayList(); //array with all rows names to delete.
        Delete del = new Delete(Bytes.toBytes("2"));//for single row named 2

        table.delete(del);
      
        //deleting all rows in rowsToDelete in array list rowsToDelete
        for (String rows : rowsToDelete) {
            del = new Delete(Bytes.toBytes(rows));//for single row named 2

            table.delete(del);
        }
        table.close();
    }
}

How can I get it to parse XML contained within a String instead of a file?

 public static Document loadXMLFromString(String xml) throws Exception
    {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(xml));
        return builder.parse(is);
    }


Comparing StAX to Other JAXP APIs

As an API in the JAXP family, StAX can be compared, among other APIs, to SAX, TrAX, and JDOM. Of the latter two, StAX is not as powerful or flexible as TrAX or JDOM, but neither does it require as much memory or processor load to be useful, and StAX can, in many cases, outperform the DOM-based APIs. The same arguments outlined above, weighing the cost/benefits of the DOM model versus the streaming model, apply here.
With this in mind, the closest comparisons between can be made between StAX and SAX, and it is here that StAX offers features that are beneficial in many cases; some of these include:


Thursday, January 19, 2012

Working with Pushpins in the Map Control


To add a basic pushpin, create the pushpin object and add it as a child to the map. The following example allows the user to push a button that adds a pushpin to the center of the current map view.
<phone:PhoneApplicationPage 
    x:Class="WindowsPhoneApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True" xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps">

    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <my:Map Height="427" HorizontalAlignment="Left" Margin="12,6,0,0" Name="map1" VerticalAlignment="Top" Width="438" />            
            <Button Content="Add Center Pushpin" Height="72" HorizontalAlignment="Left" Margin="90,467,0,0" Name="button1" VerticalAlignment="Top" Width="297" Click="button1_Click" />
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>

Use the Bing Maps Silverlight Control for Windows Phone(Source MSDN)

  1. Make sure you have downloaded and installed the Windows Phone SDK from the App Hub.
  2. Launch Visual Studio 2010 Express for Windows Phone from the Windows Start menu.
  3. Create a new project by clicking the File | New Project menu command.
  4. The New Project window will be displayed. Expand the Visual C# templates, and then select the Silverlight for Windows Phone templates.
  5. Select the Windows Phone Application template. Fill in the project Name as desired.
  6. Click OK. A new project will be created and MainPage.xaml will be opened in the Visual Studio designer window.
The next step is to lay out the controls of the application using the Visual Studio designer. After adding the controls, the final layout will look similar to the following screenshot:
MapLayout

To add the controls of the application


How to: Add a Content Type to a SharePoint List using C#

Create a SharePoint 2010 Project

In this task, you create an empty SharePoint 2010 project in Microsoft Visual Studio 2010.
To create the SharePoint project
  1. To start Visual Studio 2010, click the Start Menu, click All Programs, click Microsoft Visual Studio 2010, and then click Microsoft Visual Studio 2010.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog window, in the Installed Templates section, click Visual C#, click SharePoint, and then click2010.
  4. Select Empty SharePoint Project from the project items.
  5. In the Name box, type CreateContentType and then click OK.
  6. In the SharePoint Customization Wizard, type the local Web site that you want to use for this exercise (such as http://localhost/SampleWebSite).
  7. For the trust level, select Deploy as a farm solution and then click Finish.

Create a Content Type

Saturday, January 14, 2012

SharePoint Page Types

There are two primary types of pages in Microsoft SharePoint Foundation.

They are:

  • Site pages and
  • Application pages.

Site pages: 

Site pages are pages that are created, edited, and customized by end users. They are primarily used for the content in a site. Site pages come in two types—

  • A standard page and
  • A Web Parts page.

A standard page contains text, images, Web Parts, and other elements. A Web Parts page contains Web Parts in Web Part zones. They have a predefined layout that uses Web Part zones. Both types of site pages are edited using a Web browser or Microsoft SharePoint Designer.

Site pages are provisioned from a template page that is stored on the file system of the front-end Web server. When a site is provisioned, SharePoint Foundation creates a pointer to the instance of the page template on the file system. This allows SharePoint Foundation to avoid repeatedly creating copies of the pages, which are provisioned each time a site is created.

When a user customizes a site page, the template for the page is then stored in the content database. The page is retrieved from the content database every time it is requested by a user. A customized page can, however, be reset to the original template page through the Web browser or a tool such as SharePoint Designer.

Customized site pages cannot contain in-line server code. The set of controls that are allowed to run on the page is governed by the safe controls list in the<Drive>:\inetpub\wwwroot\wss\VirtualDirectories\<port number>\web.config file. It is a recommended best practice to avoid using server-side code on site pages when developing site definitions. If a user later edits or modifies that page, the code will no longer run.

The following are general rules for using server-side code on a site page.

  • If the page is un customized, server-side code is supported on the page.

  • If the page is customized, server-side code does not run, and the page does not render. This includes the code-behind for the page itself.

 

Application Pages:

Application pages are used to support application implementations in SharePoint Foundation. Application pages are stored on the file system of the front-end Web server in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS directory and exist for every site in a Web application. This folder is mapped to an Internet Information Services (IIS) virtual directory called _layouts. Every site and subsite will have access to the application pages by using the _layouts virtual directory. For example, http://myserver/_layouts/settings.aspx and http://myserver/subsite/_layouts/settings.aspx access the same application page on the front-end Web server unlike site pages, which are an instance for the specified site.

Application pages are not subject to the same restrictions as site pages. They allow in-line code without restriction. They cannot, however, use dynamic Web Parts or Web Part zones or be modified using SharePoint Designer. Modifying the default application pages is not supported in SharePoint Foundation. Custom application pages can be added to a subdirectory inside the _layouts folder.

Blogger Labels: SharePoint,Page,Types,Microsoft,Foundation,Site,Application,users,Parts,text,Part,zones,layout,Both,Designer,template,system,server,pointer,instance,user,database,tool,Drive,VirtualDirectories,port,definitions,Pages,implementations,ProgramFiles,Common,Files,extensions,LAYOUTS,folder,Internet,Information,Services,_layouts,example,settings,restrictions,restriction,Custom,subdirectory,browser,subsite,myserver,aspx

Programmatically launch Debugger in a remote machine


ConnectionOptions options = new ConnectionOptions();
 ManagementScope scope = new ManagementScope("\\\\machine1\\root\\cimv2", options);
 scope.Connect();

 ObjectQuery oQuery = new ObjectQuery("Select * from Win32_Process where Name Like 'ConsoleApp%'");
 //Execute the query
 ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(scope,oQuery);

 //Get the results
 ManagementObjectCollection objReturnCollection = objSearcher.Get();

 foreach (ManagementObject oReturn in objReturnCollection)
 {
 if (oReturn["Name"].ToString().Equals("ConsoleApplication1.exe"))
 {
 object outparams = oReturn.InvokeMethod("AttachDebugger", null);
 }
 }

Friday, January 13, 2012

Implementing Singleton in C#

Singleton class in oops is a facility that provide us an option to define a class to have single instance throughout the program lifetime, it also help us to have a global access point.
How to implement singleton class in c#:

using System;

public class Singlton

{

private static Singleton instance;

private singleton(){}

public static Singleton instance

{

        get

        {

               if(instance ==null)

               {

                    instance =new Singleton();                      

//Checks if the instance has already been created, 

//if yes will return the already created instance else,

                    //will create a new instance of the Singleton Class.

               }

               return instance;

        }

}

}




Featured Posts

Podman: The Complete Guide to Rootless, Daemonless Containers

Podman: The Complete Guide to Rootless, Daemonless Containers Podman is an open-source container engine designed to build, run, manage, and...