Esempio n. 1
0
        public static void ExportCSV(string filePath, object data)
        {
            using (var writer = new StreamWriter(System.IO.Path.GetFullPath(filePath)))
            {
                //TODO cast object to list
                foreach (var line in (System.Collections.IList)data)
                {
                    int count = 0;
                    if (MainTools.IsList(line))
                    {
                        var t = line.GetType();
                        var l = (System.Collections.ArrayList)line;
                        foreach (var entry in l)
                        {
                            writer.Write(MainTools.Quoted((entry ?? "").ToString().Replace("\n", string.Empty)));
                            if (++count < l.Count)
                            {
                                writer.Write(",");
                            }
                        }
                        writer.WriteLine();
                    }
                    else
                    {
                        writer.Write(MainTools.Quoted((line ?? "").ToString().Replace("\n", string.Empty)));

                        writer.Write(",");

                        writer.WriteLine();
                    }
                }
            }
        }
Esempio n. 2
0
        public override void Calculate()
        {
            var input = InputPorts[0].Data;
            var path  = InputPorts[1].Data;

            if (input != null && path != null)
            {
                if (MainTools.IsList(input))
                {
                    var t = input.GetType();
                    ExportCSV(path.ToString(), input);
                }
            }
        }
Esempio n. 3
0
 private static void StrechArgumentLists(List <Port> ports, List <Tuple <int, object> > values)
 {
     //Fill values list
     foreach (var arg in ports)
     {
         System.Collections.IList argList = null;
         if (MainTools.IsList(arg.Data))
         {
             argList = (System.Collections.IList)arg.Data;
         }
         //Check if argument is a list and include it on a Tuple with its count number
         var argResult = argList != null ? new Tuple <int, object>(argList.Count, argList) : new Tuple <int, object>(1, arg.Data);
         //if args are list, count the number of object to set how many times it should run
         values.Add(argResult);
     }
 }
Esempio n. 4
0
        public static object RunFunction(Func <object, object> method, List <Port> ports)
        {
            var properties = method.GetType().GetProperties();
            var values     = new List <Tuple <int, object> >();

            var result = new List <object>();

            //Fill values list
            StrechArgumentLists(ports, values);

            //Get highest value == longest list count
            int Highest = values.OrderBy(x => x.Item1).Reverse().ElementAt(0).Item1;



            for (int i = 0; i < Highest; i++)
            {
                var ActualArgList = new List <object>();
                foreach (var item in values)
                {
                    object currentArg = null;
                    if (item.Item1 > 1 || MainTools.IsList(item.Item2))
                    {
                        var tempArgList = (List <object>)item.Item2;
                        //get latest object

                        var currentArgListLenght = tempArgList.Count - 1;
                        currentArg = currentArgListLenght <= i ? tempArgList[currentArgListLenght] : tempArgList[i];
                        ActualArgList.Add(currentArg);
                    }
                    else
                    {
                        currentArg = item.Item2;
                        ActualArgList.Add(currentArg);
                    }
                }

                result.Add(method.DynamicInvoke(ActualArgList[0]));
            }
            return(result);
        }