Пример #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));
        }
Пример #2
0
        public JsonResult ChangeResourceName(string NewName, string env, bool isDir, string beforeName)
        {
            var result = new JsonResponse();

            HostDetailModel hostDetail = (HostDetailModel)Session[Constants.SESSION_HOST_DETAIL];

            string sessionLocalPath  = (string)Session[Constants.SESSION_LOCAL_PATH];
            string sessionRemotePath = (string)Session[Constants.SESSION_REMOTE_PATH];
            string nextFullPath      = string.Empty;
            string previousFullPath  = string.Empty;

            result.SetResult(true);

            try
            {
                if (env == Constants.ENV_LOCAL)
                {
                    nextFullPath     = sessionLocalPath + "\\" + NewName.Trim();
                    previousFullPath = sessionLocalPath + "\\" + beforeName;

                    if (isDir && Directory.Exists(previousFullPath) && !Directory.Exists(nextFullPath))
                    {
                        Directory.Move(previousFullPath, nextFullPath);
                        result.SetResult(true);
                    }
                    else if (!isDir && System.IO.File.Exists(previousFullPath) && !System.IO.File.Exists(nextFullPath))
                    {
                        System.IO.File.Move(previousFullPath, nextFullPath);
                        result.SetResult(true);
                    }
                }
                else
                {
                    previousFullPath = sessionRemotePath + "/" + beforeName;

                    List <ResourceInfoModel> remoteResourceList = FTPControl.GetRemoteResourceList(sessionRemotePath, hostDetail, false);

                    FTPControl.RenameRemoteResource(previousFullPath, NewName.Trim(), hostDetail);
                    result.SetResult(true);
                }

                if (result.Result != "success")
                {
                    result.AddErrorInfo("errorMessage", "名前を変更するファイルが存在しません。");
                }
                else
                {
                    Session[Constants.SESSION_LOG] = "[ChangeResourceName] " + DateTime.Now + " " + previousFullPath + " >> " + NewName.Trim() + "\r\n名前変更が正常終了しました。\r\n";
                }
            }
            catch (Exception e)
            {
                result.AddErrorInfo("errorMessage", "名前変更時にエラーが発生しました。");
                Session[Constants.SESSION_LOG] = string.Format("[Exception] {0},\r\n{1}", e.Message, e.StackTrace) + "\r\n";
            }

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

            HostDetailModel hostDetail = (HostDetailModel)Session[Constants.SESSION_HOST_DETAIL];

            string sessionLocalPath  = (string)Session[Constants.SESSION_LOCAL_PATH];
            string sessionRemotePath = (string)Session[Constants.SESSION_REMOTE_PATH];
            string newDirectory      = string.Empty;

            try
            {
                if (env == Constants.ENV_LOCAL)
                {
                    if (!Directory.Exists(sessionLocalPath + "\\" + DirectoryName.Trim()))
                    {
                        newDirectory = sessionLocalPath + "\\" + DirectoryName.Trim();
                        DirectoryInfo di = Directory.CreateDirectory(newDirectory);
                        result.SetResult(true);
                    }
                }
                else
                {
                    if (!FTPControl.IsExistResourceName(FTPControl.GetRemoteResourceList(sessionRemotePath, hostDetail, false), DirectoryName.Trim(), FTPClient.BL.Settings.Constants.ResourceType.Directory))
                    {
                        newDirectory = sessionRemotePath + "/" + DirectoryName.Trim();
                        FTPControl.MakeRemoteDirectory(sessionRemotePath + "/" + DirectoryName.Trim(), hostDetail);
                        result.SetResult(true);
                    }
                }

                if (result.Result != "success")
                {
                    result.AddErrorInfo("errorMessage", "既に同じ名前のディレクトリが存在します。");
                }
                else
                {
                    Session[Constants.SESSION_LOG] = "[MakeDirectory] " + DateTime.Now + " " + "New Directory >> " + env + " " + newDirectory + "\r\nディレクトリ作成が正常終了しました。\r\n";
                }
            }
            catch (Exception e)
            {
                result.AddErrorInfo("errorMessage", "ディレクトリ作成時にエラーが発生しました。");
                Session[Constants.SESSION_LOG] = string.Format("[Exception] {0},\r\n{1}", e.Message, e.StackTrace) + "\r\n";
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
0
        public JsonResult Download(string resList)
        {
            var result = new JsonResponse();

            HostDetailModel hostDetail = (HostDetailModel)Session[Constants.SESSION_HOST_DETAIL];

            string sessionLocalPath  = (string)Session[Constants.SESSION_LOCAL_PATH];
            string sessionRemotePath = (string)Session[Constants.SESSION_REMOTE_PATH];

            string[] downloadResourceList = resList.Split(':');
            string   downloadFileLog      = string.Empty;
            string   downloadDirLog       = string.Empty;

            try
            {
                if (downloadResourceList.Length > 0)
                {
                    foreach (string file in downloadResourceList)
                    {
                        // {fileName, isDir}
                        string[] downloadFile       = file.Split(',');
                        string   localFileFullPath  = string.Empty;
                        string   remoteFileFullPath = sessionRemotePath + "/" + downloadFile[0];

                        if (sessionLocalPath.IndexOf("\\") == sessionLocalPath.LastIndexOf("\\"))
                        {
                            localFileFullPath = sessionLocalPath;
                        }
                        else
                        {
                            localFileFullPath = sessionLocalPath + "\\" + downloadFile[0];
                        }

                        // ファイルの場合
                        if (downloadFile[1] == "false")
                        {
                            FTPControl.DownloadFile(localFileFullPath, remoteFileFullPath, hostDetail, ref downloadFileLog);
                        }
                        else
                        {
                            FTPControl.DownloadDirectory(localFileFullPath, remoteFileFullPath, hostDetail, ref downloadDirLog);
                        }
                    }
                }
                Session[Constants.SESSION_LOG] = downloadFileLog + downloadDirLog + "ファイルのダウンロードが正常終了しました。\r\n";

                result.SetResult(true);
            }
            catch (Exception e)
            {
                result.AddErrorInfo("errorMessage", "ダウンロード時にエラーが発生しました。");
                Session[Constants.SESSION_LOG] = string.Format("[Exception] {0},\r\n{1}", e.Message, e.StackTrace) + "\r\n";
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Пример #7
0
        public JsonResult SortHost(string hostList)
        {
            var result = new JsonResponse();

            try
            {
                HostListModel currentHostList = getHostList();
                var           newHostList     = new List <HostDetailModel>();
                string[]      hosts           = hostList.Split(':');

                foreach (HostDetailModel currentHost in currentHostList.HostList)
                {
                    foreach (string host in hosts)
                    {
                        string[] hostDetail = host.Split(',');
                        if (Convert.ToInt32(hostDetail[0]) == currentHost.HostID)
                        {
                            var newHostDetail = new HostDetailModel(currentHost);
                            newHostDetail.SortNumber = Convert.ToInt32(hostDetail[1]);
                            newHostList.Add(newHostDetail);
                            break;
                        }
                    }
                }
                currentHostList.HostList = newHostList;

                if (HostAdmin.SetHostList(currentHostList, HostListFilePath))
                {
                    Session[Constants.SESSION_HOST_SETTING] = currentHostList;
                    result.SetResult(true);
                }
                else
                {
                    result.AddErrorInfo("errorMessage", "ホスト一覧のソートに失敗!");
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Пример #8
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));
        }
Пример #9
0
        public JsonResult ConnectTest(HostDetailModel newHostDetail)
        {
            var result = new JsonResponse();

            try
            {
                if (FTPControl.IsRemoteConnected(newHostDetail))
                {
                    result.SetResult(true);
                }
                else
                {
                    result.AddErrorInfo("errorMessage", "接続テストに失敗しました!");
                }
            }
            catch (Exception)
            {
                result.AddErrorInfo("errorMessage", "予期せぬエラー");
            }

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Пример #10
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));
        }
Пример #11
0
        public JsonResult RemoveLog()
        {
            var result = new JsonResponse();

            try
            {
                Session[Constants.SESSION_OLD_LOG] = string.Empty;
                Session[Constants.SESSION_LOG]     = string.Empty;

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

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

            try
            {
                Session[Constants.SESSION_LOCAL_PATH]       = null;
                Session[Constants.SESSION_REMOTE_PATH]      = null;
                Session[Constants.SESSION_HOST_DETAIL]      = null;
                Session[Constants.SESSION_LOCAL_FILE_LIST]  = null;
                Session[Constants.SESSION_REMOTE_FILE_LIST] = null;
                Session[Constants.SESSION_LOG]     = null;
                Session[Constants.SESSION_OLD_LOG] = null;

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

            return(Json(result, "text/json", Encoding.UTF8, JsonRequestBehavior.DenyGet));
        }
Пример #13
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));
        }
Пример #14
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));
        }
Пример #15
0
        public JsonResult RemoveResource(string env, string resList)
        {
            var result = new JsonResponse();

            HostDetailModel hostDetail = (HostDetailModel)Session[Constants.SESSION_HOST_DETAIL];

            string sessionLocalPath  = (string)Session[Constants.SESSION_LOCAL_PATH];
            string sessionRemotePath = (string)Session[Constants.SESSION_REMOTE_PATH];
            string fullPath          = string.Empty;

            string[] removeResourceList = resList.Split(':');
            string   removeLocalLog     = string.Empty;
            string   removeFileLog      = string.Empty;
            string   removeDirlog       = string.Empty;

            try
            {
                if (env == Constants.ENV_LOCAL)
                {
                    foreach (string file in removeResourceList)
                    {
                        string[] removeFile = file.Split(',');
                        fullPath = sessionLocalPath + "\\" + removeFile[0];

                        if (removeFile[1] == "true" && Directory.Exists(fullPath))
                        {
                            Directory.Delete(fullPath, true);
                            result.SetResult(true);
                        }
                        else if (removeFile[1] != "true" && System.IO.File.Exists(fullPath))
                        {
                            System.IO.File.Delete(fullPath);
                            result.SetResult(true);
                        }
                        removeLocalLog += "[Remove] [" + env + "] " + DateTime.Now + " " + fullPath + "\r\n";
                    }
                }
                else
                {
                    foreach (string file in removeResourceList)
                    {
                        string[] removeFile = file.Split(',');
                        fullPath = sessionRemotePath + "/" + removeFile[0];

                        List <ResourceInfoModel> remoteResourceList = FTPControl.GetRemoteResourceList(sessionRemotePath, hostDetail, false);

                        if (removeFile[1] == "true" && FTPControl.IsExistResourceName(remoteResourceList, removeFile[0], FTPClient.BL.Settings.Constants.ResourceType.Directory))
                        {
                            FTPControl.RemoveRemoteDirectory(fullPath, hostDetail, ref removeDirlog);
                            result.SetResult(true);
                        }
                        else if (removeFile[1] != "true" && FTPControl.IsExistResourceName(remoteResourceList, removeFile[0], FTPClient.BL.Settings.Constants.ResourceType.File))
                        {
                            FTPControl.RemoveRemoteFile(fullPath, hostDetail, ref removeFileLog);
                            result.SetResult(true);
                        }
                    }
                }

                if (result.Result != "success")
                {
                    result.AddErrorInfo("errorMessage", "削除するファイルが存在しません。");
                }
                else if (env == Constants.ENV_LOCAL)
                {
                    Session[Constants.SESSION_LOG] = removeLocalLog + "ファイルの削除が正常終了しました。\r\n";
                }
                else if (env == Constants.ENV_REMOTE)
                {
                    Session[Constants.SESSION_LOG] = removeFileLog + removeDirlog + "ファイルの削除が正常終了しました。\r\n";
                }
            }
            catch (Exception e)
            {
                result.AddErrorInfo("errorMessage", "ファイル削除時にエラーが発生しました。");
                Session[Constants.SESSION_LOG] = string.Format("[Exception] {0},\r\n{1}", e.Message, e.StackTrace) + "\r\n";
            }

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