Esempio n. 1
0
 public static object Observe <T>(string callerFunctionName, object callerParameters, Func <string, object, IObservable <T> > observableSource)
 {
     return(ExcelAsyncUtil.Observe(callerFunctionName, callerParameters, () => observableSource(callerFunctionName, callerParameters).ToExcelObservable()));
 }
Esempio n. 2
0
 public static object PSQ(string Symbol, string InfoCode)
 {
     return(ExcelAsyncUtil.Run("PSQ", new object[] { Symbol, InfoCode }, () => PSQFunction(Symbol, InfoCode)));
 }
 public void Initialize()
 {
     Logger.Provider.Info("WorkbookIntelliSenseProvider.Initialize");
     _xmlProvider.Initialize();
     ExcelAsyncUtil.QueueAsMacro(OnInitialize);
 }
Esempio n. 4
0
        private void OnNewInput(object sender, EventArgs e)
        {
            string formula = BuildFormula();

            ExcelAsyncUtil.QueueAsMacro(() => UpdateEvaluation(formula));
        }
Esempio n. 5
0
 public static object Observe <T>(string functionName, object parameters, Func <IObservable <T> > observableSource)
 {
     return(ExcelAsyncUtil.Observe(functionName, parameters, () => observableSource().ToExcelObservable()));
 }
 public object Run(string udfName, object parameters, ExcelFunc func)
 {
     return(ExcelAsyncUtil.Run(udfName, parameters, func));
 }
Esempio n. 7
0
 public static object DownloadAsync(string url)
 {
     Debug.Print("DownloadAsync: " + url);
     // Don't do anything else here - might run at unexpected times...
     return(ExcelAsyncUtil.Run("DownloadAsync", url, delegate { return Download(url); }));
 }
Esempio n. 8
0
        public static object OCTOPART_DISTRIBUTOR_MOQ(
            [ExcelArgument(Description = "Part Number Lookup", Name = "MPN or SKU")] string mpn_or_sku,
            [ExcelArgument(Description = "Manufacturer of the part to query (optional)", Name = "Manufacturer")] string manuf = "",
            [ExcelArgument(Description = "Distributors for lookup (optional)", Name = "Distributor(s)")] Object[] distributors = null)
        {
            List<ApiV4Schema.PartOffer> offers = GetOffers(mpn_or_sku, manuf, GetDistributors(distributors));
            if ((offers != null) && (offers.Count > 0))
            {
                // ---- BEGIN Function Specific Information ----
                offers = offers.Where(offer => offer.GetRealMoq() > 0).ToList();
                if ((offers != null) && (offers.Count > 0))
                {
                    return offers.Min(offer => offer.GetRealMoq());
                }
                // ---- END Function Specific Information ----
            }

            mpn_or_sku = mpn_or_sku.PadRight(mpn_or_sku.Length + _refreshhack.Length);
            object asyncResult = ExcelAsyncUtil.Run("OCTOPART_DISTRIBUTOR_MOQ", new object[] { mpn_or_sku, manuf, distributors }, delegate
            {
                try
                {
                    offers = SearchAndWaitOffers(mpn_or_sku, manuf, GetDistributors(distributors));
                    if ((offers == null) || (offers.Count == 0))
                    {
                        string err = QueryManager.GetLastError(mpn_or_sku);
                        if (string.IsNullOrEmpty(err))
                            err = "Query did not provide a result. Please widen your search criteria.";

                        return "ERROR: " + err;
                    }

                    // ---- BEGIN Function Specific Information ----
                    offers = offers.Where(offer => offer.GetRealMoq() > 0).ToList();
                    if ((offers != null) && (offers.Count > 0))
                    {
                        return offers.Min(offer => offer.GetRealMoq());
                    }
                    else
                    {
                        string err = "Query did not provide a result. Please widen your search criteria.";
                        return "ERROR: " + err;
                    }
                    // ---- END Function Specific Information ----
                }
                catch (Exception ex)
                {
                    log.Fatal(ex.ToString());
                    return "ERROR: " + OctopartQueryManager.FATAL_ERROR;
                }
            });

            if (asyncResult.Equals(ExcelError.ExcelErrorNA))
            {
                return "!!! Processing !!!";
            }
            else if (!string.IsNullOrEmpty(QueryManager.GetLastError(mpn_or_sku)) || (offers == null))
            {
                _refreshhack = string.Empty.PadRight(new Random().Next(0, 100));
            }

            return asyncResult;
        }
Esempio n. 9
0
            // This function will run in the UDF context.
            // Needs extra protection to allow multithreaded use.
            public static object Resize(object[,] array)
            {
                var caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference;

                if (caller == null)
                {
                    return(array);
                }

                var rows    = array.GetLength(0);
                var columns = array.GetLength(1);

                if (rows == 0 || columns == 0)
                {
                    return(array);
                }

                if ((caller.RowLast - caller.RowFirst + 1 == rows) &&
                    (caller.ColumnLast - caller.ColumnFirst + 1 == columns))
                {
                    // Size is already OK - just return result
                    return(array);
                }

                var rowLast    = caller.RowFirst + rows - 1;
                var columnLast = caller.ColumnFirst + columns - 1;

                // Check for the sheet limits
                if (rowLast > ExcelDnaUtil.ExcelLimits.MaxRows - 1 ||
                    columnLast > ExcelDnaUtil.ExcelLimits.MaxColumns - 1)
                {
                    // Can't resize - goes beyond the end of the sheet - just return #VALUE
                    // (Can't give message here, or change cells)
                    return(ExcelError.ExcelErrorValue);
                }

                // TODO: Add some kind of guard for ever-changing result?
                if (columns > 1)
                {
                    ExcelAsyncUtil.QueueAsMacro(() =>
                    {
                        var target = new ExcelReference(caller.RowFirst, caller.RowFirst, caller.ColumnFirst + 1,
                                                        columnLast);
                        var firstRow = new object[columns - 1];
                        for (var i = 1; i < columns; i++)
                        {
                            firstRow[i - 1] = array[0, i];
                        }
                        target.SetValue(firstRow);
                    });
                }
                if (rows > 1)
                {
                    ExcelAsyncUtil.QueueAsMacro(() =>
                    {
                        var target = new ExcelReference(caller.RowFirst + 1, rowLast, caller.ColumnFirst, columnLast);
                        var data   = new object[rows - 1, columns];
                        for (var i = 1; i < rows; i++)
                        {
                            for (var j = 0; j < columns; j++)
                            {
                                data[i - 1, j] = array[i, j];
                            }
                        }
                        target.SetValue(data);
                    });
                }
                // Return what we have - to prevent flashing #N/A
                return(array);
            }
Esempio n. 10
0
        public static object OCTOPART_AVERAGE_PRICE(
            [ExcelArgument(Description = "Part Number Lookup", Name = "MPN or SKU")] string mpn_or_sku,
            [ExcelArgument(Description = "Manufacturer of the part to query (optional)", Name = "Manufacturer")] string manuf = "",
            [ExcelArgument(Description = "Quantity for lookup (optional, default = 1)", Name = "Quantity")] int qty = 1,
            [ExcelArgument(Description = "Currency for lookup (optional, default = USD). Standard currency codes apply (http://en.wikipedia.org/wiki/ISO_4217)", Name = "Currency")] string currency = "USD")
        {
            List<ApiV4Schema.PartOffer> offers = GetOffers(mpn_or_sku, manuf);
            if ((offers != null) && (offers.Count > 0))
            {
                // ---- BEGIN Function Specific Information ----
                offers = offers.Where(offer => offer.MinPrice(currency, qty) < double.MaxValue).ToList();
                if ((offers != null) && (offers.Count > 0))
                {
                    double price = offers.Average(offer => offer.MinPrice(currency, qty));
                    if (price < double.MaxValue)
                        return price;
                    else
                        return "ERROR: Query did not provide a result. Please widen your search criteria.";
                }
                // ---- END Function Specific Information ----
            }

            mpn_or_sku = mpn_or_sku.PadRight(mpn_or_sku.Length + _refreshhack.Length);
#if !TEST
            object asyncResult = ExcelAsyncUtil.Run("OCTOPART_AVERAGE_PRICE", new object[] { mpn_or_sku, manuf, qty, currency }, delegate
            {
#endif
            try
            {
                offers = SearchAndWaitOffers(mpn_or_sku, manuf);
                if ((offers == null) || (offers.Count == 0))
                {
                    string err = QueryManager.GetLastError(mpn_or_sku);
                    if (string.IsNullOrEmpty(err))
                        err = "Query did not provide a result. Please widen your search criteria.";

                    return "ERROR: " + err;
                }

                // ---- BEGIN Function Specific Information ----
                offers = offers.Where(offer => offer.MinPrice(currency, qty) < double.MaxValue).ToList();
                if ((offers != null) && (offers.Count > 0))
                {
                    double price = offers.Average(offer => offer.MinPrice(currency, qty));
                    if (price < double.MaxValue)
                        return price;
                }

                return "ERROR: Query did not provide a result. Please widen your search criteria.";
                // ---- END Function Specific Information ----
            }
            catch (Exception ex)
            {
                log.Fatal(ex.ToString());
                return "ERROR: " + OctopartQueryManager.FATAL_ERROR;
            }
#if !TEST
            });

            if (asyncResult.Equals(ExcelError.ExcelErrorNA))
            {
                return "!!! Processing !!!";
            }
            else if (!string.IsNullOrEmpty(QueryManager.GetLastError(mpn_or_sku)) || (offers == null))
            {
                _refreshhack = string.Empty.PadRight(new Random().Next(0, 100));
            }

            return asyncResult;
#endif
        }
Esempio n. 11
0
        public static void WriteCell(ExcelReference target, string value, int row = 0, int column = 0)
        {
            var output = new object[row, column];

            ExcelAsyncUtil.QueueAsMacro(() => target.SetValue(output));
        }
Esempio n. 12
0
 public static object SayHelloSlow(string name)
 => ExcelAsyncUtil.Run(nameof(SayHelloSlow), name, () =>
 {
     Thread.Sleep(4000);
     return("Done " + name);
 });
Esempio n. 13
0
 public static void ExecuteOnForegroundThread(ExcelAction action)
 {
     ExcelAsyncUtil.QueueAsMacro(action);
 }
Esempio n. 14
0
 public void AutoOpen()
 {
     ExcelAsyncUtil.Initialize();
     ExcelIntegration.RegisterUnhandledExceptionHandler(ex => "!!! EXCEPTION: " + ex.ToString());
 }