AddonHelper.Addon.RandomString C# (CSharp) Метод

RandomString() публичный статический Метод

Returns a random string based on the length and the allowed characters given
public static RandomString ( int len, string chars = "abcdefghijklmnopqrstuvwxyz0123456789" ) : string
len int The length
chars string Allowed characters
Результат string
        public static string RandomString(int len, string chars = "abcdefghijklmnopqrstuvwxyz0123456789")
        {
            string ret = "";
            for (int i = 0; i < len; i++) {
                string a = chars[rnd.Next(chars.Length)].ToString();
                if (rnd.Next(2) == 0)
                    ret += a.ToUpper();
                else
                    ret += a;
            }
            return ret;
        }

Usage Example

Пример #1
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                this.Close();
            }
            else if (keyData == Keys.P)
            {
                if (this.Selection.Width > 0 && this.Selection.Height > 0)
                {
                    Bitmap img = null;
                    try {
                        img = this.SelectionImage;
                    } catch { }

                    if (img != null)
                    {
                        if (this.settings.GetInt("DragEditor") == 0)
                        {
                            Addon.SetShortcuts(true);
                            new FormEditor(img, this.DoneDragging).Show();
                        }
                        else if (this.settings.GetInt("DragEditor") == 1)
                        {
                            string exePath = this.settings.GetString("DragExtraPath");

                            if (File.Exists(exePath))
                            {
                                string localTempPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Temp\\" + Addon.RandomString(16) + ".png";

                                MemoryStream ms = new MemoryStream();
                                img.Save(ms, ImageFormat.Png);
                                File.WriteAllBytes(localTempPath, ms.GetBuffer());

                                Process.Start(exePath, "\"" + localTempPath + "\"");
                            }
                        }

                        this.Close();

                        if (DoneDragging != null)
                        {
                            //TODO: What do with this? Could return NULL as image, but then every addon must respond
                            //      accordingly to that. Can also not be triggered, but could break some addon code
                            //      in the progress. Same goes with doing a DragCallback with DragCallbackType.None,
                            //      it could potentially break existing addon code. Decisions, decisions...
                        }
                    }
                }
            }
            else if (keyData == Keys.O)
            {
                if (this.AnimationAllowed)
                {
                    this.Close();
                    Addon.SetShortcuts(true);
                    new FormAnimation(this, this.Selection, this.DoneDragging).Show();
                }
            }

            return(base.ProcessCmdKey(ref msg, keyData));
        }