Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

Commit

Permalink
Renamed plugin 'dict' to 'lang'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianoc committed Oct 7, 2011
1 parent d005c67 commit 9df7725
Show file tree
Hide file tree
Showing 32 changed files with 145 additions and 76 deletions.
7 changes: 6 additions & 1 deletion Binboo.Core/Configuration/CoreConfig.cs
Expand Up @@ -55,7 +55,12 @@ public XmlNodeList FindConfigItems(string plugin, string xpath)

}

public void SaveConfig()
public XmlNode CommandConfigurationFor(string plugin, string commandName)
{
return FindConfigItem(plugin, string.Format("commands/{0}", commandName.ToLowerInvariant()));
}

public void SaveConfig()
{
_config.Save(ConfigFilePath());
}
Expand Down
1 change: 1 addition & 0 deletions Binboo.Core/Configuration/ICoreConfig.cs
Expand Up @@ -7,6 +7,7 @@ public interface ICoreConfig
string StoragePath { get; }
XmlNode FindConfigItem(string plugin, string xpath);
XmlNodeList FindConfigItems(string plugin, string xpath);
XmlNode CommandConfigurationFor(string pluginName, string commandName);
void SaveConfig();
}
}
2 changes: 1 addition & 1 deletion Binboo.Jira/Configuration/JiraConfig.cs
Expand Up @@ -107,7 +107,7 @@ public String Server

public TextReader CommandConfigurationFor(string commandName)
{
var commandConfigurarion = _coreConfig.FindConfigItem("jira", string.Format("commands/{0}", commandName.ToLowerInvariant()));
var commandConfigurarion = _coreConfig.CommandConfigurationFor("jira", commandName);
return new StringReader(commandConfigurarion.OuterXml);
}

Expand Down
Expand Up @@ -8,8 +8,8 @@
<ProjectGuid>{A19458F7-F499-4BCD-82AB-1D713BB464C6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Binboo.Dict.Tests</RootNamespace>
<AssemblyName>Binboo.Dict.Tests</AssemblyName>
<RootNamespace>Binboo.Language.Tests</RootNamespace>
<AssemblyName>Binboo.Language.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
Expand Down Expand Up @@ -44,15 +44,16 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tests\Commands\TranslateCommandTestCase.cs" />
<Compile Include="Tests\Configuration\TranslateConfigurationTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Binboo.Core\Binboo.Core.csproj">
<Project>{89B1E578-05FB-4C7A-A561-284F266097A6}</Project>
<Name>Binboo.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Binboo.Dict\Binboo.Dict.csproj">
<ProjectReference Include="..\Binboo.Language\Binboo.Language.csproj">
<Project>{353FE52C-915F-4D9A-BF4F-C0C5C155AC79}</Project>
<Name>Binboo.Dict</Name>
<Name>Binboo.Language</Name>
</ProjectReference>
<ProjectReference Include="..\Binboo.Plugins.Tests.Foundation\Binboo.Plugins.Tests.Foundation.csproj">
<Project>{1CE3DA6D-F44F-4319-8B59-233041B47C71}</Project>
Expand Down
Expand Up @@ -8,10 +8,11 @@
<storage path="%TEMP%\BinbooTest" />
</core>

<translate>
<endpoint value="http://what.ever.com.pqp" />
<api-key value="1234" />
</translate>
<language_services>
<commands>
<translate endpoint = "http://what.ever.com.pqp" api-key = "42.42.42" />
</commands>
</language_services>
</configuration>

<log4net>
Expand Down
@@ -1,15 +1,14 @@
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("Binboo.Dict.Tests")]
[assembly: AssemblyTitle("Binboo.Language.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Binboo.Dict.Tests")]
[assembly: AssemblyProduct("Binboo.Language.Tests")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand Down
Expand Up @@ -22,13 +22,13 @@
using System.Globalization;
using Binboo.Core;
using Binboo.Core.Commands;
using Binboo.Dict.Commands;
using Binboo.Dict.MicrosoftTranslator;
using Binboo.Language.Commands;
using Binboo.Language.MicrosoftTranslator;
using Binboo.Plugins.Tests.Foundation.Commands;
using Moq;
using NUnit.Framework;

namespace Binboo.Dict.Tests.Commands
namespace Binboo.Language.Tests.Commands
{
[TestFixture]
public class TranslateCommandTestCase : PluginCommandTestCaseBase<LanguageService>
Expand Down
@@ -0,0 +1,37 @@
/**
* Copyright (c) 2011 Adriano Carlos Verona
*
* 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 Binboo.Language.Configuration;
using NUnit.Framework;

namespace Binboo.Language.Tests.Configuration
{
[TestFixture]
public class TranslateConfigurationTest
{
[Test]
public void APIKEY_CanBeRead()
{
Assert.That(LanguageConfig.Instance.APIKey, Is.EqualTo("42.42.42"));
}
}
}
Expand Up @@ -8,8 +8,8 @@
<ProjectGuid>{353FE52C-915F-4D9A-BF4F-C0C5C155AC79}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Binboo.Dict</RootNamespace>
<AssemblyName>Binboo.Dict</AssemblyName>
<RootNamespace>Binboo.Language</RootNamespace>
<AssemblyName>Binboo.Language</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
Expand Down Expand Up @@ -42,15 +42,16 @@
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<Compile Include="Binboo.Dict.Designer.cs">
<Compile Include="Binboo.LanguageServices.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Binboo.Dict.resx</DependentUpon>
<DependentUpon>Binboo.LanguageServices.resx</DependentUpon>
</Compile>
<Compile Include="Commands\TranslatorParamValidator.cs" />
<Compile Include="Commands\TranslateCommand.cs" />
<Compile Include="Configuration\TranslateConfig.cs" />
<Compile Include="Plugin\DictPlugin.cs" />
<Compile Include="Configuration\LanguageConfig.cs" />
<Compile Include="Configuration\TranslateCommandConfig.cs" />
<Compile Include="Plugin\LanguageServicesPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Service References\MicrosoftTranslator\Reference.cs">
<AutoGen>True</AutoGen>
Expand All @@ -69,9 +70,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Binboo.Dict.resx">
<EmbeddedResource Include="Binboo.LanguageServices.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Binboo.Dict.Designer.cs</LastGenOutput>
<LastGenOutput>Binboo.LanguageServices.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
Expand All @@ -81,10 +82,10 @@
<None Include="app.config">
<SubType>Designer</SubType>
</None>
<None Include="Service References\MicrosoftTranslator\Binboo.Dict.MicrosoftTranslator.GetTranslationsResponse.datasource">
<None Include="Service References\MicrosoftTranslator\Binboo.Language.MicrosoftTranslator.GetTranslationsResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</None>
<None Include="Service References\MicrosoftTranslator\Binboo.Dict.MicrosoftTranslator.TranslateArrayResponse.datasource">
<None Include="Service References\MicrosoftTranslator\Binboo.Language.MicrosoftTranslator.TranslateArrayResponse.datasource">
<DependentUpon>Reference.svcmap</DependentUpon>
</None>
<None Include="Service References\MicrosoftTranslator\soap.wsdl" />
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Expand Up @@ -19,15 +19,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/

using System;
using Binboo.Core;
using Binboo.Core.Commands;
using Binboo.Core.Commands.Arguments;
using Binboo.Core.Commands.Support;
using Binboo.Dict.Configuration;
using Binboo.Dict.MicrosoftTranslator;
using Binboo.Language.Configuration;
using Binboo.Language.MicrosoftTranslator;

namespace Binboo.Dict.Commands
namespace Binboo.Language.Commands
{
public class TranslateCommand : BotCommandBase
{
Expand Down Expand Up @@ -63,7 +64,7 @@ public override ICommandResult Process(IContext context)
{
var langs = arguments["languagePair"].Value.Split(':');
var translated = _languageSrv.Translate(
TranslateConfig.Instance.APIKey,
LanguageConfig.Instance.APIKey,
arguments["toBeTranslated"],
EnsureValid(langs[SourceIndex], context.User.CountryCode),
EnsureValid(langs[TargetIndex], context.User.CountryCode),
Expand Down
Expand Up @@ -19,9 +19,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/

using Binboo.Core.Commands.Arguments;

namespace Binboo.Dict.Commands
namespace Binboo.Language.Commands
{
class TranslatorParamValidator : ParamValidator
{
Expand Down
Expand Up @@ -19,26 +19,31 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/

using System.IO;
using Binboo.Core.Configuration;
using TCL.Net.Extensions;

namespace Binboo.Dict.Configuration
namespace Binboo.Language.Configuration
{
class TranslateConfig
class LanguageConfig
{
public static TranslateConfig Instance = new TranslateConfig(ConfigurationFactory.Create());
public static LanguageConfig Instance = new LanguageConfig(ConfigurationFactory.Create());

private readonly ICoreConfig _coreConfig;

public TranslateConfig(ICoreConfig coreConfig)
public LanguageConfig(ICoreConfig coreConfig)
{
_coreConfig = coreConfig;
}

public string APIKey
{
get
{
return _coreConfig.FindConfigItem("translate", "api-key/@value").Value;
var value = _coreConfig.CommandConfigurationFor("language_services", "translate").OuterXml;
var config = new StringReader(value).Deserialize<TranslateCommandConfig>();
return config.ApiKey;
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions Binboo.Language/Configuration/TranslateCommandConfig.cs
@@ -0,0 +1,14 @@
using System.Xml.Serialization;

namespace Binboo.Language.Configuration
{
[XmlRoot("translate")]
public class TranslateCommandConfig
{
[XmlAttribute("api-key")]
public string ApiKey { get; set; }

[XmlAttribute("endpoint")]
public string EndPoint { get; set; }
}
}
Expand Up @@ -19,33 +19,34 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
**/

using System.ComponentModel.Composition;
using Binboo.Core.Persistence;
using Binboo.Core.Plugins;
using Binboo.Dict.Commands;
using Binboo.Dict.MicrosoftTranslator;
using Binboo.Language.Commands;
using Binboo.Language.MicrosoftTranslator;

namespace Binboo.Dict.Plugin
namespace Binboo.Language.Plugin
{
[Export(typeof(IPlugin))]
public class DictPlugin : AbstractBasePlugin
public class LanguageServicesPlugin : AbstractBasePlugin
{
[ImportingConstructor]
DictPlugin(IStorageManager storageManager) : base(storageManager)
LanguageServicesPlugin(IStorageManager storageManager) : base(storageManager)
{
}

public override string Name
{
get { return "translate"; }
get { return "lang"; }
}

public override void Initialize()
{
try
{
AddCommand(storageManager,
new TranslateCommand(new LanguageServiceClient("BasicHttpBinding_LanguageService"), Binboo_Dict.translate));
new TranslateCommand(new LanguageServiceClient("BasicHttpBinding_LanguageService"), Binboo_LanguageServices.translate));
}
finally
{
Expand Down
Expand Up @@ -5,11 +5,11 @@
// 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("Binboo.Dict")]
[assembly: AssemblyTitle("Binboo.Language")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Binboo.Dict")]
[assembly: AssemblyProduct("Binboo.Language")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand All @@ -34,3 +34,5 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: InternalsVisibleTo("Binboo.Language.Tests")]

0 comments on commit 9df7725

Please sign in to comment.