GetMediaDirectory() static private method

static private GetMediaDirectory ( int directoryIndex ) : string
directoryIndex int
return string
Esempio n. 1
0
        private void RenderList(List <FilePreview> l, int pageCount)
        {
            flowPreview.SuspendLayout();
            mediaPanelControl1.lblPage.Text = String.Format("{0} / {1}", (MediaPanelPage + 1), pageCount);

            var currentList = new List <PreviewBox>();

            for (int i = 0; i < flowPreview.Controls.Count; i++)
            {
                var pb = flowPreview.Controls[i] as PreviewBox;
                if (pb != null)
                {
                    var cd = pb.CreatedDate;
                    if (NeedsMediaRebuild || l.Count(p => p.CreatedDateTicks == cd.Ticks) == 0)
                    {
                        flowPreview.Controls.Remove(pb);
                        pb.MouseDown  -= PbMouseDown;
                        pb.MouseEnter -= PbMouseEnter;
                        pb.Dispose();
                        i--;
                    }
                    else
                    {
                        currentList.Add(pb);
                    }
                }
                else
                {
                    var lb = flowPreview.Controls[i] as Label;
                    if (lb != null)
                    {
                        flowPreview.Controls.Remove(lb);
                        i--;
                    }
                }
            }

            int      ci        = 0;
            DateTime dtCurrent = DateTime.MinValue;
            bool     first     = true;

            foreach (FilePreview fp in l)
            {
                var dt = new DateTime(fp.CreatedDateTicks);
                if (first || dtCurrent.DayOfYear != dt.DayOfYear)
                {
                    first     = false;
                    dtCurrent = dt;
                    var lb = new Label {
                        Text = dtCurrent.ToShortDateString(), Margin = new Padding(3), Padding = new Padding(0), ForeColor = Color.White, BackColor = Color.Black, Width = 96, Height = 73, TextAlign = ContentAlignment.MiddleCenter
                    };
                    flowPreview.Controls.Add(lb);
                    flowPreview.Controls.SetChildIndex(lb, ci);
                    ci++;
                }
                var cdt = new DateTime(fp.CreatedDateTicks);
                var pb  = currentList.FirstOrDefault(p => p.CreatedDate == cdt);
                if (pb == null)
                {
                    FilePreview fp1 = fp;
                    var         dir = Helper.GetMediaDirectory(fp1.ObjectTypeId, fp1.ObjectId);
                    switch (fp1.ObjectTypeId)
                    {
                    case 1:
                        var v = Microphones.SingleOrDefault(p => p.id == fp1.ObjectId);
                        if (v != null)
                        {
                            var filename = dir + "audio\\" + v.directory + "\\" + fp.Filename;
                            pb = AddPreviewControl(fp1, Resources.audio, filename, v.name);
                        }
                        break;

                    case 2:
                        var c = Cameras.SingleOrDefault(p => p.id == fp1.ObjectId);
                        if (c != null)
                        {
                            var filename = dir + "video\\" + c.directory + "\\" + fp.Filename;
                            var thumb    = dir + "video\\" + c.directory + "\\thumbs\\" +
                                           fp.Filename.Substring(0,
                                                                 fp.Filename.LastIndexOf(".", StringComparison.Ordinal)) +
                                           ".jpg";
                            pb = AddPreviewControl(fp1, thumb, filename, c.name);
                        }
                        break;
                    }
                }
                if (pb != null)
                {
                    flowPreview.Controls.SetChildIndex(pb, ci);
                    ci++;
                }
            }

            flowPreview.ResumeLayout(true);
            NeedsMediaRebuild = false;
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void RenderList(List <FilePreview> l, int pageCount)
        {
            var currentList = new List <PreviewBox>();



            int      ci        = 0;
            DateTime dtCurrent = DateTime.MinValue;
            bool     first     = true;

            foreach (FilePreview fp in l)
            {
                var dt = new DateTime(fp.CreatedDateTicks);
                if (first || dtCurrent.DayOfYear != dt.DayOfYear)
                {
                    first     = false;
                    dtCurrent = dt;
                    DateTime tag = new DateTime(dtCurrent.Year, dtCurrent.Month, dtCurrent.Day);
                    var      lb  = new Label {
                        Text = dtCurrent.ToShortDateString(), Tag = tag, Margin = new Padding(3), Padding = new Padding(0), ForeColor = Color.White, BackColor = Color.Black, Width = 96, Height = 73, TextAlign = ContentAlignment.MiddleCenter
                    };
                    lb.Click += Lb_Click;
                    lb.Cursor = Cursors.Hand;

                    ci++;
                }
                var cdt = new DateTime(fp.CreatedDateTicks);
                var pb  = currentList.FirstOrDefault(p => p.CreatedDate == cdt);
                if (pb == null)
                {
                    FilePreview fp1 = fp;
                    var         dir = Helper.GetMediaDirectory(fp1.ObjectTypeId, fp1.ObjectId);
                    switch (fp1.ObjectTypeId)
                    {
                    case 1:
                        var v = Microphones.SingleOrDefault(p => p.id == fp1.ObjectId);
                        if (v != null)
                        {
                            var filename = dir + "audio\\" + v.directory + "\\" + fp.Filename;
                            pb = AddPreviewControl(fp1, Resources.audio, filename, v.name);
                        }
                        break;

                    case 2:
                        var c = Cameras.SingleOrDefault(p => p.id == fp1.ObjectId);
                        if (c != null)
                        {
                            var filename = dir + "video\\" + c.directory + "\\" + fp.Filename;
                            var thumb    = dir + "video\\" + c.directory + "\\thumbs\\" +
                                           fp.Filename.Substring(0,
                                                                 fp.Filename.LastIndexOf(".", StringComparison.Ordinal)) +
                                           ".jpg";
                            pb = AddPreviewControl(fp1, thumb, filename, c.name);
                        }
                        break;
                    }
                }
                if (pb != null)
                {
                    ci++;
                }
            }


            NeedsMediaRebuild = false;
        }