Exemple #1
0
 public SimulationModel(IOption option, IDataFeedProvider dataFeedProvider, DateTime dateDebut, int plageEstimation)
 {
     this.option           = option ?? throw new ArgumentNullException("Option should not be null");
     this.dataFeedProvider = dataFeedProvider ?? throw new ArgumentNullException("dataFeed should not be null");
     if (dateDebut == null)
     {
         throw new ArgumentNullException("Beginning date should not be null");
     }
     this.dateDebut = new DateTime(2012, 9, 10);
     if (plageEstimation < 2)
     {
         throw new ArgumentOutOfRangeException("Estimation duration should be upper than 2 days");
     }
     this.plageEstimation = plageEstimation;
     Estimateur.dispMatrix(Estimateur.getCovMatrix(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14)));
     if (option.GetType().ToString().EndsWith("VanillaCall"))
     {
         Console.WriteLine("Volatilité: " + Estimateur.Volatilite(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14), new double[] { 1 }, dataFeedProvider));
     }
     else if (option.GetType().ToString().EndsWith("BasketOption"))
     {
         Console.WriteLine("Volatilité: " + Estimateur.Volatilite(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14), ((BasketOption)option).Weights, dataFeedProvider));
     }
     Estimateur.dispMatrix(Estimateur.getCorrMatrix(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14)));
     Console.WriteLine("Correlation moyenne: " + Estimateur.Correlation(dataFeedProvider.GetDataFeed(option, this.dateDebut), plageEstimation, this.dateDebut.AddDays(14)));
 }
Exemple #2
0
        public IPluginOptionViewModel Construct(IOption option)
        {
            if (option is IListOption)
            {
                var optionType = option.GetType().FindBaseType(typeof(ListOption <>));
                if (optionType != null)
                {
                    var tValue  = optionType.GetGenericArguments().First();
                    var generic = _constructListOptionMethodInfo.MakeGenericMethod(tValue);

                    var opt = generic.Invoke(this, new object?[] { option });
                    if (opt != null)
                    {
                        return((IPluginOptionViewModel)opt);
                    }
                }
            }

            return(option switch
            {
                BooleanOption bOption => new PluginBooleanOptionViewModel(bOption, _localizationProvider),
                NumberOption nOption => new PluginNumberOptionViewModel(nOption, _localizationProvider),
                TextOption tOption => new PluginTextOptionViewModel(tOption, _localizationProvider),
                CommandOption cOption => new PluginCommandOptionViewModel(cOption, _localizationProvider),
                EncryptedTextOption eOption => new PluginEncryptedTextOptionViewModel(eOption, _localizationProvider),
                StringCollectionOption sOption => new PluginStringCollectionOptionViewModel(sOption, _localizationProvider),
                DisplayOption dOption => new PluginDisplayOptionViewModel(dOption, _localizationProvider),

                _ => ConstructDisplayOption(option)
            });
Exemple #3
0
 /// <summary>
 /// Get operation instance that implements operation <typeparamref name="T"/> for option interface type <paramref name="optionType"/>.
 /// </summary>
 /// <param name="option"></param>
 /// <param name="optionType">option interface type, a subtype of <see cref="IOption"/></param>
 /// <returns>operation instance</returns>
 /// <exception cref="FileSystemExceptionOptionOperationNotSupported">If operation is not supported.</exception>
 public static T Operation <T>(this IOption option, Type optionType) where T : IOptionOperation
 {
     foreach (object attrib in option.GetType().GetCustomAttributes(typeof(OperationsAttribute), true))
     {
         if (attrib is OperationsAttribute opAttrib)
         {
             //if (!optionType.Equals(opAttrib.OperationsClass)) continue;
             object op = Activator.CreateInstance(opAttrib.OperationsClass);
             if (op is T casted)
             {
                 return(casted);
             }
         }
     }
     foreach (object attrib in optionType.GetCustomAttributes(typeof(OperationsAttribute), true))
     {
         if (attrib is OperationsAttribute opAttrib)
         {
             object op = Activator.CreateInstance(opAttrib.OperationsClass);
             if (op is T casted)
             {
                 return(casted);
             }
         }
     }
     throw new FileSystemExceptionOptionOperationNotSupported(null, null, option, optionType, typeof(T));
 }
Exemple #4
0
        public static object GetValue(this IOption option)
        {
            var optionType = option.GetType();

            MethodInfo getMethod;

            if (!optionValueCache.TryGetValue(optionType, out getMethod))
            {
                getMethod = optionType.GetMethod("GetValue", BindingFlags.Instance | BindingFlags.Public);
            }

            return(getMethod.Invoke(option, emptyParameters));
        }
Exemple #5
0
 /// <summary>
 /// Enumerate all the supported <see cref="IOption"/> Types.
 /// </summary>
 /// <param name="option"></param>
 /// <returns>types</returns>
 public static IEnumerable <Type> OperationTypes(this IOption option)
 {
     foreach (Type type in option.GetType().GetInterfaces())
     {
         if (typeof(IOption).IsAssignableFrom(type) && !typeof(IOption).Equals(type))
         {
             yield return(type);
         }
     }
     if (option is IAdaptableOption adaptable)
     {
         foreach (KeyValuePair <Type, IOption> line in adaptable)
         {
             yield return(line.Key);
         }
     }
 }
Exemple #6
0
 /// <summary>
 /// Get first operation instance for <paramref name="option"/>.
 /// </summary>
 /// <param name="option"></param>
 /// <param name="optionType">option interface type, a subtype of <see cref="IOption"/></param>
 /// <returns>operation instance or null</returns>
 public static IOptionOperation GetOperation(this IOption option, Type optionType)
 {
     foreach (object attrib in option.GetType().GetCustomAttributes(typeof(OperationsAttribute), true))
     {
         if (attrib is OperationsAttribute opAttrib)
         {
             //if (!optionType.Equals(opAttrib.OperationsClass)) continue;
             return((IOptionOperation)Activator.CreateInstance(opAttrib.OperationsClass));
         }
     }
     foreach (object attrib in optionType.GetCustomAttributes(typeof(OperationsAttribute), true))
     {
         if (attrib is OperationsAttribute opAttrib)
         {
             return((IOptionOperation)Activator.CreateInstance(opAttrib.OperationsClass));
         }
     }
     return(null);
 }
 /// <summary>
 /// Create composition of filesystem options.
 /// </summary>
 /// <param name="op">Join operation of same option intefaces</param>
 /// <param name="option1">option to join</param>
 /// <param name="option2">option to join</param>
 public OptionComposition(Op op, IOption option1, IOption option2)
 {
     if (option1 != null)
     {
         // IOption
         foreach (Type type in option1.GetType().GetInterfaces())
         {
             if (typeof(IOption).IsAssignableFrom(type) && !typeof(IOption).Equals(type) && !typeof(IFileSystem).IsAssignableFrom(type))
             {
                 Add(op, type, option1);
             }
         }
         // IAdaptableOption
         if (option1 is IAdaptableOption adaptable)
         {
             foreach (KeyValuePair <Type, IOption> line in adaptable)
             {
                 Add(op, line.Key, line.Value);
             }
         }
     }
     if (option2 != null)
     {
         // IOption
         foreach (Type type in option2.GetType().GetInterfaces())
         {
             if (typeof(IOption).IsAssignableFrom(type) && !typeof(IOption).Equals(type) && !typeof(IFileSystem).IsAssignableFrom(type))
             {
                 Add(op, type, option2);
             }
         }
         // IAdaptableOption
         if (option2 is IAdaptableOption adaptable)
         {
             foreach (KeyValuePair <Type, IOption> line in adaptable)
             {
                 Add(op, line.Key, line.Value);
             }
         }
     }
     Flatten();
 }
Exemple #8
0
 private T GetValueFromObject <T>(IOption value, string propertyName) => value.GetType()
 .GetProperty(propertyName)
 .VerifyNotNull($"Property {propertyName} does not exist")
 .GetValue(value)
 .VerifyNotNull("Property value is null")
 .Func(x => (T)x);
 public void SetProjectOptions(IOption option)
 {
     if (option == null)
     {
         throw new ArgumentNullException(nameof(option));
     }
     else if (!(option is SqlOption))
     {
         throw new NotSupportedException($"This project handler only supports {nameof(SqlOption)} options. {option.GetType().Name} not supported");
     }
     Option = option as SqlOption;
 }
		private static void LoadOption(IOption targetOpt, OptionBaseType opt)
		{
			targetOpt.CanOverride = opt.IsOverrideAllowed;			
			if (targetOpt is BoolOption)
			{
				(targetOpt as BoolOption).Value = Boolean.Parse(opt.Text[0]);
			}
			else if (targetOpt is StringOption)
			{
				(targetOpt as StringOption).Value = opt.Text[0];
			}
			else if (targetOpt is IntegerOption)
			{
				// If Int32.TryParse fails because the string value is null or not in the correct format the (uninitialized) result is zero which is also the default value for options of type integer.
				int result;
				Int32.TryParse(opt.Text[0], out result); 
				(targetOpt as IntegerOption).Value = result;
			}
			else if (targetOpt is EncryptionOption)
			{
				(targetOpt as EncryptionOption).Value = Workshare.Interop.Options.OptionApi.GetRawString(opt.Name, opt.Text[0], _entropy);
			}
			else if (targetOpt is EnumOption)
			{
				EnumOption eo = targetOpt as EnumOption;
				int index = Int32.Parse(opt.Text[0]);
				eo.Value = eo.GetValue(index);
			}
			else if (targetOpt is RangeOption)
			{
				(targetOpt as RangeOption).Value = Int32.Parse(opt.Text[0]);
			}
			else if (targetOpt is ColorOption)
			{
				(targetOpt as ColorOption).Value = OptionMapper.GetColor(opt.Text[0]);
			}
			else
			{
				Workshare.Interop.Logging.Logger.LogError("Option not loaded from WSO due to unknown type : " + targetOpt.Name + "  " + targetOpt.GetType().ToString());
			}

			if (opt is UIOptionType)
			{
				targetOpt.Deploy = (opt as UIOptionType).Deploy;
			}
		}