Пример #1
0
        public JsonResult AddHost(HostDetailModel newHostDetail)
        {
            var result = new JsonResponse();

            try
            {
                HostListModel hostList = getHostList();

                if (!HostAdmin.IsExistHostName(hostList.HostList, newHostDetail.HostName))
                {
                    int newHostId = hostList.MaxHostId + 1;

                    newHostDetail.HostID     = newHostId;
                    newHostDetail.SortNumber = hostList.HostList.Count;
                    hostList.HostList.Add(newHostDetail);
                    hostList.MaxHostId = newHostId;

                    if (HostAdmin.SetHostList(hostList, HostListFilePath))
                    {
                        Session[Constants.SESSION_HOST_SETTING] = hostList;
                        result.SetResult(true);
                        result.AddData("hostId", newHostId.ToString());
                        result.AddData("hostName", newHostDetail.HostName);
                    }
                    else
                    {
                        result.AddErrorInfo("errorMessage", "新規追加に失敗!");
                    }
                }
                else
                {
                    result.AddErrorInfo("errorMessage", "既に登録されているホスト名です!");
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Пример #2
0
        public JsonResult RemoveHost(int selectHostId)
        {
            var result = new JsonResponse();

            try
            {
                HostListModel hosts = getHostList();

                var newHosts       = new HostListModel();
                var hostDetailList = new List <HostDetailModel>();

                if (!HostAdmin.IsExistHostID(hosts.HostList, selectHostId))
                {
                    result.AddErrorInfo("errorMessage", "ホストは既に削除されています!");
                }
                else
                {
                    foreach (HostDetailModel hostDetail in hosts.HostList)
                    {
                        if (hostDetail.HostID != selectHostId)
                        {
                            hostDetailList.Add(hostDetail);
                        }
                    }
                    newHosts.HostList  = hostDetailList;
                    newHosts.MaxHostId = hosts.MaxHostId;

                    if (HostAdmin.SetHostList(newHosts, HostListFilePath))
                    {
                        Session[Constants.SESSION_HOST_SETTING] = newHosts;
                        result.SetResult(true);
                        result.AddData("hostId", selectHostId.ToString());
                    }
                    else
                    {
                        result.AddErrorInfo("errorMessage", "ホスト削除に失敗!");
                    }
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Пример #3
0
        public JsonResult EditHost(HostDetailModel editHostDetail)
        {
            var result = new JsonResponse();

            try
            {
                var hostList = getHostList();

                var newHosts       = new HostListModel();
                var hostDetailList = new List <HostDetailModel>();

                bool isEdit = false;

                if (HostAdmin.GetHostName(hostList.HostList, editHostDetail.HostID) == editHostDetail.HostName)
                {
                    isEdit = true;
                }
                else if (!HostAdmin.IsExistHostName(hostList.HostList, editHostDetail.HostName))
                {
                    isEdit = true;
                }

                if (isEdit)
                {
                    foreach (HostDetailModel hostDetail in hostList.HostList)
                    {
                        if (hostDetail.HostID.Equals(editHostDetail.HostID))
                        {
                            hostDetailList.Add(editHostDetail);
                        }
                        else
                        {
                            hostDetailList.Add(hostDetail);
                        }
                    }
                    newHosts.HostList  = hostDetailList;
                    newHosts.MaxHostId = hostList.MaxHostId;

                    if (HostAdmin.SetHostList(newHosts, HostListFilePath))
                    {
                        Session[Constants.SESSION_HOST_SETTING] = newHosts;
                        result.SetResult(true);
                        result.AddData("hostId", editHostDetail.HostID.ToString());
                        result.AddData("hostName", editHostDetail.HostName);
                    }
                    else
                    {
                        result.AddErrorInfo("errorMessage", "ホスト設定の修正に失敗!");
                    }
                }
                else
                {
                    result.AddErrorInfo("errorMessage", "既に登録されているホスト名です!");
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Пример #4
0
        public JsonResult HostItem(int hostId)
        {
            var result = new JsonResponse();

            try
            {
                HostListModel hosts = getHostList();

                if (!HostAdmin.IsExistHostID(hosts.HostList, hostId))
                {
                    result.AddErrorInfo("errorMessage", "該当ホスト情報が存在しません!");
                }
                else
                {
                    var hostItemDetail = new HostDetailModel();

                    foreach (HostDetailModel hostDetail in hosts.HostList)
                    {
                        if (hostDetail.HostID == hostId)
                        {
                            result.SetResult(true);
                            result.AddData("hostId", hostDetail.HostID.ToString());
                            result.AddData("hostName", hostDetail.HostName);
                            result.AddData("hostAddress", hostDetail.HostAddress);
                            result.AddData("anonymous", hostDetail.Anonymous.ToString());
                            result.AddData("userName", hostDetail.UserName);
                            result.AddData("password", hostDetail.Password);
                            result.AddData("pasvMode", hostDetail.PasvMode.ToString());
                            result.AddData("portNumber", hostDetail.PortNumber.ToString());
                            result.AddData("timeout", hostDetail.Timeout.ToString());
                            result.AddData("localServerPath", hostDetail.LocalServerPath);
                            result.AddData("remoteServerPath", hostDetail.RemoteServerPath);
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        public JsonResult CopyHost(int selectHostId, string NewHostName)
        {
            var result = new JsonResponse();

            try
            {
                HostListModel hosts = getHostList();

                if (!HostAdmin.IsExistHostID(hosts.HostList, selectHostId))
                {
                    result.AddErrorInfo("errorMessage", "コピー元のホストが存在しません!");
                }
                else
                {
                    int    newHostId   = hosts.MaxHostId + 1;
                    string newHostName = string.Empty;

                    if (NewHostName == string.Empty || HostAdmin.IsExistHostName(hosts.HostList, NewHostName))
                    {
                        newHostName = "Untitled_" + newHostId;
                    }
                    else
                    {
                        newHostName = NewHostName;
                    }

                    foreach (HostDetailModel hostDetail in hosts.HostList)
                    {
                        if (hostDetail.HostID == selectHostId)
                        {
                            var newHostDetail = new HostDetailModel(hostDetail);
                            newHostDetail.HostName   = newHostName;
                            newHostDetail.HostID     = newHostId;
                            newHostDetail.SortNumber = hosts.HostList.Count;
                            hosts.HostList.Add(newHostDetail);
                            hosts.MaxHostId = newHostId;

                            break;
                        }
                    }

                    if (HostAdmin.SetHostList(hosts, HostListFilePath))
                    {
                        Session[Constants.SESSION_HOST_SETTING] = hosts;
                        result.SetResult(true);
                        result.AddData("hostId", newHostId.ToString());
                        result.AddData("hostName", newHostName);
                    }
                    else
                    {
                        result.AddErrorInfo("errorMessage", "新規追加に失敗!");
                    }
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }