Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Sascha Tayefeh http://www.tayefeh.de

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Using Google's API to Access Picasa Albums

Google provides its API in multiple languages. Here is an example that shows how to access a picasa album.

Before you start, you need to download Google's API for .NET. Then copy the files to you project (in the project explorer) in Visual Studio and in the references in the project explorer. Now you can make use of the namespaces:

using Google.GData.Client;
using Google.GData.Photos;

namespace GetPicasaFeed
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.getAtomFeed();
            return;
        }

        private void getAtomFeed()
        {

            // Album query and picasa query are specialized atomfeed classes
            AlbumQuery aQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("saschatayefeh"));
            PicasaService pService = new PicasaService("PicasaDemo");
            AtomFeed kResultFeed = pService.Query(aQuery);

            foreach (AtomEntry entry in kResultFeed.Entries)
            {
                this.textBox1.AppendText(entry.Title.Text + "\r\n");
                foreach (AtomLink eLink in entry.Links)
                {
                    this.textBox1.AppendText("  " + eLink.HRef.ToString() + "\r\n"); ;
                }
            }
            return;
        }

 
    }
}

Accessing a web service

1. In Visual Studio, add a web reference in the project explorer.

2. Create an class describing an object that represents the web service.

    public class CurrentWeather
    {

        #region attributes

        private String location;
        private String time;
        private String wind;
        private String visibility;
        private String temperature;
        private String dewPoint;
        private String relativeHumidity;
        private String pressure;
        private String status;

        #endregion


        #region properties

        public String Location { get { return this.location; } set { this.location = value; } }
        public String Time { get { return this.time; } set { this.time = value; } }
        public String Wind { get { return this.wind; } set { this.wind = value; } }
        public String Visibility { get { return this.visibility; } set { this.visibility = value; } }
        public String Temperature { get { return this.temperature; } set { this.temperature = value; } }
        public String DewPoint { get { return this.dewPoint; } set { this.dewPoint = value; } }
        public String RelativeHumidity { get { return this.relativeHumidity; } set { this.relativeHumidity = value; } }
        public String Pressure { get { return this.pressure; } set { this.pressure = value; } }
        public String Status { get { return this.status; } set { this.status = value; } }

        #endregion

    }



Use a method like this to call the service

        private void btRead_Click(object sender, EventArgs e)
        {
            net.webservice.www.MyWeather gw = new net.webservice.www.MyWeather ();
            this.lblShowStatus.Text = "Accessing Service";
            this.Refresh();
 
            Objects.CurrentWeather cwo = new Objects.CurrentWeather();
            System.Xml.Serialization.XmlSerializer xs =
                new System.Xml.Serialization.XmlSerializer(typeof(Objects.CurrentWeather));

            // Deserialize
            try
            {
                System.IO.TextReader tr = new System.IO.StringReader(gw.GetWeather(this.tbCity.Text, this.tbCountry.Text));
                cwo = (Objects.CurrentWeather)xs.Deserialize(tr);
                this.lblShowStatus.Text = cwo.Status;
                this.lbShowHumidity.Text = cwo.RelativeHumidity;
                this.lbShowPressure.Text = cwo.Pressure;
                this.lbShowWind.Text = cwo.Wind;
                this.lbShowTemperature.Text = cwo.Temperature;
            }
            catch
            {
                this.lblShowStatus.Text = String.Empty;
                this.lbShowHumidity.Text = String.Empty;
                this.lbShowPressure.Text = String.Empty;
                this.lbShowWind.Text = String.Empty;
                this.lbShowTemperature.Text = String.Empty;
                this.lblShowStatus.Text = "Error";
            }
        }



Create DLL with C# (C-sharp)


HowTo create a dynamically linked library (DLL) with C# (C-sharp) and
Visual Studio 2005.

HowTo create a dynamically linked library (DLL) with C# (C-sharp) and
Visual Studio 2005.

1. Creating the DLL:

a) Create a new project -> C# Classlibrary.

b) Create your class adding or modifying
a class-file to the project and entering
something like:
		using System;
		using System.Collections.Generic;
		using System.Text;

		namespace MyClassLib
		{
		    public class ClassA
		    {
			public int PropA = 10;

			public void Multiply()
			{
			    PropA *= 2;
			}

			public void Multiply(Int32 myFactor)
			{
			    PropA *= myFactor;
			}

		    }
	  


2. Test-bind the DLL

a) Create another project WITHOUT closing or deleting the old project.
(This is done by right-clicking on the Project-Explorer and
choosing Add->New Project)

b) The new project needs to now about the DLL. The terminology is
different from that of C++. Here, we talk about "references" instead
of links. Thus, we have to add the DLL to the reference tree of the
new project in the project-explorer. Rightclick on your
new project->add reference->choose tab:Project and add.

c) To make life easier, use the namespace of your dll. Your
main code could look something like this:

	   
	   using System;
	   using System.Collections.Generic;
	   using System.Text;
	   using MyClassLib;
	   
	   namespace ConsoleApplication1
	   {
	       class Program
	       {
	           static void Main(string[] args)
	           {
	               ClassA obj = new ClassA();
	               obj.PropA = 9;
	               obj.Multiply(9);
	               Console.WriteLine(obj.PropA);
	               Console.ReadLine();
	           }
	       }
	   }
	   


Remember: The force is with you!


« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS