You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by ps...@apache.org on 2010/03/18 13:50:50 UTC

svn commit: r924748 - in /incubator/wookie/trunk/connector/CSharp: ./ WookieService/ WookieService/Properties/ WookieService/Wookie/

Author: psharples
Date: Thu Mar 18 12:50:49 2010
New Revision: 924748

URL: http://svn.apache.org/viewvc?rev=924748&view=rev
Log:
Adding initial CSharp connector framework (thanks to Raido Kuli for the patch). See WOOKIE-126

Added:
    incubator/wookie/trunk/connector/CSharp/
    incubator/wookie/trunk/connector/CSharp/CSharp.sln
    incubator/wookie/trunk/connector/CSharp/WookieService/
    incubator/wookie/trunk/connector/CSharp/WookieService/Properties/
    incubator/wookie/trunk/connector/CSharp/WookieService/Properties/AssemblyInfo.cs
    incubator/wookie/trunk/connector/CSharp/WookieService/TestWookieService.cs
    incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/
    incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/Widget.cs
    incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WidgetInstance.cs
    incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieConnectorService.cs
    incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieServerConnection.cs
    incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj
    incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj.user

Added: incubator/wookie/trunk/connector/CSharp/CSharp.sln
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/CSharp.sln?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/CSharp.sln (added)
+++ incubator/wookie/trunk/connector/CSharp/CSharp.sln Thu Mar 18 12:50:49 2010
@@ -0,0 +1,18 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+# SharpDevelop 3.2.0.5505
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WookieService", "WookieService\WookieService.csproj", "{C649A559-B934-482B-89C3-4F19FDFC5D62}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{C649A559-B934-482B-89C3-4F19FDFC5D62}.Debug|x86.Build.0 = Debug|x86
+		{C649A559-B934-482B-89C3-4F19FDFC5D62}.Debug|x86.ActiveCfg = Debug|x86
+		{C649A559-B934-482B-89C3-4F19FDFC5D62}.Release|x86.Build.0 = Release|x86
+		{C649A559-B934-482B-89C3-4F19FDFC5D62}.Release|x86.ActiveCfg = Release|x86
+	EndGlobalSection
+EndGlobal

Added: incubator/wookie/trunk/connector/CSharp/WookieService/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/WookieService/Properties/AssemblyInfo.cs?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/WookieService/Properties/AssemblyInfo.cs (added)
+++ incubator/wookie/trunk/connector/CSharp/WookieService/Properties/AssemblyInfo.cs Thu Mar 18 12:50:49 2010
@@ -0,0 +1,32 @@
+#region Using directives
+
+using System;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+#endregion
+
+// 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("TestWookieService")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("TestWookieService")]
+[assembly: AssemblyCopyright("Copyright 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// This sets the default COM visibility of types in the assembly to invisible.
+// If you need to expose a type to COM, use [ComVisible(true)] on that type.
+[assembly: ComVisible(false)]
+
+// The assembly version has following format :
+//
+// Major.Minor.Build.Revision
+//
+// You can specify all the values or you can use the default the Revision and 
+// Build Numbers by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.*")]

Added: incubator/wookie/trunk/connector/CSharp/WookieService/TestWookieService.cs
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/WookieService/TestWookieService.cs?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/WookieService/TestWookieService.cs (added)
+++ incubator/wookie/trunk/connector/CSharp/WookieService/TestWookieService.cs Thu Mar 18 12:50:49 2010
@@ -0,0 +1,42 @@
+/*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using WookieService.Wookie;
+
+namespace TestWookieService
+{
+    class TestWookieService
+    {
+        static void Main(string[] args)
+        {
+            WookieConnectorService conn = new WookieConnectorService("http://localhost:8080/wookie", "TEST", "csharp_localhost");
+            List<Widget> widgets = conn.getAvailableWidgets();
+            foreach (Widget widget in widgets) {
+            	Console.WriteLine(widget.getTitle() + " - " + widget.getGuid()+ " - " + widget.getDescription());
+            }
+
+            WidgetInstance retrievedInstance_1 = conn.getOrCreateInstance("http://www.getwookie.org/widgets/weather");
+            WidgetInstance retrievedInstance_2 = conn.getOrCreateInstance(widgets[3].getGuid());
+
+            Console.WriteLine("Instance 1 - "+retrievedInstance_1.getTitle());
+            Console.WriteLine("Instance 2 - " + retrievedInstance_2.getTitle());
+			// pause to read
+			Console.WriteLine("Press return to continue");
+			Console.ReadLine();
+        }
+    }
+}

Added: incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/Widget.cs
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/Widget.cs?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/Widget.cs (added)
+++ incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/Widget.cs Thu Mar 18 12:50:49 2010
@@ -0,0 +1,77 @@
+/*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace WookieService.Wookie
+{
+    class Widget
+    {
+        private String title;
+        private String icon;
+        private String desc;
+        private String guid;
+
+        public Widget(String guid, String title, String desc, String icon)
+        {
+            this.setGuid(guid);
+            this.setTitle(title);
+            this.setDescription(desc);
+            this.setIcon(icon);
+        }
+
+        public void setGuid(String guid) 
+        {
+            this.guid = guid;
+        }
+
+        public String getGuid() 
+        {
+            return this.guid;
+        }
+
+        public void setTitle(String title)
+        {
+            this.title = title;
+        }
+
+        public String getTitle()
+        {
+            return this.title;
+        }
+
+        public void setDescription(String desc)
+        {
+            this.desc = desc;
+        }
+
+        public String getDescription()
+        {
+            return this.desc;
+        }
+
+        public void setIcon(String icon)
+        {
+            this.icon = icon;
+        }
+
+        public String getIcon()
+        {
+            return this.icon;
+        }
+
+    }
+}

Added: incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WidgetInstance.cs
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WidgetInstance.cs?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WidgetInstance.cs (added)
+++ incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WidgetInstance.cs Thu Mar 18 12:50:49 2010
@@ -0,0 +1,90 @@
+/*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace WookieService.Wookie
+{
+    class WidgetInstance
+    {
+        private String url;
+        private String guid;
+        private String title;
+        private Int32 height;
+        private Int32 width;
+        private String maximize;
+
+        public WidgetInstance(String url, String guid, String title, Int32 height, Int32 width, String maximize) {
+            this.setIdentifier(guid);
+            this.setUrl(url);
+            this.setTitle(title);
+            this.setHeight(height);
+            this.setWidth(width);
+            this.setMaximize(maximize);
+        }
+      
+        public String getUrl() {
+            return this.url;
+        }
+
+        public void setUrl(String url) {
+            this.url = url;
+        }
+
+        public String getIdentifier() {
+            return this.guid;
+        }
+
+        public void setIdentifier(String guid) {
+            this.guid = guid;
+        }
+
+        public String getTitle() {
+            return this.title;
+        }
+
+        public void setTitle(String title) {
+            this.title = title;
+        }
+
+        public Int32 getHeight() {
+            return this.height;
+        }
+
+        public void setHeight(Int32 height) {
+            this.height = height;
+        }
+
+        public Int32 getWidth() {
+            return this.width;
+        }
+
+        public void setWidth(Int32 width) {
+            this.width = width;
+        }
+
+        public String getMaximize() {
+            return this.maximize;
+        }
+
+        public void setMaximize(String maximize) {
+            this.maximize = maximize;
+        }
+        public String isMaximizable() {
+            return this.getMaximize();
+        }
+    }
+}

Added: incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieConnectorService.cs
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieConnectorService.cs?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieConnectorService.cs (added)
+++ incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieConnectorService.cs Thu Mar 18 12:50:49 2010
@@ -0,0 +1,143 @@
+/*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+using System.Net;
+using System.Xml;
+
+namespace WookieService.Wookie
+{
+    class WookieConnectorService
+    {
+        private WookieServerConnection wookieConn;
+
+        public WookieConnectorService(String url, String api_key, String sharedDataKey)
+        {
+            this.wookieConn = new WookieServerConnection(url, api_key, sharedDataKey);
+        }
+
+        public WookieServerConnection getConnection()
+        {
+            return this.wookieConn;
+        }
+
+        public String getCurrentUser() {
+            return "csharp_user";
+        }
+
+        public WidgetInstance getOrCreateInstance(String guid)
+        {
+            WebRequest postReq = WebRequest.Create(this.getConnection().getUrl()+"/widgetinstances");
+            postReq.Proxy = null;
+
+            //Add these, as we're doing a POST
+            postReq.ContentType = "application/x-www-form-urlencoded";
+            postReq.Method = "POST";
+
+            StringBuilder postData = new StringBuilder();
+            postData.Append("api_key=" + this.getConnection().getApiKey());
+            postData.Append("&userid=" + this.getCurrentUser());
+            postData.Append("shareddatakey=" + this.getConnection().getSharedDataKey());
+            postData.Append("&widgetid=" + guid);
+
+            //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value&
+            byte[] bytes = Encoding.UTF8.GetBytes(postData.ToString());
+            postReq.ContentLength = bytes.Length;
+            Stream os = postReq.GetRequestStream();
+            os.Write(bytes, 0, bytes.Length); //Push it out there
+            os.Close();
+            WebResponse resp = postReq.GetResponse();
+            if (resp == null) return null;
+            StreamReader sr = new StreamReader(resp.GetResponseStream());
+
+            //let's read xml
+            XmlDocument doc = new XmlDocument();
+            String response = sr.ReadToEnd().Trim();
+            doc.LoadXml(response);
+            String widgetInstanceUrl = doc.GetElementsByTagName("url")[0].InnerText;;
+            String widgetTitle = doc.GetElementsByTagName("title")[0].InnerText;;
+            Int32 widgetHeight = Int32.Parse(doc.GetElementsByTagName("height")[0].InnerText);
+            Int32 widgetWidth = Int32.Parse(doc.GetElementsByTagName("width")[0].InnerText);
+            String widgetMaximize = doc.GetElementsByTagName("maximize")[0].InnerText;;
+
+          
+            WidgetInstance newInstance = new WidgetInstance(widgetInstanceUrl, guid, widgetTitle, 
+                                                            widgetHeight, widgetWidth, widgetMaximize);
+            return newInstance;            
+        }
+
+        public List<Widget> getAvailableWidgets()
+        {
+            // Create a request for the URL.         
+            WebRequest request = WebRequest.Create(this.getConnection().getUrl() + "/widgets?all=true");
+
+            request.Proxy = null;
+
+            // Get the response.
+            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+
+            // Display the status.
+            // Console.WriteLine (response.StatusDescription);
+
+            // Get the stream containing content returned by the server.
+            Stream dataStream = response.GetResponseStream();
+
+            // Open the stream using a StreamReader for easy access.
+            StreamReader reader = new StreamReader(dataStream);
+
+            string responseFromServer = reader.ReadToEnd();
+
+            // Cleanup the streams and the response.
+            reader.Close();
+            dataStream.Close();
+            response.Close();
+
+            XmlDocument doc = new XmlDocument();
+            doc.LoadXml(responseFromServer);
+            XmlNodeList elements = doc.GetElementsByTagName("widget");
+
+            List<Widget> widgets = new List<Widget>();
+
+            foreach (XmlElement widget in elements) {
+                String guid = widget.GetAttribute("identifier");
+                String title = "";
+                String description = "";
+                String iconUrl = "";
+
+                XmlNodeList children = widget.ChildNodes;
+                foreach (XmlElement child in children)
+                {
+                    switch(child.Name) {
+                        case "title":
+                            title = child.InnerText;
+                            break;
+                        case "description":
+                            description = child.InnerText;
+                            break;
+                        case "icon":
+                            iconUrl = child.InnerText;
+                            break;
+                    }
+                }
+                Widget newWidget = new Widget(guid, title, description, iconUrl);
+                widgets.Add(newWidget);
+            }
+
+            return widgets;
+        }
+    }
+}

Added: incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieServerConnection.cs
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieServerConnection.cs?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieServerConnection.cs (added)
+++ incubator/wookie/trunk/connector/CSharp/WookieService/Wookie/WookieServerConnection.cs Thu Mar 18 12:50:49 2010
@@ -0,0 +1,60 @@
+/*
+*  Licensed under the Apache License, Version 2.0 (the "License");
+*  you may not use this file except in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*  Unless required by applicable law or agreed to in writing, software
+*  distributed under the License is distributed on an "AS IS" BASIS,
+*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+*  See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+using System;
+
+namespace WookieService.Wookie
+{
+    class WookieServerConnection
+    {
+        private String url;
+        private String api_key;
+        private String shareddatakey;
+
+        public WookieServerConnection(String url, String api_key, String sharedDataKey) {
+            this.setUrl(url);
+            this.setApiKey(api_key);
+            this.setSharedDataKey(sharedDataKey);
+        }
+
+        public void setUrl(String url) {
+            this.url = url;
+        }
+
+        public String getUrl()
+        {
+            return this.url;
+        }
+
+        public void setApiKey(String apikey)
+        {
+            this.api_key = apikey;
+        }
+
+        public String getApiKey()
+        {
+            return this.api_key;
+        }
+
+        public void setSharedDataKey(String sharedDataKey)
+        {
+            this.shareddatakey = sharedDataKey;
+        }
+
+        public String getSharedDataKey()
+        {
+            return this.shareddatakey;
+        }
+
+    }
+}

Added: incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj (added)
+++ incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj Thu Mar 18 12:50:49 2010
@@ -0,0 +1,59 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <ProjectGuid>{C649A559-B934-482B-89C3-4F19FDFC5D62}</ProjectGuid>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>CSharp</RootNamespace>
+    <AssemblyName>WookieService</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Platform)' == 'x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <OutputPath>bin\Debug\</OutputPath>
+    <DebugSymbols>True</DebugSymbols>
+    <DebugType>Full</DebugType>
+    <Optimize>False</Optimize>
+    <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+    <OutputPath>bin\Release\</OutputPath>
+    <DebugSymbols>False</DebugSymbols>
+    <DebugType>None</DebugType>
+    <Optimize>True</Optimize>
+    <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
+    <DefineConstants>TRACE</DefineConstants>
+  </PropertyGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Data.DataSetExtensions">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Xml" />
+    <Reference Include="System.Xml.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="TestWookieService.cs" />
+    <Compile Include="Wookie\Widget.cs" />
+    <Compile Include="Wookie\WidgetInstance.cs" />
+    <Compile Include="Wookie\WookieConnectorService.cs" />
+    <Compile Include="Wookie\WookieServerConnection.cs" />
+    <None Include="WookieService.csproj" />
+    <None Include="WookieService.csproj.user" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Wookie" />
+  </ItemGroup>
+</Project>
\ No newline at end of file

Added: incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj.user
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj.user?rev=924748&view=auto
==============================================================================
--- incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj.user (added)
+++ incubator/wookie/trunk/connector/CSharp/WookieService/WookieService.csproj.user Thu Mar 18 12:50:49 2010
@@ -0,0 +1 @@
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
\ No newline at end of file