Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial Commit

  • Loading branch information...
commit 6aaf0b710e430e8c784f33f60f734fa9c322248a 0 parents
Bill Dollins authored
49 .gitattributes
@@ -0,0 +1,49 @@
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
+
+*.jpg binary
+*.png binary
+*.gif binary
+
+*.cs text=auto diff=csharp
+*.vb text=auto
+*.c text=auto
+*.cpp text=auto
+*.cxx text=auto
+*.h text=auto
+*.hxx text=auto
+*.py text=auto
+*.rb text=auto
+*.java text=auto
+*.html text=auto
+*.htm text=auto
+*.css text=auto
+*.scss text=auto
+*.sass text=auto
+*.less text=auto
+*.js text=auto
+*.lisp text=auto
+*.clj text=auto
+*.sql text=auto
+*.php text=auto
+*.lua text=auto
+*.m text=auto
+*.asm text=auto
+*.erl text=auto
+*.fs text=auto
+*.fsx text=auto
+*.hs text=auto
+
+*.csproj text=auto merge=union
+*.vbproj text=auto merge=union
+*.fsproj text=auto merge=union
+*.dbproj text=auto merge=union
+*.sln text=auto eol=crlf merge=union
165 .gitignore
@@ -0,0 +1,165 @@
+
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/**
+tmp/**
+tmp/**/*
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+**/[Dd]ebug/
+**/[Rr]elease/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.vspscc
+.builds
+**/*.dotCover
+
+## TODO: If you have NuGet Package Restore enabled, uncomment this
+#**/packages/
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+*.Cache
+ClientBin
+stylecop.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+
+
+############
+## Windows
+############
+
+# Windows image file caches
+Thumbs.db
+
+# Folder config file
+Desktop.ini
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+# Mac crap
+.DS_Store
141 Data/EndpointDefinition.cs
@@ -0,0 +1,141 @@
+//The MIT License
+
+//Copyright (c) 2012 Zekiah Technologies, Inc.
+
+//Permission is hereby granted, free of charge, to any person obtaining a copy
+//of this software and associated documentation files (the "Software"), to deal
+//in the Software without restriction, including without limitation the rights
+//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//copies of the Software, and to permit persons to whom the Software is
+//furnished to do so, subject to the following conditions:
+
+//The above copyright notice and this permission notice shall be included in
+//all copies or substantial portions of the Software.
+
+//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Json;
+
+namespace GeoIQ.Net.Data
+{
+ [Serializable]
+ [DataContract()]
+ public class EndpointDefinition
+ {
+ [DataMember(Name = "endpoint")]
+ public string EndpointURL { get; set; }
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+
+ //non-serialized members
+ public string UserID { get; set; }
+ public string Password { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class EndpointDefinitions
+ {
+
+ public EndpointDefinitions()
+ {
+ this.Items = new ObservableCollection<EndpointDefinition>();
+ }
+
+ [DataMember(Name = "items")]
+
+ public ObservableCollection<EndpointDefinition> Items { get; set; }
+ }
+
+ public class EndpointManager
+ {
+ private EndpointDefinitions _endpoints = null;
+ private string _saveFolder = "";
+
+ public EndpointManager()
+ {
+ _saveFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\GeoIQ";
+ }
+
+ public EndpointDefinitions Endpoints
+ {
+ get { return _endpoints; }
+ }
+
+ public string SaveFolder
+ {
+ get { return _saveFolder; }
+ set
+ {
+ _saveFolder = value;
+ _endpoints = null;
+ Load();
+ }
+ }
+
+ public void Load()
+ {
+ if (!System.IO.Directory.Exists(_saveFolder))
+ {
+ System.IO.Directory.CreateDirectory(_saveFolder);
+ }
+ if (System.IO.File.Exists(_saveFolder + "\\endpoints.json"))
+ {
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(EndpointDefinitions));
+ System.IO.FileStream fs = new System.IO.FileStream(_saveFolder + "\\endpoints.json", System.IO.FileMode.Open);
+ //System.IO.TextReader reader = new System.IO.StreamReader(_saveFolder + "\\endpoints.json");
+ _endpoints = (EndpointDefinitions)serializer.ReadObject(fs);
+ fs.Close();
+ }
+ else
+ {
+ _endpoints = new EndpointDefinitions();
+ _endpoints.Items.Add(new EndpointDefinition { Name = "GeoCommons", EndpointURL = "http://finder.geocommons.com" });
+ Save();
+ //System.IO.MemoryStream ms = new System.IO.MemoryStream();
+ //serializer.WriteObject(ms, Extension.Endpoints);
+ //byte[] data = ms.ToArray();
+ //System.IO.FileStream fs = new System.IO.FileStream(_saveFolder + "\\endpoints.json", System.IO.FileMode.Create, System.IO.FileAccess.Write);
+ //fs.Write(data, 0, data.Length);
+ //fs.Close();
+ //ms.Close();
+ //serializer.WriteObject(
+ }
+ _endpoints.Items.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Items_CollectionChanged);
+ }
+
+ void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
+ {
+ Save();
+ }
+
+ public void Save()
+ {
+ if (_endpoints.Items.Count == 0)
+ {
+ _endpoints.Items.Add(new EndpointDefinition { Name = "GeoCommons", EndpointURL = "http://finder.geocommons.com" });
+ }
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(EndpointDefinitions));
+ System.IO.MemoryStream ms = new System.IO.MemoryStream();
+ serializer.WriteObject(ms, _endpoints);
+ byte[] data = ms.ToArray();
+ System.IO.FileStream fs = new System.IO.FileStream(_saveFolder + "\\endpoints.json", System.IO.FileMode.Create, System.IO.FileAccess.Write);
+ fs.Write(data, 0, data.Length);
+ fs.Close();
+ ms.Close();
+ }
+ }
+}
187 Data/MapsApiData.cs
@@ -0,0 +1,187 @@
+//The MIT License
+
+//Copyright (c) 2012 Zekiah Technologies, Inc.
+
+//Permission is hereby granted, free of charge, to any person obtaining a copy
+//of this software and associated documentation files (the "Software"), to deal
+//in the Software without restriction, including without limitation the rights
+//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//copies of the Software, and to permit persons to whom the Software is
+//furnished to do so, subject to the following conditions:
+
+//The above copyright notice and this permission notice shall be included in
+//all copies or substantial portions of the Software.
+
+//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+using System.Runtime.Serialization;
+
+namespace GeoIQ.Net.Data
+{
+
+ [Serializable]
+ [DataContract()]
+ public class MapDetails
+ {
+ [DataMember(Name = "updated_at")]
+ public String LastUpdated { get; set; }
+ [DataMember(Name = "title")]
+ public string Title { get; set; }
+ [DataMember(Name = "id")]
+ public int ID { get; set; }
+ [DataMember(Name = "description")]
+ public string Description { get; set; }
+ [DataMember(Name = "classification")]
+ public string Classification { get; set; }
+ [DataMember(Name = "basemap")]
+ public string Basemap { get; set; }
+ [DataMember(Name = "created_at")]
+ public String CreateDate { get; set; }
+ [DataMember(Name = "layers")]
+ public List<MapLayerInfo> Layers { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class MapLayerInfo
+ {
+ [DataMember(Name = "type")]
+ public string Type { get; set; }
+ [DataMember(Name = "title")]
+ public string Title { get; set; }
+ [DataMember(Name = "source")]
+ public string Source { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class MapInfo
+ {
+ [DataMember(Name = "sortable_name")]
+ public string SortableName { get; set; }
+ [DataMember(Name = "score")]
+ public double Score { get; set; }
+ [DataMember(Name = "updated_at")]
+ public string LastUpdated { get; set; }
+ [DataMember(Name = "download_group_ids")]
+ public List<int> DownloadGroups { get; set; }
+ [DataMember(Name = "min_longitude")]
+ public double MinLongitude { get; set; }
+ [DataMember(Name = "title")]
+ public string Title { get; set; }
+ [DataMember(Name = "max_longitude")]
+ public double MaxLongtiude { get; set; }
+ [DataMember(Name = "text")]
+ public string Text { get; set; }
+ [DataMember(Name = "is_featured")]
+ public bool IsFeatured { get; set; }
+ [DataMember(Name = "user_login")]
+ public string UserLogin { get; set; }
+ [DataMember(Name = "is_private")]
+ public bool isPrivate { get; set; }
+ [DataMember(Name = "min_latitude")]
+ public double MinLatitude { get; set; }
+ [DataMember(Name = "edit_group_ids")]
+ public List<int> EditGroups { get; set; }
+ [DataMember(Name = "type")]
+ public string Type { get; set; }
+ [DataMember(Name = "pk")]
+ public int Key { get; set; }
+ [DataMember(Name = "shared")]
+ public bool Shared { get; set; }
+ [DataMember(Name = "id")]
+ public string ID { get; set; }
+ [DataMember(Name = "updated_by")]
+ public string UpdatedBy { get; set; }
+ [DataMember(Name = "description")]
+ public string Description { get; set; }
+ [DataMember(Name = "max_latitude")]
+ public double MaxLatitude { get; set; }
+ [DataMember(Name = "num_charts")]
+ public int NumCharts { get; set; }
+ [DataMember(Name = "view_group_ids")]
+ public List<int> ViewGroups { get; set; }
+ [DataMember(Name = "is_public")]
+ public bool IsPublic { get; set; }
+ [DataMember(Name = "num_layers")]
+ public int LayerCount { get; set; }
+ [DataMember(Name = "created_at")]
+ public string CreateDate { get; set; }
+ [DataMember(Name = "is_copy")]
+ public bool IsCopy { get; set; }
+ [DataMember(Name = "state")]
+ public string State { get; set; }
+ }
+
+
+ [Serializable]
+ [DataContract()]
+ public class MapSearchResult
+ {
+ [DataMember(Name = "title")]
+ public string Title { get; set; }
+ [DataMember(Name = "pk")]
+ public int Key { get; set; }
+ [DataMember(Name = "type")]
+ public string Type { get; set; }
+ [DataMember(Name = "short_classification")]
+ public string ShortClassification { get; set; }
+ [DataMember(Name = "description")]
+ public string Description { get; set; }
+ [DataMember(Name = "bbox")]
+ public string BBox { get; set; }
+ [DataMember(Name = "author")]
+ public UserInfo Author { get; set; }
+ [DataMember(Name = "created")]
+ public string CreateDate { get; set; }
+ [DataMember(Name = "permissions")]
+ public Permissions Permissions { get; set; }
+ [DataMember(Name = "tags")]
+ public string Tags { get; set; }
+ [DataMember(Name = "id")]
+ public string ID { get; set; }
+ [DataMember(Name = "link")]
+ public string Link { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class UserInfo
+ {
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ [DataMember(Name = "uri")]
+ public string URI { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class Permissions
+ {
+ [DataMember(Name = "view")]
+ public bool View { get; set; }
+ [DataMember(Name = "edit")]
+ public bool Edit { get; set; }
+ [DataMember(Name = "download")]
+ public bool Download { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class MapSearchResults
+ {
+ [DataMember(Name = "entries")]
+ public List<MapSearchResult> Entries { get; set; }
+ }
+}
206 Data/OverlayInfo.cs
@@ -0,0 +1,206 @@
+//The MIT License
+
+//Copyright (c) 2012 Zekiah Technologies, Inc.
+
+//Permission is hereby granted, free of charge, to any person obtaining a copy
+//of this software and associated documentation files (the "Software"), to deal
+//in the Software without restriction, including without limitation the rights
+//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//copies of the Software, and to permit persons to whom the Software is
+//furnished to do so, subject to the following conditions:
+
+//The above copyright notice and this permission notice shall be included in
+//all copies or substantial portions of the Software.
+
+//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+using System.Runtime.Serialization;
+
+namespace GeoIQ.Net.Data
+{
+ [Serializable]
+ [DataContract(Name = "overlay", Namespace="")]
+ public class OverlaySublayerInfoContainer
+ {
+ [DataMember(Name = "id")]
+ public int ID { get; set; }
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ [DataMember(Name = "data_attributes")]
+ public SublayerInfo[] SubLayers { get; set; }
+ //[DataMember(Name = "overlay")]
+ //public OverlaySublayerInfoContainer Info { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class OverlaySublayerInfo
+ {
+ private List<string> _tags = null;
+
+ [DataMember(Name = "id")]
+ public int ID { get; set; }
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ [DataMember(Name = "data_type")]
+ public string DataType { get; set; }
+ [DataMember(Name = "tags")]
+ public string Tags { get; set; }
+ [DataMember(Name = "data_attributes")]
+ public List<SublayerInfo> SubLayers { get; set; }
+
+ public List<string> TagList
+ {
+ get
+ {
+ if (_tags == null)
+ {
+ if (!String.IsNullOrEmpty(this.Tags))
+ {
+ string tags = this.Tags.ToLower();
+ string[] t = tags.Split(',');
+ _tags = t.ToList();
+ }
+ }
+ return _tags;
+ }
+ }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class SublayerInfo
+ {
+ [DataMember(Name = "data_type")]
+ public string DataType { get; set; }
+ [DataMember(Name = "description")]
+ public string Description { get; set; }
+ [DataMember(Name = "id")]
+ public int ID { get; set; }
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ [DataMember(Name = "original_name")]
+ public string OriginalName { get; set; }
+ [DataMember(Name = "overlay_id")]
+ public int OverlayID { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class OverlayInfo
+ {
+ [DataMember(Name = "description")]
+ public string Description { get; set; }
+ [DataMember(Name = "overlay_id")]
+ public int OverlayID { get; set; }
+ [DataMember(Name = "tags")]
+ public string Tags { get; set; }
+ [DataMember(Name = "detail_link")]
+ public string DetailLink { get; set; }
+ [DataMember(Name = "link")]
+ public string Link { get; set; }
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ [DataMember(Name = "short_classification")]
+ public string ShortClassification { get; set; }
+ [DataMember(Name = "can_view")]
+ public bool CanView { get; set; }
+ [DataMember(Name = "published")]
+ public string DatePublished { get; set; }
+ [DataMember(Name = "bbox")]
+ public string BoundingBox { get; set; }
+ [DataMember(Name = "layer_size")]
+ public int LayerSize { get; set; }
+ [DataMember(Name = "can_edit")]
+ public bool CanEdit { get; set; }
+ [DataMember(Name = "created")]
+ public string DateCreated { get; set; }
+ [DataMember(Name = "icon_path")]
+ public string IconPath { get; set; }
+ [DataMember(Name = "source")]
+ public string Source { get; set; }
+ [DataMember(Name = "id")]
+ public string ID { get; set; }
+ [DataMember(Name = "can_download")]
+ public bool CanDownload { get; set; }
+ [DataMember(Name = "author")]
+ public User Author { get; set; }
+ [DataMember(Name = "contributor")]
+ public User Contributor { get; set; }
+
+ #region "Non-Serialized Members"
+ public string title { get; set; }
+ public string shapelink
+ {
+ get
+ {
+ return this.Link.ToLower().Replace(".json", ".zip");
+ }
+ }
+ public string kmllink
+ {
+ get
+ {
+ return this.Link.ToLower().Replace(".json", ".kml");
+ }
+ }
+ public string infolink
+ {
+ get
+ {
+ return this.Link.ToLower().Replace(".json", ".html");
+ }
+ }
+ public string atomlink
+ {
+ get
+ {
+ return this.Link.ToLower().Replace(".json", ".atom");
+ }
+ }
+ public string csvlink
+ {
+ get
+ {
+ return this.Link.ToLower().Replace(".json", ".csv");
+ }
+ }
+ public string spatialitelink
+ {
+ get
+ {
+ return this.Link.ToLower().Replace(".json", ".sqlite");
+ }
+ }
+ #endregion
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class User
+ {
+ [DataMember(Name = "uri")]
+ public string URI { get; set; }
+ [DataMember(Name = "name")]
+ public string Name { get; set; }
+ }
+
+ [Serializable]
+ [DataContract()]
+ public class Overlays
+ {
+ [DataMember(Name = "entries")]
+ public List<OverlayInfo> entries { get; set; }
+ }
+}
663 Finder.cs
@@ -0,0 +1,663 @@
+//The MIT License
+
+//Copyright (c) 2012 Zekiah Technologies, Inc.
+
+//Permission is hereby granted, free of charge, to any person obtaining a copy
+//of this software and associated documentation files (the "Software"), to deal
+//in the Software without restriction, including without limitation the rights
+//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//copies of the Software, and to permit persons to whom the Software is
+//furnished to do so, subject to the following conditions:
+
+//The above copyright notice and this permission notice shall be included in
+//all copies or substantial portions of the Software.
+
+//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Net;
+using System.Net.Security;
+using System.Web;
+using System.Security.Cryptography.X509Certificates;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Json;
+
+using GeoIQ.Net.Data;
+using System.ComponentModel;
+using System.Xml.Serialization;
+using System.Xml;
+
+//using GeoCommonsWebClient;
+
+namespace GeoIQ.Net
+{
+ #region Delegates
+
+ public delegate void AsynchSearchCompleteHandler(SearchEventArgs args);
+ public delegate void AsynchUploadFileCompleteHandler(ResponseStatusEventArgs args);
+ public delegate void AsynchValidateUserCompleteHandler(ResponseStatusEventArgs args);
+
+ #endregion
+
+ #region EventArgs classes
+
+ public class SearchEventArgs
+ {
+ internal Exception _error = null;
+ internal Overlays _result = null;
+
+ public Exception Error
+ {
+ get
+ {
+ return _error;
+ }
+ }
+
+ public Overlays Result
+ {
+ get
+ {
+ return _result;
+ }
+ }
+ }
+
+ public class ResponseStatusEventArgs
+ {
+ internal Exception _error = null;
+ internal string _location = null;
+ internal string _result = null;
+
+ public Exception Error
+ {
+ get
+ {
+ return _error;
+ }
+
+ }
+
+ public string Location
+ {
+ get
+ {
+ return _location;
+ }
+ }
+
+ public string Result
+ {
+ get
+ {
+ return _result;
+ }
+ }
+
+ }
+
+
+
+ #endregion
+
+ #region Finder
+
+ public class Finder
+ {
+ #region Properties and Delegates
+
+ public string EndpointURI { get; set; }
+ public string UserName { get; set; }
+ public string Password { get; set; }
+ public Exception LastError { get; set; }
+
+
+ public event AsynchSearchCompleteHandler AsynchSearchComplete;
+ public event AsynchUploadFileCompleteHandler AsyncUploadFileComplete;
+ public event AsynchValidateUserCompleteHandler AsyncValidateCredentialsComplete;
+
+ private static List<string> allowedTypes = new List<string>
+ {
+ ".kml",
+ ".csv",
+ ".shp",
+ ".shx",
+ ".dbf",
+ ".xml",
+ ".atom",
+ ".rss",
+ ".prj",
+ ".climgen"
+ };
+
+ #endregion
+
+ #region Constructors
+
+ public Finder(string endpointUri)
+ {
+
+ EndpointURI = prepareEndpointURI(endpointUri);
+
+ }
+
+ public Finder(string endpointUri, string username, string password)
+ {
+ EndpointURI = prepareEndpointURI(endpointUri);
+ UserName = username;
+ Password = password;
+ }
+
+ #endregion
+
+ #region Synchronous Methods
+ //compiler directive to prevent synchronous method
+ //from being made available if library is compiled for Silverlight
+#if !SILVERLIGHT
+
+ public ResponseStatusEventArgs Delete(int overlayID)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ try
+ {
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/datasets/{1}.json", EndpointURI, overlayID);
+ setCredentials(request);
+
+ //validateFileType(files);
+ ResponseEventArgs response = request.Delete(url, UserName, Password, "application/json");
+
+ args._result = response.Status;
+ //args._location = response.Location;
+ }
+ catch
+ {
+ }
+ return args;
+ }
+
+ public SearchEventArgs ExecuteSearch(int limit, string terms, double maxx, double maxy, double minx, double miny)
+ {
+ SearchEventArgs args = new SearchEventArgs();
+ try
+ {
+ WebClient request = new WebClient();
+ string url = String.Format("{0}/search.json?query={1}&limit={2}&bbox={3},{4},{5},{6}", EndpointURI, terms, limit, minx, miny, maxx, maxy);
+ setCredentials(request);
+
+ Stream stream = request.OpenRead(url);
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GeoIQ.Net.Data.Overlays));
+
+ GeoIQ.Net.Data.Overlays overlays = (GeoIQ.Net.Data.Overlays)serializer.ReadObject(stream);
+ args._result = overlays;
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+ public SearchEventArgs ExecuteSearch(int limit, string terms, string model)
+ {
+ SearchEventArgs args = new SearchEventArgs();
+ try
+ {
+ WebClient request = new WebClient();
+ string url = String.Format("{0}/search.json?query={1}&limit={2}&model={3}", EndpointURI, terms, limit, model);
+ setCredentials(request);
+
+ Stream stream = request.OpenRead(url);
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GeoIQ.Net.Data.Overlays));
+
+ GeoIQ.Net.Data.Overlays overlays = (GeoIQ.Net.Data.Overlays)serializer.ReadObject(stream);
+ args._result = overlays;
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+ public List<string> GetTagList()
+ {
+ List<string> retval = new List<string>();
+ try
+ {
+ WebClient request = new WebClient();
+ string url = String.Format("{0}/tags.json", EndpointURI);
+ setCredentials(request);
+
+ Stream stream = request.OpenRead(url);
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<string>));
+ retval = (List<string>)serializer.ReadObject(stream);
+ }
+ catch (Exception ex)
+ {
+ }
+ return retval;
+ }
+
+ public OverlaySublayerInfo GetLayerDetails(int overlayid)
+ {
+ OverlaySublayerInfo retval = null;
+ try
+ {
+ WebClient request = new WebClient();
+ string url = String.Format("{0}/overlays/{1}.json?include_attributes=1", EndpointURI, overlayid);
+ setCredentials(request);
+
+ Stream stream = request.OpenRead(url);
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GeoIQ.Net.Data.OverlaySublayerInfo));
+ retval = (GeoIQ.Net.Data.OverlaySublayerInfo)serializer.ReadObject(stream);
+ }
+ catch(Exception ex)
+ {
+ this.LastError = ex;
+ }
+
+ return retval;
+ }
+
+ public ResponseStatusEventArgs UploadFile(string[] files)
+ {
+ ResponseStatusEventArgs args = UploadFile(files, null);
+ //try
+ //{
+ // GeoComWebClient request = new GeoComWebClient();
+ // string url = String.Format("{0}/overlays.json?tags=test%20tags", EndpointURI);
+ // setCredentials(request);
+
+ // validateFileType(files);
+ // ResponseEventArgs response = request.UploadFiles(url, files);
+
+ // args._result = response.Status;
+ // try
+ // {
+ // args._location = response.Location;
+ // }
+ // catch { }
+
+ //}
+ //catch (Exception ex)
+ //{
+ // args._error = ex;
+ //}
+ return args;
+ }
+
+ public ResponseStatusEventArgs UploadFile(string[] files, string[] tags)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ try
+ {
+ string parms = "";
+ if (tags != null)
+ {
+ parms = "?tags=" + String.Join("%20", tags);
+ }
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/datasets.json" + parms, EndpointURI);
+ setCredentials(request);
+
+ validateFileType(files);
+ ResponseEventArgs response = request.UploadFiles(url, files);
+
+ args._result = response.Status;
+ try
+ {
+ args._location = response.Location;
+ }
+ catch { }
+
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+ public ResponseStatusEventArgs UploadFile(string[] files, string[] tags, string title)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ try
+ {
+ string parms = "";
+ string tags2 = "";
+ string title2 = "";
+ List<string> parmlist = new List<string>();
+
+ if (tags != null)
+ {
+ tags2 = "tags=" + String.Join("%20", tags);
+ parmlist.Add(tags2);
+ }
+ if (title != null)
+ {
+ title2 = "name=" + title;
+ parmlist.Add(title2);
+ }
+ if (parmlist.Count > 0)
+ {
+ parms = "?";
+ var tmp = String.Join("&", parmlist.ToArray());
+ parms += tmp;
+ }
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/datasets.json" + parms, EndpointURI);
+ setCredentials(request);
+
+ validateFileType(files);
+ ResponseEventArgs response = request.UploadFiles(url, files);
+
+ args._result = response.Status;
+ try
+ {
+ args._location = response.Location;
+ }
+ catch { }
+
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+ public ResponseStatusEventArgs UpdateTags(int overlayid, List<string> taglist)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ try
+ {
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/datasets/{1}.json?tags=", EndpointURI, overlayid);
+ string tags = String.Join("%20", taglist.ToArray());
+ url += tags;
+ setCredentials(request);
+
+ //validateFileType(files);
+ ResponseEventArgs response = request.Put(url, "");
+
+ args._result = response.Status;
+ args._location = response.Location;
+
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+ public ResponseStatusEventArgs UpdateTitle(int overlayid, string title)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ try
+ {
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/datasets/{1}.json?title={2}", EndpointURI, overlayid, title);
+ setCredentials(request);
+
+ //validateFileType(files);
+ ResponseEventArgs response = request.Put(url, "");
+
+ args._result = response.Status;
+ args._location = response.Location;
+
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+ public ResponseStatusEventArgs UpdateTitle(string overlayUrl, string title)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ try
+ {
+ GeoComWebClient request = new GeoComWebClient();
+ string url = overlayUrl + "?title=" + title;
+ setCredentials(request);
+
+ //validateFileType(files);
+ ResponseEventArgs response = request.Put(url, "");
+
+ args._result = response.Status;
+ args._location = response.Location;
+
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+
+
+ public ResponseStatusEventArgs ValidateUser()
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ try
+ {
+ WebClient request = new WebClient();
+
+ string url = String.Format("{0}/#", EndpointURI);
+ setCredentials(request);
+ string result = request.DownloadString(url);
+
+ args._result = "valid";
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+
+#endif
+ #endregion
+
+ #region Asynchronous Methods
+ #region ExecuteSearchAsync
+ public void ExecuteSearchAsynch(int limit, string terms, double maxx, double maxy, double minx, double miny)
+ {
+ WebClient request = new WebClient();
+ string url = String.Format("{0}/search.json?query={1}&limit={2}&bbox={3},{4},{5},{6}", EndpointURI, terms, limit, minx, miny, maxx, maxy);
+ setCredentials(request);
+
+ request.DownloadStringCompleted += new DownloadStringCompletedEventHandler(request_DownloadStringCompleted);
+ request.DownloadStringAsync(new Uri(url));
+ }
+
+ void request_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
+ {
+ SearchEventArgs args = new SearchEventArgs();
+
+ if (e.Error == null)
+ {
+ string s = e.Result;
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(GeoIQ.Net.Data.Overlays));
+ byte[] bytes = Encoding.ASCII.GetBytes(s);
+ System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
+ GeoIQ.Net.Data.Overlays overlays = (GeoIQ.Net.Data.Overlays)serializer.ReadObject(stream);
+ args._result = overlays;
+ }
+ else
+ {
+ args._error = e.Error;
+ }
+ if (this.AsynchSearchComplete != null)
+ AsynchSearchComplete(args);
+ }
+ #endregion
+
+
+ #region UploadFilesAsync
+ public void UploadFileAsync(string[] files)
+ {
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/datasets.xml", EndpointURI);
+ setCredentials(request);
+
+ validateFileType(files);
+
+ request.GeoComResponseReceived += new GeoComWebClient.GeoComAsyncReturn(UploadFilesDataResponse);
+ request.UploadFilesAsync(url, files);
+ }
+
+
+ private void UploadFilesDataResponse(object webClient, ResponseEventArgs e)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ if (e.Error == null)
+ {
+ args._result = e.Status;
+ args._location = e.Location;
+ }
+ else
+ {
+ args._error = e.Error;
+ }
+ if (this.AsyncUploadFileComplete != null)
+ AsyncUploadFileComplete(args);
+ }
+
+
+ #endregion
+
+ #region ValidateUserAsync
+ public void ValidateUserAsync()
+ {
+ WebClient request = new WebClient();
+
+ string url = String.Format("{0}/#", EndpointURI);
+ setCredentials(request);
+
+ request.DownloadStringCompleted += new DownloadStringCompletedEventHandler(validateCredentials_DownloadStringCompleted);
+ request.DownloadStringAsync(new Uri(url));
+ }
+
+ void validateCredentials_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ if (e.Error == null)
+ {
+ args._result = "Credentials validate.";
+ }
+ else
+ {
+ args._error = e.Error;
+ }
+ if (this.AsyncValidateCredentialsComplete != null)
+ {
+ AsyncValidateCredentialsComplete(args);
+ }
+ }
+
+ #endregion
+ #endregion
+
+ #region Static Methods
+
+ public static bool isValidFileType(string file)
+ {
+
+ string ext = Path.GetExtension(file.ToLower());
+
+ return allowedTypes.Contains(ext);
+ }
+
+
+ #endregion
+
+ #region Private Methods
+
+
+ private string getStatus(byte[] response)
+ {
+ string result = "";
+ string raw = System.Text.Encoding.ASCII.GetString(response);
+ string[] words = raw.Split(' ');
+ if (words != null)
+ {
+ result = words[1];
+ }
+ return result;
+ }
+
+ private string prepareEndpointURI(string url)
+ {
+ string result = url;
+ int notFound = -1;
+
+ int httpExists = result.IndexOf("http://");
+
+ if (httpExists == notFound)
+ result = String.Format("http://{0}", url);
+
+ //int finderExists = result.IndexOf("finder");
+
+ //if (finderExists == notFound)
+ //{
+ // System.Uri domain = new System.Uri(result);
+ // result = String.Format("http://finder.{0}", domain.Authority);
+ //}
+ return result;
+ }
+
+ private void setCredentials(WebClient request)
+ {
+ if (!String.IsNullOrEmpty(UserName) && !String.IsNullOrEmpty(Password))
+ {
+ string authInfo = UserName + ":" + Password;
+ authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(UserName + ":" + Password));
+ request.Headers["Authorization"] = "Basic " + authInfo;
+ }
+ }
+
+ private void setCredentials(GeoComWebClient request)
+ {
+ if (!String.IsNullOrEmpty(UserName) && !String.IsNullOrEmpty(Password))
+ {
+ string authInfo = UserName + ":" + Password;
+ authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(UserName + ":" + Password));
+ request.Headers["Authorization"] = "Basic " + authInfo;
+ }
+ }
+
+ private void validateFileType(string[] files)
+ {
+ for (int i = 0; i < files.Length; i++)
+ {
+ if (!isValidFileType(files[i]))
+ {
+ string ext = Path.GetExtension(files[i].ToLower());
+ throw new Exception("GeoCommons API doesn't support file extension type: " + ext);
+ }
+ }
+
+ }
+
+ #endregion
+ }
+
+ #endregion
+
+}
683 GeoCommonsWebClient.cs
@@ -0,0 +1,683 @@
+//The MIT License
+
+//Copyright (c) 2012 Zekiah Technologies, Inc.
+
+//Permission is hereby granted, free of charge, to any person obtaining a copy
+//of this software and associated documentation files (the "Software"), to deal
+//in the Software without restriction, including without limitation the rights
+//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//copies of the Software, and to permit persons to whom the Software is
+//furnished to do so, subject to the following conditions:
+
+//The above copyright notice and this permission notice shall be included in
+//all copies or substantial portions of the Software.
+
+//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Linq;
+using System.Text;
+
+using System.Net;
+using System.IO;
+
+
+namespace GeoIQ.Net
+{
+
+ public class ResponseEventArgs : EventArgs
+ {
+ internal string _location = null;
+ internal string _status = null;
+ internal Exception _error = null;
+
+ public string Location
+ {
+ get { return _location; }
+ }
+
+ public string Status
+ {
+ get { return _status; }
+ }
+
+ public Exception Error
+ {
+ get { return _error; }
+ }
+ }
+
+ public class GeoComWebClient
+ {
+ public event GeoComAsyncReturn GeoComResponseReceived;
+
+ public delegate void GeoComAsyncReturn(object webclient, ResponseEventArgs response);
+
+ public HttpWebRequest WebReq;
+ public Dictionary<string, string> Headers;
+ private string NL = "\r\n";
+
+ public GeoComWebClient()
+ {
+ Headers = new Dictionary<string, string>();
+ }
+
+ #region Public Methods
+
+#if !Silverlight
+ public ResponseEventArgs Delete(string url, string userName, string password, string content)
+ {
+ ResponseEventArgs result = new ResponseEventArgs();
+ HttpWebResponse webRes = null;
+ //Stream requestStream = null;
+ WebReq = (HttpWebRequest)WebRequest.Create(url);
+ if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
+ {
+ //request.Credentials = new NetworkCredential(userName, password);
+ string authInfo = userName + ":" + password;
+ authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(userName + ":" + password));
+ WebReq.Headers["Authorization"] = "Basic " + authInfo;
+ }
+ WebReq.Method = "DELETE";
+ WebReq.KeepAlive = true;
+ WebReq.ContentType = content;
+
+ //hasAuthenticationHeader();
+ //addHeaders();
+ try
+ {
+ webRes = (HttpWebResponse)WebReq.GetResponse();
+ result._status = ((int)webRes.StatusCode).ToString();
+ webRes.Close();
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ finally
+ {
+ if (WebReq != null)
+ {
+ WebReq = null;
+ }
+
+ if (webRes != null)
+ {
+ webRes = null;
+ }
+ }
+ return result;
+ }
+
+ public ResponseEventArgs Put(string url, string data)
+ {
+ ResponseEventArgs result = new ResponseEventArgs();
+ HttpWebResponse webRes = null;
+ Stream requestStream = null;
+
+ byte[] content = System.Text.Encoding.ASCII.GetBytes(data);
+
+ WebReq = (HttpWebRequest)WebRequest.Create(url);
+ WebReq.Method = "PUT";
+ WebReq.KeepAlive = true;
+ WebReq.ContentType = "text/plain";
+
+ hasAuthenticationHeader();
+ addHeaders();
+ try
+ {
+ requestStream = WebReq.GetRequestStream();
+ requestStream.Write(content, 0, content.Length);
+ requestStream.Close();
+
+ webRes = (HttpWebResponse)WebReq.GetResponse();
+
+ var response = webRes.GetResponseStream();
+
+ result._status = webRes.StatusCode.ToString();
+
+ response.Close();
+ webRes.Close();
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+
+ finally
+ {
+ if (requestStream != null)
+ {
+ requestStream = null;
+ }
+
+ if (WebReq != null)
+ {
+ WebReq = null;
+ }
+
+ if (webRes != null)
+ {
+ webRes = null;
+ }
+ }
+
+ return result;
+ }
+
+ /// <summary>
+ /// Executes an HTTP POST command and retrives the information.
+ /// This function will automatically include a "source" parameter if the "Source" property is set.
+ /// </summary>
+ /// <param name="url">The URL to perform the POST operation</param>
+ /// <param name="userName">The username to use with the request</param>
+ /// <param name="password">The password to use with the request</param>
+ /// <param name="data">The data to post</param>
+ /// <returns>The response of the request, or null if we got 404 or nothing.</returns>
+ public string Post(string url, string userName, string password, string contentType, string data)
+ {
+ WebRequest request = WebRequest.Create(url);
+ try
+ {
+ //if (this.IgnoreCertificateErrors)
+ // ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
+ if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
+ {
+ //request.Credentials = new NetworkCredential(userName, password);
+ string authInfo = userName + ":" + password;
+ authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(userName + ":" + password));
+ request.Headers["Authorization"] = "Basic " + authInfo;
+ }
+ request.ContentType = contentType;
+ request.Method = "POST";
+
+ byte[] bytes = Encoding.UTF8.GetBytes(data);
+
+ request.ContentLength = bytes.Length;
+
+ using (Stream requestStream = request.GetRequestStream())
+ {
+ requestStream.Write(bytes, 0, bytes.Length);
+
+ using (WebResponse response = request.GetResponse())
+ {
+ using (StreamReader reader = new StreamReader(response.GetResponseStream()))
+ {
+ return reader.ReadToEnd();
+ }
+ }
+ }
+ //}
+
+ //return null;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ public string GetCookie(string url, string userName, string password)
+ {
+ WebRequest request = WebRequest.Create(url);
+ try
+ {
+ //if (this.IgnoreCertificateErrors)
+ // ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
+ if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
+ {
+ //request.Credentials = new NetworkCredential(userName, password);
+ string authInfo = userName + ":" + password;
+ authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(userName + ":" + password));
+ request.Headers["Authorization"] = "Basic " + authInfo;
+ }
+ request.ContentType = "";
+ request.Method = "POST";
+
+ byte[] bytes = Encoding.UTF8.GetBytes("");
+
+ request.ContentLength = bytes.Length;
+
+ using (Stream requestStream = request.GetRequestStream())
+ {
+ requestStream.Write(bytes, 0, bytes.Length);
+
+ using (WebResponse response = request.GetResponse())
+ {
+ return response.Headers["Set-Cookie"];
+ //using (StreamReader reader = new StreamReader(response.GetResponseStream()))
+ //{
+ // return reader.ReadToEnd();
+ //}
+ }
+ }
+ //}
+
+ //return null;
+ }
+ catch
+ {
+ return "";
+ }
+ }
+
+ public ResponseEventArgs UploadFiles(string url, string[] files)
+ {
+ ResponseEventArgs result = new ResponseEventArgs();
+ HttpWebResponse webRes = null;
+ Stream requestStream = null;
+
+ string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
+
+ WebReq = (HttpWebRequest)WebRequest.Create(url);
+
+ WebReq.Method = "POST";
+ WebReq.Timeout = System.Threading.Timeout.Infinite;
+ WebReq.Accept = "*/*";
+ WebReq.PreAuthenticate = true;
+ WebReq.KeepAlive = true;
+ WebReq.ContentType = "multipart/form-data; boundary=" + boundary;
+
+ hasAuthenticationHeader();
+ addHeaders();
+
+ try
+ {
+ Stream memStream = getFilesMemoryStream(files, boundary);
+ byte[] tempBuffer = getByteArray(memStream);
+ memStream.Close();
+
+ WebReq.ContentLength = tempBuffer.Length;
+
+ requestStream = WebReq.GetRequestStream();
+ requestStream.Write(tempBuffer, 0, tempBuffer.Length);
+ requestStream.Close();
+
+ webRes = (HttpWebResponse)WebReq.GetResponse();
+
+ Stream response = webRes.GetResponseStream();
+ try
+ {
+ result._status = webRes.StatusCode.ToString();
+ }
+ catch { }
+ try
+ {
+ result._location = webRes.Headers["Location"].ToString();
+ }
+ catch { }
+
+ response.Close();
+ webRes.Close();
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ finally
+ {
+ if (WebReq != null)
+ {
+ WebReq = null;
+ }
+
+ if (webRes != null)
+ {
+ webRes.Close();
+ WebReq = null;
+ }
+ }
+ return result;
+ }
+#endif
+ public void PutAsync(string url, string data)
+ {
+ byte[] content = System.Text.Encoding.ASCII.GetBytes(data);
+
+ WebReq = (HttpWebRequest)WebRequest.Create(url);
+ WebReq.Method = "PUT";
+ WebReq.KeepAlive = true;
+ WebReq.ContentType = "text/plain";
+
+ hasAuthenticationHeader();
+ addHeaders();
+
+ try
+ {
+ Stream requestStream = WebReq.GetRequestStream();
+ requestStream.Write(content, 0, content.Length);
+ requestStream.Close();
+
+ WebReq.BeginGetResponse(new AsyncCallback(GetResponseBack), WebReq);
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ }
+
+ public void UploadFilesAsync(string url, string[] files)
+ {
+ Stream requestStream = null;
+
+ string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
+
+ WebReq = (HttpWebRequest)WebRequest.Create(url);
+
+ WebReq.Method = "POST";
+ //WebReq.AllowWriteStreamBuffering = false;
+ WebReq.SendChunked = true;
+ WebReq.Accept = "*/*";
+ WebReq.PreAuthenticate = true;
+ WebReq.KeepAlive = true;
+ WebReq.ContentType = "multipart/form-data; boundary=" + boundary;
+
+ ServicePointManager.DefaultConnectionLimit = 100;
+ ServicePointManager.MaxServicePointIdleTime = 240000;
+
+ hasAuthenticationHeader();
+ addHeaders();
+
+ try
+ {
+ // Refactor here perhaps?
+ //Stream memStream = getFilesMemoryStream(files, boundary);
+ //byte[] tempBuffer = getByteArray(memStream);
+ //memStream.Close();
+
+ //WebReq.ContentLength = tempBuffer.Length;
+ //WebReq.Timeout = tempBuffer.Length;
+
+ requestStream = WebReq.GetRequestStream();
+ requestStream.ReadTimeout = 240000;
+ requestStream.WriteTimeout = 240000;
+ getFilesMemoryStream(requestStream, files, boundary); // WebReq.GetRequestStream();
+
+ //requestStream.Write(tempBuffer, 0, tempBuffer.Length);
+ requestStream.Close();
+ //WebReq.Timeout = (int)requestStream.Length;
+ //WebReq.ReadWriteTimeout = (int)requestStream.Length;
+ WebReq.BeginGetResponse(new AsyncCallback(GetResponseBack), WebReq);
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ }
+
+ private void GetResponseBack(IAsyncResult asynchronousResult)
+ {
+ ResponseEventArgs args = new ResponseEventArgs();
+
+ try
+ {
+ HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
+ HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
+
+ args._status = response.StatusCode.ToString();
+
+ if (response.Headers["Location"] != null)
+ {
+ args._location = response.Headers["Location"].ToString();
+ }
+
+ response.Close();
+
+ OnGeoComResponseReceived(this, args);
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ OnGeoComResponseReceived(this, args);
+ }
+ }
+
+ public void OnGeoComResponseReceived(object geoComWebClient, ResponseEventArgs response)
+ {
+ if (GeoComResponseReceived != null)
+ {
+ GeoComResponseReceived(geoComWebClient, response);
+ }
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private void addHeaders()
+ {
+ foreach (string key in Headers.Keys)
+ {
+ WebReq.Headers.Add(String.Format("{0}: {1}", key, Headers[key]));
+ }
+ }
+
+ private void copyStream(Stream input, Stream output)
+ {
+ byte[] buffer = new byte[8 * 1024];
+ int len;
+ while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
+ {
+ output.Write(buffer, 0, len);
+ }
+ }
+
+
+ private byte[] getByteArray(Stream s)
+ {
+ byte[] result = new byte[s.Length];
+ s.Position = 0;
+ s.Read(result, 0, result.Length);
+
+ return result;
+ }
+
+ private Stream getFilesMemoryStream(string[] files, string boundary)
+ {
+ Stream result = new MemoryStream();
+ FileStream fileStream = null;
+
+ try
+ {
+ byte[] newLine = System.Text.Encoding.ASCII.GetBytes(NL);
+
+ byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes(NL + "--" + boundary + NL);
+
+ string fileHeaderTemplate = "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"overlay[{0}]\" ; filename=\"{1}\"; " + NL +
+ "Content-Type: application/octet-stream" + NL + NL;
+
+ for (int i = 0; i < files.Length; i++)
+ {
+ string fileName = Path.GetFileName(files[i]);
+ string type = getOverlayType(files[i]);
+ string header = "";
+ if (type.ToLower() == "wild")
+ {
+ header += getWildHeaders(fileName, boundary);
+ }
+ header += string.Format(fileHeaderTemplate, getOverlayType(files[i]), fileName);
+ byte[] headerBytes = System.Text.Encoding.UTF8.GetBytes(header);
+ result.Write(headerBytes, 0, headerBytes.Length);
+
+ fileStream = new FileStream(files[i], FileMode.Open, FileAccess.Read);
+ byte[] buffer = new byte[1024];
+
+ int bytesRead = 0;
+
+ while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ result.Write(buffer, 0, bytesRead);
+ }
+ fileStream.Close();
+ result.Write(newLine, 0, newLine.Length);
+ }
+
+ result.Write(boundaryBytes, 0, boundaryBytes.Length);
+
+ fileStream = null;
+ }
+ catch (Exception ex)
+ {
+ if (fileStream != null)
+ {
+ fileStream.Close();
+ fileStream = null;
+ }
+ throw ex;
+ }
+
+ return result;
+ }
+
+ private void getFilesMemoryStream(Stream result, string[] files, string boundary)
+ {
+ //Stream result = new MemoryStream();
+ FileStream fileStream = null;
+
+ try
+ {
+ byte[] newLine = System.Text.Encoding.ASCII.GetBytes(NL);
+
+ byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes(NL + "--" + boundary + NL);
+
+ string fileHeaderTemplate = "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"overlay[{0}]\" ; filename=\"{1}\"; " + NL +
+ "Content-Type: application/octet-stream" + NL + NL;
+
+ for (int i = 0; i < files.Length; i++)
+ {
+ string fileName = Path.GetFileName(files[i]);
+ string type = getOverlayType(files[i]);
+ string header = "";
+ if (type.ToLower() == "wild")
+ {
+ header += getWildHeaders(fileName, boundary);
+ }
+ header += string.Format(fileHeaderTemplate, getOverlayType(files[i]), fileName);
+ byte[] headerBytes = System.Text.Encoding.UTF8.GetBytes(header);
+ result.Write(headerBytes, 0, headerBytes.Length);
+
+ fileStream = new FileStream(files[i], FileMode.Open, FileAccess.Read);
+ byte[] buffer = new byte[1024];
+
+ int bytesRead = 0;
+
+ while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
+ {
+ result.Write(buffer, 0, bytesRead);
+ }
+ fileStream.Close();
+ result.Write(newLine, 0, newLine.Length);
+ }
+
+ result.Write(boundaryBytes, 0, boundaryBytes.Length);
+
+ fileStream = null;
+ }
+ catch (Exception ex)
+ {
+ if (fileStream != null)
+ {
+ fileStream.Close();
+ fileStream = null;
+ }
+ throw ex;
+ }
+
+ //return result;
+ }
+
+ private string getWildHeaders(string filename, string boundary)
+ {
+ string retval = "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"Filename\" " + NL + NL +
+ filename + NL;
+
+ retval += "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"overlay[file_key_seed]\" " + NL + NL +
+ "1315531831" + NL;
+
+ retval += "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"fileext\" " + NL + NL +
+ "*.dbf;*.shx;*.prj;*.shp;*.csv;*.kml;*.rss;*.kmz;*.climgen" + NL;
+
+ retval += "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"uploadify\" " + NL + NL +
+ "true" + NL;
+
+ retval += "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"z\" " + NL + NL +
+ "z" + NL;
+
+ retval += "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"folder\" " + NL + NL +
+ "/" + NL;
+
+ retval += "--" + boundary + NL +
+ "Content-Disposition: form-data; name=\"overlay[target_state]\" " + NL + NL +
+ "complete" + NL;
+
+ return retval;
+ }
+
+ private Dictionary<string, string> getOverlayDictionary()
+ {
+ Dictionary<string, string> result = new Dictionary<string, string>();
+
+ result.Add(".kml", "kml");
+ result.Add(".csv", "csv");
+ result.Add(".shp", "shp");
+ result.Add(".shx", "shx");
+ result.Add(".dbf", "dbf");
+ result.Add(".xml", "rss");
+ result.Add(".atom", "rss");
+ result.Add(".rss", "rss");
+ result.Add(".prj", "prj");
+ result.Add(".climgen", "wild");
+
+ return result;
+ }
+
+ private string getOverlayType(string file)
+ {
+ string result = "";
+
+ Dictionary<string, string> overlayTypes = getOverlayDictionary();
+
+ string ext = Path.GetExtension(file).ToLower();
+
+ foreach (string key in overlayTypes.Keys)
+ {
+ if (key == ext)
+ {
+ result = overlayTypes[key];
+ }
+ }
+
+ return result;
+ }
+
+ private void hasAuthenticationHeader()
+ {
+ List<string> headerNames = Headers.Keys.ToList<string>();
+
+ if (!headerNames.Contains("Authorization"))
+ {
+ throw new Exception("No Authorization header. Please include one to use this method.");
+ }
+ }
+
+
+ }
+ #endregion
+
+}
97 GeoIQ.Net.csproj
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{5B163051-07A2-4107-9C8F-30286698BFE2}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>GeoIQ.Net</RootNamespace>
+ <AssemblyName>GeoIQ.Net</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <RegisterForComInterop>false</RegisterForComInterop>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+ <DebugSymbols>true</DebugSymbols>
+ <OutputPath>bin\x64\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DebugType>full</DebugType>
+ <PlatformTarget>x64</PlatformTarget>
+ <CodeAnalysisLogFile>bin\Debug\GeoIQ.Net.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+ <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+ <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+ <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+ <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+ <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
+ <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+ <OutputPath>bin\x64\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>x64</PlatformTarget>
+ <CodeAnalysisLogFile>bin\Release\GeoIQ.Net.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+ <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+ <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+ <CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
+ <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+ <CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Runtime.Serialization" />
+ <Reference Include="System.ServiceModel.Web" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="WindowsBase" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Data\EndpointDefinition.cs" />
+ <Compile Include="Data\MapsApiData.cs" />
+ <Compile Include="Data\OverlayInfo.cs" />
+ <Compile Include="Finder.cs" />
+ <Compile Include="GeoCommonsWebClient.cs" />
+ <Compile Include="Maps.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
80 GeoIQ.Net4.csproj
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{5B163051-07A2-4107-9C8F-30286698BFE2}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>GeoIQ.Net</RootNamespace>
+ <AssemblyName>GeoIQ.Net</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkProfile />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <PlatformTarget>x86</PlatformTarget>
+ <RegisterForComInterop>true</RegisterForComInterop>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test|AnyCPU'">
+ <OutputPath>bin\Test\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <CodeAnalysisLogFile>bin\Release\GeoIQ.Net.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+ <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+ <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+ <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+ <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
+ <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Runtime.Serialization" />
+ <Reference Include="System.ServiceModel.Web" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ <Reference Include="WindowsBase" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Data\EndpointDefinition.cs" />
+ <Compile Include="Data\MapsApiData.cs" />
+ <Compile Include="Data\OverlayInfo.cs" />
+ <Compile Include="Finder.cs" />
+ <Compile Include="GeoCommonsWebClient.cs" />
+ <Compile Include="Maps.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
228 Maps.cs
@@ -0,0 +1,228 @@
+//The MIT License
+
+//Copyright (c) 2012 Zekiah Technologies, Inc.
+
+//Permission is hereby granted, free of charge, to any person obtaining a copy
+//of this software and associated documentation files (the "Software"), to deal
+//in the Software without restriction, including without limitation the rights
+//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//copies of the Software, and to permit persons to whom the Software is
+//furnished to do so, subject to the following conditions:
+
+//The above copyright notice and this permission notice shall be included in
+//all copies or substantial portions of the Software.
+
+//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//THE SOFTWARE.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Net;
+using System.Net.Security;
+using System.Web;
+using System.Security.Cryptography.X509Certificates;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Json;
+
+using GeoIQ.Net.Data;
+using System.ComponentModel;
+using System.Xml.Serialization;
+using System.Xml;
+
+namespace GeoIQ.Net
+{
+ #region classes
+ public class MapSearchEventArgs
+ {
+ internal Exception _error = null;
+ internal MapSearchResults _result = null;
+
+ public Exception Error
+ {
+ get
+ {
+ return _error;
+ }
+ }
+
+ public MapSearchResults Result
+ {
+ get
+ {
+ return _result;
+ }
+ }
+ }
+
+ public class MapsApi
+ {
+ #region Properties and Events
+
+ public string EndpointURI { get; set; }
+ public string UserName { get; set; }
+ public string Password { get; set; }
+
+ #endregion
+
+ #region Constructors
+
+ public MapsApi(string endpointUri)
+ {
+
+ EndpointURI = prepareEndpointURI(endpointUri);
+
+ }
+
+ public MapsApi(string endpointUri, string username, string password)
+ {
+ EndpointURI = prepareEndpointURI(endpointUri);
+ UserName = username;
+ Password = password;
+ }
+
+ #endregion
+
+ #region Synchronous Methods
+
+ public MapSearchEventArgs ExecuteSearch(int limit)
+ {
+ MapSearchEventArgs args = new MapSearchEventArgs();
+ try
+ {
+ WebClient request = new WebClient();
+ string url = String.Format("{0}/search.json?model=Map&limit={1}", EndpointURI, limit);
+ setCredentials(request);
+
+ Stream stream = request.OpenRead(url);
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(MapSearchResults));
+
+ MapSearchResults maps = (MapSearchResults)serializer.ReadObject(stream);
+ args._result = maps;
+ }
+ catch (Exception ex)
+ {
+ args._error = ex;
+ }
+ return args;
+ }
+
+ public MapDetails GetMapDetails(int id)
+ {
+ //MapSearchEventArgs args = new MapSearchEventArgs();
+ MapDetails maps = null;
+ try
+ {
+ WebClient request = new WebClient();
+ string url = String.Format("{0}/maps/{1}.json", EndpointURI, id);
+ setCredentials(request);
+
+ Stream stream = request.OpenRead(url);
+ DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(MapDetails));
+
+ maps = (MapDetails)serializer.ReadObject(stream);
+ //args._result = maps;
+ }
+ catch (Exception ex)
+ {
+ string s = ex.ToString();
+ //args._error = ex;
+ }
+ return maps;
+ }
+ #endregion
+
+ #region privates
+
+ private string prepareEndpointURI(string url)
+ {
+ string result = url;
+ int notFound = -1;
+
+ int httpExists = result.IndexOf("http://");
+
+ if (httpExists == notFound)
+ result = String.Format("http://{0}", url);
+
+ //int finderExists = result.IndexOf("finder");
+
+ //if (finderExists == notFound)
+ //{
+ // System.Uri domain = new System.Uri(result);
+ // result = String.Format("http://finder.{0}", domain.Authority);
+ //}
+ return result;
+ }
+
+ private void setCredentials(WebClient request)
+ {
+ if (!String.IsNullOrEmpty(UserName) && !String.IsNullOrEmpty(Password))
+ {
+ string authInfo = UserName + ":" + Password;
+ authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(UserName + ":" + Password));
+ request.Headers["Authorization"] = "Basic " + authInfo;
+ }
+ }
+
+ public string createMap(string options)
+ {
+ try
+ {
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/maps.json", EndpointURI);
+ var result = request.Post(url, UserName, Password, "application/x-www-form-urlencoded", options);
+ return result;
+ }
+ catch
+ {
+ return "";
+ }
+ }
+
+ public ResponseStatusEventArgs deleteMap(int mapid)
+ {
+ ResponseStatusEventArgs args = new ResponseStatusEventArgs();
+ try
+ {
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/maps/{1}.json", EndpointURI, mapid);
+ var result = request.Delete(url, UserName, Password, "application/json");
+ args._result = result.Status;
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ return args;
+ }
+
+ public string getSession()
+ {
+ try
+ {
+ GeoComWebClient request = new GeoComWebClient();
+ string url = String.Format("{0}/sessions.json", EndpointURI);
+ var result = request.GetCookie(url, this.UserName, this.Password);
+ return result;
+ }
+ catch
+ {
+ return "";
+ }
+ }
+
+ #endregion
+
+
+
+ }
+ #endregion
+
+}
58 Properties/AssemblyInfo.cs
@@ -0,0 +1,58 @@
+//The MIT License
+
+//Copyright (c) 2012 Zekiah Technologies, Inc.
+
+//Permission is hereby granted, free of charge, to any person obtaining a copy
+//of this software and associated documentation files (the "Software"), to deal
+//in the Software without restriction, including without limitation the rights
+//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//copies of the Software, and to permit persons to whom the Software is
+//furnished to do so, subject to the following conditions:
+
+//The above copyright notice and this permission notice shall be included in
+//all copies or substantial portions of the Software.
+
+//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//THE SOFTWARE.
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("GeoIQ.Net")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("GeoIQ.Net")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("52a34c5d-a1bc-4bf2-ae8d-bf303e53e900")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
Please sign in to comment.
Something went wrong with that request. Please try again.