Пример #1
0
 public void ShowMessage()
 {
     logger.Debug("Inside show message method");
     LogDisplay.Clear();
     LogDisplay.WriteLine("Button Clicked");
     LogDisplay.Show();
 }
Пример #2
0
        private object ErrorHandler(object exceptionObject)
        {
            if (exceptionObject != null)
            {
                LogDisplay.WriteLine("Exception: " + exceptionObject.ToString());
            }

            // return #VALUE into the cell.
            return(ExcelError.ExcelErrorValue);
        }
Пример #3
0
 public static void LoadForm()
 {
     try
     {
         _windowStarter.ShowSingeltonWindow <MainWindow, MainWindowViewModel>();
     }
     catch (Exception ex)
     {
         LogDisplay.WriteLine(ex.ToString());
     }
 }
 internal static void InitializeRDotNet()
 {
     try
     {
         REngine.SetEnvironmentVariables();
         _engine = REngine.GetInstance();
         _engine.Initialize();
     }
     catch (Exception ex)
     {
         LogDisplay.WriteLine("Error initializing RDotNet: " + ex.Message);
     }
 }
Пример #5
0
        private object ErrorHandler(object exceptionObject)
        {
            ExcelReference caller = (ExcelReference)XlCall.Excel(XlCall.xlfCaller);

            // Calling reftext here requires all functions to be marked IsMacroType=true, which is undesirable.
            // A better plan would be to build the reference text oneself, using the RowFirst / ColumnFirst info
            // Not sure where to find the SheetName then....
            string callingName = (string)XlCall.Excel(XlCall.xlfReftext, caller, true);

            LogDisplay.WriteLine(callingName + " Error: " + exceptionObject.ToString());

            // return #VALUE into the cell anyway.
            return(ExcelError.ExcelErrorValue);
        }
Пример #6
0
        private static ACQ.Math.Interpolation.ScatteredInterpolationInterface construct_interpolator(double[,] x, double[] y, object input_scales, object method)
        {
            ACQ.Math.Interpolation.ScatteredInterpolationInterface interpolator = null;
            try
            {
                ACQ.Math.Interpolation.enRadialBasisFunction rbf_function = ExcelHelper.CheckEnum <ACQ.Math.Interpolation.enRadialBasisFunction>(method, ACQ.Math.Interpolation.enRadialBasisFunction.Linear);

                double[] scales = null; //null argument is ok

                if (!(input_scales is ExcelMissing) && input_scales != null)
                {
                    if (input_scales is double)
                    {
                        double const_scale = (double)input_scales;
                        scales = new double[x.GetLength(1)];

                        for (int i = 0; i < scales.Length; i++)
                        {
                            scales[i] = const_scale;
                        }
                    }
                    else if (input_scales is object[])
                    {
                        object[] vect_scale = input_scales as object[];
                        scales = new double[x.GetLength(1)];

                        for (int i = 0; i < scales.Length; i++)
                        {
                            if (i < vect_scale.Length && vect_scale[i] is double)
                            {
                                scales[i] = (double)vect_scale[i];
                            }
                            else
                            {
                                scales[i] = 1.0;
                            }
                        }
                    }
                }

                interpolator = new ACQ.Math.Interpolation.RbfInterpolation(x, y, rbf_function, scales, 0.0);
            }
            catch (Exception ex)
            {
                LogDisplay.WriteLine("Error: " + ex.ToString());
            }
            return(interpolator);
        }
Пример #7
0
        public void AutoOpen()
        {
            var configFileName = "AddInReloaderConfiguration.xml";
            var xllDirectory   = Path.GetDirectoryName(ExcelDnaUtil.XllPath);
            var configPath     = Path.Combine(xllDirectory, configFileName);

            try
            {
                // Load config
                XmlSerializer configLoader        = new XmlSerializer(typeof(AddInReloaderConfiguration));
                AddInReloaderConfiguration config = (AddInReloaderConfiguration)configLoader.Deserialize(File.OpenRead(configPath));
                _watcher = new AddInWatcher(config);
            }
            catch (Exception ex)
            {
                LogDisplay.WriteLine("AddInReloader - Error loading the configuration file: " + ex.ToString());
            }
        }
Пример #8
0
        private static ACQ.Math.Interpolation.InterpolationInterface2D construct_interpolator(double[] x1, double[] x2, double[,] y, object method)
        {
            ACQ.Math.Interpolation.InterpolationInterface2D interpolator = null;
            try
            {
                string interpolation_method = ExcelHelper.Check(method, m_defaultInterpolator);

                interpolator = ACQ.Math.Interpolation.InterpolationFactory2D.GetInterpolator(interpolation_method, x1, x2, y);
            }
            catch (Exception ex)
            {
                lock (m_sync)
                {
                    LogDisplay.WriteLine("Error: " + ex.ToString());
                }
            }
            return(interpolator);
        }
        private static LiborRates construct_LiborCurve(double[] curva)
        {
            LiborRates LiborRate_Array = null;

            try
            {
                LiborRate_Array = new LiborRates(curva);
            }
            catch (Exception ex)
            {
                lock (m_sync)
                {
                    LogDisplay.WriteLine("Error: " + ex.ToString());
                }
            }

            return(LiborRate_Array);
        }
Пример #10
0
        private static ACQ.Math.Regression.Lowess construct_lowess(double[] x, double[] y, object span, object nsteps, object delta)
        {
            ACQ.Math.Regression.Lowess lowess = null;
            try
            {
                double span_input   = ExcelHelper.CheckValue <double>(span, 2.0 / 3.0);
                double delta_input  = ExcelHelper.CheckValue <double>(delta, 0.0); //set to zero so that lowess will pick default based on data range
                int    nsteps_input = (int)ExcelHelper.CheckValue <double>(nsteps, 3);

                lowess = new Math.Regression.Lowess(x, y, span_input, nsteps_input, delta_input);
            }
            catch (Exception ex)
            {
                lock (m_sync)
                {
                    LogDisplay.WriteLine("Error: " + ex.ToString());
                }
            }
            return(lowess);
        }
Пример #11
0
        private static ACQ.Math.Interpolation.InterpolationInterface construct_interpolator(double[] x, double[] y, object method, object bounds)
        {
            ACQ.Math.Interpolation.InterpolationInterface interpolator = null;
            try
            {
                string interpolation_method = ExcelHelper.Check(method, m_defaultInterpolator);
                bool   interpolation_bounds = ExcelHelper.CheckValue(bounds, true);

                interpolator        = ACQ.Math.Interpolation.InterpolationFactory.GetInterpolator(interpolation_method, x, y);
                interpolator.Bounds = interpolation_bounds;
            }
            catch (Exception ex)
            {
                lock (m_sync)
                {
                    LogDisplay.WriteLine("Error: " + ex.ToString());
                }
            }
            return(interpolator);
        }
Пример #12
0
        public static object acq_regression_linear_create(
            [ExcelArgument(Description = "x")] double[,] x,
            [ExcelArgument(Description = "y")]  double[] y,
            [ExcelArgument(Description = "Intercept, optional(default=true)")]  object intercept,
            [ExcelArgument(Description = "Weights, optional(default = none)")]  object weights)
        {
            if (ExcelDnaUtil.IsInFunctionWizard())
            {
                return(ExcelError.ExcelErrorRef);
            }
            else
            {
                bool     include_intercept = ExcelHelper.CheckValue(intercept, true);
                double[] reg_weights       = ExcelHelper.CheckArray <double>(weights);

                return(ACQ.Excel.Handles.GlobalCache.CreateHandle(m_tag, new object[] { x, y, reg_weights, include_intercept, "acq_regression_linear_create" },
                                                                  (objectType, parameters) =>
                {
                    ACQ.Math.Regression.LinearRegression regression = null;

                    try
                    {
                        regression = new Math.Regression.LinearRegression(x, y, reg_weights, include_intercept);
                    }
                    catch (Exception ex)
                    {
                        LogDisplay.WriteLine("Error: " + ex.ToString());
                    }

                    if (regression == null)
                    {
                        return ExcelError.ExcelErrorNull;
                    }
                    else
                    {
                        return regression;
                    }
                }));
            }
        }
        private static IMortgageLoan construct_loan(double Balance, double Rate, double Spread, int Maturity, int Resetting, string FixedOrARM, string PIOrIO, string Libor_Name)
        {
            LiborRates LiborRate;

            GlobalCache.TryGetObject <LiborRates>(Libor_Name, out LiborRate);

            IMortgageLoan loan = null;

            try
            {
                // Build the loan
                IRepayment rmPI = RepaymentFactory.GetRep(PIOrIO);
                loan = MortgageLoanFactory.GetLoan(FixedOrARM, Balance, Maturity, Rate, Resetting, Spread, LiborRate, rmPI);
            }
            catch (Exception ex)
            {
                lock (m_sync)
                {
                    LogDisplay.WriteLine("Error: " + ex.ToString());
                }
            }
            return(loan);
        }
        internal List <ExportedAssembly> GetAssemblies(string pathResolveRoot, DnaLibrary dnaLibrary)
        {
            List <ExportedAssembly> list = new List <ExportedAssembly>();

            try
            {
                string realPath = Path;
                if (Path.StartsWith("packed:"))
                {
                    // The ExternalLibrary is packed.
                    // We'll have to load it from resources.
                    string resourceName = Path.Substring(7);
                    if (Path.EndsWith(".DNA", StringComparison.OrdinalIgnoreCase))
                    {
                        byte[]     dnaContent = ExcelIntegration.GetDnaFileBytes(resourceName);
                        DnaLibrary lib        = DnaLibrary.LoadFrom(dnaContent, pathResolveRoot);
                        if (lib == null)
                        {
                            LogDisplay.WriteLine("External library could not be registered - Path: " + Path);
                            LogDisplay.WriteLine("    Error: Packed DnaLibrary could not be loaded.");
                            return(list);
                        }

                        return(lib.GetAssemblies(pathResolveRoot));
                    }
                    else
                    {
                        // DOCUMENT: TypeLibPath which is a resource in a library is denoted as fileName.dll\4
                        // For packed assemblies, we set TypeLibPath="packed:2"
                        string typeLibPath = null;
                        if (!string.IsNullOrEmpty(TypeLibPath) && TypeLibPath.StartsWith("packed:"))
                        {
                            typeLibPath = DnaLibrary.XllPath + @"\" + TypeLibPath.Substring(7);
                        }

                        // It would be nice to check here whether the assembly is loaded already.
                        // But because of the name mangling in the packing we can't easily check.

                        // So we make the following assumptions:
                        // 1. Packed assemblies won't also be loadable from files (else they might be loaded twice)
                        // 2. ExternalLibrary loads will happen before reference loads via AssemblyResolve.
                        // Under these assumptions we should not have assemblies loaded more than once,
                        // even if not checking here.
                        byte[]   rawAssembly = ExcelIntegration.GetAssemblyBytes(resourceName);
                        Assembly assembly    = Assembly.Load(rawAssembly);
                        list.Add(new ExportedAssembly(assembly, ExplicitExports, ExplicitRegistration, ComServer, false, typeLibPath, dnaLibrary));
                        return(list);
                    }
                }
                if (Uri.IsWellFormedUriString(Path, UriKind.Absolute))
                {
                    // Here is support for loading ExternalLibraries from http.
                    Uri uri = new Uri(Path, UriKind.Absolute);
                    if (uri.IsUnc)
                    {
                        realPath = uri.LocalPath;
                        // Will continue to load later with the regular file load part below...
                    }
                    else
                    {
                        string scheme = uri.Scheme.ToLowerInvariant();
                        if (scheme != "http" && scheme != "file" && scheme != "https")
                        {
                            Logging.LogDisplay.WriteLine("The ExternalLibrary path {0} is not a valid Uri scheme.", Path);
                            return(list);
                        }
                        else
                        {
                            if (uri.AbsolutePath.EndsWith("dna", StringComparison.InvariantCultureIgnoreCase))
                            {
                                DnaLibrary lib = DnaLibrary.LoadFrom(uri);
                                if (lib == null)
                                {
                                    LogDisplay.WriteLine("External library could not be registered - Path: " + Path);
                                    LogDisplay.WriteLine("    Error: DnaLibrary could not be loaded.");
                                    return(list);
                                }
                                // CONSIDER: Should we add a resolve story for .dna files at Uris?
                                return(lib.GetAssemblies(null)); // No explicit resolve path
                            }
                            else
                            {
                                // Load as a regular assembly - TypeLib not supported.
                                Assembly assembly = Assembly.LoadFrom(Path);
                                list.Add(new ExportedAssembly(assembly, ExplicitExports, ExplicitRegistration, ComServer, false, null, dnaLibrary));
                                return(list);
                            }
                        }
                    }
                }
                // Keep trying with the current value of realPath.
                string resolvedPath = DnaLibrary.ResolvePath(realPath, pathResolveRoot);
                if (resolvedPath == null)
                {
                    LogDisplay.WriteLine("External library could not be registered - Path: " + Path);
                    LogDisplay.WriteLine("    Error: The library could not be found at this location.");
                    return(list);
                }
                if (System.IO.Path.GetExtension(resolvedPath).Equals(".DNA", StringComparison.OrdinalIgnoreCase))
                {
                    // Load as a DnaLibrary
                    DnaLibrary lib = DnaLibrary.LoadFrom(resolvedPath);
                    if (lib == null)
                    {
                        LogDisplay.WriteLine("External library could not be registered - Path: " + Path);
                        LogDisplay.WriteLine("    Error: DnaLibrary could not be loaded.");
                        return(list);
                    }

                    string pathResolveRelative = System.IO.Path.GetDirectoryName(resolvedPath);
                    return(lib.GetAssemblies(pathResolveRelative));
                }
                else
                {
                    Assembly assembly;
                    // Load as a regular assembly
                    // First check if it is already loaded (e.g. as a reference from another assembly)
                    // DOCUMENT: Some cases might still have assemblies loaded more than once.
                    // E.g. for an assembly that is both ExternalLibrary and references from another assembly,
                    // having the assembly LoadFromBytes and in the file system would load it twice,
                    // because LoadFromBytes here happens before the .NET loaders assembly resolution.
                    string assemblyName = System.IO.Path.GetFileNameWithoutExtension(resolvedPath);
                    assembly = GetAssemblyIfLoaded(assemblyName);
                    if (assembly == null)
                    {
                        // Really have to load it.
                        if (LoadFromBytes)
                        {
                            // We need to be careful here to not re-load the assembly if it had already been loaded,
                            // e.g. as a dependency of an assembly loaded earlier.
                            // In that case we won't be able to have the library 'LoadFromBytes'.
                            byte[] bytes = File.ReadAllBytes(resolvedPath);

                            string pdbPath = System.IO.Path.ChangeExtension(resolvedPath, "pdb");
                            if (File.Exists(pdbPath))
                            {
                                byte[] pdbBytes = File.ReadAllBytes(pdbPath);
                                assembly = Assembly.Load(bytes, pdbBytes);
                            }
                            else
                            {
                                assembly = Assembly.Load(bytes);
                            }
                        }
                        else
                        {
                            assembly = Assembly.LoadFrom(resolvedPath);
                        }
                    }
                    string resolvedTypeLibPath = null;
                    if (!string.IsNullOrEmpty(TypeLibPath))
                    {
                        resolvedTypeLibPath = DnaLibrary.ResolvePath(TypeLibPath, pathResolveRoot); // null is unresolved
                        if (resolvedTypeLibPath == null)
                        {
                            resolvedTypeLibPath = DnaLibrary.ResolvePath(TypeLibPath, System.IO.Path.GetDirectoryName(resolvedPath));
                        }
                    }
                    else
                    {
                        // Check for .tlb with same name next to resolvedPath
                        string tlbCheck = System.IO.Path.ChangeExtension(resolvedPath, "tlb");
                        if (System.IO.File.Exists(tlbCheck))
                        {
                            resolvedTypeLibPath = tlbCheck;
                        }
                    }
                    list.Add(new ExportedAssembly(assembly, ExplicitExports, ExplicitRegistration, ComServer, false, resolvedTypeLibPath, dnaLibrary));
                    return(list);
                }
            }
            catch (Exception e)
            {
                // Assembly could not be loaded.
                LogDisplay.WriteLine("External library could not be registered - Path: " + Path);
                LogDisplay.WriteLine("    Error: " + e.Message);
                return(list);
            }
        }
 public override void WriteLine(string format, params object[] args)
 {
     LogDisplay.WriteLine(format, args);
 }