示例#1
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));
        }
示例#2
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));
        }