summaryrefslogtreecommitdiff
path: root/BCT/TranslationPlugins
diff options
context:
space:
mode:
Diffstat (limited to 'BCT/TranslationPlugins')
-rw-r--r--BCT/TranslationPlugins/PhoneControlsPlugin.cs205
-rw-r--r--BCT/TranslationPlugins/Properties/AssemblyInfo.cs36
-rw-r--r--BCT/TranslationPlugins/TranslationPlugin.cs10
-rw-r--r--BCT/TranslationPlugins/TranslationPlugins.csproj55
4 files changed, 306 insertions, 0 deletions
diff --git a/BCT/TranslationPlugins/PhoneControlsPlugin.cs b/BCT/TranslationPlugins/PhoneControlsPlugin.cs
new file mode 100644
index 00000000..d63b6489
--- /dev/null
+++ b/BCT/TranslationPlugins/PhoneControlsPlugin.cs
@@ -0,0 +1,205 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+
+namespace TranslationPlugins {
+ public enum Visibility { Visible, Collapsed };
+
+ public enum Event { Click, Checked, Unchecked };
+
+ public class HandlerSignature {
+ public static string[] getParameterTypesForHandler(Event controlEvent) {
+ switch (controlEvent) {
+ case Event.Checked:
+ case Event.Unchecked:
+ case Event.Click:
+ return new string[] { "object", "System.WindowsRoutedventArgs" };
+ default:
+ throw new NotImplementedException("Handlers for event: " + controlEvent + " not supported yet");
+ }
+ }
+ // TODO it would be nice to be dynamic on handler names and parameters
+ // TODO for now you just have to know the handler signature for each event at load time, and for now we only handle a handful of default control events
+ public string Name;
+ public string[] ParameterTypes;
+ }
+
+ class ControlInfoStructure {
+ public string Name;
+ public string ClassName;
+ public bool IsEnabled;
+ public Visibility Visible;
+ private IDictionary<Event, IList<HandlerSignature>> handlers;
+
+ public ControlInfoStructure() {
+ handlers = new Dictionary<Event, IList<HandlerSignature>>();
+ }
+
+ public void setHandler(Event p, string handler) {
+ IList<HandlerSignature> eventHandlers;
+ try {
+ eventHandlers = handlers[p];
+ } catch (KeyNotFoundException) {
+ eventHandlers= new List<HandlerSignature>();
+ }
+
+ HandlerSignature newHandler= new HandlerSignature();
+ newHandler.Name= handler;
+ newHandler.ParameterTypes= HandlerSignature.getParameterTypesForHandler(p);
+ eventHandlers.Add(newHandler);
+ }
+
+ public IList<HandlerSignature> getHandlers(Event p) {
+ try {
+ return handlers[p];
+ } catch (KeyNotFoundException) {
+ return new List<HandlerSignature>();
+ }
+ }
+ }
+
+ class PageStructure {
+ public PageStructure() {
+ controlsInfo = new Dictionary<string, ControlInfoStructure>();
+ }
+
+ public string PageClassName;
+ public string PageXAML;
+
+ private IDictionary<string, ControlInfoStructure> controlsInfo;
+ public ControlInfoStructure getControlInfo(string controlName) {
+ try {
+ return controlsInfo[controlName];
+ } catch (KeyNotFoundException) {
+ return null;
+ }
+ }
+
+ public void setControlInfo(string controlName, ControlInfoStructure controlInfo) {
+ controlsInfo[controlName] = controlInfo;
+ }
+ }
+
+ public class PhoneControlsPlugin : TranslationPlugin {
+ // TODO this will probably need a complete rewrite once it is event based, and make it more push than pull
+ // TODO but it doesn't make sense right now to make it BCT or CCI aware
+ private static int CONFIG_LINE_FIELDS= 9;
+ private static int PAGE_CLASS_FIELD= 0;
+ private static int PAGE_XAML_FIELD= 1;
+ private static int CONTROL_CLASS_FIELD= 2;
+ private static int CONTROL_NAME_FIELD= 3;
+ private static int ENABLED_FIELD= 4;
+ private static int VISIBILITY_FIELD= 5;
+ private static int CLICK_HANDLER_FIELD= 6;
+ private static int CHECKED_HANDLER_FIELD= 7;
+ private static int UNCHECKED_HANDLER_FIELD = 8;
+
+ private IDictionary<string, PageStructure> pageStructureInfo;
+
+ public PhoneControlsPlugin(string configFile) {
+ pageStructureInfo = new Dictionary<string, PageStructure>();
+ StreamReader fileStream = null;
+ try {
+ fileStream = new StreamReader(configFile);
+ } catch (Exception e) {
+ if (e is DirectoryNotFoundException || e is FileNotFoundException || e is IOException) {
+ // TODO log, I don't want to terminate BCT because of this
+ } else if (e is ArgumentException || e is ArgumentNullException) {
+ // TODO log, I don't want to terminate BCT because of this
+ } else {
+ throw;
+ }
+ }
+
+ LoadControlStructure(fileStream);
+
+ if (fileStream != null)
+ fileStream.Close();
+ }
+
+ private void LoadControlStructure(StreamReader configStream) {
+ // TODO it would be nice to have some kind of dynamic definition of config format
+ // TODO for now remember that config format is CSV
+ // TODO each line is <pageClassName>,<pageXAMLPath>,<controlClassName>,<controlName>,<IsEnabledValue>,<VisibilityValue>,<ClickValue>,<CheckedValue>,<UncheckedValue>
+ // TODO check PhoneControlsExtractor.py
+
+ // TODO the page.xaml value is saved with no directory information: if two pages exist with same name but different directories it will treat them as the same
+ // TODO I'm not handling this for now, and I won't be handling relative/absolute URI either for now
+
+ try {
+ string pageClass, pageXAML, controlClass, controlName, enabled, visibility, clickHandler, checkedHandler, uncheckedHandler;
+ string configLine = configStream.ReadLine();
+ string[] inputLine;
+ PageStructure pageStr;
+ ControlInfoStructure controlInfoStr;
+
+ while (configLine != null) {
+ inputLine = configLine.Split(',');
+
+ if (inputLine.Length != CONFIG_LINE_FIELDS)
+ throw new ArgumentException("Config input line contains wrong number of fields: " + inputLine.Length + ", expected " + CONFIG_LINE_FIELDS);
+
+ pageClass = inputLine[PAGE_CLASS_FIELD];
+ pageXAML = inputLine[PAGE_XAML_FIELD];
+ controlClass = inputLine[CONTROL_CLASS_FIELD];
+ controlName = inputLine[CONTROL_NAME_FIELD];
+ enabled = inputLine[ENABLED_FIELD];
+ visibility = inputLine[VISIBILITY_FIELD];
+ clickHandler = inputLine[CLICK_HANDLER_FIELD];
+ checkedHandler = inputLine[CHECKED_HANDLER_FIELD];
+ uncheckedHandler = inputLine[UNCHECKED_HANDLER_FIELD];
+
+ try {
+ pageStr = pageStructureInfo[pageClass];
+ } catch (KeyNotFoundException) {
+ pageStr = new PageStructure();
+ pageStr.PageClassName = pageClass;
+ pageStr.PageXAML = pageXAML;
+ }
+
+ controlInfoStr= pageStr.getControlInfo(controlName);
+ if (controlInfoStr == null) {
+ controlInfoStr = new ControlInfoStructure();
+ controlInfoStr.Name = controlName;
+ controlInfoStr.ClassName = controlClass;
+ }
+ controlInfoStr.IsEnabled = Boolean.Parse(enabled);
+ controlInfoStr.Visible = visibility == "Collapsed" ? Visibility.Collapsed : Visibility.Visible;
+ controlInfoStr.setHandler(Event.Click, clickHandler);
+ controlInfoStr.setHandler(Event.Checked, checkedHandler);
+ controlInfoStr.setHandler(Event.Unchecked, uncheckedHandler);
+
+ pageStr.setControlInfo(controlName, controlInfoStr);
+ configLine = configStream.ReadLine();
+
+ }
+ } catch (Exception) {
+ // TODO log, I don't want to terminate BCT because of this
+ }
+ }
+
+ public void getControlsForPage(string pageClass) {
+ }
+
+ public string getXAMLForPage(string pageClass) {
+ return pageStructureInfo[pageClass].PageXAML;
+ }
+
+ public bool getIsEnabled(string pageClass, string controlName) {
+ return pageStructureInfo[pageClass].getControlInfo(controlName).IsEnabled;
+ }
+
+ public Visibility getVisibility(string pageClass, string controlName) {
+ return pageStructureInfo[pageClass].getControlInfo(controlName).Visible;
+ }
+
+ public IList<HandlerSignature> getHandlers(string pageClass, string controlName, string eventName) {
+ if (eventName != "Checked" && eventName != "Unchecked" && eventName != "Click")
+ throw new NotImplementedException("Event " + eventName + " is not translated or defined for control " + controlName + " in page " + pageClass);
+
+ return pageStructureInfo[pageClass].getControlInfo(controlName).getHandlers((Event) Event.Parse(typeof(Event), eventName));
+ }
+ }
+}
diff --git a/BCT/TranslationPlugins/Properties/AssemblyInfo.cs b/BCT/TranslationPlugins/Properties/AssemblyInfo.cs
new file mode 100644
index 00000000..8158eb08
--- /dev/null
+++ b/BCT/TranslationPlugins/Properties/AssemblyInfo.cs
@@ -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("TranslationPlugins")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("TranslationPlugins")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 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("c26f68f2-14fb-4a47-8707-b7de569865cc")]
+
+// 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")]
diff --git a/BCT/TranslationPlugins/TranslationPlugin.cs b/BCT/TranslationPlugins/TranslationPlugin.cs
new file mode 100644
index 00000000..e8907a09
--- /dev/null
+++ b/BCT/TranslationPlugins/TranslationPlugin.cs
@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TranslationPlugins {
+ public class TranslationPlugin {
+ // TODO ideally these should really work as plugins, possibly registering as callbacks to some BCT events.
+ }
+}
diff --git a/BCT/TranslationPlugins/TranslationPlugins.csproj b/BCT/TranslationPlugins/TranslationPlugins.csproj
new file mode 100644
index 00000000..9a27e949
--- /dev/null
+++ b/BCT/TranslationPlugins/TranslationPlugins.csproj
@@ -0,0 +1,55 @@
+<?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>{8C242D42-9714-440F-884D-F64F09E78C7B}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>TranslationPlugins</RootNamespace>
+ <AssemblyName>TranslationPlugins</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>
+ <ItemGroup>
+ <Reference Include="System" />
+ <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="PhoneControlsPlugin.cs" />
+ <Compile Include="TranslationPlugin.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> \ No newline at end of file