Exemplo n.º 1
0
        private static object Concat(ICellContext ctx, IList <IExpression> args, out string error)
        {
            var realArgs = args.Eval(ctx, out error);

            if (error is null)
            {
                var result = new System.Text.StringBuilder();
                foreach (var arg in realArgs)
                {
                    // Arg is actually a range.
                    if (arg is Dictionary <int, object> dict)
                    {
                        result.AppendJoin("", dict.Values);
                    }
                    // Arg is an array defined in the language, arrays should always be IList<object>
                    else if (arg is IList <object> arr)
                    {
                        result.AppendJoin("", arr);
                    }
                    // Arg is: null, string, double or bool.
                    else
                    {
                        result.Append(arg?.ToString() ?? "");
                    }
                }
                return(result.ToString());
            }
            return(null);
        }
        public static string ToJointString <T>(this IEnumerable <T> source, string delimeter = "") where T : IConvertible
        {
            if (source != null && source.Count() > 0 && delimeter != null)
            {
                var sb = new StringBuilder();
                sb.AppendJoin(delimeter, source);
                return(sb.ToString());
            }
            else if (source == null || delimeter == null)
            {
                throw new ArgumentNullException(source == null ? "source" : "delimeter");
            }

            return(string.Empty);
        }
Exemplo n.º 3
0
        public static string GetNiceTypeName(System.Type type, NamingOptions options)
        {
            if (options != null && options.NameOverrideFunc != null)
            {
                string s = options.NameOverrideFunc(type);
                if (s != null)
                {
                    return(s);
                }
            }

            if (ReflectionUtil.IsNullableType(type))
            {
                var actualtype = type.GetGenericArguments()[0];
                return(ReflectionUtil.GetNiceTypeName(actualtype, options) + "?");
            }

            if (type.IsArray)
            {
                var at = type.GetElementType();
                return(String.Format("{0}[]", ReflectionUtil.GetNiceTypeName(at, options)));
            }

            if (type.IsGenericType)
            {
                var sb     = new System.Text.StringBuilder();
                var tokens = type.Name.Split('`');

                sb.Append(tokens[0]);
                var gas      = type.GetGenericArguments();
                var ga_names = gas.Select(i => ReflectionUtil.GetNiceTypeName(i, options));

                sb.Append("<");
                sb.AppendJoin(", ", ga_names);
                sb.Append(">");
                return(sb.ToString());
            }

            return(type.Name);
        }
Exemplo n.º 4
0
        private static Stream createSigningImage(string imageName, IEnumerable <string> lines)
        {
            var path   = $"images\\{imageName}";
            var result = new MemoryStream();

            //Creates an instance of Image
            using (var file = new FileStream(path, FileMode.Open))
            {
                using (var image = new System.Drawing.Bitmap(file))
                {
                    //Creates and initialize an instance of Graphics class
                    using (var graphics = System.Drawing.Graphics.FromImage(image))
                    {
                        using (var font = new System.Drawing.Font("Helvetica", 17))
                        {
                            using (var brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black))
                            {
                                var units = System.Drawing.GraphicsUnit.Point;
                                var rectF = image.GetBounds(ref units);
                                var sb    = new System.Text.StringBuilder();
                                sb.AppendJoin(System.Environment.NewLine, lines);
                                var stringFormat = new System.Drawing.StringFormat();
                                stringFormat.Alignment     = System.Drawing.StringAlignment.Center;
                                stringFormat.LineAlignment = System.Drawing.StringAlignment.Center;
                                //Draw a String
                                graphics.DrawString(sb.ToString(), font, brush, rectF, stringFormat);
                            }
                        }
                    }

                    // save all changes
                    image.Save(result, System.Drawing.Imaging.ImageFormat.Png);
                }
            }

            return(result);
        }
Exemplo n.º 5
0
 public IndentedStringBuilder AppendJoin <T>(System.Char separator, System.Collections.Generic.IEnumerable <T> values)
 {
     AppendIndent();
     _inner.AppendJoin <T>(separator, values);
     return(this);
 }
        public static string GetNiceTypeName(System.Type type, NamingOptions options)
        {
            if (options != null && options.NameOverrideFunc !=null)
            {
                string s = options.NameOverrideFunc(type);
                if (s != null)
                {
                    return s;
                }
            }

            if (ReflectionUtil.IsNullableType(type))
            {
                var actualtype = type.GetGenericArguments()[0];
                return ReflectionUtil.GetNiceTypeName(actualtype, options) + "?";
            }

            if (type.IsArray)
            {
                var at = type.GetElementType();
                return $"{ReflectionUtil.GetNiceTypeName(at, options)}[]";
            }

            if (type.IsGenericType)
            {
                var sb = new System.Text.StringBuilder();
                var tokens = type.Name.Split('`');

                sb.Append(tokens[0]);
                var gas = type.GetGenericArguments();
                var ga_names = gas.Select(i => ReflectionUtil.GetNiceTypeName(i, options));

                sb.Append("<");
                sb.AppendJoin(", ", ga_names);
                sb.Append(">");
                return sb.ToString();
            }

            return type.Name;
        }
Exemplo n.º 7
0
        public static AppInfo createFromUid(Context context, int uid)
        {
            var pm   = context.PackageManager;
            var list = new List <Entry>();

            if (uid > 0)
            {
                try
                {
                    string[] pkgNames = pm.GetPackagesForUid(uid);
                    if (pkgNames == null || pkgNames.Length <= 0)
                    {
                        list.Add(new Entry("System", "nonpkg.noname"));
                    }
                    else
                    {
                        foreach (var pkgName in pkgNames)
                        {
                            if (pkgName != null)
                            {
                                try
                                {
                                    var    appPackageInfo = pm.GetPackageInfo(pkgName, 0);
                                    string appName        = null;

                                    if (appPackageInfo != null)
                                    {
                                        appName = appPackageInfo.ApplicationInfo.LoadLabel(pm).ToString();
                                    }

                                    if (string.IsNullOrEmpty(appName))
                                    {
                                        appName = pkgName;
                                    }

                                    list.Add(new Entry(appName, pkgName));
                                }
                                catch (PackageManager.NameNotFoundException)
                                {
                                    list.Add(new Entry(pkgName, pkgName));
                                }
                            }
                        }
                    }
                }
                catch (RuntimeException)
                {
                    Log.Info("NRFW", "error getPackagesForUid(). package manager has died");
                    return(null);
                }
            }

            if (list.Count == 0)
            {
                list.Add(new Entry("System", "root.uid=0"));
            }

            list.Sort();

            /*Collections.sort(list, new Comparator<Entry>()
             * {
             *      public int compare(Entry lhs, Entry rhs)
             * {
             *  int ret = lhs.appName.compareToIgnoreCase(rhs.appName);
             *  if (ret == 0)
             *  {
             *      return lhs.pkgName.compareToIgnoreCase(rhs.pkgName);
             *  }
             *  return ret;
             * }
             * });*/
            var pkgs = new string[list.Count];
            var apps = new string[list.Count];

            for (int i = 0; i < list.Count; i++)
            {
                pkgs[i] = list[i].PkgName;
                apps[i] = list[i].AppName;
            }

            var sb = new System.Text.StringBuilder();

            return(new AppInfo(apps[0], sb.AppendJoin(',', apps).ToString(), pkgs));
        }