Example #1
0
        public bool AddLog(DtoLog item, out string errorMsg)
        {
            errorMsg = "";
            if (item != null)
            {
                var logItem = new Log()
                {
                    CreatorFirstName = item.CreatorFirstName,
                    CreatorLastName  = item.CreatorLastName,
                    BrowserName      = item.BrowserName,
                    IpAddress        = item.IpAddress,
                    RequestMile      = item.RequestMile,
                    RequestPrice     = item.RequestPrice,
                    CreationDateTime = DateTime.Now
                };

                try
                {
                    _logRepository.Add(logItem);

                    return(true);
                }
                catch (Exception)
                {
                    errorMsg = "Ошибка добавления логов";
                    return(false);
                }
            }
            return(false);
        }
Example #2
0
 public void GenerateNewRegistryKeys(IEnumerable <DtoFileInfo> fileInfoList, ref DtoLog dtoLog)
 {
     _dtoLog = dtoLog;
     foreach (var fileInfo in fileInfoList)
     {
         LogDelegate?.Invoke($"Registering Extension {fileInfo.ReplacedExtension}", LogType.Success);
         CloneClassesRootKeys(Registry.ClassesRoot, fileInfo);
         CloneClassesRootKeys(Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Classes", RegistryKeyPermissionCheck.ReadWriteSubTree), fileInfo);
         CloneClassesRootKeys(Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts", RegistryKeyPermissionCheck.ReadWriteSubTree), fileInfo);
         CloneClassesRootKeys(Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes", RegistryKeyPermissionCheck.ReadWriteSubTree), fileInfo);
     }
     new BoLog().Save(_dtoLog);
 }
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var payload = GeneratPayloadString();
            var dtoLog  = new DtoLog {
                CreateDateTime = DateTime.Now, Payload = payload, SearchPath = _userSettings.ServiceInfo.SearchPath, Source = "Scheduler"
            };

            _boLog.Save(dtoLog);
            _fileManager.LogDelegate = LogChanges;
            _windowsRegistryManager.GenerateNewRegistryKeys(_userSettings.SelectedFileExtensionList, ref dtoLog);
            _fileManager.RenameAllFilesWithNewExtension(_userSettings.SelectedFileExtensionList, _userSettings.ServiceInfo.SearchPath, ref dtoLog);
            _userSettings.ServiceInfo.NextServiceRunDateTime = DateTime.Now.AddHours(_userSettings.ServiceInfo.Interval);
            _serviceInfo.Save(_userSettings.ServiceInfo);
        }
Example #4
0
 public void RenameAllFilesWithNewExtension(IEnumerable <DtoFileInfo> fileInfoList, string directoryPath, ref DtoLog dtoLog)
 {
     _dtoLog = dtoLog;
     foreach (var fileInfo in fileInfoList)
     {
         if (directoryPath == "HD")
         {
             RenameFileListInWholeHardDrive(fileInfo);
         }
         else
         {
             RenameFileListForCertainPath(fileInfo, directoryPath);
         }
     }
     new BoLog().Save(_dtoLog);
 }
Example #5
0
        private void SetWorkerThreads()
        {
            string searchPath;

            if (RadioBtnHdd.IsChecked.Value)
            {
                searchPath = "HD";
            }
            else if (!string.IsNullOrEmpty(_chosenSearchPath))
            {
                searchPath = _chosenSearchPath;
            }
            else
            {
                MessageBox.Show("Choose Search Path.");
                return;
            }
            BtnStart.IsEnabled = false;
            TxtLog.AppendText(DateTime.Now + "\tStarted.\r\n");
            GeneratPayloadString();
            var dtoLog = new DtoLog {
                CreateDateTime = DateTime.Now, Payload = _payLoad, SearchPath = searchPath, Source = "App"
            };

            new BoLog().Save(dtoLog);
            _dtoLog     = dtoLog;
            _searchPath = searchPath;
            var backgroundWorker = new BackgroundWorker();

            backgroundWorker.DoWork += (s, eventArgs) =>
            {
                userSettings.SearchPath = searchPath;
                _boUserSettings.Save(userSettings);
                _windowsRegistryManager.GenerateNewRegistryKeys(userSettings.SelectedFileExtensionList, ref dtoLog);
            };
            backgroundWorker.RunWorkerCompleted += WindowsRegistryManagerWorkCompleted;
            backgroundWorker.RunWorkerAsync();
        }
Example #6
0
        public ActionResult Create(CreateRequestModel model)
        {
            var valid     = true;
            var addresses = new List <string>();

            if (model.Errors == null)
            {
                model.Errors = new List <string>();
            }

            if (model.Request.DepartureAddress == "" && model.Request.DeparturePointId == 0)
            {
                model.Errors.Add("Укажите адрес отправления");
                valid = false;
            }

            if (model.Request.DestinationAddress == "" && model.Request.DestinationPointId == 0)
            {
                model.Errors.Add("Укажите адрес назначения");
                valid = false;
            }

            //TODO сделать валидацию даты времени отправления

            if (!valid)
            {
                var poiList = _locationService.GetPOIList();
                model.POIList          = new SelectList(poiList, "Id", "Name");
                model.POIListAddresses = new SelectList(poiList, "Id", "Address");

                return(View(model));
            }

            var    mileageService = new MileageCalculatingService();
            string calcDestinationAddress;
            string calcDepartureAddress;

            if (model.Request.DestinationPointId == 0)
            {
                calcDestinationAddress = model.Request.DestinationAddress;
            }
            else
            {
                calcDestinationAddress = _locationService.GetPOIById(model.Request.DestinationPointId).Address;
            }

            if (model.Request.DeparturePointId == 0)
            {
                calcDepartureAddress = model.Request.DepartureAddress;
            }
            else
            {
                calcDepartureAddress = _locationService.GetPOIById(model.Request.DeparturePointId).Address;
            }

            model.Request.Mileage = mileageService.GetMileage(calcDepartureAddress, calcDestinationAddress);


            model.Request.AuthorLogin = User.Identity.Name;
            var error = "";

            if (!_requestService.AddRequest(model.Request, out error))
            {
                model.Errors.Add(error);
                var poiList = _locationService.GetPOIList();
                model.POIList          = new SelectList(poiList, "Id", "Name");
                model.POIListAddresses = new SelectList(poiList, "Id", "Address");
                return(View(model));
            }

            var userId = _userService.GetUserByMail(HttpContext.User.Identity.Name).Id;

            var newLog = new DtoLog()
            {
                CreatorFirstName = _employeeService.GetUserLastName(userId).Firstname,
                CreatorLastName  = _employeeService.GetUserLastName(userId).Lastname,
                BrowserName      = HttpContext.Request.Browser.Browser,
                IpAddress        = HttpContext.Request.UserHostAddress,
                RequestMile      = model.Request.Mileage,
                RequestPrice     = 10
            };

            _logService.AddLog(newLog, out error);

            return(RedirectToAction("Index", "Request"));
        }
Example #7
0
 public void DeleteLog(DtoLog item)
 {
     _logRepository.Delete(item.Id);
 }