Пример #1
0
        public void MultiThreadWarnings()
        {
            Assert.DoesNotThrow(() =>
            {
                for (int i = 0; i < 3; i++)
                {
                    LogWarningMessageEvents.OnLogWarningMessage($"Test{i}");
                }

                waitHandle1 = 1;// make thread1 wait until waitHandle is 0

                Thread thread1 = new Thread(AddWarning);
                thread1.Start();

                while (waitHandle2 == 0 && thread1.IsAlive)// wait for thread1 to reach the Warning iteration
                {
                    Thread.Sleep(100);
                }

                LogWarningMessageEvents.OnLogWarningMessage($"Test3");

                Interlocked.Decrement(ref waitHandle1);

                thread1.Join();

                if (addWarningEx != null)
                {
                    throw addWarningEx;
                }

                ProtoCore.RuntimeCore runtimeCore = CurrentDynamoModel.EngineController.LiveRunnerRuntimeCore;
                Assert.AreEqual(4, runtimeCore.RuntimeStatus.WarningCount);
            });
        }
Пример #2
0
 /// <summary>
 /// Performs a cast to long in a checked context. If the operation produces an overflow,
 /// then a warning is produced and the overflowed result is returned.
 /// </summary>
 /// <param name="value">Operation to be performed</param>
 /// <returns>The result of the operation</returns>
 private static long DoCheckedCast(double value)
 {
     try
     {
         return(checked ((long)value));
     }
     catch (OverflowException)
     {
         LogWarningMessageEvents.OnLogWarningMessage(string.Format($"{Properties.Resources.IntegerOverflow}href=IntegerOverflow.html"));
         return((long)value);
     }
 }
Пример #3
0
        private static object[,] ConvertToDimensionalArray(object[][] input, out int rows, out int cols)
        {
            if (input == null)
            {
                rows = cols = 1;
                return(new object[, ] {
                    { "" }
                });
            }

            rows = input.GetUpperBound(0) + 1;
            cols = 0;
            for (int i = 0; i < rows; i++)
            {
                if (input[i] != null)
                {
                    cols = Math.Max(cols, input[i].GetUpperBound(0) + 1);
                }
            }

            // if the input data is an empty list or a list of nested empty lists
            // return an empty cell
            if (rows == 0 || cols == 0)
            {
                rows = cols = 1;
                return(new object[, ] {
                    { "" }
                });
            }

            object[,] output = new object[rows, cols];

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    if (input[i] == null || j > input[i].GetUpperBound(0))
                    {
                        output[i, j] = "";
                    }
                    else
                    {
                        var item = input[i][j];

                        if (item is double)
                        {
                            output[i, j] = ((double)item).ToString(CultureInfo.InvariantCulture);
                        }
                        else if (item is float)
                        {
                            output[i, j] = ((float)item).ToString(CultureInfo.InvariantCulture);
                        }
                        else if (item is DateTime)
                        {
                            output[i, j] = ((DateTime)item).ToString(CultureInfo.InvariantCulture);
                        }
                        else if (item == null)
                        {
                            output[i, j] = "";
                        }
                        else if (item is StackValue)
                        {
                            if (((StackValue)item).IsPointer)
                            {
                                string message = string.Format(Properties.Resources.kMethodResolutionFailureWithTypes,
                                                               "Excel.WriteToFile", "_SingleFunctionObject");
                                LogWarningMessageEvents.OnLogWarningMessage(message);
                                return(null);
                            }

                            output[i, j] = item.ToString();
                        }
                        else
                        {
                            output[i, j] = item.ToString();
                        }
                    }
                }
            }

            return(output);
        }