Beispiel #1
0
        public static bool RemoteServerFolderWriteAccessible(int packageId, string path)
        {
            try
            {
                // copy to space folder
                int osServiceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.Os);
                if (osServiceId > 0)
                {
                    OS.OperatingSystem os = new OS.OperatingSystem();
                    ServiceProviderProxy.Init(os, osServiceId);

                    string remoteServerPathCheck = FilesController.GetFullPackagePath(packageId,
                                                                                      Path.Combine(path, "check.txt"));

                    //
                    os.CreateFile(remoteServerPathCheck);
                    os.AppendFileBinaryContent(remoteServerPathCheck, Encoding.UTF8.GetBytes(remoteServerPathCheck));
                    os.DeleteFile(remoteServerPathCheck);
                }
                //
                return(true);
            }
            catch
            {                           //
                return(false);
            }
        }
        public static int CreateFile(int packageId, string path)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check package
            int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive);

            if (packageCheck < 0)
            {
                return(packageCheck);
            }

            // place log record
            TaskManager.StartTask("FILES", "CREATE_FILE", path, packageId);

            try
            {
                OS.OperatingSystem os       = GetOS(packageId);
                string             fullPath = GetFullPackagePath(packageId, path);

                // cannot create a file with the same name as a directory
                if (os.DirectoryExists(fullPath))
                {
                    return(BusinessErrorCodes.ERROR_FILE_CREATE_FILE_WITH_DIR_NAME);
                }

                // create file
                os.CreateFile(fullPath);

                return(0);
            }
            catch (Exception ex)
            {
                //Log and return a generic error rather than throwing an exception
                TaskManager.WriteError(ex);
                return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED);
            }
            finally
            {
                TaskManager.CompleteTask();
            }
        }