RandomString() public static method

public static RandomString ( int length ) : string
length int
return string
Beispiel #1
0
        private bool Save()
        {
            if (!CheckStep1())
            {
                return(false);
            }

            string err = "";

            int nosoundinterval;

            if (!int.TryParse(txtNoSound.Text, out nosoundinterval))
            {
                err += LocRm.GetString("Validate_Microphone_NoSound") + Environment.NewLine;
            }
            int soundinterval;

            if (!int.TryParse(txtSound.Text, out soundinterval))
            {
                err += LocRm.GetString("Validate_Microphone_Sound") + Environment.NewLine;
            }


            if (txtBuffer.Text.Length < 1 || txtInactiveRecord.Text.Length < 1 ||
                txtMaxRecordTime.Text.Length < 1)
            {
                err += LocRm.GetString("Validate_Camera_RecordingSettings") + Environment.NewLine;
            }

            if (err != "")
            {
                MessageBox.Show(err, LocRm.GetString("Error"));
                return(false);
            }


            VolumeLevel.Micobject.settings.buffer         = Convert.ToInt32(txtBuffer.Value);
            VolumeLevel.Micobject.recorder.inactiverecord = Convert.ToInt32(txtInactiveRecord.Value);
            VolumeLevel.Micobject.recorder.maxrecordtime  = Convert.ToInt32(txtMaxRecordTime.Value);

            VolumeLevel.Micobject.name = txtMicrophoneName.Text.Trim();

            VolumeLevel.Micobject.alerts.active = chkSound.Checked;

            VolumeLevel.Micobject.alerts.mode = "sound";
            if (rdoNoMovement.Checked)
            {
                VolumeLevel.Micobject.alerts.mode = "nosound";
            }
            VolumeLevel.Micobject.detector.nosoundinterval = nosoundinterval;
            VolumeLevel.Micobject.detector.soundinterval   = soundinterval;

            VolumeLevel.Micobject.schedule.active = chkSchedule.Checked;
            VolumeLevel.Micobject.width           = VolumeLevel.Width;
            VolumeLevel.Micobject.height          = VolumeLevel.Height;

            VolumeLevel.Micobject.settings.active         = chkActive.Checked;
            VolumeLevel.Micobject.detector.recordondetect = rdoRecordDetect.Checked;
            VolumeLevel.Micobject.detector.recordonalert  = rdoRecordAlert.Checked;
            VolumeLevel.Micobject.recorder.minrecordtime  = (int)numMinRecord.Value;

            VolumeLevel.Micobject.settings.accessgroups = txtAccessGroups.Text;
            VolumeLevel.Micobject.settings.messaging    = chkMessaging.Checked;


            if (txtDirectory.Text.Trim() == "")
            {
                txtDirectory.Text = MainForm.RandomString(5);
            }

            var md     = (ListItem)ddlMediaDirectory.SelectedItem;
            var newind = Convert.ToInt32(md.Value);

            string olddir = Helper.GetMediaDirectory(1, VolumeLevel.Micobject.id) + "video\\" + VolumeLevel.Micobject.directory + "\\";

            bool needsFileRefresh = (VolumeLevel.Micobject.directory != txtDirectory.Text || VolumeLevel.Micobject.settings.directoryIndex != newind);

            int tempidx = VolumeLevel.Micobject.settings.directoryIndex;

            VolumeLevel.Micobject.settings.directoryIndex = newind;

            string newdir = Helper.GetMediaDirectory(1, VolumeLevel.Micobject.id) + "video\\" + txtDirectory.Text + "\\";

            if (IsNew)
            {
                try
                {
                    if (!Directory.Exists(newdir))
                    {
                        Directory.CreateDirectory(newdir);
                    }
                    else
                    {
                        switch (
                            MessageBox.Show(this,
                                            LocRm.GetString("Validate_Directory_Exists"),
                                            LocRm.GetString("Confirm"), MessageBoxButtons.YesNoCancel))
                        {
                        case DialogResult.Yes:
                            Directory.Delete(newdir, true);
                            Directory.CreateDirectory(newdir);
                            break;

                        case DialogResult.Cancel:
                            VolumeLevel.Micobject.settings.directoryIndex = tempidx;
                            return(false);

                        case DialogResult.No:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, LocRm.GetString("Validate_Directory_String") + Environment.NewLine + ex.Message);
                    VolumeLevel.Micobject.settings.directoryIndex = tempidx;
                    return(false);
                }
            }
            else
            {
                if (newdir != olddir)
                {
                    try
                    {
                        if (!Directory.Exists(newdir))
                        {
                            if (Directory.Exists(olddir))
                            {
                                Helper.CopyFolder(olddir, newdir);
                            }
                            else
                            {
                                Directory.CreateDirectory(newdir);
                            }
                        }
                        else
                        {
                            switch (
                                MessageBox.Show(this,
                                                LocRm.GetString("Validate_Directory_Exists"),
                                                LocRm.GetString("Confirm"), MessageBoxButtons.YesNoCancel))
                            {
                            case DialogResult.Yes:
                                if (Directory.Exists(olddir))
                                {
                                    Helper.CopyFolder(olddir, newdir);
                                }
                                else
                                {
                                    Directory.Delete(newdir, true);
                                    Directory.CreateDirectory(newdir);
                                }
                                break;

                            case DialogResult.Cancel:
                                VolumeLevel.Micobject.settings.directoryIndex = tempidx;
                                return(false);

                            case DialogResult.No:
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(this, LocRm.GetString("Validate_Directory_String") + Environment.NewLine + ex.Message);
                        VolumeLevel.Micobject.settings.directoryIndex = tempidx;
                        return(false);
                    }
                }
            }


            VolumeLevel.Micobject.directory        = txtDirectory.Text;
            VolumeLevel.Micobject.recorder.trigger = ((ListItem)ddlTriggerRecording.SelectedItem).Value;

            SetStorageManagement();

            MainForm.NeedsSync = true;

            if (needsFileRefresh)
            {
                VolumeLevel.GenerateFileList();
                MainForm.NeedsMediaRebuild = true;
                MainForm.NeedsMediaRefresh = Helper.Now;
            }
            return(true);
        }
Beispiel #2
0
        private void BtnFinishClick(object sender, EventArgs e)
        {
            //validate page 0
            if (CheckStep1())
            {
                string err = "";
                if (chkSendSMSMovement.Checked && MainForm.Conf.ServicesEnabled &&
                    txtSMSNumber.Text.Trim() == "")
                {
                    err += LocRm.GetString("Validate_Camera_MobileNumber") + Environment.NewLine;
                }

                int nosoundinterval;
                if (!int.TryParse(txtNoSound.Text, out nosoundinterval))
                {
                    err += LocRm.GetString("Validate_Microphone_NoSound") + Environment.NewLine;
                }
                int soundinterval;
                if (!int.TryParse(txtSound.Text, out soundinterval))
                {
                    err += LocRm.GetString("Validate_Microphone_Sound") + Environment.NewLine;
                }


                string sms = txtSMSNumber.Text.Trim().Replace(" ", "");
                if (sms.StartsWith("00"))
                {
                    sms = sms.Substring(2);
                }
                if (sms.StartsWith("+"))
                {
                    sms = sms.Substring(1);
                }
                if (sms != "")
                {
                    if (!IsNumeric(sms))
                    {
                        err += LocRm.GetString("Validate_Camera_SMSNumbers") + Environment.NewLine;
                    }
                }
                string email = txtEmailAlert.Text.Replace(" ", "");
                if (email != "" && !email.IsValidEmail())
                {
                    err += LocRm.GetString("Validate_Camera_EmailAlerts") + Environment.NewLine;
                }

                if (email == "")
                {
                    chkSendEmailSound.Checked    = false;
                    chkEmailOnDisconnect.Checked = false;
                }
                if (sms == "")
                {
                    chkSendSMSMovement.Checked = false;
                }

                if (txtBuffer.Text.Length < 1 || txtInactiveRecord.Text.Length < 1 || txtMinimumInterval.Text.Length < 1 ||
                    txtMaxRecordTime.Text.Length < 1)
                {
                    err += LocRm.GetString("Validate_Camera_RecordingSettings") + Environment.NewLine;
                }

                if (err != "")
                {
                    MessageBox.Show(err, LocRm.GetString("Error"));
                    return;
                }


                VolumeLevel.Micobject.settings.buffer         = Convert.ToInt32(txtBuffer.Value);
                VolumeLevel.Micobject.recorder.inactiverecord = Convert.ToInt32(txtInactiveRecord.Value);
                VolumeLevel.Micobject.alerts.minimuminterval  = Convert.ToInt32(txtMinimumInterval.Value);
                VolumeLevel.Micobject.recorder.maxrecordtime  = Convert.ToInt32(txtMaxRecordTime.Value);

                VolumeLevel.Micobject.name = txtMicrophoneName.Text.Trim();
                VolumeLevel.Micobject.detector.sensitivity = tbSensitivity.Value;
                VolumeLevel.Micobject.alerts.active        = chkSound.Checked;
                VolumeLevel.Micobject.alerts.executefile   = txtExecuteAudio.Text;
                VolumeLevel.Micobject.alerts.alertoptions  = chkBeep.Checked + "," + chkRestore.Checked;
                VolumeLevel.Micobject.alerts.mode          = "sound";
                if (rdoNoMovement.Checked)
                {
                    VolumeLevel.Micobject.alerts.mode = "nosound";
                }
                VolumeLevel.Micobject.detector.nosoundinterval = nosoundinterval;
                VolumeLevel.Micobject.detector.soundinterval   = soundinterval;
                VolumeLevel.Micobject.notifications.sendemail  = chkSendEmailSound.Checked;
                VolumeLevel.Micobject.notifications.sendsms    = chkSendSMSMovement.Checked;
                VolumeLevel.Micobject.settings.smsnumber       = sms;
                VolumeLevel.Micobject.settings.emailaddress    = email;

                VolumeLevel.Micobject.schedule.active = chkSchedule.Checked;
                VolumeLevel.Micobject.width           = VolumeLevel.Width;
                VolumeLevel.Micobject.height          = VolumeLevel.Height;

                VolumeLevel.Micobject.settings.active             = chkActive.Checked;
                VolumeLevel.Micobject.detector.recordondetect     = rdoRecordDetect.Checked;
                VolumeLevel.Micobject.detector.recordonalert      = rdoRecordAlert.Checked;
                VolumeLevel.Micobject.notifications.sendtwitter   = chkTwitter.Checked;
                VolumeLevel.Micobject.settings.notifyondisconnect = chkEmailOnDisconnect.Checked;

                VolumeLevel.Micobject.alerts.arguments = txtArguments.Text;

                VolumeLevel.Micobject.settings.accessgroups = txtAccessGroups.Text;

                if (txtDirectory.Text.Trim() == "")
                {
                    txtDirectory.Text = MainForm.RandomString(5);
                }

                if (VolumeLevel.Micobject.directory != txtDirectory.Text)
                {
                    string path = MainForm.Conf.MediaDirectory + "audio\\" + txtDirectory.Text + "\\";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                }

                VolumeLevel.Micobject.directory = txtDirectory.Text;

                VolumeLevel.Micobject.alerts.trigger   = ((ListItem)ddlTrigger.SelectedItem).Value;
                VolumeLevel.Micobject.recorder.trigger = ((ListItem)ddlTriggerRecording.SelectedItem).Value;

                DialogResult       = DialogResult.OK;
                MainForm.NeedsSync = true;
                Close();
            }
        }