El TecnoBaúl de Kiquenet

Kiquenet boring stories

Archive for 26 diciembre 2014

Google Calendar API

Posted by kiquenet en 26 diciembre 2014

Nuget: https://www.nuget.org/packages?q=google+calendar

Install-Package Google.GData.Calendar 
Install-Package Google.Apis.Calendar.v3

http://support.google.com/mail/bin/answer.py?hl=it&answer=1173270 to get  Application-specific password

http://googleappsupdates.blogspot.com.es/2014/06/calendar-gdata-api-google-calendar.html

Back in November 2011, we announced the deprecation of the Calendar GData API (v1, v2) when the APIv3 was made available. We’ll now be shutting down these older versions on November 17, 2014.
Any service dependent on the Calendar GData API (v1, v2), such as the Google Calendar Connectors (GCC), will no longer work as intended. GCC users should update to use Calendar Interop or their own custom built connectors that sync with v3 of the API.

Migration guide:

https://developers.google.com/google-apps/calendar/migration

http://www.programmableweb.com/news/google-calendar-api-v1-and-v2-to-shut-down-nov-17/2014/10/27

Code

NOT YET

    

Source:
http://dotnetoday.blogspot.com.es/search/label/Google%20API%20-%20Calendar

Posted in .NET, Google | Etiquetado: , | Leave a Comment »

Google Contacts API

Posted by kiquenet en 26 diciembre 2014

Nuget: https://www.nuget.org/packages?q=google+contacts

Install-Package Google.GData.Contacts (version 2.2)
Install-Package Google.GData.Client (version 2.2 stable)

http://support.google.com/mail/bin/answer.py?hl=it&answer=1173270 to get  Application-specific password

Code

      [TestMethod]
      public void Obtener_contactos_de_google()
      {
          // login
          var Service = new ContactsService("google-contacts");
          Service.setUserCredentials("xxxx@gmail.com", "xxxxx");
          Service.QueryClientLoginToken();

          var Contacts = new List<string[]>();

          var query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
          query.StartIndex = 1;

          ContactsFeed feed = Service.Query(query);

          var total = 0;
          while (feed != null && feed.Entries.Count > 0)
          {
              total += feed.Entries.Count;
              foreach (ContactEntry entry in feed.Entries)
              {
                  // This Example gets the phone numbers but we can obtain the info we want/need about the contact
                  if (entry.Phonenumbers.Count > 0)
                  {
                      string phoneNumbers = "";
                      // get all phone numbers
                      for (int a = 0; a < entry.Phonenumbers.Count; a++)
                      {
                          phoneNumbers += entry.Phonenumbers[a].Value + "; ";
                      }

                      int x = phoneNumbers.LastIndexOf(";");
                      phoneNumbers = phoneNumbers.Substring(0, phoneNumbers.LastIndexOf(";"));

                      // in the array "item" there are: fullname(name and surname), phone number1;phonenumber2;…., contact url for edit
                      string[] item = { entry.Name.FullName, phoneNumbers, entry.Id.AbsoluteUri };
                      Contacts.Add(item);
                  }
              }

              // move to next page until end
              if (feed.NextChunk != null)
              {
                  query.Uri = new Uri(feed.NextChunk);
                  feed = Service.Query(query) as ContactsFeed;
              }
              else
                  feed = null;
          }

          // sorting the list for full name
          Contacts.Sort(delegate(string[] item1, string[] item2)
          {
              return item1[0].CompareTo(item2[0]);
          });

          Assert.AreNotEqual(0, Contacts.Count);
          Assert.IsTrue(total > 900);

      }

Source:
http://dotnetoday.blogspot.com.es/2012/10/c-google-api-getting-google-contacts.html?showComment=1382645543065

Posted in .NET, Google | Etiquetado: , | Leave a Comment »

C# String contains any characters

Posted by kiquenet en 23 diciembre 2014

private static readonly char[] Punctuation = "*&#...".ToCharArray();
public static bool ContainsPunctuation(string text)
{
   return text.IndexOfAny(Punctuation) >= 0;
}

var match = str.IndexOfAny("*&#".ToCharArray()) != -1

finding out if a string contains exactly one of the characters.

private static readonly HashSet<char> Punctuation = new HashSet<char>("*&#...");

public static bool ContainsOnePunctuationMark(string text)

       bool seenOne = false;
       foreach (char c in text)
       {
              // TODO: Experiment to see whether HashSet is really faster than
              // Array.Contains. If all the punctuation is ASCII, there are other
              // alternatives...
              if (Punctuation.Contains(c))
              {
                     if (seenOne) { return false; // This is the second punctuation character } 
                     seenOne = true;
              }
       }
       return seenOne;
}


Sources: http://stackoverflow.com/questions/1390749/check-if-a-string-contains-one-of-10-characters

Posted in .NET | Etiquetado: | Leave a Comment »

WinForms. ListView. SelectedItem

Posted by kiquenet en 23 diciembre 2014

Using SelectedItems:

if (listView1.SelectedItems.Count > 0)
{
     var item = listView1.SelectedItems[0];
    var text = listView1.SelectedItems[0].Text;
    // listView1.SelectedItems[0].SubItems[0].Text

     //rest of your logic
}

Using SelectedIndices:

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
     if (listView1.SelectedIndices.Count <= 0) { return; }
     int intselectedindex = listView1.SelectedIndices[0];
     if (intselectedindex >= 0)
     {
          String text = listView1.Items[intselectedindex].Text;
          //do something
     //MessageBox.Show(listView1.Items[intselectedindex].Text);
     }
}

Sources:
http://stackoverflow.com/questions/15091400/get-single-listview-selecteditem

Posted in .NET | Etiquetado: , | Leave a Comment »

Getting started with Image Processing: ImageMagick, AForge

Posted by kiquenet en 13 diciembre 2014

https://magick.codeplex.com/
https://magick.codeplex.com/documentation

  • Visual C++ Redistributable for Visual Studio
    • .NET 4.0: Visual C++ Redistributable for Visual Studio 2012 (x86 or x64)
    • .NET 2.0: Visual C++ Redistributable for Visual Studio 2008 (x86 or x64)
  • If you want to convert an AI/EPS/PDF/PS file you need to install Ghostscript

Click here to download Magick.NET. You can also install Magick.NET using NuGet, click here to see the available packages.

http://imagemagick.codeplex.com/

– Added a reference to ‘ImageMagickNet.dll’ in my project;

– Downloaded ‘ImageMagick-6.5.3-10-Q160-windows-dll.exe’ file from this link: http://image_magick.veidrodis.com/image_magick/binaries/

– After installing it copied all DLL files from ‘C:\Program Files\ImageMagick-6.5.3-Q16’ to ‘bin’ folder.

A sample requires .Net 2.0, ImageMagick and GhostScript to be installed to work.
http://sourceforge.net/projects/imagemagickapp/

GraphicsMagick is originally derived from ImageMagick 5.5.2 as of November 2002 but has been completely independent
https://graphicsmagick.codeplex.com/documentation
http://www.graphicsmagick.org/

AForge
http://www.aforgenet.com/framework/
https://nuget.org/packages?q=AForge.NET

Accord
http://accord-framework.net/
https://www.nuget.org/packages/Accord/

Sources:
http://stackoverflow.com/questions/2996973/how-to-use-imagemagick-net-in-net
https://imagemagick.codeplex.com/discussions/66874
http://www.gisandchips.org/2009/11/11/procesamiento-de-imagenes-digitales-con-c-y-una-aplicacion-para-el-analisis-de-parcelas-agricolas/

Posted in .NET | Etiquetado: , , | Leave a Comment »