You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/01/29 21:43:01 UTC

[17/31] incubator-reef git commit: [REEF-97] Add the REEF.NET code base

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Exceptions/IllegalStateException.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Exceptions/IllegalStateException.cs b/lang/cs/Source/TANG/Tang/Exceptions/IllegalStateException.cs
new file mode 100644
index 0000000..3e4bd19
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Exceptions/IllegalStateException.cs
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 Org.Apache.Reef.Tang.Exceptions
+{
+    public class IllegalStateException : Exception
+    {
+        public IllegalStateException()
+            : base()
+        {
+        }
+
+        public IllegalStateException(String msg)
+            : base(msg)
+        {           
+        }
+
+        public IllegalStateException(string message, Exception innerException)
+            : base(message, innerException)
+        {
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Exceptions/InjectionException.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Exceptions/InjectionException.cs b/lang/cs/Source/TANG/Tang/Exceptions/InjectionException.cs
new file mode 100644
index 0000000..c1e248f
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Exceptions/InjectionException.cs
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 Org.Apache.Reef.Tang.Exceptions
+{
+    public class InjectionException : Exception
+    {
+        public InjectionException(String msg)
+            : base(msg)
+        {           
+        }
+
+        public InjectionException(string message, Exception innerException)
+            : base(message, innerException)
+        {
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Exceptions/NameResolutionException.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Exceptions/NameResolutionException.cs b/lang/cs/Source/TANG/Tang/Exceptions/NameResolutionException.cs
new file mode 100644
index 0000000..45209ac
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Exceptions/NameResolutionException.cs
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 Org.Apache.Reef.Tang.Exceptions
+{
+    public class NameResolutionException : BindException
+    {
+        //private static readonly long serialVersionUID = 1L;
+        public NameResolutionException(String name, String longestPrefix) :
+            base(string.Format("Could not resolve {0}.  Search ended at prefix {1}. This can happen due to typos in class names that are passed as strings, or because Tang uses Assembly loader other than the one that generated the class reference ((make sure you use the full name of a class)",
+                name, longestPrefix))
+        {
+        }
+
+        public NameResolutionException(string message, Exception innerException)
+            : base(message, innerException)
+        {
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Exceptions/ParseException.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Exceptions/ParseException.cs b/lang/cs/Source/TANG/Tang/Exceptions/ParseException.cs
new file mode 100644
index 0000000..1c52463
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Exceptions/ParseException.cs
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 Org.Apache.Reef.Tang.Exceptions
+{
+    public class ParseException : BindException
+    {
+       // private static readonly long serialVersionUID = 1L;
+        public ParseException(String message)
+            : base(message)
+        {           
+        }
+
+        public ParseException(string message, Exception innerException)
+            : base(message, innerException)
+        {
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/AvroConfiguration.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/AvroConfiguration.cs b/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/AvroConfiguration.cs
new file mode 100644
index 0000000..8d1c952
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/AvroConfiguration.cs
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Collections.Generic;
+using System.Runtime.Serialization;
+using Newtonsoft.Json;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    [KnownType(typeof(HashSet<ConfigurationEntry>))]
+    [DataContract(Name = "AvroConfiguration", Namespace = "org.apache.reef.tang.formats.avro")]
+    public class AvroConfiguration
+    {
+        public AvroConfiguration(HashSet<ConfigurationEntry> bindings)
+        {
+            this.Bindings = bindings;
+        }
+
+        public AvroConfiguration()
+        {
+        }
+
+        [DataMember]
+        public HashSet<ConfigurationEntry> Bindings { get; set; }
+
+        public static AvroConfiguration GetAvroConfigurationFromEmbeddedString(string jsonString)
+        {
+            return JsonConvert.DeserializeObject<AvroConfiguration>(jsonString);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/ConfigurationEntry.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/ConfigurationEntry.cs b/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/ConfigurationEntry.cs
new file mode 100644
index 0000000..bfa23cb
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/ConfigurationEntry.cs
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Runtime.Serialization;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    [DataContract(Name = "ConfigurationEntry", Namespace = "org.apache.reef.tang.formats.avro")]
+    [KnownType(typeof(string))]
+    public class ConfigurationEntry
+    {
+        public ConfigurationEntry(string key, string value)
+        {
+            this.key = key;
+            this.value = value;
+        }
+
+        public ConfigurationEntry()
+        {
+        }
+
+        [DataMember]
+        public string key { get; set; }
+
+        [DataMember]
+        public string value { get; set; }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationSerializer.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationSerializer.cs b/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationSerializer.cs
new file mode 100644
index 0000000..e82e4e3
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationSerializer.cs
@@ -0,0 +1,324 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using Microsoft.Hadoop.Avro;
+using Microsoft.Hadoop.Avro.Container;
+using Org.Apache.Reef.Utilities.Logging;
+using Org.Apache.Reef.Tang.Annotations;
+using Org.Apache.Reef.Tang.Exceptions;
+using Org.Apache.Reef.Tang.Implementations;
+using Org.Apache.Reef.Tang.Interface;
+using Org.Apache.Reef.Tang.Types;
+using Newtonsoft.Json;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public class AvroConfigurationResolver : Microsoft.Hadoop.Avro.AvroPublicMemberContractResolver
+    {
+        public override TypeSerializationInfo ResolveType(Type type)
+        {
+            var serInfo = base.ResolveType(type);
+            serInfo.Aliases.Add("org.apache.reef.tang.formats.avro.AvroConfiguration");
+            serInfo.Aliases.Add("org.apache.reef.tang.formats.avro.Bindings");
+            serInfo.Aliases.Add("org.apache.reef.tang.formats.avro.ConfigurationEntry");
+
+            return serInfo;
+        }
+    }
+
+    public class AvroConfigurationSerializer : IConfigurationSerializer
+    {
+        private static readonly Logger LOGGER = Logger.GetLogger(typeof(AvroConfigurationResolver));
+
+        [Inject]
+        public AvroConfigurationSerializer()
+        {
+        }
+
+        public byte[] ToByteArray(IConfiguration c)
+        {
+            AvroConfiguration obj = ToAvroConfiguration(c);
+            return AvroSerialize(obj);
+        }
+
+        public string GetSchema()
+        {
+            var serializer = AvroSerializer.Create<AvroConfiguration>();
+            return serializer.WriterSchema.ToString();
+        }
+
+        public void ToFileStream(IConfiguration c, string fileName)
+        {
+            using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate))
+            {
+                byte[] data = ToByteArray(c);
+                fs.Write(data, 0, data.Length);
+            }
+        }
+
+        public void ToFile(IConfiguration c, string fileName)
+        {
+            var avronConfigurationData = ToAvroConfiguration(c);
+            using (var buffer = new MemoryStream())
+            {
+                using (var w = AvroContainer.CreateWriter<AvroConfiguration>(buffer, Codec.Null))
+                {
+                    using (var writer = new SequentialWriter<AvroConfiguration>(w, 24))
+                    {
+                        // Serialize the data to stream using the sequential writer
+                        writer.Write(avronConfigurationData);
+                    }
+                }
+
+                if (!WriteFile(buffer, fileName))
+                {
+                    var e = new ApplicationException("Error during file operation. Quitting method: " + fileName);
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                }
+            }          
+        }
+
+        public IConfiguration FromByteArray(byte[] bytes)
+        {
+            AvroConfiguration avroConf = AvroDeseriaize(bytes);
+            return FromAvro(avroConf);
+        }
+
+        public IConfiguration AddFromByteArray(ICsConfigurationBuilder cb, byte[] bytes)
+        {
+            AvroConfiguration avroConf = AvroDeseriaize(bytes);
+            return AddFromAvro(cb, avroConf);
+        }
+
+        public IConfiguration FromFileStream(string fileName)
+        {
+            byte[] bytes = File.ReadAllBytes(fileName);
+            AvroConfiguration avroConf = AvroDeseriaize(bytes);
+            return FromAvro(avroConf);
+        }
+
+        public IConfiguration FromFile(string fileName)
+        {
+            AvroConfiguration avroConf = AvroDeseriaizeFromFile(fileName);
+            return FromAvro(avroConf);
+        }
+
+        public string ToBase64String(IConfiguration c)
+        {
+            return Convert.ToBase64String(ToByteArray(c));
+        }
+
+        public IConfiguration FromBase64String(string serializedConfig)
+        {
+            var b = Convert.FromBase64String(serializedConfig);
+            return FromByteArray(b);
+        }
+
+        public string ToString(IConfiguration c)
+        {
+            byte[] bytes = ToByteArray(c);
+            AvroConfiguration avroConf = AvroDeseriaize(bytes);
+            string s = JsonConvert.SerializeObject(avroConf, Formatting.Indented);
+            return s;
+        }
+
+        public IConfiguration FromString(string josonString)
+        {
+            AvroConfiguration avroConf = JsonConvert.DeserializeObject<AvroConfiguration>(josonString);
+            return FromAvro(avroConf);
+        }
+
+        public AvroConfiguration AvroDeseriaizeFromFile(string fileName)
+        {
+            AvroConfiguration avroConf = null;
+            try
+            {
+                using (var buffer = new MemoryStream())
+                {
+                    if (!ReadFile(buffer, fileName))
+                    {
+                        var e = new ApplicationException("Error during file operation. Quitting method : " + fileName);
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                    }
+
+                    buffer.Seek(0, SeekOrigin.Begin);
+                    //AvroSerializerSettings settings = new AvroSerializerSettings();
+                    //settings.Resolver = new AvroConfigurationResolver();
+                    //using (var reader = new SequentialReader<AvroConfiguration>(AvroContainer.CreateReader<AvroConfiguration>(buffer, true, settings, new CodecFactory())))
+                    using (var reader = new SequentialReader<AvroConfiguration>(AvroContainer.CreateReader<AvroConfiguration>(buffer, true))) 
+                    {
+                        var results = reader.Objects;
+
+                        if (results != null)
+                        {
+                            avroConf = (AvroConfiguration)results.First();
+                        }
+                    }
+                }
+            }
+            catch (SerializationException ex)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
+                var e = new ApplicationException("Cannot deserialize the file: " + fileName, ex);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+
+            return avroConf;
+        }
+
+        public IConfiguration FromAvro(AvroConfiguration avroConfiguration)
+        {
+            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+
+            return AddFromAvro(cb, avroConfiguration);
+        }
+
+        public IConfiguration FromAvro(AvroConfiguration avroConfiguration, IClassHierarchy classHierarchy)
+        {
+            IConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(classHierarchy);
+
+            return AddFromAvro(cb, avroConfiguration);
+        }
+
+        public AvroConfiguration ToAvroConfiguration(IConfiguration c)
+        {
+            ConfigurationImpl conf = (ConfigurationImpl)c;
+            HashSet<ConfigurationEntry> l = new HashSet<ConfigurationEntry>();
+
+            foreach (IClassNode opt in conf.GetBoundImplementations())
+            {
+                l.Add(new ConfigurationEntry(opt.GetFullName(), conf.GetBoundImplementation(opt).GetFullName()));
+            }
+
+            foreach (IClassNode opt in conf.GetBoundConstructors())
+            {
+                l.Add(new ConfigurationEntry(opt.GetFullName(), conf.GetBoundConstructor(opt).GetFullName()));
+            }
+            foreach (INamedParameterNode opt in conf.GetNamedParameters())
+            {
+                l.Add(new ConfigurationEntry(opt.GetFullName(), conf.GetNamedParameter(opt)));
+            }
+            foreach (IClassNode cn in conf.GetLegacyConstructors())
+            {
+                StringBuilder sb = new StringBuilder();
+                ConfigurationFile.Join(sb, "-", conf.GetLegacyConstructor(cn).GetArgs().ToArray<IConstructorArg>());
+                l.Add(new ConfigurationEntry(cn.GetFullName(), ConfigurationBuilderImpl.INIT + '(' + sb.ToString() + ')'));
+            }
+
+            IEnumerator bs = conf.GetBoundSets();
+            while (bs.MoveNext())
+            {
+                KeyValuePair<INamedParameterNode, object> e = (KeyValuePair<INamedParameterNode, object>)bs.Current;
+
+                string val = null;
+                if (e.Value is string)
+                {
+                    val = (string)e.Value;
+                }
+                else if (e.Value is INode)
+                {
+                    val = ((INode)e.Value).GetFullName();
+                }
+                else
+                {
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER);
+                }
+
+                l.Add(new ConfigurationEntry(e.Key.GetFullName(), val));
+            }
+
+            return new AvroConfiguration(l);
+        }
+        
+        private byte[] AvroSerialize(AvroConfiguration obj)
+        {
+            var serializer = AvroSerializer.Create<AvroConfiguration>();
+            using (MemoryStream stream = new MemoryStream())
+            {
+                serializer.Serialize(stream, obj);
+                return stream.GetBuffer();
+            }
+        }
+
+        private AvroConfiguration AvroDeseriaize(string serializedConfig)
+        {
+            return AvroDeseriaize(Convert.FromBase64String(serializedConfig));
+        }
+
+        private AvroConfiguration AvroDeseriaize(byte[] serializedBytes)
+        {
+            var serializer = AvroSerializer.Create<AvroConfiguration>();
+            using (var stream = new MemoryStream(serializedBytes))
+            {
+                return serializer.Deserialize(stream);
+            }
+        }
+
+        private bool ReadFile(MemoryStream outputStream, string path)
+        {
+            try
+            {
+                byte[] data = File.ReadAllBytes(path);
+                outputStream.Write(data, 0, data.Length);
+                return true;
+            }
+            catch (Exception e)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                return false;
+            }
+        }
+
+        private bool WriteFile(MemoryStream inputStream, string path)
+        {
+            try
+            {
+                using (FileStream fs = File.Create(path))
+                {
+                    inputStream.WriteTo(fs);
+                }
+                return true;
+            }
+            catch (Exception e)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                return false;
+            }
+        }
+
+        private IConfiguration AddFromAvro(IConfigurationBuilder cb, AvroConfiguration avroConfiguration)
+        {
+            IList<KeyValuePair<string, string>> settings = new List<KeyValuePair<string, string>>();
+
+            foreach (ConfigurationEntry e in avroConfiguration.Bindings)
+            {
+                settings.Add(new KeyValuePair<string, string>(e.key, e.value));
+            }
+            ConfigurationFile.ProcessConfigData(cb, settings);   //TODO
+            return cb.Build();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/ConfigurationFile.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/ConfigurationFile.cs b/lang/cs/Source/TANG/Tang/Formats/ConfigurationFile.cs
new file mode 100644
index 0000000..506cc85
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/ConfigurationFile.cs
@@ -0,0 +1,371 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Org.Apache.Reef.Utilities.Logging;
+using Org.Apache.Reef.Tang.Exceptions;
+using Org.Apache.Reef.Tang.Implementations;
+using Org.Apache.Reef.Tang.Interface;
+using Org.Apache.Reef.Tang.Types;
+using Org.Apache.Reef.Tang.Util;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public class ConfigurationFile
+    {
+        private static readonly Logger LOGGER = Logger.GetLogger(typeof(ConfigurationFile));
+
+        //#region Avro serialization
+        //public static string AvroSerialize(IConfiguration c)
+        //{
+        //    var obj = new ConfigurationDataContract(ToConfigurationStringList(c));
+        //    var serializer = AvroSerializer.Create<ConfigurationDataContract>();
+        //    var schema = serializer.WriterSchema.ToString();
+
+        //    var stream = new MemoryStream();
+        //    serializer.Serialize(stream, obj);
+        //    return Convert.ToBase64String(stream.GetBuffer());
+        //}
+
+        //public static void AvroDeseriaize(IConfigurationBuilder conf, string serializedConfig)
+        //{
+        //    var serializer2 = AvroSerializer.Create<ConfigurationDataContract>();
+        //    ConfigurationDataContract confgDataObj;
+        //    using (var stream2 = new MemoryStream(Convert.FromBase64String(serializedConfig)))
+        //    {
+        //        confgDataObj = serializer2.Deserialize(stream2);
+        //    }
+
+        //    IList<KeyValuePair<string, string>> settings = new List<KeyValuePair<string, string>>();
+
+        //    foreach (string line in confgDataObj.Bindings)
+        //    {
+        //        string[] p = line.Split('=');
+        //        settings.Add(new KeyValuePair<string, string>(p[0], p[1]));
+        //    }
+        //    ProcessConfigData(conf, settings);
+        //}
+
+        //public static IConfiguration AvroDeseriaize(string serializedConfig)
+        //{
+        //    ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+        //    AvroDeseriaize(cb, serializedConfig);
+        //    return cb.Build();
+        //}
+
+        //public static IConfiguration AvroDeseriaizeFromFile(string configFileName)
+        //{
+        //    ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+        //    AddConfigurationFromFileUsingAvro(cb, configFileName);
+        //    return cb.Build();
+        //}
+
+        //public static void WriteConfigurationFileUsingAvro(IConfiguration c, string fileName)
+        //{
+        //    using (FileStream aFile = new FileStream(fileName, FileMode.OpenOrCreate))
+        //    {
+        //        using (StreamWriter sw = new StreamWriter(aFile))
+        //        {
+        //            sw.Write(AvroSerialize(c));
+        //        }
+        //    }
+        //}
+
+        //public static void AddConfigurationFromFileUsingAvro(IConfigurationBuilder conf, string configFileName)
+        //{
+        //    string serializedString;
+        //    using (StreamReader reader = new StreamReader(configFileName))
+        //    {
+        //        serializedString = reader.ReadLine();
+        //    }
+        //    AvroDeseriaize(conf, serializedString);
+        //}
+        //#endregion Avro serialization
+
+        #region text file serialization
+        public static void WriteConfigurationFile(IConfiguration c, string fileName)
+        {
+            using (FileStream aFile = new FileStream(fileName, FileMode.Create))
+            {
+                using (StreamWriter sw = new StreamWriter(aFile))
+                {
+                    sw.Write(ToConfigurationString(c));
+                }
+            }
+        }
+
+        public static String ToConfigurationString(IConfiguration c) 
+        {
+            StringBuilder sb = new StringBuilder();
+            foreach (string s in ToConfigurationStringList(c)) 
+            {
+                sb.Append(s);
+                sb.Append('\n');
+            }
+            return sb.ToString();
+        }
+
+        private static string GetFullName(INode n)
+        {
+            string s = n.GetFullName();
+            Type t = ReflectionUtilities.GetTypeByName(s);
+            return t.FullName;
+        }
+    
+
+        private static string GetFullName(string name)
+        {
+            try
+            {
+                Type t = ReflectionUtilities.GetTypeByName(name);
+                return t.FullName;
+            }
+            catch (ApplicationException e)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Warning, LOGGER);
+                return name;//if name is not a type, return as it was
+                
+            }
+        }
+
+        private static string GetAssemlyName(string s)
+        {
+            try
+            {
+                Type t = ReflectionUtilities.GetTypeByName(s);
+                return ReflectionUtilities.GetAssemblyQualifiedName(t);
+            }
+            catch (ApplicationException e)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Warning, LOGGER);
+                return s;//if name is not a type, return as it was
+            }
+        }
+
+        public static HashSet<String> ToConfigurationStringList(IConfiguration c) 
+        {
+            ConfigurationImpl conf = (ConfigurationImpl) c;
+            HashSet<string> l = new HashSet<string>();
+            foreach (IClassNode opt in conf.GetBoundImplementations()) 
+            {
+//                l.Add(opt.GetFullName() + '=' + Escape(conf.GetBoundImplementation(opt).GetFullName()));
+                l.Add(GetFullName(opt) + '=' + Escape(GetFullName(conf.GetBoundImplementation(opt))));
+            }
+            
+            foreach (IClassNode opt in conf.GetBoundConstructors()) 
+            {
+//                l.Add(opt.GetFullName() + '=' + Escape(conf.GetBoundConstructor(opt).GetFullName()));
+                l.Add(GetFullName(opt) + '=' + Escape(GetFullName(conf.GetBoundConstructor(opt))));
+            }
+            foreach (INamedParameterNode opt in conf.GetNamedParameters()) 
+            {
+//                l.Add(opt.GetFullName() + '=' + Escape(conf.GetNamedParameter(opt)));
+                l.Add(GetFullName(opt) + '=' + Escape(GetFullName(conf.GetNamedParameter(opt))));
+            }
+            foreach (IClassNode cn in conf.GetLegacyConstructors())
+            {
+                StringBuilder sb = new StringBuilder();
+                Join(sb, "-", conf.GetLegacyConstructor(cn).GetArgs().ToArray<IConstructorArg>());
+                l.Add(GetFullName(cn) + Escape('=' + ConfigurationBuilderImpl.INIT + '(' + sb.ToString() + ')'));
+                //l.Add(cn.GetFullName() + Escape('=' + ConfigurationBuilderImpl.INIT + '(' + sb.ToString() + ')'));
+                //s.append(cn.getFullName()).append('=').append(ConfigurationBuilderImpl.INIT).append('(');
+                //      .append(")\n");
+            }
+
+
+            IEnumerator bs = conf.GetBoundSets();
+            while (bs.MoveNext())
+            {
+                KeyValuePair<INamedParameterNode, object> e = (KeyValuePair<INamedParameterNode, object>)bs.Current;
+
+            //}
+            //foreach (KeyValuePair<INamedParameterNode, object> e in conf.GetBoundSets()) 
+            //{
+                string val = null;
+                if (e.Value is string) 
+                {
+                    val = GetFullName((string)e.Value);
+                } 
+                else if (e.Value is INode) 
+                {
+//                    val = ((INode)e.Value).GetFullName();
+                    val = GetFullName((INode)e.Value);
+                } 
+                else 
+                {
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER);
+                }
+                
+//                l.Add(e.Key.GetFullName() + '=' + Escape(val));
+                l.Add(GetFullName(e.Key) + '=' + Escape(val));
+                //      s.append(e.getKey().getFullName()).append('=').append(val).append("\n");
+            }
+
+            return l;//s.toString();
+        }
+
+        public static IConfiguration GetConfiguration(string configString)
+        {
+            byte[] array = Encoding.Default.GetBytes(configString);
+            return GetConfiguration(array);
+        }
+
+        public static IConfiguration GetConfiguration(byte[] configStream)
+        {
+            ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
+            AddConfigurationFromStream(cb, configStream);
+            return cb.Build();
+        }
+
+        public static void AddConfigurationFromStream(IConfigurationBuilder conf, byte[] configData)
+        {
+            using (StreamReader reader = new StreamReader(new MemoryStream(configData), Encoding.Default))
+            {
+                 AddConfiguration(conf, reader);
+            }
+        }
+
+        public static void AddConfigurationFromFile(IConfigurationBuilder conf, string configFileName)
+        {            
+            using (StreamReader reader = new StreamReader(configFileName))
+            {
+                 AddConfiguration(conf, reader);
+            }
+        }
+
+        public static void AddConfigurationFromString(IConfigurationBuilder conf, string configData)
+        {
+            byte[] array = Encoding.ASCII.GetBytes(configData);
+            AddConfigurationFromStream(conf, array);
+        }
+
+        private static void AddConfiguration(IConfigurationBuilder conf, StreamReader reader)
+        {
+            //IDictionary<string, string> settings = new Dictionary<string, string>();
+            IList<KeyValuePair<string, string>> settings = new List<KeyValuePair<string, string>>();
+
+            while (!reader.EndOfStream)
+            {
+                string line = reader.ReadLine();
+                string[] p = line.Split('=');
+                if (p.Length == 2)
+                {
+                    settings.Add(new KeyValuePair<string, string>(GetAssemlyName(p[0]), GetAssemlyName(p[1])));
+                } 
+                else if (p.Length > 2)
+                {
+                    string v = line.Substring(p[0].Length + 1, line.Length - p[0].Length - 1);
+                    settings.Add(new KeyValuePair<string, string>(GetAssemlyName(p[0]), GetAssemlyName(v)));
+                }
+                else
+                {
+                    var e = new ApplicationException("Config data is not in format of KeyValuePair: " + line);
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                }  
+            }
+            ProcessConfigData(conf, settings);
+        }
+
+        public static IDictionary<string, string> FromFile(string fileName)
+        {
+            IDictionary<string, string> property = new Dictionary<string, string>();
+            using (StreamReader sr = new StreamReader(fileName))
+            {
+                while (!sr.EndOfStream)
+                {
+                    string line = sr.ReadLine();
+                    string[] p = line.Split('=');
+                    property.Add(ConfigurationFile.GetAssemlyName(p[0]), ConfigurationFile.GetAssemlyName(p[1]));
+                }
+            }
+            return property;
+        }
+
+        public static void ProcessConfigData(IConfigurationBuilder conf, IList<KeyValuePair<string, string>> settings)
+        {
+            foreach (KeyValuePair<string, string> kv in settings)
+            {
+                try
+                {
+                    conf.Bind(kv.Key, kv.Value);
+                }
+                catch (BindException ex)
+                {
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
+                    var e = new BindException("Failed to process configuration tuple: [" + kv.Key + "=" + kv.Value + "]", ex);
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                }
+                catch (ClassHierarchyException ex)
+                {
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
+                    var e = new ClassHierarchyException("Failed to process configuration tuple: [" + kv.Key + "=" + kv.Value + "]", ex);
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                }
+            }
+        }
+
+        public static void ProcessConfigData(IConfigurationBuilder conf, IDictionary<string, string> settings)
+        {
+            IList<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
+
+            foreach (KeyValuePair<string, string> kv in settings)
+            {
+                list.Add(kv);
+            }
+
+            ProcessConfigData(conf, list);
+        }
+ 
+       /**
+        * Replace any \'s in the input string with \\. and any "'s with \".
+        * @param in
+        * @return
+        */
+        private static string Escape(string str) 
+        {
+            return str;  //TODO
+            // After regexp escaping \\\\ = 1 slash, \\\\\\\\ = 2 slashes.
+
+            // Also, the second args of replaceAll are neither strings nor regexps, and
+            // are instead a special DSL used by Matcher. Therefore, we need to double
+            // escape slashes (4 slashes) and quotes (3 slashes + ") in those strings.
+            // Since we need to write \\ and \", we end up with 8 and 7 slashes,
+            // respectively.
+            //return in.ReplaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\\\"");
+        }
+
+        public static StringBuilder Join(StringBuilder sb, String sep, IConstructorArg[] types) 
+        {
+            if (types.Length > 0) 
+            {
+                sb.Append(types[0].GetType());
+                for (int i = 1; i < types.Length; i++) 
+                {
+                    sb.Append(sep).Append(types[i].GetType());
+                }
+            }
+            return sb;
+        }
+        #endregion text file serialization
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/ConfigurationModule.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/ConfigurationModule.cs b/lang/cs/Source/TANG/Tang/Formats/ConfigurationModule.cs
new file mode 100644
index 0000000..a75428b
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/ConfigurationModule.cs
@@ -0,0 +1,302 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Org.Apache.Reef.Utilities.Logging;
+using Org.Apache.Reef.Tang.Exceptions;
+using Org.Apache.Reef.Tang.Interface;
+using Org.Apache.Reef.Tang.Util;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    /**
+     * Allows applications to bundle sets of configuration options together into 
+     * discrete packages.  Unlike more conventional approaches,
+     * ConfigurationModules store such information in static data structures that
+     * can be statically discovered and sanity-checked. 
+     * 
+     * @see Org.Apache.Reef.Tang.Formats.TestConfigurationModule for more information and examples.
+     *
+     */
+    public class ConfigurationModule
+    {
+        public readonly ConfigurationModuleBuilder Builder;
+        private static readonly Logger LOGGER = Logger.GetLogger(typeof(ConfigurationModule));
+        private readonly MonotonicHashSet<FieldInfo> reqSet = new MonotonicHashSet<FieldInfo>();
+        private readonly MonotonicHashMap<object, Type> setImpls = new MonotonicHashMap<object, Type>();
+        private readonly MonotonicMultiHashMap<object, Type> setImplSets = new MonotonicMultiHashMap<object, Type>();
+        private readonly MonotonicMultiHashMap<object, string> setLateImplSets = new MonotonicMultiHashMap<object, string>();
+        private readonly MonotonicMultiHashMap<object, string> setParamSets = new MonotonicMultiHashMap<object, string>();
+        private readonly MonotonicHashMap<object, string> setLateImpls = new MonotonicHashMap<object, string>();
+        private readonly MonotonicHashMap<object, string> setParams = new MonotonicHashMap<object, string>();
+
+        private readonly MonotonicHashMap<object, IList<Type>> setImplLists = new MonotonicHashMap<object, IList<Type>>();
+        private readonly MonotonicHashMap<object, IList<string>> setParamLists = new MonotonicHashMap<object, IList<string>>();
+        private readonly MonotonicHashMap<object, IList<string>> setLateImplLists = new MonotonicHashMap<object, IList<string>>();
+        
+        public ConfigurationModule(ConfigurationModuleBuilder builder) 
+        {
+            this.Builder = builder.DeepCopy();
+        }
+
+         //public final <T> ConfigurationModule set(Impl<T> opt, Class<? extends T> impl)
+        public ConfigurationModule Set<T, U>(IImpl<T> opt, GenericType<U> impl) 
+            where U : T 
+        {
+            Type implType = typeof(U);
+            
+            ConfigurationModule c = DeepCopy();
+            c.ProcessSet(opt);
+            if (c.Builder.SetOpts.Contains(opt)) 
+            {
+                c.setImplSets.Add(opt, implType);
+            } 
+            else 
+            {
+                c.setImpls.Add(opt, implType);
+            }
+            return c;
+        }
+
+        public ConfigurationModule Set<T>(IImpl<T> opt, string impl) 
+        {
+            ConfigurationModule c = DeepCopy();
+            c.ProcessSet(opt);
+            if (c.Builder.SetOpts.Contains(opt)) 
+            {
+                c.setLateImplSets.Add(opt, impl);
+            } 
+            else 
+            {
+                c.setLateImpls.Add(opt, impl);
+            }
+            return c;
+        }
+
+        public ConfigurationModule Set<T, U>(IParam<T> opt, GenericType<U> val) 
+            where U : T
+        {
+            Type t = typeof(U);
+            string n = ReflectionUtilities.GetAssemblyQualifiedName(t);
+            return Set(opt, n);
+        }
+
+        public ConfigurationModule Set(IParam<bool> opt, bool val)
+        {
+            return Set(opt, val);
+        }
+
+        ////TODO
+        ////public readonly ConfigurationModule set(Param<? extends Number> opt, Number val) 
+        ////{
+        ////    return set(opt, val);
+        ////}
+
+        public ConfigurationModule Set<T>(IParam<T> opt, string val) 
+        {
+            //var o = (IParam<object>)opt;
+            ConfigurationModule c = DeepCopy();
+            c.ProcessSet(opt);
+            if (c.Builder.SetOpts.Contains(opt)) 
+            {
+                c.setParamSets.Add(opt, val);
+            } 
+            else 
+            {
+                c.setParams.Add(opt, val);
+            }
+            return c;
+        }
+
+        public ConfigurationModule Set<T>(IImpl<IList<T>> opt, IList<string> impl)
+        {
+            ConfigurationModule c = DeepCopy();
+            c.ProcessSet(opt);
+            c.setLateImplLists.Add(opt, impl);
+            return c;
+        }
+
+        public ConfigurationModule Set<T>(IParam<IList<T>> opt, IList<string> impl)
+        {
+            ConfigurationModule c = DeepCopy();
+            c.ProcessSet(opt);
+            c.setParamLists.Add(opt, impl);
+            return c;
+        }
+
+        public ConfigurationModule Set<T>(IImpl<IList<T>> opt, IList<Type> impl)
+        {
+            ConfigurationModule c = DeepCopy();
+            c.ProcessSet(opt);
+            c.setImplLists.Add(opt, impl);
+            return c;
+        }
+
+        public IConfiguration Build()
+        {
+            ConfigurationModule c = DeepCopy();
+    
+            if (!c.reqSet.ContainsAll(c.Builder.ReqDecl)) 
+            {
+                ISet<FieldInfo> missingSet = new MonotonicHashSet<FieldInfo>();
+                foreach (FieldInfo f in c.Builder.ReqDecl) 
+                {
+                    if (!c.reqSet.Contains(f)) 
+                    {
+                        missingSet.Add(f);
+                    }
+                }
+                var e = new BindException(
+                    "Attempt to build configuration before setting required option(s): "
+                    + Builder.ToString(missingSet));
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+  
+            foreach (Type clazz in c.Builder.FreeImpls.Keys) 
+            {
+                object i = c.Builder.FreeImpls.Get(clazz);
+                if (c.setImpls.ContainsKey(i))
+                {
+                    var cb = (ICsInternalConfigurationBuilder)c.Builder.B;
+                    cb.Bind(clazz, c.setImpls.Get(i));
+                } 
+                else if (c.setLateImpls.ContainsKey(i)) 
+                {
+                    c.Builder.B.Bind(ReflectionUtilities.GetAssemblyQualifiedName(clazz), c.setLateImpls.Get(i));
+                } 
+                else if (c.setImplSets.ContainsKey(i) || c.setLateImplSets.ContainsKey(i))
+                {
+                    foreach (Type clz in c.setImplSets.GetValuesForKey(i))
+                    {
+                        ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder) c.Builder.B;
+                        b.BindSetEntry(clazz, clz);
+                    }
+                    foreach (string s in c.setLateImplSets.GetValuesForKey(i))
+                    {
+                        ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder) c.Builder.B;
+                        b.BindSetEntry(clazz, s);
+                    }
+                } 
+                else if (c.setImplLists.ContainsKey(i))
+                {
+                    ICsConfigurationBuilder b = (ICsConfigurationBuilder) c.Builder.B;
+                    b.BindList(clazz, setImplLists.Get(i));
+                }
+                else if (c.setLateImplLists.ContainsKey(i))
+                {
+                    ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.Builder.B;
+                    b.BindList(clazz, setLateImplLists.Get(i));
+                }
+            }
+            
+            //for (Class<? extends Name<?>> clazz : c.builder.freeParams.Keys) {
+            foreach (Type clazz in c.Builder.FreeParams.Keys) 
+            {
+                object p = c.Builder.FreeParams.Get(clazz);
+                string s = c.setParams.Get(p);
+                bool foundOne = false;
+                if (s != null) 
+                {
+                    ICsConfigurationBuilder cb = c.Builder.B;
+                    cb.BindNamedParameter(clazz, s);
+                    foundOne = true;
+                }
+
+                IList<string> paramListStr = c.setParamLists.Get(p);
+                if (paramListStr != null)
+                {
+                    ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.Builder.B;
+                    b.BindList(clazz, paramListStr);
+                    foundOne = true;
+                }
+
+                foreach (string paramStr in c.setParamSets.GetValuesForKey(p)) 
+                {
+                    ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.Builder.B;
+                    b.BindSetEntry(clazz, paramStr);   
+                    foundOne = true;
+                }
+
+                if (!foundOne) 
+                {
+                    //if (!(p is OptionalParameter<object>)) //p: OptionalParameter<int>, "is" doesn't work here for generic type object
+                    if (!ReflectionUtilities.IsInstanceOfGeneric(p, typeof(OptionalParameter<>)))
+                    {
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new IllegalStateException(), LOGGER);
+                    }
+                }
+            }
+            return c.Builder.B.Build();
+        }
+
+        public void AssertStaticClean() 
+        {
+            if (!(
+                setImpls.IsEmpty() &&
+                setParams.IsEmpty()) &&
+                setImplSets.IsEmpty() &&
+                setLateImplSets.IsEmpty() &&
+                setParamSets.IsEmpty() &&
+                setImplLists.IsEmpty() &&
+                setLateImplLists.IsEmpty() &&
+                setParamLists.IsEmpty() &&
+                setLateImpls.IsEmpty())
+            {
+                var e = new ClassHierarchyException("Detected statically set ConfigurationModule Parameter / Implementation.  set() should only be used dynamically.  Use bind...() instead.");
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+        }
+
+        private ConfigurationModule DeepCopy()
+        {
+            ConfigurationModule cm = new ConfigurationModule(Builder.DeepCopy());
+            cm.setImpls.AddAll(setImpls);
+            cm.setParams.AddAll(setParams);
+            cm.setImplSets.AddAll(setImplSets);
+            cm.setParamSets.AddAll(setParamSets);
+            cm.setLateImplSets.AddAll(setLateImplSets);
+            cm.setImplLists.AddAll(setImplLists);
+            cm.setParamLists.AddAll(setParamLists);
+            cm.setLateImplLists.AddAll(setLateImplLists);
+            cm.setLateImpls.AddAll(setLateImpls);
+            cm.reqSet.AddAll(reqSet);
+            return cm;
+        }
+
+        private void ProcessSet(object impl)
+        {
+            FieldInfo f;
+            Builder.Map.TryGetValue(impl, out f);
+            if (f == null)
+            { 
+                var e = new ClassHierarchyException("Unknown Impl/Param when setting " + impl.GetType().Name + ".  Did you pass in a field from some other module?");
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+            if (!reqSet.Contains(f))
+            {
+                reqSet.Add(f);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/ConfigurationModuleBuilder.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/ConfigurationModuleBuilder.cs b/lang/cs/Source/TANG/Tang/Formats/ConfigurationModuleBuilder.cs
new file mode 100644
index 0000000..e9640d5
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/ConfigurationModuleBuilder.cs
@@ -0,0 +1,519 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Reflection;
+using System.Text;
+using Org.Apache.Reef.Utilities.Logging;
+using Org.Apache.Reef.Tang.Annotations;
+using Org.Apache.Reef.Tang.Exceptions;
+using Org.Apache.Reef.Tang.Implementations;
+using Org.Apache.Reef.Tang.Interface;
+using Org.Apache.Reef.Tang.Util;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public class ConfigurationModuleBuilder
+    {
+        public readonly ICsConfigurationBuilder B = TangFactory.GetTang().NewConfigurationBuilder();
+        public readonly MonotonicHashSet<FieldInfo> ReqDecl = new MonotonicHashSet<FieldInfo>();
+        public readonly MonotonicHashSet<FieldInfo> OptDecl = new MonotonicHashSet<FieldInfo>();
+        public readonly MonotonicHashSet<object> SetOpts = new MonotonicHashSet<object>();
+        public readonly MonotonicHashMap<object, FieldInfo> Map = new MonotonicHashMap<object, FieldInfo>();
+        public readonly MonotonicHashMap<Type, object> FreeImpls = new MonotonicHashMap<Type, object>();
+        public readonly MonotonicHashMap<Type, object> FreeParams = new MonotonicHashMap<Type, object>(); //Type must extends from Name<>
+
+        private static readonly Logger LOGGER = Logger.GetLogger(typeof(ConfigurationModuleBuilder));
+        private static readonly ISet<Type> ParamBlacklist = new MonotonicHashSet<Type>(new Type[] { typeof(IParam<>), typeof(IImpl<>) });
+        private static readonly ISet<string> ParamTypes =
+            new MonotonicHashSet<string>(new string[] { typeof(RequiredImpl<>).Name, typeof(OptionalImpl<>).Name, typeof(RequiredParameter<>).Name, typeof(OptionalParameter<>).Name });
+
+        private readonly MonotonicHashSet<FieldInfo> reqUsed = new MonotonicHashSet<FieldInfo>();
+        private readonly MonotonicHashSet<FieldInfo> optUsed = new MonotonicHashSet<FieldInfo>();
+        private readonly MonotonicHashMap<Type, string> lateBindClazz = new MonotonicHashMap<Type, string>();
+
+        public ConfigurationModuleBuilder()
+        {
+            foreach (FieldInfo f in GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static))
+            {
+                Type t = f.FieldType;
+                if (ParamBlacklist.Contains(t)) 
+                {
+                    var e = new ClassHierarchyException(
+                    "Found a field of type " + t + " which should be a Required/Optional Parameter/Implementation instead");
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                } 
+                if (ParamTypes.Contains(t.Name)) 
+                {
+                    if (!f.IsPublic) 
+                    {
+                        var e = new ClassHierarchyException("Found a non-public configuration option in " + GetType() + ": " + f);
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                    }
+                
+                    if (!f.IsStatic) 
+                    {
+                        var e = new ClassHierarchyException("Found a non-static configuration option in " + GetType() + ": " + f);
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                    }
+                    if (!f.IsInitOnly)
+                    {
+                        var e = new ClassHierarchyException("Found a non-readonly configuration option in " + GetType() + ": " + f);
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                    }
+                    object o = null;
+                    try 
+                    {
+                        o = f.GetValue(null);
+                    } 
+                    catch (ArgumentException e)  
+                    {
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                        var ex = new ClassHierarchyException("Could not look up field instance in " + GetType() + " field: " + f, e);
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
+                    }
+                    catch (FieldAccessException e) 
+                    {
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                        var ex = new ClassHierarchyException("Could not look up field instance in " + GetType() + " field: " + f, e);
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
+                    }
+
+                    if (Map.ContainsKey(o)) 
+                    {
+                        FieldInfo fi;
+                        Map.TryGetValue(o, out fi);
+                        var e = new ClassHierarchyException("Detected aliased instances in class " + GetType() + " for fields " + fi + " and " + f);
+                        Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+                    }
+                    if (ReflectionUtilities.IsGenericTypeof(typeof(RequiredImpl<>), t) || ReflectionUtilities.IsGenericTypeof(typeof(RequiredParameter<>), t))  
+                    {
+                        ReqDecl.Add(f);
+                    } 
+                    else 
+                    {
+                        OptDecl.Add(f);
+                    }
+                    Map.Add(o, f);
+               }
+            }
+        }
+
+        private ConfigurationModuleBuilder(ConfigurationModuleBuilder c)
+        {
+            try
+            {
+                B.AddConfiguration(c.B.Build());
+            }
+            catch (BindException e)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                var ex = new ClassHierarchyException("Build error in ConfigurationModuleBuilder: " + e);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
+            }
+            ReqDecl.UnionWith(c.ReqDecl);
+            OptDecl.UnionWith(c.OptDecl);
+            reqUsed.UnionWith(c.reqUsed);
+            optUsed.UnionWith(c.optUsed);
+            SetOpts.UnionWith(c.SetOpts);
+            Map.AddAll(c.Map);
+            FreeImpls.AddAll(c.FreeImpls);
+            FreeParams.AddAll(c.FreeParams);
+            lateBindClazz.AddAll(c.lateBindClazz);
+        }
+
+        public ConfigurationModuleBuilder Merge(ConfigurationModule d) 
+        {
+            if (d == null) 
+            {
+                var e = new NullReferenceException("If merge() was passed a static final field that is initialized to non-null, then this is almost certainly caused by a circular class dependency.");
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+            try 
+            {
+                d.AssertStaticClean();
+            } 
+            catch (ClassHierarchyException ex) 
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
+                var e = new ClassHierarchyException(ReflectionUtilities.GetAssemblyQualifiedName(GetType()) + ": detected attempt to merge with ConfigurationModule that has had set() called on it", ex);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+            ConfigurationModuleBuilder c = DeepCopy();
+            try 
+            {
+                c.B.AddConfiguration(d.Builder.B.Build());
+            } 
+            catch (BindException ex) 
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
+                var e = new ClassHierarchyException("Error in AddConfiguration in Merge: " + ex);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+            c.ReqDecl.AddAll(d.Builder.ReqDecl);
+            c.OptDecl.AddAll(d.Builder.OptDecl);
+            c.reqUsed.AddAll(d.Builder.reqUsed);
+            c.optUsed.AddAll(d.Builder.optUsed);
+            c.SetOpts.AddAll(d.Builder.SetOpts);
+            //c.ListOpts.AddAll(d.Builder.ListOpts);
+            c.Map.AddAll(d.Builder.Map);
+            c.FreeImpls.AddAll(d.Builder.FreeImpls);
+            c.FreeParams.AddAll(d.Builder.FreeParams);
+            c.lateBindClazz.AddAll(d.Builder.lateBindClazz);
+    
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindSetEntry<U, T>(GenericType<U> iface, string impl) 
+            where U : Name<ISet<T>>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            try 
+            {
+                ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.B;
+                b.BindSetEntry(typeof(U), impl);
+            } 
+            catch (BindException ex) 
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
+                var e = new ClassHierarchyException("Error in BindSetEntry: " + ex);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindSetEntry<U, V, T>(GenericType<U> iface, GenericType<V> impl) 
+            where U : Name<ISet<T>> 
+            where V : T
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            try 
+            {
+                c.B.BindSetEntry<U, V, T>(iface, impl);
+            } 
+            catch (BindException ex) 
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(ex, Level.Error, LOGGER);
+                var e = new ClassHierarchyException("Error in BindSetEntry: " + ex);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindSetEntry<U, T>(GenericType<U> iface, IImpl<T> opt) 
+            where U : Name<ISet<T>> 
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            Type ifaceType = typeof(U);
+
+            c.ProcessUse(opt);
+            c.FreeImpls.Add(ifaceType, opt);  
+            
+            if (!SetOpts.Contains(opt)) 
+            { 
+                c.SetOpts.Add(opt); 
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindSetEntry<U, T>(GenericType<U> iface, IParam<T> opt)
+            where U : Name<ISet<T>>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            Type ifaceType = typeof(U);
+            c.ProcessUse(opt);
+
+            c.FreeParams.Add(ifaceType, opt);
+            if (!SetOpts.Contains(opt)) 
+            { 
+                c.SetOpts.Add(opt); 
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindList<U, T>(GenericType<U> iface, IList<string> impl)
+            where U : Name<IList<T>>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            try
+            {
+                ICsInternalConfigurationBuilder b = (ICsInternalConfigurationBuilder)c.B;
+                b.BindList(typeof(U), impl);
+            }
+            catch (BindException ex)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.CaughtAndThrow(new ClassHierarchyException("Error in BindList: " + ex), Level.Error, LOGGER);
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindList<U, T>(GenericType<U> iface, IImpl<IList<T>> opt)
+            where U : Name<IList<T>>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            Type ifaceType = typeof(U);
+
+            c.ProcessUse(opt);
+            c.FreeImpls.Add(ifaceType, opt);
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindList<U, T>(GenericType<U> iface, IParam<IList<T>> opt)
+            where U : Name<IList<T>>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            Type ifaceType = typeof(U);
+            c.ProcessUse(opt);
+
+            c.FreeParams.Add(ifaceType, opt);
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindImplementation<U, T>(GenericType<U> iface, GenericType<T> impl) 
+            where T : U
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            try 
+            {
+                c.B.BindImplementation(iface, impl);
+            } 
+            catch (BindException e) 
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                 Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindImplementation: ", e), LOGGER);
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindImplementation<T>(GenericType<T> iface, string impl) 
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+
+            c.lateBindClazz.Add(typeof(T), impl);
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindImplementation<U, T>(GenericType<T> iface, IImpl<U> opt) 
+            where U : T
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            c.ProcessUse(opt);
+            Type ifaceType = typeof(T);
+            c.FreeImpls.Add(ifaceType, opt);
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindNamedParameter<U, T>(GenericType<U> name, string value) 
+            where U : Name<T>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            try 
+            {
+                c.B.BindNamedParameter<U, T>(name, value);
+            } 
+            catch (BindException e) 
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindNamedParameter: ", e), LOGGER);
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindNamedParameter<U, T>(GenericType<U> name, IParam<T> opt)
+            where U : Name<T>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            c.ProcessUse(opt);
+            Type nameType = typeof(U);
+            c.FreeParams.Add(nameType, opt);
+            return c;
+        }
+
+        //public final <T> ConfigurationModuleBuilder bindNamedParameter(Class<? extends Name<T>> iface, Class<? extends T> impl)  
+        //if V is T, you'd better to use public ConfigurationModuleBuilder BindNamedParameter<U, T>(GenericType<U> iface, GenericType<T> impl) defined below
+        public ConfigurationModuleBuilder BindNamedParameter<U, V, T>(GenericType<U> iface, GenericType<V> impl)
+            where U : Name<T>
+            where V : T
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            try
+            {
+                c.B.BindNamedParameter<U, V, T>(iface, impl);
+            }
+            catch (BindException e)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindNamedParameter: ", e), LOGGER);
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindNamedParameter<U, T>(GenericType<U> iface, GenericType<T> impl)
+            where U : Name<T>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            try
+            {
+                c.B.BindNamedParameter<U, T, T>(iface, impl);
+            }
+            catch (BindException e)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindNamedParameter: ", e), LOGGER);
+            }
+            return c;
+        }
+
+        // public final <T> ConfigurationModuleBuilder bindNamedParameter(Class<? extends Name<T>> iface, Impl<? extends T> opt)
+        //if ValueType is T, you would better to use public ConfigurationModuleBuilder BindNamedParameter<U, T>(GenericType<U> iface, IImpl<T> opt)
+        public ConfigurationModuleBuilder BindNamedParameter<U, V, T>(GenericType<U> iface, IImpl<V> opt)
+            where U : Name<T>
+            where V : T
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            c.ProcessUse(opt);
+            Type ifaceType = typeof(U);
+            c.FreeImpls.Add(ifaceType, opt);
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindNamedParameter<U, T>(GenericType<U> iface, IImpl<T> opt)
+            where U : Name<T>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            c.ProcessUse(opt);
+            Type ifaceType = typeof(U);
+            c.FreeImpls.Add(ifaceType, opt);
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindConstructor<T, U>(GenericType<T> clazz, GenericType<U> constructor)
+            where U : IExternalConstructor<T>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            try
+            {
+               c.B.BindConstructor<T, U>(clazz, constructor);
+            }
+            catch (BindException e)
+            {
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException("Error in BindConstructor: ", e), LOGGER);
+            }
+            return c;
+        }
+
+        public ConfigurationModuleBuilder BindConstructor<T, U>(GenericType<T> cons, IImpl<U> v)
+            where U : IExternalConstructor<T>
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+            c.ProcessUse(v);
+            Type consType = typeof(T);
+            var i = (IImpl<object>)v;
+            c.FreeImpls.Add(consType, i);
+            return c;
+        }
+
+        public ConfigurationModule Build()
+        {
+            ConfigurationModuleBuilder c = DeepCopy();
+    
+            if (!(c.reqUsed.ContainsAll(c.ReqDecl) && c.optUsed.ContainsAll(c.OptDecl))) 
+            {
+                ISet<FieldInfo> fset = new MonotonicHashSet<FieldInfo>();
+                foreach (FieldInfo f in c.ReqDecl) 
+                {
+                    if (!c.reqUsed.Contains(f)) 
+                    {
+                        fset.Add(f);
+                    }
+                }
+                foreach (FieldInfo f in c.OptDecl) 
+                {
+                    if (!c.optUsed.Contains(f)) 
+                    {
+                        fset.Add(f);
+                    }
+                }
+                var e = new ClassHierarchyException(
+                    "Found declared options that were not used in binds: "
+                    + ToString(fset));
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+            foreach (Type clz in c.lateBindClazz.Keys) 
+            {
+                try 
+                {
+                    c.B.Bind(ReflectionUtilities.GetAssemblyQualifiedName(clz), c.lateBindClazz.Get(clz));
+                } 
+                catch (NameResolutionException e) 
+                {
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                    var ex = new ClassHierarchyException("ConfigurationModule refers to unknown class: " + c.lateBindClazz.Get(clz), e);
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
+                } 
+                catch (BindException e) 
+                {
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
+                    var ex = new ClassHierarchyException("bind failed while initializing ConfigurationModuleBuilder", e);
+                    Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
+                }
+            }
+            return new ConfigurationModule(c);
+        }
+
+        public ConfigurationModuleBuilder DeepCopy() 
+        {
+            return new ConfigurationModuleBuilder(this);
+        }
+
+        public string ToString(ISet<FieldInfo> s) 
+        {
+            StringBuilder sb = new StringBuilder("{");
+            bool first = true;
+            foreach (FieldInfo f in s) 
+            {
+                sb.Append((first ? " " : ", ") + f.Name);
+                first = false;
+            }
+            sb.Append(" }");
+            return sb.ToString();
+        }
+
+        private void ProcessUse(object impl)
+        {
+            FieldInfo f;
+            Map.TryGetValue(impl, out f);
+            if (f == null)
+            {
+                var e = new ClassHierarchyException("Unknown Impl/Param when binding " + impl.GetType().Name + ".  Did you pass in a field from some other module?");
+                Org.Apache.Reef.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
+            }
+            if (!reqUsed.Contains(f))
+            {
+                reqUsed.Add(f);
+            }
+            if (!optUsed.Contains(f))
+            {
+                optUsed.Add(f);
+            }
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/IConfigurationSerializer.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/IConfigurationSerializer.cs b/lang/cs/Source/TANG/Tang/Formats/IConfigurationSerializer.cs
new file mode 100644
index 0000000..ec3baac
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/IConfigurationSerializer.cs
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 Org.Apache.Reef.Tang.Annotations;
+using Org.Apache.Reef.Tang.Formats;
+using Org.Apache.Reef.Tang.Interface;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    [DefaultImplementation(typeof(AvroConfigurationSerializer), "default")]
+    public interface IConfigurationSerializer
+    {
+        void ToFileStream(IConfiguration c, string fileName);
+
+        void ToFile(IConfiguration c, string fileName);
+
+        byte[] ToByteArray(IConfiguration c);
+
+        string ToBase64String(IConfiguration c);
+
+        string ToString(IConfiguration c);
+
+        IConfiguration FromFileStream(string fileName);
+
+        IConfiguration FromFile(string fileName);
+
+        IConfiguration FromByteArray(byte[] bytes);
+
+        IConfiguration FromBase64String(string serializedConfig);
+
+        IConfiguration FromString(string josonString);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/IImpl.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/IImpl.cs b/lang/cs/Source/TANG/Tang/Formats/IImpl.cs
new file mode 100644
index 0000000..70a454d
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/IImpl.cs
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Threading.Tasks;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public interface IImpl<T>
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/IParam.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/IParam.cs b/lang/cs/Source/TANG/Tang/Formats/IParam.cs
new file mode 100644
index 0000000..fa2f93b
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/IParam.cs
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Threading.Tasks;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public interface IParam<T>
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/OptionalImpl.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/OptionalImpl.cs b/lang/cs/Source/TANG/Tang/Formats/OptionalImpl.cs
new file mode 100644
index 0000000..5ba77aa
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/OptionalImpl.cs
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Threading.Tasks;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public sealed class OptionalImpl<T> : IImpl<T> 
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/OptionalParameter.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/OptionalParameter.cs b/lang/cs/Source/TANG/Tang/Formats/OptionalParameter.cs
new file mode 100644
index 0000000..35f0993
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/OptionalParameter.cs
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Threading.Tasks;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public sealed class OptionalParameter<T> : IParam<T> 
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/Provides.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/Provides.cs b/lang/cs/Source/TANG/Tang/Formats/Provides.cs
new file mode 100644
index 0000000..aa5b99b
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/Provides.cs
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Threading.Tasks;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public sealed class Provides<T> 
+    { 
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/RequiredImpl.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/RequiredImpl.cs b/lang/cs/Source/TANG/Tang/Formats/RequiredImpl.cs
new file mode 100644
index 0000000..4181dce
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/RequiredImpl.cs
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Threading.Tasks;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public sealed class RequiredImpl<T> : IImpl<T> 
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/2ae282de/lang/cs/Source/TANG/Tang/Formats/RequiredParameter.cs
----------------------------------------------------------------------
diff --git a/lang/cs/Source/TANG/Tang/Formats/RequiredParameter.cs b/lang/cs/Source/TANG/Tang/Formats/RequiredParameter.cs
new file mode 100644
index 0000000..7c13dd3
--- /dev/null
+++ b/lang/cs/Source/TANG/Tang/Formats/RequiredParameter.cs
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.Threading.Tasks;
+
+namespace Org.Apache.Reef.Tang.Formats
+{
+    public sealed class RequiredParameter<T> : IParam<T> 
+    {
+    }
+}