示例#1
0
        public Response UpdateComDetails(ComDetails obj)
        {
            List <ComDetails> itemList = new List <ComDetails>();
            var IsExist = entities.comports.Where(x => x.id == obj.id).ToList();

            if (IsExist.Count != 0)
            {
                comport itemObj = entities.comports.Where(x => x.id == obj.id).FirstOrDefault();

                itemObj.port     = obj.port;
                itemObj.buadRate = obj.buadRate;
                itemObj.parity   = obj.parity;
                itemObj.dataBit  = obj.dataBit;
                itemObj.stopBit  = obj.stopBit;
                entities.SaveChanges();
                return(new Response {
                    IsSuccess = true, Message = "COM Port Configured successfully"
                });
            }
            else
            {
                return new Response {
                           IsSuccess = false, Message = "Configuration Error. Contact Administrator"
                }
            };
        }

        #endregion
    }
示例#2
0
        public ActionResult ConfigureComPort(string id, string port, string buadRate, string parity, string dataBit, string stopBit)
        {
            Response      res        = new Response();
            List <object> resultList = new List <object>();
            ComDetails    item       = new ComDetails();

            item.port     = port;
            item.id       = long.Parse(id);
            item.buadRate = buadRate;
            item.parity   = parity;
            item.dataBit  = dataBit;
            item.stopBit  = stopBit;

            res = masterDal.UpdateComDetails(item);
            resultList.Add(res);
            resultList.Add(ReadComDetails());


            return(Json(resultList, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        /// <summary>
        /// Parse all the Subkeys of the given SearchKey into ComObjects and returns a list of them
        /// </summary>
        /// <param name="SearchKey">The Registry Key to search</param>
        /// <param name="View">The View of the registry to use</param>
        public static IEnumerable <CollectObject> ParseComObjects(RegistryKey SearchKey, RegistryView View)
        {
            if (SearchKey == null)
            {
                return(new List <CollectObject>());
            }
            List <ComObject> comObjects = new List <ComObject>();

            try
            {
                Parallel.ForEach(SearchKey.GetSubKeyNames(), (SubKeyName) =>
                {
                    try
                    {
                        RegistryKey CurrentKey = SearchKey.OpenSubKey(SubKeyName);

                        var RegObj = RegistryWalker.RegistryKeyToRegistryObject(CurrentKey, View);

                        if (RegObj != null)
                        {
                            ComObject comObject = new ComObject(RegObj);

                            foreach (string ComDetails in CurrentKey.GetSubKeyNames())
                            {
                                if (ComDetails.Contains("InprocServer32"))
                                {
                                    var ComKey          = CurrentKey.OpenSubKey(ComDetails);
                                    var obj             = RegistryWalker.RegistryKeyToRegistryObject(ComKey, View);
                                    string?BinaryPath32 = null;

                                    if (obj != null && obj.Values?.TryGetValue("", out BinaryPath32) is bool successful)
                                    {
                                        if (successful && BinaryPath32 != null)
                                        {
                                            // Clean up cases where some extra spaces are thrown into the start (breaks our permission checker)
                                            BinaryPath32 = BinaryPath32.Trim();
                                            // Clean up cases where the binary is quoted (also breaks permission checker)
                                            if (BinaryPath32.StartsWith("\"") && BinaryPath32.EndsWith("\""))
                                            {
                                                BinaryPath32 = BinaryPath32.AsSpan().Slice(1, BinaryPath32.Length - 2).ToString();
                                            }
                                            // Unqualified binary name probably comes from Windows\System32
                                            if (!BinaryPath32.Contains("\\") && !BinaryPath32.Contains("%"))
                                            {
                                                BinaryPath32 = Path.Combine(Environment.SystemDirectory, BinaryPath32.Trim());
                                            }

                                            comObject.x86_Binary = FileSystemCollector.FilePathToFileSystemObject(BinaryPath32.Trim(), true);
                                        }
                                    }
                                }
                                if (ComDetails.Contains("InprocServer64"))
                                {
                                    var ComKey          = CurrentKey.OpenSubKey(ComDetails);
                                    var obj             = RegistryWalker.RegistryKeyToRegistryObject(ComKey, View);
                                    string?BinaryPath64 = null;

                                    if (obj != null && obj.Values?.TryGetValue("", out BinaryPath64) is bool successful)
                                    {
                                        if (successful && BinaryPath64 != null)
                                        {
                                            // Clean up cases where some extra spaces are thrown into the start (breaks our permission checker)
                                            BinaryPath64 = BinaryPath64.Trim();
                                            // Clean up cases where the binary is quoted (also breaks permission checker)
                                            if (BinaryPath64.StartsWith("\"") && BinaryPath64.EndsWith("\""))
                                            {
                                                BinaryPath64 = BinaryPath64.AsSpan().Slice(1, BinaryPath64.Length - 2).ToString();
                                            }
                                            // Unqualified binary name probably comes from Windows\System32
                                            if (!BinaryPath64.Contains("\\") && !BinaryPath64.Contains("%"))
                                            {
                                                BinaryPath64 = Path.Combine(Environment.SystemDirectory, BinaryPath64.Trim());
                                            }

                                            comObject.x64_Binary = FileSystemCollector.FilePathToFileSystemObject(BinaryPath64.Trim(), true);
                                        }
                                    }
                                }
                            }

                            comObjects.Add(comObject);
                        }
                    }
                    catch (Exception e) when(
                        e is System.Security.SecurityException ||
                        e is ObjectDisposedException ||
                        e is UnauthorizedAccessException ||
                        e is IOException)
                    {
                        Log.Debug($"Couldn't parse {SubKeyName}");
                    }
                });
            }
            catch (Exception e) when(
                e is System.Security.SecurityException ||
                e is ObjectDisposedException ||
                e is UnauthorizedAccessException ||
                e is IOException)
            {
                Log.Debug($"Failing parsing com objects {SearchKey.Name} {e.GetType().ToString()} {e.Message}");
            }

            return(comObjects);
        }