Permalink
Browse files

Imified CHAsHLib v0.5 with basic feature set to find users, getusers …

…AND send messages to a particular userid
  • Loading branch information...
1 parent a6902a6 commit d631ff2371047d8a31d868391268de55472b062b @brijrajsingh committed Dec 18, 2011
Showing with 1,338 additions and 0 deletions.
  1. +36 −0 trunk/ImifiedCHash/ImifiedCHash.sln
  2. BIN trunk/ImifiedCHash/ImifiedCHash.suo
  3. +6 −0 trunk/ImifiedCHash/ImifiedCHash.vsmdi
  4. +8 −0 trunk/ImifiedCHash/ImifiedCHashLib/App.config
  5. +59 −0 trunk/ImifiedCHash/ImifiedCHashLib/ImifiedCHashLib.csproj
  6. +225 −0 trunk/ImifiedCHash/ImifiedCHashLib/ImifiedFacade.cs
  7. +36 −0 trunk/ImifiedCHash/ImifiedCHashLib/Properties/AssemblyInfo.cs
  8. BIN trunk/ImifiedCHash/ImifiedCHashLib/bin/Debug/ImifiedCHashLib.dll
  9. +7 −0 trunk/ImifiedCHash/ImifiedCHashLib/bin/Debug/ImifiedCHashLib.dll.VisualState.xml
  10. +8 −0 trunk/ImifiedCHash/ImifiedCHashLib/bin/Debug/ImifiedCHashLib.dll.config
  11. BIN trunk/ImifiedCHash/ImifiedCHashLib/bin/Debug/ImifiedCHashLib.pdb
  12. BIN trunk/ImifiedCHash/ImifiedCHashLib/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
  13. +6 −0 trunk/ImifiedCHash/ImifiedCHashLib/obj/Debug/ImifiedCHashLib.csproj.FileListAbsolute.txt
  14. BIN trunk/ImifiedCHash/ImifiedCHashLib/obj/Debug/ImifiedCHashLib.dll
  15. BIN trunk/ImifiedCHash/ImifiedCHashLib/obj/Debug/ImifiedCHashLib.pdb
  16. +71 −0 trunk/ImifiedCHash/ImifiedCHashLibUnitTests/ImifiedCHashLibUnitTests.csproj
  17. +111 −0 trunk/ImifiedCHash/ImifiedCHashLibUnitTests/ImifiedFacadeTest.cs
  18. +35 −0 trunk/ImifiedCHash/ImifiedCHashLibUnitTests/Properties/AssemblyInfo.cs
  19. BIN trunk/ImifiedCHash/ImifiedCHashLibUnitTests/bin/Debug/ImifiedCHashLib.dll
  20. BIN trunk/ImifiedCHash/ImifiedCHashLibUnitTests/bin/Debug/ImifiedCHashLib.pdb
  21. BIN trunk/ImifiedCHash/ImifiedCHashLibUnitTests/bin/Debug/ImifiedCHashLibUnitTests.dll
  22. BIN trunk/ImifiedCHash/ImifiedCHashLibUnitTests/bin/Debug/ImifiedCHashLibUnitTests.pdb
  23. BIN trunk/ImifiedCHash/ImifiedCHashLibUnitTests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
  24. +7 −0 ...fiedCHash/ImifiedCHashLibUnitTests/obj/Debug/ImifiedCHashLibUnitTests.csproj.FileListAbsolute.txt
  25. BIN trunk/ImifiedCHash/ImifiedCHashLibUnitTests/obj/Debug/ImifiedCHashLibUnitTests.dll
  26. BIN trunk/ImifiedCHash/ImifiedCHashLibUnitTests/obj/Debug/ImifiedCHashLibUnitTests.pdb
  27. BIN trunk/ImifiedCHash/ImifiedCHashLibUnitTests/obj/Debug/ResolveAssemblyReference.cache
  28. +10 −0 trunk/ImifiedCHash/Local.testsettings
  29. +35 −0 trunk/ImifiedCHash/TestProject1/Properties/AssemblyInfo.cs
  30. +59 −0 trunk/ImifiedCHash/TestProject1/TestProject1.csproj
  31. +17 −0 trunk/ImifiedCHash/TestProject1/UnitTest1.cs
  32. BIN trunk/ImifiedCHash/TestProject1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
  33. +80 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_26_39.trx
  34. +54 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_27_54.trx
  35. BIN trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_27_54/Out/AgentRestart.dat
  36. +54 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_30_06.trx
  37. BIN trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_30_06/Out/AgentRestart.dat
  38. +73 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_30_52.trx
  39. +73 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_31_04.trx
  40. +62 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_31_12.trx
  41. BIN trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_31_12/Out/AgentRestart.dat
  42. +73 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_32_42.trx
  43. +70 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_33_09.trx
  44. BIN trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_33_09/Out/AgentRestart.dat
  45. +54 −0 trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_33_26.trx
  46. BIN trunk/ImifiedCHash/TestResults/tpf_TPF-PC 2011-12-18 14_33_26/Out/AgentRestart.dat
  47. +9 −0 trunk/ImifiedCHash/TraceAndTestImpact.testsettings
@@ -0,0 +1,36 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImifiedCHashLib", "ImifiedCHashLib\ImifiedCHashLib.csproj", "{D611C0A4-F161-4BE9-924B-AAAB0D9A3325}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AACDDE21-C059-44AB-8920-D0E66CB1F039}"
+ ProjectSection(SolutionItems) = preProject
+ ImifiedCHash.vsmdi = ImifiedCHash.vsmdi
+ Local.testsettings = Local.testsettings
+ TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImifiedCHashLibUnitTests", "ImifiedCHashLibUnitTests\ImifiedCHashLibUnitTests.csproj", "{397EC074-4F09-4422-8DBD-F414430BB6EB}"
+EndProject
+Global
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = ImifiedCHash.vsmdi
+ EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D611C0A4-F161-4BE9-924B-AAAB0D9A3325}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D611C0A4-F161-4BE9-924B-AAAB0D9A3325}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D611C0A4-F161-4BE9-924B-AAAB0D9A3325}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D611C0A4-F161-4BE9-924B-AAAB0D9A3325}.Release|Any CPU.Build.0 = Release|Any CPU
+ {397EC074-4F09-4422-8DBD-F414430BB6EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {397EC074-4F09-4422-8DBD-F414430BB6EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {397EC074-4F09-4422-8DBD-F414430BB6EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {397EC074-4F09-4422-8DBD-F414430BB6EB}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Binary file not shown.
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
+ <RunConfiguration id="0c0b3f71-4a2f-44fd-996e-bb9ca5f13928" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ </TestList>
+</TestLists>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <appSettings>
+ <add key="botKey" value=""/>
+ <add key="username" value=""/>
+ <add key="password" value=""/>
+ </appSettings>
+</configuration>
@@ -0,0 +1,59 @@
+<?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>{D611C0A4-F161-4BE9-924B-AAAB0D9A3325}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ImifiedCHashLib</RootNamespace>
+ <AssemblyName>ImifiedCHashLib</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </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>
+ </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 />
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.configuration" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="ImifiedFacade.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </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>
@@ -0,0 +1,225 @@
+/// <FileName>ImifiedFacade.cs</FileName>
+/// <copyright>
+/// Copyright Brijrajsingh.com, available under MIT Licence
+/// All this work may be used, practiced, performed, copied, distributed,
+/// revised, modified, translated, abridged, condensed, expanded, collected,
+/// compiled, linked, recast or adapted.
+/// A reference will be very much appreciated.
+/// <copyright>
+/// <remarks>
+/// Date Author Changes
+///13,Dec 2011 brijraj singh Created
+///Copyright (c) 2011 Brijrajsingh.com, MIT Licence
+/// </remarks>
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Net;
+using System.IO;
+using System.Text.RegularExpressions;
+using System.Configuration;
+
+
+namespace ImifiedCHashLib
+{
+ /// <summary>
+ /// Class provides facade based implementation for
+ /// </summary>
+ public static class ImifiedFacade
+ {
+
+
+ /// <summary>
+ /// Queries the Bot for all users connected/disconnected to it.
+ /// </summary>
+ /// <param name="NetworkName"> NetworkNAme - Optional, use this to filter out the users of a particular bot.</param>
+ /// <returns>XML structure of all user details</returns>
+ public static string GetAllUsers(string NetworkName=null)
+ {
+ string _allUsersXml = string.Empty;
+ string _botkey = ConfigurationManager.AppSettings["botKey"];
+ string _username = ConfigurationManager.AppSettings["username"];
+ string _password = ConfigurationManager.AppSettings["password"];
+
+ string _postData = string.Empty;
+
+ try
+ {
+ HttpWebRequest request = (HttpWebRequest)(WebRequest.Create("https://www.imified.com/api/bot/"));
+ request.Method = "POST";
+
+ if ((NetworkName != null) && (NetworkName != string.Empty))
+ {
+ _postData = "botkey=" + _botkey + "&apimethod=getAllUsers&" + "networkname=" + NetworkName ;
+ }
+ else
+ {
+ _postData = "botkey=" + _botkey + "&apimethod=getAllUsers";
+ }
+
+ byte[] _bytes;
+ System.Text.ASCIIEncoding _a = new ASCIIEncoding();
+ _bytes = _a.GetBytes(_username + ":" + _password);
+
+ request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(_bytes, 0, _bytes.Length));
+
+
+ byte[] byteArray = Encoding.UTF8.GetBytes(_postData);
+
+ // Set the ContentType property of the WebRequest.
+
+ request.ContentType = "application/x-www-form-urlencoded";
+
+ // Set the ContentLength property of the WebRequest.
+
+ request.ContentLength = byteArray.Length;
+
+ // Get the request stream.
+
+ Stream dataStream = request.GetRequestStream();
+
+ // Write the data to the request stream.
+
+ dataStream.Write(byteArray, 0, byteArray.Length);
+
+ // Close the Stream object.
+ dataStream.Close();
+ // Get the response.
+ WebResponse response = request.GetResponse();
+
+ // Get the stream containing content returned by the server.
+ dataStream = response.GetResponseStream();
+
+ // Open the stream using a StreamReader for easy access.
+ StreamReader reader = new StreamReader(dataStream);
+ // Read the content.
+ _allUsersXml = reader.ReadToEnd();
+
+ // Clean up the streams.
+ reader.Close();
+ dataStream.Close();
+ response.Close();
+
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+
+ return _allUsersXml;
+ }
+
+
+ /// <summary>
+ /// Find the given username in the network{optional} or all the BOT networks, and return the unique Userid
+ /// </summary>
+ /// <param name="UserName">ChatID of the User</param>
+ /// <param name="NetworkName">NetworkNAme - Optional, use this to filter out the users of a particular bot.</param>
+ /// <returns>Unique userid</returns>
+ public static string GetUserIdByUserName(string UserName, string NetworkName = null)
+ {
+ string _allusersXML = GetAllUsers(NetworkName);
+ string _userKey = string.Empty;
+
+ string strRegex = @"([A-Za-z0-9\-]+)\</userkey>";
+ RegexOptions myRegexOptions = RegexOptions.Multiline | RegexOptions.Singleline;
+ Regex myRegex = new Regex(strRegex, myRegexOptions);
+ string strTargetString = _allusersXML;
+
+ foreach (Match myMatch in myRegex.Matches(strTargetString))
+ {
+ if (myMatch.Success)
+ {
+ _userKey = myMatch.Captures[0].Value.Replace("</userkey>", string.Empty);
+ break;
+ }
+ else
+ {
+ _userKey = string.Empty;
+ }
+ }
+
+ return _userKey;
+ }
+
+
+ /// <summary>
+ /// Send the message to given userkey/userid
+ /// </summary>
+ /// <param name="UserKey">Unique UserKey or USerId</param>
+ /// <param name="MessageText">Message to be sent</param>
+ /// <returns>Success/Failure/User Not Found</returns>
+ public static string SendMessage(string UserKey, string MessageText)
+ {
+ string _retVal = string.Empty;
+ string _botkey = ConfigurationManager.AppSettings["botKey"];
+ string _username = ConfigurationManager.AppSettings["username"];
+ string _password = ConfigurationManager.AppSettings["password"];
+
+
+ try
+ {
+
+ HttpWebRequest request = (HttpWebRequest)(WebRequest.Create("https://www.imified.com/api/bot/"));
+ request.Method = "POST";
+
+ string postData = "botkey=" + _botkey + "&apimethod=send&userkey=" + UserKey + "&msg=" + MessageText;
+
+ byte[] _bytes;
+ System.Text.ASCIIEncoding _a = new ASCIIEncoding();
+ _bytes = _a.GetBytes(_username + ":" + _password);
+
+ request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(_bytes, 0, _bytes.Length));
+
+
+ byte[] byteArray = Encoding.UTF8.GetBytes(postData);
+
+ // Set the ContentType property of the WebRequest.
+
+ request.ContentType = "application/x-www-form-urlencoded";
+
+ // Set the ContentLength property of the WebRequest.
+
+ request.ContentLength = byteArray.Length;
+
+ // Get the request stream.
+
+ Stream dataStream = request.GetRequestStream();
+
+ // Write the data to the request stream.
+
+ dataStream.Write(byteArray, 0, byteArray.Length);
+
+ // Close the Stream object.
+ dataStream.Close();
+ // Get the response.
+ WebResponse response = request.GetResponse();
+
+ // Get the stream containing content returned by the server.
+ dataStream = response.GetResponseStream();
+
+ // Open the stream using a StreamReader for easy access.
+ StreamReader reader = new StreamReader(dataStream);
+ // Read the content.
+ _retVal = reader.ReadToEnd();
+
+ // Clean up the streams.
+ reader.Close();
+ dataStream.Close();
+ response.Close();
+ }
+ catch (Exception)
+ {
+
+ throw;
+ }
+
+ return _retVal;
+
+ }
+
+
+ }
+}
@@ -0,0 +1,36 @@
+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("ImifiedCHashLib")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ImifiedCHashLib")]
+[assembly: AssemblyCopyright("Copyright © 2011")]
+[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("f71e085d-1ece-4394-9195-d4b689495a01")]
+
+// 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")]
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<VisualState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ShowCheckBoxes="false">
+ <TopNode>[0-1000]E:\Projects\ImifiedCHashLib\trunk\ImifiedCHash\ImifiedCHashLib\bin\Debug\ImifiedCHashLib.dll</TopNode>
+ <SelectedNode>[0-1000]E:\Projects\ImifiedCHashLib\trunk\ImifiedCHash\ImifiedCHashLib\bin\Debug\ImifiedCHashLib.dll</SelectedNode>
+ <ExcludeCategories>false</ExcludeCategories>
+ <Nodes />
+</VisualState>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <appSettings>
+ <add key="botKey" value=""/>
+ <add key="username" value=""/>
+ <add key="password" value=""/>
+ </appSettings>
+</configuration>
Oops, something went wrong.

0 comments on commit d631ff2

Please sign in to comment.