/// <summary>
        /// Create the specified Registry Key & Subkeys (if not existing) and sets the specified value.
        /// </summary>
        /// <param name="value">The value for the Key to be created</param>
        /// <param name="registry">The Registry Model Containing RegistryName and SubKey</param>
        public void Create(object value, RegistryModel registry)
        {
            if (registry.IsRegistryReal)
            {
                return;
            }

            //If the subKey exists, let's create our entry.
            if (registry.IsSubKeyReal)
            {
                registry.SubKey.CreateSubKey(registry.RegistryName, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None);
                registry.SubKey.SetValue(registry.RegistryName, value);
            }
            else
            {
                //Let's create the Sub SubKey before.
                string lastRealSubKeyName = registry.LastRealSubKey.Name;
                var    subKeyToCreate     = registry.SubKeySeparatedByBackSlashes.Remove(0, lastRealSubKeyName.Count());

                while (subKeyToCreate[0] == '\\')
                {
                    subKeyToCreate = subKeyToCreate.Remove(0, 1);
                }

                registry.LastRealSubKey.CreateSubKey(subKeyToCreate, RegistryKeyPermissionCheck.ReadWriteSubTree);
                Create(value, registry);
            }
        }
        public IHttpActionResult PostRegistryModel(RegistryModel registryModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.RegistryModels.Add(registryModel);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (RegistryModelExists(registryModel.UserName))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = registryModel.UserName }, registryModel));
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutRegistryModel(int id, RegistryModel registryModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != registryModel.Id)
            {
                return(BadRequest());
            }

            db.Entry(registryModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RegistryModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        public IHttpActionResult PostRegistryModel(RegistryModel registryModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            registryModel.Password = ComputeHash(registryModel.Password);

            try
            {
                if (db.RegistryModels.Where(m => m.UserName == registryModel.UserName).Any())
                {
                    throw new DbUpdateException();
                }
                db.RegistryModels.Add(registryModel);
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(Conflict());
            }


            return(CreatedAtRoute("DefaultApi", new { id = registryModel.Id }, registryModel));
        }
        public async Task <ActionResult> Register(RegistryModel model)
        {
            if (ModelState.IsValid)
            {
                User user = new User();
                user.Name        = model.UserName;
                user.Nick        = model.NickName;
                user.Password    = model.Password.MD5();
                user.Admin       = false;
                user.CreatedTime = DateTime.Now;

                var(id, message) = await _accountService.RegisterAsync(user);

                if (id == 0)
                {
                    ModelState.AddModelError("", message);
                }
                else
                {
                    user.Id = id;
                    HttpContext.SignIn(user.Nick, DateTime.Now.AddMinutes(30), true, user.Id.ToString().Encrypt());
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }
Ejemplo n.º 6
0
        public async Task <HttpStatusCode> Register(RegistryModel model)
        {
            var request = new RestRequest("registry", Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddBody(model);

            var taskCompletionSource = new TaskCompletionSource <IRestResponse>();

            restClient.ExecuteAsync(request, restResponse =>
            {
                if (restResponse.ErrorException != null)
                {
                    const string message = "Error retrieving response.";
                    throw new ApplicationException(message, restResponse.ErrorException);
                }
                taskCompletionSource.SetResult(restResponse);
            });



            var result = await taskCompletionSource.Task;

            return(result.StatusCode);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Retrieves the value of a RegistryModel within the specified RegistryKey.
        /// Ex: RegistryKey is used as a startpoint, for example Registry.CurrentUser
        /// Side Note: In case your RegistryModel does not contain the SubKeys, the finder will recursively search through the registry.
        /// </summary>
        /// <param name="startPoint">RegistryKey or Folder to start the search, Example: Registry.LocalMachine</param>
        /// <param name="registry">The Registry you want to get the value for.</param>
        /// <returns>The value of the registry, if there is no registry, it retrieves null.</returns>
        public object GetValueFrom(RegistryModel registry, RegistryKey startPoint = null)
        {
            if (string.IsNullOrEmpty(registry.RegistryName))
            {
                throw new Exception();
            }

            //Checking that SubKey does not include the RegistryHive.
            //var firstSplit = registry.SubKeySeparatedByBackSlashes.Substring(0, registry.SubKeySeparatedByBackSlashes.IndexOf('\\'));
            //if (_startPoints.Any(x => x.ToString() == firstSplit))
            //    registry.SubKeySeparatedByBackSlashes = registry.SubKeySeparatedByBackSlashes.Remove(0, registry.SubKeySeparatedByBackSlashes.IndexOf('\\') + 1);

            if (startPoint == null)
            {
                foreach (var searchPoint in _startPoints)
                {
                    object value = GetValueFrom(registry, searchPoint);

                    if (value != null)
                    {
                        return(value);
                    }
                }
            }

            RegistryKey pathToRegistry = string.IsNullOrEmpty(registry.SubKeySeparatedByBackSlashes)
                ? GetRegistryKeyWithRecursiveSearch(startPoint, registry)
                : GetStraightRegistryKey(startPoint, registry);

            return(GetValueFromRegistryKey(pathToRegistry, registry));
        }
Ejemplo n.º 8
0
        public ActionResult SignUp(RegistryModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }
            this.ViewBag.AllMonths = this.GetAllMonths();
            string birthdayDate = model.Date.ToString() + model.Month + model.Year;

            if (this._registryService.CheckTheUser(model.FirstName, model.LastName, birthdayDate, model.Gender))
            {
                return(this.View("SignUpAlreadyExists", new RegistryModel()
                {
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Date = model.Date,
                    Month = model.Month,
                    Year = model.Year,
                    Gender = model.Gender,
                    HasClone = true
                }));
            }

            return(this.View("SignUpCredentials", new FinalRegistryModel()
            {
                FirstName = model.FirstName,
                LastName = model.LastName,
                Date = model.Date,
                Month = model.Month,
                Year = model.Year,
                Gender = model.Gender,
                HasClone = false
            }));
        }
Ejemplo n.º 9
0
        public ActionResult SignUp()
        {
            var model = new RegistryModel();

            this.ViewBag.AllMonths = this.GetAllMonths();
            return(this.View(model));
        }
        public void GoBackTest()
        {
            RegistryModel model = new RegistryModel("HKEY_CURRENT_USER\\SOFTWARE\\Google\\Chrome", false);

            var subKey = model.SubKey.GoBack();

            Assert.IsTrue(subKey.Name == "HKEY_CURRENT_USER\\SOFTWARE\\Google");
        }
Ejemplo n.º 11
0
 public ActionResult RegisterEvent(RegistryModel model)
 {
     //Thêm mới đăng ký
     _context.Entry(model).State = System.Data.EntityState.Added;
     _context.SaveChanges();
     ViewBag.IsSuccess = true;
     return(View("RegisterCourse", model));
 }
Ejemplo n.º 12
0
        public void ConstructorTest1()
        {
            string path = "HKEY_CURRENT_USER\\Control Panel\\Desktop\\BlockSendInputResets";

            var model = new RegistryModel(path);

            Assert.IsTrue(model.IsRegistryReal);
            Assert.IsTrue(model.IsSubKeyReal);
        }
Ejemplo n.º 13
0
        private object GetValueFromRegistryKey(RegistryKey key, RegistryModel registry)
        {
            if (key == null)
            {
                return(null);
            }

            return(key.GetValue(registry.RegistryName));
        }
        public void TryGetValue()
        {
            RegistryModel model = new RegistryModel("Control Panel\\Desktop", true);

            object logPixelsValue;
            bool   gotValue = model.SubKey.TryGetValue("LogPixels", out logPixelsValue);

            Assert.IsNotNull(logPixelsValue);
            Assert.IsTrue(gotValue);
        }
        public void TryGetSubKey()
        {
            RegistryModel model = new RegistryModel("HKEY_CURRENT_USER\\SOFTWARE\\Google", false);

            RegistryKey chromeSubKey;
            bool        gotSubKey = model.SubKey.TryGetSubKey("Chrome", out chromeSubKey);

            Assert.IsNotNull(chromeSubKey);
            Assert.IsTrue(gotSubKey);
        }
        public IEnumerable <RegistryModel> DeleteRegistryModel(string userName)
        {
            RegistryModel registryModel = db.RegistryModels.Find(userName);


            db.RegistryModels.Remove(registryModel);
            db.SaveChanges();

            return(db.RegistryModels.Where(m => m.UserName == userName));;
        }
Ejemplo n.º 17
0
 public ActionResult Edit(RegistryModel rolesmodel)
 {
     if (ModelState.IsValid)
     {
         _context.Entry(rolesmodel).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rolesmodel));
 }
Ejemplo n.º 18
0
        public ActionResult Edit(int id = 0)
        {
            RegistryModel regismodel = _context.RegistryModel.Find(id);

            if (regismodel == null)
            {
                return(HttpNotFound());
            }
            return(View(regismodel));
        }
        private void AddNewModelToCollection(string section, string path, string key, string value, string type)
        {
            var model = RegistryKeysToAdd.FirstOrDefault(x =>
            {
                return((x.RegistrySectionLong.Equals(section) &&
                        x.RegistryPathToKey.Equals(path) &&
                        x.RegistryKeyName != null && x.RegistryKeyName.Equals(key) &&
                        x.RegistryKeyValue != null && x.RegistryKeyValue.Equals(value) &&
                        x.RegistryKeyType != null && x.RegistryKeyType.Equals(type))
                       ||
                       (x.RegistrySectionLong.Equals(section) &&
                        x.RegistryPathToKey.Equals(path)));
            });

            if (model == null)
            {
                model = new RegistryModel
                {
                    RegistrySectionLong  = section,
                    RegistrySectionShort = ConvertSectionNameLongToShort(section),
                    RegistryPathToKey    = path,
                    RegistryKeyName      = key,
                    RegistryKeyValue     = value,
                    RegistryKeyType      = type
                };
                RegistryKeysToAdd.Add(model);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(model.RegistryKeyName) &&
                    !string.IsNullOrWhiteSpace(model.RegistryKeyValue) &&
                    !string.IsNullOrWhiteSpace(model.RegistryKeyType))
                {
                    model = new RegistryModel
                    {
                        RegistrySectionLong  = section,
                        RegistrySectionShort = ConvertSectionNameLongToShort(section),
                        RegistryPathToKey    = path,
                        RegistryKeyName      = key,
                        RegistryKeyValue     = value,
                        RegistryKeyType      = type
                    };
                    RegistryKeysToAdd.Add(model);
                }
                else
                {
                    model.RegistrySectionShort = ConvertSectionNameLongToShort(section);
                    model.RegistryKeyName      = key;
                    model.RegistryKeyValue     = value;
                    model.RegistryKeyType      = type;
                }
            }
        }
        public void GetRegistryKeyByRecursivity2()
        {
            RegistryFinder finder   = new RegistryFinder();
            RegistryModel  registry = new RegistryModel
            {
                RegistryName = "LogPixels"
            };

            RegistryKey value = finder.GetRegistryKeyFor(registry);

            Assert.IsTrue(value.ContainsKey(registry.RegistryName));
        }
        public void GetValueByRecursivity()
        {
            RegistryFinder finder   = new RegistryFinder();
            RegistryModel  registry = new RegistryModel
            {
                SubKeySeparatedByBackSlashes = "Control Panel\\Desktop",
                RegistryName = "LogPixels"
            };

            object value = finder.GetValueFrom(registry);

            Assert.IsNotNull(value);
        }
        public void GetRegistryKeyByRecursivity()
        {
            RegistryFinder finder   = new RegistryFinder();
            RegistryModel  registry = new RegistryModel
            {
                SubKeySeparatedByBackSlashes = "Control Panel\\Desktop",
                RegistryName = "LogPixels"
            };

            RegistryKey value = finder.GetRegistryKeyFor(registry);

            Assert.IsTrue(value.ContainsKey(registry.RegistryName));
        }
        public void GetStraightValueHiveLoad()
        {
            RegistryFinder finder   = new RegistryFinder();
            RegistryModel  registry = new RegistryModel
            {
                SubKeySeparatedByBackSlashes = "Control Panel\\Desktop",
                RegistryName = "LogPixels"
            };

            object value = finder.GetValueFrom(registry, RegistryHive.CurrentUser);

            Assert.IsNotNull(value);
        }
        public void GetStraightValueFail()
        {
            RegistryFinder finder   = new RegistryFinder();
            RegistryModel  registry = new RegistryModel
            {
                SubKeySeparatedByBackSlashes = "Control Panel\\Desktop",
                RegistryName = "UnexistingKey"
            };

            object value = finder.GetValueFrom(registry, Registry.CurrentUser);

            Assert.IsNull(value);
        }
        public void GetStraightKeyHiveLoad()
        {
            RegistryFinder finder   = new RegistryFinder();
            RegistryModel  registry = new RegistryModel
            {
                SubKeySeparatedByBackSlashes = "Control Panel\\Desktop",
                RegistryName = "LogPixels"
            };

            RegistryKey value = finder.GetRegistryKeyFor(registry, RegistryHive.CurrentUser);

            Assert.IsTrue(value.ContainsKey(registry.RegistryName));
        }
        /// <summary>
        /// Sets the specified value into the specified registry key
        /// </summary>
        /// <param name="value">the new value for the registry</param>
        /// <param name="registry">registry to modify.</param>
        public void Set(object value, RegistryModel registry)
        {
            try
            {
                //TODO: Pick the proper type set depending the object.
                var type = RegistryValueKind.String;

                registry.SubKey.SetValue(registry.RegistryName, value, type);
            }
            catch
            {
                throw;
            }
        }
        private void AddNewRegistryKeyCommandAction()
        {
            var item = new RegistryModel
            {
                RegistrySectionLong  = SectionName,
                RegistrySectionShort = ConvertSectionNameLongToShort(SectionName),
                RegistryPathToKey    = Path,
                RegistryKeyName      = KeyName,
                RegistryKeyValue     = KeyValue,
                RegistryKeyType      = ConvertKeyType(KeyType)
            };

            RegistryKeysToAdd.Add(item);
        }
        public void GetStraightKeyFail()
        {
            RegistryFinder finder   = new RegistryFinder();
            RegistryModel  registry = new RegistryModel
            {
                SubKeySeparatedByBackSlashes = "Control Panel\\Unexistingshit",
                RegistryName = "UnexistingKey"
            };

            RegistryKey value = finder.GetRegistryKeyFor(registry, Registry.CurrentUser);

            Assert.IsNull(registry.SubKey);
            Assert.IsFalse(registry.IsRegistryReal);
        }
Ejemplo n.º 29
0
        public IHttpActionResult DeleteRegistryModel(int id)
        {
            RegistryModel registryModel = db.RegistryModels.Find(id);

            if (registryModel == null)
            {
                return(NotFound());
            }

            db.RegistryModels.Remove(registryModel);
            db.SaveChanges();

            return(Ok(registryModel));
        }
Ejemplo n.º 30
0
 public ActionResult SignUpAlreadyExists(RegistryModel model)
 {
     this.ViewBag.AllMonths = this.GetAllMonths();
     return(this.View("SignUpCredentials", new FinalRegistryModel()
     {
         FirstName = model.FirstName,
         LastName = model.LastName,
         Date = model.Date,
         Month = model.Month,
         Year = model.Year,
         Gender = model.Gender,
         HasClone = model.HasClone
     }));
 }