Esempio n. 1
0
        public static string GetTempDocsPathToNewFileSystemPath(ContentURI uri, bool isLocalCacheDirectory,
                                                                string newFileName)
        {
            //210 added specifically for script file handling (http to file server path conversions)
            string sTempDocPath = string.Empty;

            if (!string.IsNullOrEmpty(uri.URIDataManager.TempDocPath))
            {
                string sOldTempFileName = Path.GetFileName(uri.URIDataManager.TempDocPath);
                sTempDocPath = uri.URIDataManager.TempDocPath.Replace(sOldTempFileName, newFileName);
            }
            else
            {
                //make a new temp doc path for temp storage of script file
                string sDirectoryPath = GetTempWebDirectory(uri,
                                                            isLocalCacheDirectory, GeneralHelpers.Get2RandomInteger());
                string sDelimiter = FileStorageIO.GetDelimiterForFileStorage(sDirectoryPath);
                //make the tempdocpath
                string sTempDocPath2 = string.Concat(sDirectoryPath, sDelimiter, newFileName);
                //return sTempDocPath;
                bool bHasDirectory = FileStorageIO.DirectoryCreate(
                    uri, sTempDocPath2);
            }
            return(sTempDocPath);
        }
Esempio n. 2
0
        public void WriteFileXml(ContentURI uri,
                                 XmlDocument doc, string filePath)
        {
            bool          bCanWrite = true;
            XmlTextWriter oTextWriter;

            try
            {
                //uses FileStream to open filepath; could open filestream here asynchronously and pass filestream instead of filePath
                FileStorageIO.DirectoryCreate(uri, filePath);
                oTextWriter = new XmlTextWriter(filePath, Encoding.UTF8);
                using (oTextWriter)
                {
                    bCanWrite = oTextWriter.BaseStream.CanWrite;
                    if (bCanWrite == true)
                    {
                        doc.WriteTo(oTextWriter);
                        oTextWriter.Flush();
                    }
                    else
                    {
                        bCanWrite = false;
                    }
                }
            }
            catch (Exception x)
            {
                uri.ErrorMessage = Exceptions.DevTreksErrors.MakeStandardErrorMsg(
                    x.ToString(), "FILEIO_CANTSAVEFILE");
                File.Delete(filePath);
            }
        }
Esempio n. 3
0
        public async Task <bool> WriteFileXmlAsync(
            ContentURI uri, XmlReader reader, string filePath)
        {
            bool bHasSaved = false;

            FileStorageIO.DirectoryCreate(uri, filePath);
            using (reader)
            {
                reader.MoveToContent();
                FileIO fileIO = new FileIO();
                bHasSaved = await fileIO.WriteTextFileAsync(filePath, reader.ReadOuterXml());
            }
            return(bHasSaved);
        }
Esempio n. 4
0
        public void WriteFileXml(ContentURI uri,
                                 XmlReader reader, string filePath,
                                 out string errorMsg)
        {
            errorMsg = string.Empty;
            bool          bCanWrite = true;
            XmlTextWriter oTextWriter;

            try
            {
                //uses FileStream to open filepath; could open filestream here asynchronously and pass filestream instead of filePath
                FileStorageIO.DirectoryCreate(uri, filePath);
                oTextWriter = new XmlTextWriter(filePath, Encoding.UTF8);
                using (oTextWriter)
                {
                    bCanWrite = oTextWriter.BaseStream.CanWrite;
                    if (bCanWrite == true)
                    {
                        using (reader)
                        {
                            reader.MoveToContent();
                            oTextWriter.WriteRaw(reader.ReadOuterXml());
                            oTextWriter.Flush();
                        }
                    }
                    else
                    {
                        bCanWrite = false;
                    }
                }
            }
            catch (Exception x)
            {
                errorMsg = Exceptions.DevTreksErrors.MakeStandardErrorMsg(
                    x.ToString(), "FILEIO_CANTSAVEFILE");
                File.Delete(filePath);
            }
            if (!bCanWrite)
            {
                errorMsg = Exceptions.DevTreksErrors.MakeStandardErrorMsg(
                    string.Empty, "FILEIO_STREAMCLOSED");
            }
            oTextWriter = null;
        }
Esempio n. 5
0
        public static string GetTempWebDirectory(ContentURI uri,
                                                 bool isPackageDirectory, int randomId)
        {
            //if randomid is not enough switch to guid
            string sTempDirPath   = string.Empty;
            string sRootDirectory = string.Empty;

            if (isPackageDirectory)
            {
                sRootDirectory = GetTempCacheRootPath(uri);
                sTempDirPath   = string.Concat(sRootDirectory, randomId.ToString());
            }
            else
            {
                //0.9.1: multiple servers won't work with local cache; needs blob storage
                sRootDirectory = GetTempRootPath(uri);
                sTempDirPath   = string.Concat(sRootDirectory, randomId.ToString());
            }
            FileStorageIO.DirectoryCreate(uri, sTempDirPath);
            return(sTempDirPath);
        }