private void DeleteHardware()
        {
            Log("Reading hardware info from csv");
            var hardwareDtos = CsvReadWriteHelper.Read <HardwareInfo>(CsvFile).ToList();

            Log("Retrieving hardware records from VMS");
            var hardware = _xprotect.GetHardware();

            foreach (var hw in hardware.Where(h => hardwareDtos.Any(d => string.Equals(d.ReadOnlyId.ToString(), h.Id, StringComparison.CurrentCultureIgnoreCase))))
            {
                _xprotect.DeleteConfigurationItem(hw.Path);
            }
        }
        private void ImportHardwareData()
        {
            Log("Reading hardware info from csv");
            var hardwareDtos = CsvReadWriteHelper.Read <HardwareInfo>(CsvFile).ToList();

            Log("Retrieving hardware records from VMS");
            var hardware = _xprotect.GetHardware();

            //var hardware = _xprotect.GetHardware(hardwareDtos);

            Log($"Processing {hardwareDtos.Count()} hardware items from CSV");
            Parallel.ForEach(hardwareDtos, hardwareInfo =>
            {
                var hw = hardware.FirstOrDefault(h =>
                                                 h.Id.Equals(hardwareInfo.ReadOnlyId.ToString(), StringComparison.OrdinalIgnoreCase));
                if (hw != null)
                {
                    Log($"Updating {hw.DisplayName}");
                    hw.Address  = hardwareInfo.Address;
                    hw.Name     = hardwareInfo.Name;
                    hw.UserName = hardwareInfo.UserName;
                    try
                    {
                        hw.ChangePasswordHardware(hardwareInfo.Password);
                    }
                    catch (Exception ex)
                    {
                        Log($"Unable to set password. Error '{ex.Message}'");
                    }
                    try
                    {
                        hw.Save();
                    }
                    catch (ValidateResultException)
                    {
                        Log(
                            $"Hardware '{hw.DisplayName}' not updated due to one or more invalid fields:\r\n{hardwareInfo.ToPrettyString()}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    Log($"No hardware was found on the VMS matching Id '{hardwareInfo.ReadOnlyId}'");
                }
            });
        }
        private void ImportHardwareData()
        {
            if (ProfessionalVmsHardware == null)
            {
                Log("Reading hardware info from csv");
                var hardwareDtos = CsvReadWriteHelper.Read <NewHardwareInfo>(CsvFile).ToList();

                Log($"Processing {hardwareDtos.Count()} hardware items from CSV");
                Parallel.ForEach(hardwareDtos, hardwareInfo =>
                {
                    try
                    {
                        AddCamera(hardwareInfo);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("An error occurred adding hardware named " + hardwareInfo.HardwareName + ". Error " + ex.Message);
                    }
                });
            }
            else
            {
                if (string.IsNullOrEmpty(RecordingServerName))
                {
                    Console.WriteLine("You must supply the name of the Recording Server to which to migrate cameras from the local Professional VMS");
                    return;
                }
                foreach (var hardwareInfo in ProfessionalVmsHardware)
                {
                    try
                    {
                        if (!AddCamera(hardwareInfo, RecordingServerName, CameraGroupName))
                        {
                            _failedMigrations.Add(hardwareInfo);
                        }
                    }
                    catch (Exception ex)
                    {
                        _failedMigrations.Add(hardwareInfo);
                        Console.WriteLine("An error occurred adding hardware named " + hardwareInfo.DisplayName + ". Error " + ex.Message);
                        Console.WriteLine(ex.StackTrace);
                    }
                }

                ShowFailedMigrationReport();
            }
        }
        private void ImportData()
        {
            Log("Reading microphone info from csv");
            var micDtos = CsvReadWriteHelper.Read <MicInfo>(CsvFile);

            Log("Retrieving microphone records from VMS");
            var microphones = _xprotect.GetMicrophones();

            Log($"Processing {micDtos.Count()} microphones from CSV");
            Parallel.ForEach(micDtos, micInfo =>
            {
                var mic = microphones.FirstOrDefault(m =>
                                                     m.Id.Equals(micInfo.ReadOnlyId.ToString(), StringComparison.OrdinalIgnoreCase));
                if (mic != null)
                {
                    Log($"Updating {mic.DisplayName}");
                    mic.Name    = micInfo.Name;
                    mic.Enabled = micInfo.Enabled;
                    mic.SetProperty("RecordingEnabled", micInfo.RecordingEnabled.ToString());
                    try
                    {
                        mic.Save();
                    }
                    catch (ValidateResultException)
                    {
                        Log(
                            $"Microphone '{mic.DisplayName}' not updated due to one or more invalid fields:\r\n{micInfo.ToPrettyString()}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        throw;
                    }
                }
                else
                {
                    Log($"No microphone was found on the VMS matching Id '{micInfo.ReadOnlyId}'");
                }
            });
        }
        private void ImportCameraData()
        {
            Log("Reading camera info from csv");
            var cameraDtos = CsvReadWriteHelper.Read <CameraInfo>(CsvFile).ToList();

            Log("Retrieving camera records from VMS");
            var cameras = _xprotect.GetCameras();

            Log($"Processing {cameraDtos.Count()} cameras from CSV");
            Parallel.ForEach(cameraDtos, cameraInfo =>
            {
                var camera = cameras.FirstOrDefault(h =>
                                                    h.Id.Equals(cameraInfo.ReadOnlyId.ToString(), StringComparison.OrdinalIgnoreCase));
                if (camera != null)
                {
                    Log($"Updating {camera.DisplayName}");
                    camera.Name    = cameraInfo.Name;
                    camera.Enabled = cameraInfo.Enabled;
                    camera.SetProperty("RecordingEnabled", cameraInfo.RecordingEnabled.ToString());
                    try
                    {
                        camera.Save();
                    }
                    catch (ValidateResultException)
                    {
                        Log(
                            $"Camera '{camera.DisplayName}' not updated due to one or more invalid fields:\r\n{cameraInfo.ToPrettyString()}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        throw;
                    }
                }
                else
                {
                    Log($"No camera was found on the VMS matching Id '{cameraInfo.ReadOnlyId}'");
                }
            });
        }
Пример #6
0
        private void ImportData()
        {
            Log("Reading speaker info from csv");
            var speakerDtos = CsvReadWriteHelper.Read <SpeakerInfo>(CsvFile);

            Log("Retrieving speaker records from VMS");
            var speakers = _xprotect.GetSpeakers();

            Log($"Processing {speakerDtos.Count()} speakers from CSV");
            Parallel.ForEach(speakerDtos, speakerInfo =>
            {
                var speaker = speakers.FirstOrDefault(m =>
                                                      m.Id.Equals(speakerInfo.ReadOnlyId.ToString(), StringComparison.OrdinalIgnoreCase));
                if (speaker != null)
                {
                    Log($"Updating {speaker.DisplayName}");
                    speaker.Name    = speakerInfo.Name;
                    speaker.Enabled = speakerInfo.Enabled;
                    speaker.SetProperty("RecordingEnabled", speakerInfo.RecordingEnabled.ToString());
                    try
                    {
                        speaker.Save();
                    }
                    catch (ValidateResultException)
                    {
                        Log(
                            $"Speaker '{speaker.DisplayName}' not updated due to one or more invalid fields:\r\n{speakerInfo.ToPrettyString()}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        throw;
                    }
                }
                else
                {
                    Log($"No speaker was found on the VMS matching Id '{speakerInfo.ReadOnlyId}'");
                }
            });
        }
Пример #7
0
        private void ImportOutputData()
        {
            Log($"Reading output info from csv");
            var outputDtos = CsvReadWriteHelper.Read <OutputInfo>(CsvFile).ToList();

            Log($"Retrieving output records from VMS");
            var outputs = _xprotect.GetOutputs();

            Log($"Processing {outputDtos.Count()} output records from CSV");
            Parallel.ForEach(outputDtos, outputInfo =>
            {
                var output = outputs.FirstOrDefault(m =>
                                                    m.Id.Equals(outputInfo.ReadOnlyId.ToString(), StringComparison.OrdinalIgnoreCase));
                if (output != null)
                {
                    Log($"Updating {output.DisplayName}");
                    output.Name    = outputInfo.Name;
                    output.Enabled = outputInfo.Enabled;
                    try
                    {
                        output.Save();
                    }
                    catch (ValidateResultException)
                    {
                        Log(
                            $"Output '{output.DisplayName}' not updated due to one or more invalid fields:\r\n{outputInfo.ToPrettyString()}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        throw;
                    }
                }
                else
                {
                    Log($"No output record was found on the VMS matching Id '{outputInfo.ReadOnlyId}'");
                }
            });
        }
        private void ImportRecorderData()
        {
            Log("Reading recorder info from csv");
            var recorderDtos = CsvReadWriteHelper.Read <RecorderInfo>(CsvFile);

            Log("Retrieving recorder records from VMS");
            var recordingServers = _xprotect.GetRecordingServers();

            Log($"Processing {recorderDtos.Count()} recorders from CSV");
            Parallel.ForEach(recorderDtos, recorderInfo =>
            {
                var recorder = recordingServers.FirstOrDefault(h =>
                                                               h.Id.Equals(recorderInfo.ReadOnlyId.ToString(), StringComparison.OrdinalIgnoreCase));
                if (recorder != null)
                {
                    Log($"Updating {recorder.DisplayName}");
                    recorder.Name = recorderInfo.Name;
                    try
                    {
                        recorder.Save();
                    }
                    catch (ValidateResultException)
                    {
                        Log(
                            $"Recorder '{recorder.DisplayName}' not updated due to one or more invalid fields:\r\n{recorderInfo.ToPrettyString()}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        throw;
                    }
                }
                else
                {
                    Log($"No recorder was found on the VMS matching Id '{recorderInfo.ReadOnlyId}'");
                }
            });
        }