Exemplo n.º 1
0
        public JsonResult Connect(int selectHostId)
        {
            var             result     = new JsonResponse();
            HostDetailModel hostDetail = null;

            try
            {
                var hosts = (HostListModel)Session[Constants.SESSION_HOST_SETTING];

                if (hosts == null)
                {
                    hosts = HostAdmin.GetHostList(ConfigurationManager.AppSettings["HostList"]);
                }

                if (!HostAdmin.IsExistHostID(hosts.HostList, selectHostId))
                {
                    result.AddErrorInfo("errorMessage", "接続先のホスト情報が存在しません!");
                }
                else
                {
                    foreach (HostDetailModel host in hosts.HostList)
                    {
                        if (host.HostID == selectHostId)
                        {
                            hostDetail = new HostDetailModel(host);
                            break;
                        }
                    }

                    if (hostDetail != null && FTPControl.IsRemoteConnected(hostDetail))
                    {
                        Session[Constants.SESSION_LOCAL_PATH]  = hostDetail.LocalServerPath != "" && hostDetail.LocalServerPath != null ? hostDetail.LocalServerPath : "C:\\forwork\\localFolder";
                        Session[Constants.SESSION_REMOTE_PATH] = hostDetail.HostAddress;

                        List <ResourceInfoModel> localResourceList  = FTPControl.GetLocalResourceList((string)Session[Constants.SESSION_LOCAL_PATH]);
                        List <ResourceInfoModel> remoteResourceList = FTPControl.GetRemoteResourceList(hostDetail.HostAddress, hostDetail, true);

                        Session[Constants.SESSION_LOCAL_FILE_LIST]  = localResourceList;
                        Session[Constants.SESSION_REMOTE_FILE_LIST] = remoteResourceList;

                        Session[Constants.SESSION_HOST_DETAIL] = hostDetail;
                        string log = (string)Session[Constants.SESSION_OLD_LOG] + "ホスト" + hostDetail.HostAddress + "に接続しました。\r\n";
                        Session[Constants.SESSION_LOG]     = log;
                        Session[Constants.SESSION_OLD_LOG] = log;

                        result.SetResult(true);
                    }
                    else
                    {
                        result.AddErrorInfo("errorMessage", "FTP接続に失敗しました。");
                    }
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "接続時にエラーが発生しました。");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        public JsonResult Reconnect(int selectHostId)
        {
            var result = new JsonResponse();

            try
            {
                var           bgHost = new BGHostController();
                HostListModel hosts  = bgHost.getHostList();

                if (!HostAdmin.IsExistHostID(hosts.HostList, selectHostId))
                {
                    result.AddErrorInfo("errorMessage", "接続先のホスト情報が存在しません!");
                }

                result.SetResult(true);
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "接続時にエラーが発生しました。");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Exemplo n.º 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));
        }