http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/FileNames.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/FileNames.cs b/lang/cs/Source/TANG/Examples/FileNames.cs deleted file mode 100644 index d371908..0000000 --- a/lang/cs/Source/TANG/Examples/FileNames.cs +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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.Examples -{ - public class FileNames - { - public static string Examples = @"Org.Apache.Reef.Tang.Examples"; - public static string Common = @"Org.Apache.Reef.Common"; - public static string Tasks = @"Org.Apache.Reef.Tasks"; - public static string Seconds = "Org.Apache.Reef.Tang.Examples.Timer+Seconds"; - public static string Timer = "Org.Apache.Reef.Tang.Examples.Timer"; - public static string B = "Org.Apache.Reef.Tang.Examples.B"; - public static string B1 = "Org.Apache.Reef.Tang.Examples.B+B1"; - public static string B2 = "Org.Apache.Reef.Tang.Examples.B+B1+B2"; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/ForksInjectorInConstructor.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/ForksInjectorInConstructor.cs b/lang/cs/Source/TANG/Examples/ForksInjectorInConstructor.cs deleted file mode 100644 index c78141a..0000000 --- a/lang/cs/Source/TANG/Examples/ForksInjectorInConstructor.cs +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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; -/** - * 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.Linq; -using System.Text; -using System.Threading.Tasks; -using Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Tang.Implementations; -using Org.Apache.Reef.Tang.Interface; - -namespace Org.Apache.Reef.Tang.Examples -{ - public class ForksInjectorInConstructor - { - [Inject] - public ForksInjectorInConstructor(IInjector i) - { - ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { @"Org.Apache.Reef.Tang.Examples" }); - //cb.BindImplementation(Number.class, typeof(Int32)); - i.ForkInjector(new IConfiguration[] { cb.Build() }); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/GenericArgument.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/GenericArgument.cs b/lang/cs/Source/TANG/Examples/GenericArgument.cs deleted file mode 100644 index dd1a228..0000000 --- a/lang/cs/Source/TANG/Examples/GenericArgument.cs +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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 Org.Apache.Reef.Tang.Annotations; -using Org.Apache.Reef.Wake.RX; - -namespace Org.Apache.Reef.Tang.Examples -{ - public class GenericArgument<T> : AbstractObserver<T> - { - [Inject] - public GenericArgument() - { - } - - public override void OnNext(T arg1) - { - throw new NotImplementedException(); - } - } - - public class ClassWithGenericArgument<T> - { - private T _obj; - - public ClassWithGenericArgument(T obj) - { - _obj = obj; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/GenericAsArgument.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/GenericAsArgument.cs b/lang/cs/Source/TANG/Examples/GenericAsArgument.cs deleted file mode 100644 index 54e73ab..0000000 --- a/lang/cs/Source/TANG/Examples/GenericAsArgument.cs +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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. - */ - -namespace Org.Apache.Reef.Tang.Examples -{ - public class Event<TPayload> - { - public Event() - { - } - - public Event(StreamEvent<TPayload> trillEvent) - { - } - - public StreamEvent<TPayload> ToStreamEvent() - { - return null; - } - } - - public class StreamEvent<T> - { - public StreamEvent() - { - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/NamedParameterConstructors.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/NamedParameterConstructors.cs b/lang/cs/Source/TANG/Examples/NamedParameterConstructors.cs deleted file mode 100644 index 347c6a4..0000000 --- a/lang/cs/Source/TANG/Examples/NamedParameterConstructors.cs +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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; -using Org.Apache.Reef.Tang.Annotations; - -namespace Org.Apache.Reef.Tang.Examples -{ - public class NamedParameterConstructors - { - [NamedParameter()] - public class X : Name<String> - { - }; - - [Inject] - public NamedParameterConstructors(String x, [Parameter(typeof(X))] String y) - { - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/Properties/AssemblyInfo.cs b/lang/cs/Source/TANG/Examples/Properties/AssemblyInfo.cs deleted file mode 100644 index dcb9bc5..0000000 --- a/lang/cs/Source/TANG/Examples/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,55 +0,0 @@ -/** - * 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.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("Examples")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Examples")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[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("cb44520c-2fd1-4d3b-9b9a-250f94a11239")] - -// 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")] http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/ShortNameFooAB.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/ShortNameFooAB.cs b/lang/cs/Source/TANG/Examples/ShortNameFooAB.cs deleted file mode 100644 index ae81a82..0000000 --- a/lang/cs/Source/TANG/Examples/ShortNameFooAB.cs +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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; -using Org.Apache.Reef.Tang.Annotations; - -namespace Org.Apache.Reef.Tang.Examples -{ - [NamedParameter(ShortName = "fooA")] - public class ShortNameFooA : Name<String> - { - } - - //when same short name is used, exception would throw when building the class hierarchy - [NamedParameter(ShortName = "fooB")] - public class ShortNameFooB : Name<Int32> - { - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/SimpleConstructors.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/SimpleConstructors.cs b/lang/cs/Source/TANG/Examples/SimpleConstructors.cs deleted file mode 100644 index 2a4aa4c..0000000 --- a/lang/cs/Source/TANG/Examples/SimpleConstructors.cs +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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 Org.Apache.Reef.Tang.Annotations; - -namespace Org.Apache.Reef.Tang.Examples -{ - public class SimpleConstructors - { - [Inject] - public SimpleConstructors() - { - } - - [Inject] - public SimpleConstructors(int x) - { - } - - [Inject] - public SimpleConstructors(int x, String y) - { - } - - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/TestClasses.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/TestClasses.cs b/lang/cs/Source/TANG/Examples/TestClasses.cs deleted file mode 100644 index 03a7c70..0000000 --- a/lang/cs/Source/TANG/Examples/TestClasses.cs +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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; -using Org.Apache.Reef.Tang.Annotations; - -namespace Org.Apache.Reef.Tang.Examples -{ - public interface A - { - - } - - public class B : A - { - public class B1 - { - public class B2 { } - } - } - - public class C : B - { - string s; - int v; - - [Inject] - public C(string s, int v) - { - this.s = s; - this.v = v; - } - } - - public static class E - { - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/Timer.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/Timer.cs b/lang/cs/Source/TANG/Examples/Timer.cs deleted file mode 100644 index a65d717..0000000 --- a/lang/cs/Source/TANG/Examples/Timer.cs +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.Threading; -using Org.Apache.Reef.Tang.Annotations; - -namespace Org.Apache.Reef.Tang.Examples -{ - public class Timer - { - [NamedParameter("Number of seconds to sleep", "sec", "10")] - public class Seconds : Name<Int32> { } - private readonly int seconds; - - [Inject] - public Timer([Parameter(typeof(Seconds))] int seconds) - { - if (seconds < 0) - { - throw new ArgumentException("Cannot sleep for negative time!"); - } - this.seconds = seconds; - } - - public void sleep() - { - Thread.Sleep(seconds * 1000); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Examples/TweetExample.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Examples/TweetExample.cs b/lang/cs/Source/TANG/Examples/TweetExample.cs deleted file mode 100644 index 774f48d..0000000 --- a/lang/cs/Source/TANG/Examples/TweetExample.cs +++ /dev/null @@ -1,90 +0,0 @@ -/** - * 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 Org.Apache.Reef.Tang.Annotations; - -namespace Org.Apache.Reef.Tang.Examples -{ - public interface ISMS - { - void SendSMS(String msg, long phoneNumber); - } - - public interface ITweetFactory - { - String GetTweet(); - } - - public class MockTweetFactory : ITweetFactory - { - [Inject] - public MockTweetFactory() { - } - - public String GetTweet() - { - return "@tw #bbq bbqftw!!! gopher://vuwed.wefd/bbqftw!"; - } - } - - public class MockSMS : ISMS - { - [Inject] - public MockSMS() - { - } - - public void SendSMS(String msg, long phoneNumber) - { - if (phoneNumber != 8675309) - { - throw new ArgumentException("Unknown recipient"); - } - // success! - } - } - - public class Tweeter - { - ITweetFactory tw; - ISMS sms; - long phoneNumber; - - [NamedParameter(Documentation="Phone number", ShortName="number", DefaultValue="1800")] - public class PhoneNumber : Name<long> { } - [Inject] - public Tweeter(ITweetFactory tw, ISMS sms, [Parameter(typeof(PhoneNumber))] long phoneNumber) - { - this.tw = tw; - this.sms = sms; - this.phoneNumber = phoneNumber; - } - - [Inject] - public Tweeter([Parameter(typeof(PhoneNumber))] long phoneNumber) - { - this.phoneNumber = phoneNumber; - } - - public void sendMessage() - { - sms.SendSMS(tw.GetTweet(), phoneNumber); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Tang/Annotations/DefaultImplementation.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Tang/Annotations/DefaultImplementation.cs b/lang/cs/Source/TANG/Tang/Annotations/DefaultImplementation.cs deleted file mode 100644 index 26ac15b..0000000 --- a/lang/cs/Source/TANG/Tang/Annotations/DefaultImplementation.cs +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 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.Annotations -{ - /// <summary> - /// DefaultImplementationAttribute - /// </summary> - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)] - public class DefaultImplementationAttribute : System.Attribute - { - public Type Value { get; set; } - public string Name { get; set; } - - public DefaultImplementationAttribute(Type val = null, string n = "") - { - Name = n; - Value = val; - } - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Tang/Annotations/Inject.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Tang/Annotations/Inject.cs b/lang/cs/Source/TANG/Tang/Annotations/Inject.cs deleted file mode 100644 index 2816a18..0000000 --- a/lang/cs/Source/TANG/Tang/Annotations/Inject.cs +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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. - */ -namespace Org.Apache.Reef.Tang.Annotations -{ - /// <summary> - /// InjectAttribute - /// </summary> - [System.AttributeUsage(System.AttributeTargets.Constructor)] - public class InjectAttribute : System.Attribute - { - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Tang/Annotations/Name.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Tang/Annotations/Name.cs b/lang/cs/Source/TANG/Tang/Annotations/Name.cs deleted file mode 100644 index a9316c4..0000000 --- a/lang/cs/Source/TANG/Tang/Annotations/Name.cs +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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. - */ -namespace Org.Apache.Reef.Tang.Annotations -{ - /// <summary> - /// Base class for named parameters - /// </summary> - /// <typeparam name="T"></typeparam> - public interface Name<T> - { - } -} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Tang/Annotations/NamedParameter.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Tang/Annotations/NamedParameter.cs b/lang/cs/Source/TANG/Tang/Annotations/NamedParameter.cs deleted file mode 100644 index d156a32..0000000 --- a/lang/cs/Source/TANG/Tang/Annotations/NamedParameter.cs +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.Annotations -{ - [System.AttributeUsage(System.AttributeTargets.Class)] - public class NamedParameterAttribute : System.Attribute - { - public string Documentation { get; set; } - public string ShortName { get; set; } - public string DefaultValue { get; set; } - public Type DefaultClass { get; set; } - public string[] DefaultValues { get; set; } - public Type[] DefaultClasses { get; set; } - - public NamedParameterAttribute(string documentation = "", string shortName = "", - string defaultValue = "", Type defaultClass = null, string[] defaultValues = null, Type[] defaultClasses = null) - { - this.Documentation = documentation; - this.ShortName = shortName; - this.DefaultValue = defaultValue; - this.DefaultClass = defaultClass; - this.DefaultValues = defaultValues; - this.DefaultClasses = defaultClasses; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Tang/Annotations/Parameter.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Tang/Annotations/Parameter.cs b/lang/cs/Source/TANG/Tang/Annotations/Parameter.cs deleted file mode 100644 index 7c3c2ae..0000000 --- a/lang/cs/Source/TANG/Tang/Annotations/Parameter.cs +++ /dev/null @@ -1,39 +0,0 @@ -/** - * 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.Annotations -{ - /// <summary> - /// ParameterAttribute - /// </summary> - [System.AttributeUsage(System.AttributeTargets.Parameter)] - public class ParameterAttribute : System.Attribute - { - public ParameterAttribute() - { - } - - public ParameterAttribute(Type value) - { - Value = value; - } - - public Type Value { get; set; } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Tang/Annotations/Unit.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Tang/Annotations/Unit.cs b/lang/cs/Source/TANG/Tang/Annotations/Unit.cs deleted file mode 100644 index bd3cad0..0000000 --- a/lang/cs/Source/TANG/Tang/Annotations/Unit.cs +++ /dev/null @@ -1,29 +0,0 @@ -/** - * 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.Annotations -{ - /// <summary> - /// UnitAttribute - /// </summary> - [AttributeUsage(AttributeTargets.Class, Inherited = false)] - public class UnitAttribute : System.Attribute - { - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Tang/Exceptions/BindException.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Tang/Exceptions/BindException.cs b/lang/cs/Source/TANG/Tang/Exceptions/BindException.cs deleted file mode 100644 index 2ad1658..0000000 --- a/lang/cs/Source/TANG/Tang/Exceptions/BindException.cs +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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 BindException : SystemException - { - //private static readonly long serialVersionUID = 1L; - public BindException(String message) - : base(message) - { - } - - public BindException(string message, Exception innerException) - : base(message, innerException) - { - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Source/TANG/Tang/Exceptions/ClassHierarchyException.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Source/TANG/Tang/Exceptions/ClassHierarchyException.cs b/lang/cs/Source/TANG/Tang/Exceptions/ClassHierarchyException.cs deleted file mode 100644 index 5b29f35..0000000 --- a/lang/cs/Source/TANG/Tang/Exceptions/ClassHierarchyException.cs +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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 ClassHierarchyException : SystemException - { - public ClassHierarchyException(String msg) : base(msg) - { - } - - public ClassHierarchyException(string message, Exception innerException) - : base(message, innerException) - { - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/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 deleted file mode 100644 index 3e4bd19..0000000 --- a/lang/cs/Source/TANG/Tang/Exceptions/IllegalStateException.cs +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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/c1b5200f/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 deleted file mode 100644 index c1e248f..0000000 --- a/lang/cs/Source/TANG/Tang/Exceptions/InjectionException.cs +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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/c1b5200f/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 deleted file mode 100644 index 45209ac..0000000 --- a/lang/cs/Source/TANG/Tang/Exceptions/NameResolutionException.cs +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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/c1b5200f/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 deleted file mode 100644 index 1c52463..0000000 --- a/lang/cs/Source/TANG/Tang/Exceptions/ParseException.cs +++ /dev/null @@ -1,36 +0,0 @@ -/** - * 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/c1b5200f/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 deleted file mode 100644 index 8d1c952..0000000 --- a/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/AvroConfiguration.cs +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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/c1b5200f/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 deleted file mode 100644 index bfa23cb..0000000 --- a/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationDataContract/ConfigurationEntry.cs +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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/c1b5200f/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 deleted file mode 100644 index e82e4e3..0000000 --- a/lang/cs/Source/TANG/Tang/Formats/AvroConfigurationSerializer.cs +++ /dev/null @@ -1,324 +0,0 @@ -/** - * 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/c1b5200f/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 deleted file mode 100644 index 506cc85..0000000 --- a/lang/cs/Source/TANG/Tang/Formats/ConfigurationFile.cs +++ /dev/null @@ -1,371 +0,0 @@ -/** - * 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
