public async Task <IActionResult> PutDeviceHistory(int id, DeviceHistory deviceHistory)
        {
            if (id != deviceHistory.Id)
            {
                return(BadRequest());
            }

            _context.Entry(deviceHistory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeviceHistoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <DeviceHistory> > PostDeviceHistory(DeviceHistory deviceHistory)
        {
            _context.DeviceHistory.Add(deviceHistory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDeviceHistory", new { id = deviceHistory.Id }, deviceHistory));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            DeviceHistory deviceHistory = db.DeviceHistory.Find(id);

            db.DeviceHistory.Remove(deviceHistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
        public override void Execute()
        {
            #line 6 "..\..\Areas\WiFi\Views\DeviceHistory\_List_Search.cshtml"

            var fact = ViewBag.Factory as IEntityOperate;
            var page = ViewBag.Page as Pager;

            var dic = new Dictionary <Int32, String>();
            dic.Add(1, "成功");
            dic.Add(0, "失败");


            #line default
            #line hidden
            WriteLiteral("\r\n<div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\r\n    <label");

            WriteLiteral(" for=\"action\"");

            WriteLiteral(" class=\"control-label\"");

            WriteLiteral(">操作:</label>\r\n");

            WriteLiteral("    ");


            #line 16 "..\..\Areas\WiFi\Views\DeviceHistory\_List_Search.cshtml"
            Write(Html.ForDropDownList("action", DeviceHistory.FindAllActionName(), Request["action"], "全部", true));


            #line default
            #line hidden
            WriteLiteral("\r\n</div>\r\n<div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\r\n    <label");

            WriteLiteral(" for=\"result\"");

            WriteLiteral(" class=\"control-label\"");

            WriteLiteral(">结果:</label>\r\n");

            WriteLiteral("    ");


            #line 20 "..\..\Areas\WiFi\Views\DeviceHistory\_List_Search.cshtml"
            Write(Html.ForDropDownList("success", dic, Request["success"], "全部", true));


            #line default
            #line hidden
            WriteLiteral("\r\n</div>\r\n");
        }
Пример #5
0
        /// <summary>创建历史</summary>
        /// <returns></returns>
        protected override IHistory CreateHistory()
        {
            var hi = new DeviceHistory
            {
                Version = Version,
                Name    = Current + "",
                //NetType = NetType
            };

            return(hi);
        }
 public ActionResult Edit([Bind(Include = "DeviceHistoryID,DeviceFKID,DateRepaired,Remarks")] DeviceHistory deviceHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(deviceHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DeviceFKID = new SelectList(db.Device, "DeviceID", "DeviceName", deviceHistory.DeviceFKID);
     return(View(deviceHistory));
 }
        // GET: DeviceHistories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DeviceHistory deviceHistory = db.DeviceHistory.Find(id);

            if (deviceHistory == null)
            {
                return(HttpNotFound());
            }
            return(View(deviceHistory));
        }
Пример #8
0
        /// <summary>登录</summary>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        protected virtual Device Login(String code, String name, String ip)
        {
            var dv = Device;

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

            dv = Device.FindByCode(code);
            if (dv == null)
            {
                dv = new Device
                {
                    Name   = name,
                    Code   = code,
                    Enable = true,
                };
                dv.Insert();
            }

            if (!dv.Enable)
            {
                throw new Exception($"[{dv.Name}/{dv.Code}]禁止登录");
            }

            dv.Logins++;
            dv.LocalIP     = ip;
            dv.LastLogin   = DateTime.Now;
            dv.LastLoginIP = ip;

            dv.SaveAsync();

            Device = dv;

            // 登录历史
            var hi = new DeviceHistory
            {
                DeviceID       = dv.ID,
                Name           = dv.Name,
                Action         = "登录",
                Success        = true,
                CreateDeviceID = dv.ID,
            };

            hi.SaveAsync();

            return(dv);
        }
        // GET: DeviceHistories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DeviceHistory deviceHistory = db.DeviceHistory.Find(id);

            if (deviceHistory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DeviceFKID = new SelectList(db.Device, "DeviceID", "DeviceName", deviceHistory.DeviceFKID);
            return(View(deviceHistory));
        }
Пример #10
0
 private DeviceHistory CreateDeviceHistoryOnConnect(Device deviceFromDb, DeviceHistory lastHistoryByDevice)
 {
     return(new DeviceHistory()
     {
         CreatedOn = DateTime.UtcNow,
         IsOnline = true,
         CurrentDeviceLocationLatitude = lastHistoryByDevice?.CurrentDeviceLocationLatitude ?? deviceFromDb.Latitude,
         CurrentDeviceLocationLongitude = lastHistoryByDevice?.CurrentDeviceLocationLongitude ?? deviceFromDb.Longitude,
         DeviceLocationLatitude = deviceFromDb.Latitude,
         DeviceLocationLongitude = deviceFromDb.Longitude,
         DeviceRadius = deviceFromDb.Radius,
         LoggedInUserId = lastHistoryByDevice?.LoggedInUserId ?? null,
         DeviceId = deviceFromDb.Id,
         CompanyId = deviceFromDb.CompanyId,
         IsInLocation = lastHistoryByDevice?.IsInLocation ?? true
     });
 }
Пример #11
0
        protected virtual DeviceHistory WriteHistory(String action, IDevice dv)
        {
            var ip = Remote?.EndPoint.Address + "";
            var hi = new DeviceHistory
            {
                DeviceID       = dv.ID,
                Name           = dv.Name,
                Action         = action,
                Success        = true,
                CreateDeviceID = dv.ID,

                CreateTime = DateTime.Now,
                CreateIP   = ip,
            };

            hi.SaveAsync();

            return(hi);
        }
Пример #12
0
        /// <summary>保存操作历史</summary>
        /// <param name="action"></param>
        /// <param name="success"></param>
        /// <param name="content"></param>
        protected override void SaveHistory(String action, Boolean success, String content)
        {
            var hi = new DeviceHistory();

            if (Current is Device dv)
            {
                if (hi.DeviceID == 0)
                {
                    hi.DeviceID = dv.ID;
                }
                if (hi.Name.IsNullOrEmpty())
                {
                    hi.Name = dv + "";
                }

                hi.Version     = dv.Version;
                hi.CompileTime = dv.CompileTime;
            }
            else if (Online is DeviceOnline olt)
            {
                if (hi.DeviceID == 0)
                {
                    hi.DeviceID = olt.DeviceID;
                }
                if (hi.Name.IsNullOrEmpty())
                {
                    hi.Name = olt.Name;
                }
            }

            hi.Action     = action;
            hi.Success    = success;
            hi.Remark     = content;
            hi.CreateTime = DateTime.Now;

            if (Session is INetSession ns)
            {
                hi.CreateIP = ns.Remote + "";
            }

            hi.SaveAsync();
        }
Пример #13
0
        protected void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    if (shell != null)
                    {
                        if (shell.Connected)
                        {
                            shell.close();
                        }
                        shell = null;
                    }
                    if (UserArray != null)
                    {
                        UserArray.Clear();
                    }
                    UserArray = null;
                    if (PWDArray != null)
                    {
                        PWDArray.Clear();
                    }
                    PWDArray = null;
                    if (enPWDArray != null)
                    {
                        enPWDArray.Clear();
                    }
                    enPWDArray = null;
                    if (DeviceHistory != null)
                    {
                        DeviceHistory.Clear();
                    }
                    DeviceHistory = null;
                }

                //free unmanaged objects
                //AdditionalCleanup();

                this.disposed = true;
            }
        }
Пример #14
0
        public List <DeviceHistory> getDeviceDetails(int id)
        {
            string connectionString            = GetConnectionString();
            List <DeviceHistory> deviceHistory = new List <DeviceHistory>();

            DataSet devicesDataSet = new DataSet();

            using (SqlConnection connection = new SqlConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();
                string queryString = String.Format("SELECT * from deviceHistory where deviceId={0};", id);

                SqlCommand command =
                    new SqlCommand(queryString, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                // Call Read before accessing data.
                while (reader.Read())
                {
                    //Mapper
                    DeviceHistory history = new DeviceHistory();
                    history.DeviceId    = Convert.ToInt32(reader["Id"]);
                    history.HistoryId   = Convert.ToInt32(reader["DeviceHistoryId"].ToString());
                    history.Temperature = reader["Temperature"].ToString();
                    history.Pressure    = reader["Pressure"].ToString();
                    history.MeasureTime = Convert.ToDateTime(reader["Time"].ToString());

                    deviceHistory.Add(history);
                }

                // Call Close when done reading.
                reader.Close();

                return(deviceHistory);
            }
        }
Пример #15
0
        public LoginStatus Jump2NextDevice(string nextDevice, string ConnectOptions)
        {
            LoginStatus l_LoginResult = LoginStatus.InProgress;

            DeviceHistoryData DeviceData = new DeviceHistoryData();

            DeviceData.bConnected         = bConnected;
            DeviceData.DevicePromptString = DevicePromptString;
            DeviceData.DevicePrompt       = DevicePrompt;
            DeviceData.DevicePromptConfig = DevicePromptConfig;
            DeviceData.EnableMode         = EnableMode;
            DeviceData.DeviceType         = DeviceType;
            DeviceData.Device             = nextDevice;
            DeviceHistory.Add(DeviceData);

            l_LoginResult = doLogin(nextDevice, ConnectOptions);
            if ((l_LoginResult == LoginStatus.Success) || (l_LoginResult == LoginStatus.UserMode))
            {
                //Login success
                DeviceCounter++;
            }
            else
            {
                //Restore Status from Last Device
                bConnected         = DeviceData.bConnected;
                DevicePromptString = DeviceData.DevicePromptString;
                DevicePrompt       = DeviceData.DevicePrompt;
                DevicePromptConfig = DeviceData.DevicePromptConfig;
                EnableMode         = DeviceData.EnableMode;
                DeviceType         = DeviceData.DeviceType;
                //Device = DeviceData.Device;
                DeviceHistory.RemoveAt(DeviceHistory.Count - 1);
            }

            return(l_LoginResult);
        }
Пример #16
0
 protected virtual void WriteHistory(IDevice dv, String action, Boolean success, String remark)
 {
     DeviceHistory.Create(dv, action, success, remark, Setting.Current.NodeName, UserHost);
 }
Пример #17
0
        private async Task AddAndSendDeviceHistory(string udid, DeviceHistory history)
        {
            await _deviceHistoryRepository.AddAsync(history);

            await _webHubContext.Clients.Group(udid).SendAsync("DeviceUpdated", JsonConvert.SerializeObject(history));
        }
Пример #18
0
        private async Task AddAndSendDeviceHistoryToAll(DeviceHistory history)
        {
            await _deviceHistoryRepository.AddAsync(history);

            await _webHubContext.Clients.All.SendAsync("DeviceAdded", JsonConvert.SerializeObject(history));
        }
Пример #19
0
        public override void Execute()
        {
            #line 5 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"

            var fact = ViewBag.Factory as IEntityOperate;
            var page = ViewBag.Page as Pager;

            var dic = new Dictionary <Int32, String>();
            dic.Add(1, "成功");
            dic.Add(0, "失败");


            #line default
            #line hidden
            WriteLiteral("\n<div");

            WriteLiteral(" class=\"tableTools-container list-toolbar\"");

            WriteLiteral(">\n    <div");

            WriteLiteral(" class=\"form-inline clear-fix\"");

            WriteLiteral(">\n        <form");

            WriteAttribute("action", Tuple.Create(" action=\"", 355), Tuple.Create("\"", 435)

            #line 15 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
                           , Tuple.Create(Tuple.Create("", 364), Tuple.Create <System.Object, System.Int32>(Url.Action("index")

            #line default
            #line hidden
                                                                                                            , 364), false)

            #line 15 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
                           , Tuple.Create(Tuple.Create("", 384), Tuple.Create <System.Object, System.Int32>(Html.Raw("?" + page.GetBaseUrl(false, true, true))

            #line default
            #line hidden
                                                                                                            , 384), false)
                           );

            WriteLiteral(" method=\"post\"");

            WriteLiteral(" role=\"form\"");

            WriteLiteral(">\n            <div");

            WriteLiteral(" class=\"pull-right form-group\"");

            WriteLiteral(">\n                <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\n                    <label");

            WriteLiteral(" for=\"type\"");

            WriteLiteral(" class=\"control-label\"");

            WriteLiteral(">类型:</label>\n");

            WriteLiteral("                    ");


            #line 19 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
            Write(Html.ForDropDownList("type", DeviceHistory.FindAllTypeName(), Request["type"], "全部", true));


            #line default
            #line hidden
            WriteLiteral("\n                </div>\n                <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\n                    <label");

            WriteLiteral(" for=\"action\"");

            WriteLiteral(" class=\"control-label\"");

            WriteLiteral(">操作:</label>\n");

            WriteLiteral("                    ");


            #line 23 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
            Write(Html.ForDropDownList("action", DeviceHistory.FindAllActionName(), Request["action"], "全部", true));


            #line default
            #line hidden
            WriteLiteral("\n                </div>\n                <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\n                    <label");

            WriteLiteral(" for=\"result\"");

            WriteLiteral(" class=\"control-label\"");

            WriteLiteral(">结果:</label>\n");

            WriteLiteral("                    ");


            #line 27 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
            Write(Html.ForDropDownList("result", dic, Request["result"], "全部", true));


            #line default
            #line hidden
            WriteLiteral("\n                </div>\n                <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\n                    <label");

            WriteLiteral(" for=\"dtStart\"");

            WriteLiteral(" class=\"control-label\"");

            WriteLiteral(">时间:</label>\n                    <div");

            WriteLiteral(" class=\"input-group\"");

            WriteLiteral(">\n                        <span");

            WriteLiteral(" class=\"input-group-addon\"");

            WriteLiteral("><i");

            WriteLiteral(" class=\"fa fa-calendar\"");

            WriteLiteral("></i></span>\n                        <input");

            WriteLiteral(" name=\"dtStart\"");

            WriteLiteral(" id=\"dtStart\"");

            WriteAttribute("value", Tuple.Create(" value=\"", 1556), Tuple.Create("\"", 1583)

            #line 33 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
                           , Tuple.Create(Tuple.Create("", 1564), Tuple.Create <System.Object, System.Int32>(Request["dtStart"]

            #line default
            #line hidden
                                                                                                             , 1564), false)
                           );

            WriteLiteral(" dateformat=\"yyyy-MM-dd\"");

            WriteLiteral(" class=\"form-control form_datetime\"");

            WriteLiteral(" />\n                    </div>\n                </div>\n                <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\n                    <label");

            WriteLiteral(" for=\"dtEnd\"");

            WriteLiteral(" class=\"control-label\"");

            WriteLiteral(">至</label>\n                    <div");

            WriteLiteral(" class=\"input-group\"");

            WriteLiteral(">\n                        <span");

            WriteLiteral(" class=\"input-group-addon\"");

            WriteLiteral("><i");

            WriteLiteral(" class=\"fa fa-calendar\"");

            WriteLiteral("></i></span>\n                        <input");

            WriteLiteral(" name=\"dtEnd\"");

            WriteLiteral(" id=\"dtEnd\"");

            WriteAttribute("value", Tuple.Create(" value=\"", 2003), Tuple.Create("\"", 2028)

            #line 40 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
                           , Tuple.Create(Tuple.Create("", 2011), Tuple.Create <System.Object, System.Int32>(Request["dtEnd"]

            #line default
            #line hidden
                                                                                                             , 2011), false)
                           );

            WriteLiteral(" dateformat=\"yyyy-MM-dd\"");

            WriteLiteral(" class=\"form-control form_datetime\"");

            WriteLiteral(" />\n                    </div>\n                </div>\n                <div");

            WriteLiteral(" class=\"input-group btn-toolbar\"");

            WriteLiteral(">\n                    <input");

            WriteLiteral(" type=\"hidden\"");

            WriteLiteral(" name=\"TokenID\"");

            WriteAttribute("value", Tuple.Create(" value=\"", 2251), Tuple.Create("\"", 2275)

            #line 44 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
                           , Tuple.Create(Tuple.Create("", 2259), Tuple.Create <System.Object, System.Int32>(page["TokenID"]

            #line default
            #line hidden
                                                                                                             , 2259), false)
                           );

            WriteLiteral(" />\n");

            WriteLiteral("                    ");


            #line 45 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
            Write(Html.Partial("_List_Toolbar_Search"));


            #line default
            #line hidden
            WriteLiteral("\n");

            WriteLiteral("                    ");


            #line 46 "..\..\Areas\Device\Views\DeviceHistory\_List_Toolbar.cshtml"
            Write(Html.Partial("_List_Toolbar_Adv"));


            #line default
            #line hidden
            WriteLiteral("\n                </div>\n            </div>\n        </form>\n    </div>\n</div>\n");
        }
Пример #20
0
        protected override void OnReceive(ReceivedEventArgs e)
        {
            //base.OnReceive(e);

            var str = e.Packet.ToStr();

            if (str.IsNullOrEmpty())
            {
                return;
            }

            var dic = new JsonParser(str).Decode() as IDictionary <String, Object>;

            if (dic == null || dic.Count == 0)
            {
                return;
            }

            ManageProvider.UserHost = Remote.Host;

            object result = null;
            var    cmd    = dic["cmd"] + "";

            // 输出日志
            if (Host.CommandLog)
            {
                WriteLog("<={0}", str.Trim());
            }
            else
            {
                WriteLog("<={0}", cmd);
            }

            var remark = "";

            try
            {
                switch (cmd)
                {
                case "dHeartbeat":
                    result = Heartbeat(cmd, dic);
                    break;

                case "dRecord":
                    result = UploadRecord(cmd, dic);
                    break;
                }

                // 处理结果,做出响应
                if (result != null)
                {
                    var js = result.ToJson();

                    if (Host.CommandLog)
                    {
                        WriteLog("=>{0}", js.Trim());
                    }

                    Send(js.GetBytes());
                }
            }
            catch (Exception ex)
            {
                remark = ex.GetTrue()?.Message;
            }
            finally
            {
                if (cmd != "dHeartbeat")
                {
                    var dv = Device ?? new Device();

                    // 写入历史
                    var hi = new DeviceHistory
                    {
                        DeviceID       = dv.ID,
                        Name           = dv.Name,
                        Action         = cmd,
                        Success        = result != null,
                        CreateDeviceID = dv.ID,
                        Remark         = remark,
                    };

                    hi.SaveAsync();
                }
            }
        }
Пример #21
0
        public async Task <IActionResult> PutDevice(int id, Device device)
        {
            if (id != device.Id)
            {
                return(BadRequest());
            }

            var original = await _context.Devices.FindAsync(id);

            var history = new DeviceHistory(original);

            // Only allow status update changes if device is lost
            if (device.Status == DeviceStatus.Lost)
            {
                device.StatusEffectiveDate = DateTime.Now;
            }
            else
            {
                device.Status = original.Status;
            }

            bool canManage = User.HasClaim(AppClaimTypes.Permission, AppClaims.CanManage);

            if (original.Name == device.Name &&
                original.OS_Type == device.OS_Type &&
                original.OS_Version == device.OS_Version &&
                original.Status == device.Status &&
                original.Disowned == device.Disowned &&
                original.StatusEffectiveDate == device.StatusEffectiveDate &&
                (!canManage ||
                 original.Notes == device.Notes &&
                 original.Shared == device.Shared &&
                 original.ItracsBuilding == device.ItracsBuilding &&
                 original.ItracsRoom == device.ItracsRoom &&
                 original.ItracsOutlet == device.ItracsOutlet &&
                 original.UserName == device.UserName))
            {
                // No changes, prevent adding unnecessary history entries
                return(NoContent());
            }

            _context.DeviceHistories.Add(history);

            device.DateEdit   = DateTime.Now;
            device.UserEditId = User.GetUserName();
            _context.UpdateProperties(device, d => d.Name, d => d.OS_Type, d => d.OS_Version, d => d.Status, d => d.Disowned,
                                      d => d.StatusEffectiveDate, d => d.UserEditId, d => d.DateEdit);
            if (canManage)
            {
                _context.UpdateProperties(device, d => d.Notes, d => d.Shared, d => d.ItracsBuilding, d => d.ItracsRoom,
                                          d => d.ItracsOutlet, d => d.UserName);
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeviceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #22
0
        public void doLogout()
        {
            string l_DevType   = DeviceType;
            string l_DevPrompt = DevicePrompt;
            string strOutput   = "";
            string match       = "";

            if (DeviceCounter > 0)
            {
                if (bConfigMode)
                {
                    //@strLines = $shell->cmd(String   => "end", Timeout  => $Timeout, Prompt   => $DevicePrompt);
                    ExitConfigMode();
                }
                if (l_DevType.Equals("HP"))
                {
                    l_DevPrompt = l_DevPrompt.Replace('#', '>');

                    strOutput = shell.cmd("exit", l_DevPrompt);
                }
                DeviceCounter--;

                // Restore Status from Last Device
                DeviceHistoryData DeviceData = DeviceHistory[DeviceCounter];
                bConnected         = DeviceData.bConnected;
                DevicePromptString = DeviceData.DevicePromptString;
                DevicePrompt       = DeviceData.DevicePrompt;
                DevicePromptConfig = DeviceData.DevicePromptConfig;
                EnableMode         = DeviceData.EnableMode;
                DeviceType         = DeviceData.DeviceType;
                //Device = DeviceData.Device;
                DeviceHistory.RemoveAt(DeviceCounter);


                if (l_DevType.Equals("HP"))
                {
                    match = "";
                    string[] LogoutPrompt = { "Do you want to log out [y/n]", "[y/n]" };

                    //@strLines = $shell->cmd(String   => "exit", Timeout  => $Timeout, Prompt   => 'Do you want to log out [y/n]');
                    shell.print("exit");
                    match = shell.WaitFor(LogoutPrompt, false, Timeout);
                    // if ( (match == null) || (match.Length == 0) ) {}
                    if (match.ToLower().Contains("do you want to log out [y/n]"))
                    {
                        match = "";
                        shell.print("y");
                        match = shell.WaitForRegEx(DevicePromptString + @"|Do you want to save current configuration \[y\/n\]|\[y\/n\]");
                        if ((match != null) && (match.ToLower().Contains("/[y/n]")))
                        {
                            strOutput = shell.cmd("n", DevicePrompt);
                        }

                        strOutput = shell.cmd(" ", DevicePrompt);
                    }
                }
                else if (l_DevType.Equals("H3C"))
                {
                    strOutput = shell.cmd("quit", DevicePrompt);
                }
                else
                {
                    strOutput = shell.cmd("exit", DevicePrompt);
                }
                if (_Debug > 0)
                {
                    Console.WriteLine("Last Device-Promts are restored: " + DevicePrompt);
                }
            }
            else
            {
                if (l_DevType.Equals("H3C"))
                {
                    if (bConfigMode)
                    {
                        ExitConfigMode();
                    }
                    shell.print("quit");
                }
                else
                {
                    shell.print("end");
                    //sleep 1;
                    shell.print("logout");
                    if (shell.Connected)
                    {
                        shell.print("exit");
                    }
                }
                if (shell.Connected)
                {
                    shell.close();
                }
                if (shell != null)
                {
                    shell = null;
                }

                if (_Debug > 0)
                {
                    Console.WriteLine("Telnet-Session is closed.");
                }
            }
        }