Exemplo n.º 1
0
        public static string GetTempRootPath(ContentURI uri)
        {
            string sPathToTempContent = string.Empty;

            FileStorageIO.PLATFORM_TYPES ePlatform = FileStorageIO.GetPlatformType(uri);
            if (ePlatform == FileStorageIO.PLATFORM_TYPES.webserver)
            {
                //store in temp subfolder of resources directory (set permissions once)
                bool   bIsAzureStorage = false;
                string sRoot           = GetResourceRootPath(uri, bIsAzureStorage);
                if (!sRoot.EndsWith(GeneralHelpers.FILE_PATH_DELIMITER) &&
                    (!string.IsNullOrEmpty(sRoot)))
                {
                    sRoot = string.Concat(sRoot, GeneralHelpers.FILE_PATH_DELIMITER);
                }
                sPathToTempContent = string.Format("{0}{1}{2}",
                                                   sRoot, uri.URIDataManager.TempDocsURIName,
                                                   GeneralHelpers.FILE_PATH_DELIMITER);
            }
            else if (ePlatform == FileStorageIO.PLATFORM_TYPES.azure)
            {
                //performance will be better when temp files are in same cloud storage as content
                //copying back and forth will be easier
                sPathToTempContent = string.Format("{0}{1}{2}",
                                                   uri.URIDataManager.DefaultRootWebStoragePath,
                                                   uri.URIDataManager.TempDocsURIName,
                                                   GeneralHelpers.WEBFILE_PATH_DELIMITER);
            }
            return(sPathToTempContent);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public static async Task <bool> NeedsNewXhtmlDoc(ContentURI uri,
                                                         GeneralHelpers.DOC_STATE_NUMBER displayDocType,
                                                         string xmlDocPath, string xhtmlDocPath)
        {
            bool bNeedsNewXhtmlDoc = false;

            //rule 1: authorized edits always get new html
            bNeedsNewXhtmlDoc = await AuthorizedEditNeedsHtmlFragment(uri,
                                                                      displayDocType, xmlDocPath);

            if (bNeedsNewXhtmlDoc)
            {
                bNeedsNewXhtmlDoc = true;
                return(bNeedsNewXhtmlDoc);
            }
            if (!await FileStorageIO.URIAbsoluteExists(uri, xhtmlDocPath))
            {
                //rule 2: if the html doesn't exist, make it
                bNeedsNewXhtmlDoc = true;
                return(bNeedsNewXhtmlDoc);
            }
            bNeedsNewXhtmlDoc = await FileStorageIO.File1IsNewerAsync(
                uri, xmlDocPath, xhtmlDocPath);

            return(bNeedsNewXhtmlDoc);
        }
Exemplo n.º 4
0
        public async Task <bool> GetXmlFromFile(ContentURI uri,
                                                string filePath, XPathNavigator xPathNav)
        {
            bool bHasCompleted = false;

            xPathNav = null;
            if (await FileStorageIO.URIAbsoluteExists(uri, filePath))
            {
                XmlDocument oSelectedDoc = new XmlDocument();
                XmlReader   reader
                    = await Helpers.FileStorageIO.GetXmlReaderAsync(uri, filePath);

                if (reader != null)
                {
                    using (reader)
                    {
                        oSelectedDoc.Load(reader);
                    }
                }
                if (oSelectedDoc != null)
                {
                    xPathNav = oSelectedDoc.CreateNavigator();
                }
            }
            bHasCompleted = true;
            return(bHasCompleted);
        }
Exemplo n.º 5
0
        public static async Task <bool> File1IsNewerAsync(ContentURI uri,
                                                          string file1Path, string file2Path)
        {
            bool bXmlIsNewer  = false;
            bool bFile2Exists = await FileStorageIO.URIAbsoluteExists(uri, file2Path);

            if (!bFile2Exists)
            {
                return(true);
            }
            if (await FileStorageIO.URIAbsoluteExists(uri, file1Path) &&
                bFile2Exists)
            {
                DateTime xmlFileTime
                    = await GetLastWriteTimeUtcAsync(uri, file1Path);

                DateTime xhtmlFileTime
                    = await GetLastWriteTimeUtcAsync(uri, file2Path);

                if (xmlFileTime > xhtmlFileTime)
                {
                    //rule 3: if the xmldoc is older than than the html, make a new html
                    bXmlIsNewer = true;
                }
            }
            return(bXmlIsNewer);
        }
Exemplo n.º 6
0
        public static async Task <bool> AddNewestXmlFileWithExtensionToList(
            ContentURI uri, string docPath,
            string fileExtension, IDictionary <string, string> lstFilePaths)
        {
            bool          bHasCompleted = false;
            DirectoryInfo dir           = null;

            if (!FileStorageIO.DirectoryExists(uri, docPath))
            {
                uri.ErrorMessage = Exceptions.DevTreksErrors.MakeStandardErrorMsg(
                    string.Empty, "DIRECTORY_NOEXIST");
                return(bHasCompleted);
            }
            if (Path.HasExtension(docPath))
            {
                //if it has an extension it needs the parent directory
                dir = new DirectoryInfo(
                    Path.GetDirectoryName(docPath));
            }
            else
            {
                dir = new DirectoryInfo(docPath);
            }
            bHasCompleted = await AddNewestFileWithFileExtension(uri, dir, fileExtension,
                                                                 lstFilePaths);

            bHasCompleted = true;
            return(bHasCompleted);
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        public async Task <bool> PackageIDPFFiles(ContentURI uri, string packageFilePathName,
                                                  IDictionary <string, string> args)
        {
            bool      bIsPackaged = false;
            string    errorMsg    = string.Empty;
            PackageIO packIO      = new PackageIO();

            packIO.CheckForPackageFileErrors(packageFilePathName, args,
                                             ref errorMsg);
            if (!string.IsNullOrEmpty(errorMsg))
            {
                return(bIsPackaged);
            }
            //files are found in this directory and its subfolders
            CurrentDirectory = FileStorageIO.GetDirectoryName(packageFilePathName);
            //Directory.SetCurrentDirectory(Path.GetDirectoryName(packageFilePathName));
            //1. copy container.xml file into a meta-inf subfolder
            string sContainerNewPath = await CopyContainerFile(uri, errorMsg);

            //2. copy mimetype.txt into root folder
            string sMimeTypeNewPath = await CopyEPubFile(uri, MIMETYPE_FILE, MIMETYPE_FILE, errorMsg);

            //3. create content.opf file and place in root folder
            //.opf extension is not liked when saving file so use temp.xml
            string sTempFileName = string.Concat(Helpers.GeneralHelpers.GetRandomInteger(0).ToString(),
                                                 Helpers.GeneralHelpers.EXTENSION_XML);
            string sContentNewPath = await CopyEPubFile(uri, CONTENT_FILE, sTempFileName, errorMsg);

            //copy the files in args into content.opf
            if (errorMsg == string.Empty)
            {
                await MakeContentFile(uri, Path.GetFileNameWithoutExtension(packageFilePathName),
                                      args, sContentNewPath, errorMsg);

                //4. create toc.ncx file and place in root
                //.ncx extension is not liked when saving file so use temp.xml
                sTempFileName = string.Concat(Helpers.GeneralHelpers.GetRandomInteger(12223).ToString(),
                                              Helpers.GeneralHelpers.EXTENSION_XML);
                string sNavigationNewPath = await CopyEPubFile(uri, NCX_FILE, sTempFileName, errorMsg);

                //copy whatever files from args that are needed into the ncx file
                await MakeNavigationFile(uri, packageFilePathName,
                                         args, sNavigationNewPath, errorMsg);

                //copy misc. files
                string sTitlePath = await CopyEPubFile(uri, TITLEPAGE_FILE, TITLEPAGE_FILE, errorMsg);

                //add the epub files to args for zipping
                args.Add(sContainerNewPath, "epub");
                args.Add(sMimeTypeNewPath, "epub");
                args.Add(sContentNewPath, "epub");
                args.Add(sNavigationNewPath, "epub");
                args.Add(sTitlePath, "epub");
                if (errorMsg == string.Empty)
                {
                    bIsPackaged = true;
                }
            }
            return(bIsPackaged);
        }
Exemplo n.º 9
0
        public static void AddNewestXmlFileWithExtensionToList(
            ContentURI uri, string docPath,
            string fileExtension, IDictionary <string, string> lstFilePaths,
            ref string errorMsg)
        {
            DirectoryInfo dir = null;

            if (!FileStorageIO.DirectoryExists(uri, docPath))
            {
                errorMsg = Exceptions.DevTreksErrors.MakeStandardErrorMsg(
                    string.Empty, "DIRECTORY_NOEXIST");
                return;
            }
            if (Path.HasExtension(docPath))
            {
                //if it has an extension it needs the parent directory
                dir = new DirectoryInfo(
                    Path.GetDirectoryName(docPath));
            }
            else
            {
                dir = new DirectoryInfo(docPath);
            }
            AddNewestFileWithFileExtension(uri, dir, fileExtension,
                                           lstFilePaths);
        }
Exemplo n.º 10
0
        public static string GetResourceRootPath(ContentURI uri,
                                                 string networkWebFileSystemPath)
        {
            string sPathToContent = string.Empty;
            //networkWebFileSystemName derives from uri.URINetwork.WebFileSystemPath
            //and is stored in db table Network
            string sContentContainerOrFolderName =
                (string.IsNullOrEmpty(networkWebFileSystemPath)) ?
                uri.URIDataManager.ContentURIName
                : networkWebFileSystemPath;

            FileStorageIO.PLATFORM_TYPES ePlatform = FileStorageIO.GetPlatformType(uri);
            if (ePlatform == FileStorageIO.PLATFORM_TYPES.webserver)
            {
                //store in temp subfolder of resources directory (set permissions once)
                bool   bIsAzureStorage = false;
                string sRoot           = GetResourceRootPath(uri, bIsAzureStorage);
                if (!sRoot.EndsWith(GeneralHelpers.FILE_PATH_DELIMITER) &&
                    (!string.IsNullOrEmpty(sRoot)))
                {
                    sRoot = string.Concat(sRoot, GeneralHelpers.FILE_PATH_DELIMITER);
                }
                sPathToContent = string.Format("{0}{1}{2}",
                                               sRoot, sContentContainerOrFolderName,
                                               GeneralHelpers.FILE_PATH_DELIMITER);
            }
            else if (ePlatform == FileStorageIO.PLATFORM_TYPES.azure)
            {
                //store in 'commontreks' (or other network containername) container
                sPathToContent = string.Format("{0}{1}{2}",
                                               uri.URIDataManager.DefaultRootWebStoragePath,
                                               sContentContainerOrFolderName, GeneralHelpers.WEBFILE_PATH_DELIMITER);
            }
            return(sPathToContent);
        }
Exemplo n.º 11
0
        private static async Task <bool> AddSiblingFilesAsync(
            ContentURI uri, DirectoryInfo folder,
            string currentFilePath, string packageName, string fileType,
            string newFilePath, IDictionary <string, string> zipArgs)
        {
            bool   bHasCopied       = false;
            string sPackageFilePath = string.Empty;

            if (folder != null)
            {
                string sNoCalcDocExt = string.Concat(Helpers.GeneralHelpers.FILENAME_DELIMITER,
                                                     Helpers.GeneralHelpers.FILENAME_EXTENSIONS.addin.ToString());
                FileInfo[] files = folder.GetFiles();
                if (files != null)
                {
                    string sFileExtension = string.Empty;
                    foreach (FileInfo file in files)
                    {
                        if (fileType == Helpers.GeneralHelpers.EXTENSION_CSV)
                        {
                            bHasCopied = AddSiblingCSVFilesAsync(
                                uri, file, currentFilePath, sNoCalcDocExt,
                                packageName, fileType, newFilePath, zipArgs);
                        }
                        else
                        {
                            //current file is already in the package
                            if (!file.FullName.Equals(currentFilePath))
                            {
                                //package either all html or all xml files
                                if (Path.GetExtension(file.FullName).Equals(fileType))
                                {
                                    //v174 exclude calcdocs because too much unneeded docs in package
                                    if (!file.Name.Contains(sNoCalcDocExt))
                                    {
                                        sPackageFilePath = Path.Combine(newFilePath, Path.GetFileName(file.FullName));
                                        bHasCopied       = await FileStorageIO.CopyURIsAsync(
                                            uri, file.FullName, sPackageFilePath);

                                        if (Helpers.FileStorageIO.URIAbsoluteExists(
                                                uri, sPackageFilePath))
                                        {
                                            if (!zipArgs.ContainsKey(sPackageFilePath))
                                            {
                                                zipArgs.Add(sPackageFilePath, packageName);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(bHasCopied);
        }
Exemplo n.º 12
0
        public static string GetMiscDocURI(string existingURI)
        {
            string sMiscDocURI    = string.Empty;
            string sDirectory     = FileStorageIO.GetDirectoryName(existingURI);
            string sFileNameNoExt = Path.GetFileNameWithoutExtension(existingURI);
            string sExt           = Path.GetExtension(existingURI);
            string sMiscFileName  = string.Concat(sFileNameNoExt,
                                                  GeneralHelpers.EXTENSION_MISC, sExt);

            sMiscDocURI = Path.Combine(sDirectory, sMiscFileName);
            return(sMiscDocURI);
        }
Exemplo n.º 13
0
        //set in ViewDataHelper when uri is configured with appsettings
        public static void SetAbsoluteURLPath(ContentURI uri,
                                              string absoluteURLPath)
        {
            string sWebPath = absoluteURLPath;

            FileStorageIO.PLATFORM_TYPES ePlatform = FileStorageIO.GetPlatformType(uri);
            if (ePlatform != FileStorageIO.PLATFORM_TYPES.azure)
            {
                //only azure should be using https
                sWebPath = absoluteURLPath.Replace("https", "http");
            }
            uri.URIDataManager.WebPath = sWebPath;
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        public static async Task <bool> AuthorizedEditNeedsHtmlFragment(ContentURI uri,
                                                                        GeneralHelpers.DOC_STATE_NUMBER displayDocType,
                                                                        string xmlDocPath)
        {
            bool bNeedsNewXhtmlFrag = false;

            //tempdocs can be edited by anyone
            if (uri.URIMember.ClubInUse.PrivateAuthorizationLevel
                == AccountHelper.AUTHORIZATION_LEVELS.fulledits ||
                uri.URIFileExtensionType == GeneralHelpers.FILENAME_EXTENSIONS.temp.ToString())
            {
                if (uri.URIDataManager.ServerSubActionType
                    == GeneralHelpers.SERVER_SUBACTION_TYPES.runaddin)
                {
                    //if temp doc exists they are in the middle of running calcs
                    //if save = calcs they have just finished running calcs
                    if (await FileStorageIO.URIAbsoluteExists(
                            uri, uri.URIDataManager.TempDocPath) &&
                        (!string.IsNullOrEmpty(uri.URIDataManager.TempDocSaveMethod) &&
                         uri.URIDataManager.TempDocSaveMethod != Helpers.GeneralHelpers.NONE))
                    {
                        if (displayDocType
                            == GeneralHelpers.DOC_STATE_NUMBER.seconddoc)
                        {
                            //v1.2.0: need to pass params to seconddoc telling which save message to display
                            bNeedsNewXhtmlFrag = true;
                        }
                        else
                        {
                            bNeedsNewXhtmlFrag = false;
                        }
                    }
                    else
                    {
                        if (displayDocType
                            == GeneralHelpers.DOC_STATE_NUMBER.seconddoc)
                        {
                            //always init calcors/analyzers with new doc
                            bNeedsNewXhtmlFrag = true;
                        }
                    }
                }
                else
                {
                    bNeedsNewXhtmlFrag = true;
                }
            }
            return(bNeedsNewXhtmlFrag);
        }
Exemplo n.º 16
0
 public static void GetXmlFromFile(string filePath,
                                   out XmlReader reader)
 {
     reader = null;
     //filepath can be uri with http or filesystem
     if (FileStorageIO.FileExists(filePath))
     {
         //keep settings consistent with linq to xml default
         XmlReaderSettings oSettings = new XmlReaderSettings();
         oSettings.ConformanceLevel = ConformanceLevel.Document;
         oSettings.IgnoreWhitespace = true;
         oSettings.IgnoreComments   = true;
         reader = XmlReader.Create(filePath, oSettings);
     }
 }
Exemplo n.º 17
0
        public static async Task <bool> AddNewestFileWithFileExtension(
            ContentURI uri, DirectoryInfo folder,
            string fileExtension, IDictionary <string, string> lstFilePaths)
        {
            bool bHasCompleted = false;

            FileInfo[] files        = folder.GetFiles();
            FileInfo   newestFile   = null;
            bool       bIsNewerFile = false;

            foreach (FileInfo file in files)
            {
                if (Path.GetFileNameWithoutExtension(file.FullName).EndsWith(fileExtension) &&
                    file.Extension == Helpers.GeneralHelpers.EXTENSION_XML)
                {
                    //rule 1: analyzers can only use calculator data
                    if (file.Name.StartsWith(GeneralHelpers.ADDIN))
                    {
                        //rule2: use only the latest file calculated with that fileextension
                        //if this folder had more than one file with this extension,
                        //it could mean that an old calculation,
                        //from a previous calculator, was not deleted properly
                        uri.URIDataManager.ParentStartRow++;
                        if (newestFile != null)
                        {
                            bIsNewerFile
                                = await FileStorageIO.File1IsNewerAsync(
                                      uri, file.FullName, newestFile.FullName);

                            if (bIsNewerFile)
                            {
                                newestFile = file;
                            }
                        }
                        else
                        {
                            newestFile = file;
                        }
                    }
                }
            }
            if (newestFile != null)
            {
                AddFileToList(newestFile, uri, lstFilePaths);
            }
            bHasCompleted = true;
            return(bHasCompleted);
        }
Exemplo n.º 18
0
 public void GetXmlFromFile(ContentURI uri,
                            string filePath, out XPathDocument xPathDoc)
 {
     xPathDoc = null;
     if (FileStorageIO.URIAbsoluteExists(uri, filePath))
     {
         XmlReader reader = FileStorageIO.GetXmlReader(uri, filePath);
         if (reader != null)
         {
             using (reader)
             {
                 xPathDoc = new XPathDocument(reader);
             }
         }
     }
 }
Exemplo n.º 19
0
 public async Task WriteXhtmlFragmentAsync(StringWriter writer,
                                           ContentURI uri, string xmlDocToReadPath, string htmlFragmentDocPath,
                                           DataHelpers.GeneralHelpers.DOC_STATE_NUMBER displayDocType)
 {
     if (DataHelpers.FileStorageIO.URIAbsoluteExists(uri, htmlFragmentDocPath))
     {
         //write html
         DataHelpers.FileStorageIO oFileStorageIO = new DataHelpers.FileStorageIO();
         await oFileStorageIO.SaveHtmlURIToWriterAsync(uri, writer, htmlFragmentDocPath);
     }
     else
     {
         //transform xml
         await WriteXhtmlFragmentAsync(writer, uri, xmlDocToReadPath, displayDocType);
     }
 }
Exemplo n.º 20
0
        public bool ZipFiles(ContentURI uri, string zipFilePath,
                             IDictionary <string, string> args)
        {
            bool      bIsZipped = false;
            string    errorMsg  = string.Empty;
            PackageIO packIO    = new PackageIO();

            packIO.CheckForPackageFileErrors(zipFilePath, args,
                                             ref errorMsg);
            if (!string.IsNullOrEmpty(errorMsg))
            {
                return(bIsZipped);
            }
            //filesystem
            //don't want the temp directory info in the file path, disrupts subfolders (i.e. in packages)
            Directory.SetCurrentDirectory(Path.GetDirectoryName(zipFilePath));
            string sCurrentDirectory = FileStorageIO.GetDirectoryName(zipFilePath);

            //init the zip with the zip's file name
            using (FileStream zipToOpen = new FileStream(Path.GetFileName(zipFilePath), FileMode.Create))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                {
                    string[] arrValues    = { };
                    string   sRelPartPath = string.Empty;
                    string   sKey         = string.Empty;
                    string   sValue       = string.Empty;
                    foreach (KeyValuePair <string, string> kvp in args)
                    {
                        sKey   = kvp.Key;
                        sValue = kvp.Value;
                        if (string.IsNullOrEmpty(sKey) == false &&
                            Helpers.FileStorageIO.URIAbsoluteExists(
                                uri, sKey))
                        {
                            //convert the absolute path of partFullPath into a path relative to the package root (getcurrentdirectory)
                            sRelPartPath = AppSettings.ConvertAbsPathToRelPath(sCurrentDirectory, sKey);
                            //will add files to the same directory as setcurrentdirectory
                            //2.0.0 change required adding a reference to System.IO.Compression.FileSystem
                            archive.CreateEntryFromFile(sKey, sRelPartPath);
                        }
                    }
                    bIsZipped = true;
                }
            }
            return(bIsZipped);
        }
Exemplo n.º 21
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;
        }
Exemplo n.º 22
0
        public static async Task <bool> AddNewestIOFile(
            ContentURI uri, DirectoryInfo folder,
            IDictionary <string, string> lstFilePaths)
        {
            bool bHasCompleted = false;

            //inputs and outputs don't have base NPV calcs and can be used directly without running new calculations
            FileInfo[] files        = folder.GetFiles();
            FileInfo   newestFile   = null;
            bool       bIsNewerFile = false;

            foreach (FileInfo file in files)
            {
                if (file.Extension == Helpers.GeneralHelpers.EXTENSION_XML)
                {
                    //rule2: use only the latest file calculated with that fileextension
                    //if this folder had more than one file with this extension,
                    //it could mean that an old calculation,
                    //from a previous calculator, was not deleted properly
                    uri.URIDataManager.ParentStartRow++;
                    if (newestFile != null)
                    {
                        bIsNewerFile
                            = await FileStorageIO.File1IsNewerAsync(
                                  uri, file.FullName, newestFile.FullName);

                        if (bIsNewerFile)
                        {
                            newestFile = file;
                        }
                    }
                    else
                    {
                        newestFile = file;
                    }
                }
            }
            if (newestFile != null)
            {
                AddFileToList(newestFile, uri, lstFilePaths);
            }
            bHasCompleted = true;
            return(bHasCompleted);
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        public async Task <bool> GetXmlFromFile(ContentURI uri,
                                                string filePath, XPathDocument xPathDoc)
        {
            bool bHasCompleted = false;

            xPathDoc = null;
            if (await FileStorageIO.URIAbsoluteExists(uri, filePath))
            {
                XmlReader reader = await FileStorageIO.GetXmlReaderAsync(uri, filePath);

                if (reader != null)
                {
                    using (reader)
                    {
                        xPathDoc = new XPathDocument(reader);
                    }
                }
            }
            bHasCompleted = true;
            return(bHasCompleted);
        }
Exemplo n.º 25
0
        public static string GetTempDocPath(ContentURI uri, bool isLocalCacheDirectory,
                                            string uriPattern, string tempURIPattern)
        {
            string sTempDocPath = string.Empty;
            //use uri.URIDataManager.TempDocURI to set subdirectory for holding
            //all related tempdocs (easy to package)
            string sRandomId  = ContentURI.GetURIPatternPart(tempURIPattern, ContentURI.URIPATTERNPART.id);
            string sNodeName  = ContentURI.GetURIPatternPart(tempURIPattern, ContentURI.URIPATTERNPART.node);
            string sDirectory = string.Empty;

            //ok to put empty uris in a "0" subfolder
            if (sRandomId != string.Empty &&
                sNodeName != GeneralHelpers.NONE &&
                sRandomId != "0")
            {
                //has a tempdoc to work with
                //uri.uridatamanager.tempdocuri's random urid is always subdir
                sDirectory = GetTempWebDirectory(uri, isLocalCacheDirectory,
                                                 GeneralHelpers.ConvertStringToInt(sRandomId));
            }
            else
            {
                //may be starting to build a tempdoc
                //need a random directory
                sDirectory = GetTempWebDirectory(uri, isLocalCacheDirectory,
                                                 GeneralHelpers.Get2RandomInteger());
            }
            string sDelimiter = FileStorageIO.GetDelimiterForFileStorage(sDirectory);
            //don't use uri.uriclubdocpath filename because it may not need to be set
            //for the selectedlinkedviewuri
            string sFileName = string.Concat(
                ContentHelper.MakeStandardFileNameFromURIPattern(uriPattern),
                GeneralHelpers.EXTENSION_XML);

            //make the tempdocpath
            sTempDocPath = string.Concat(sDirectory, sDelimiter,
                                         ContentHelper.MakeStandardFileNameFromURIPattern(uriPattern),
                                         GeneralHelpers.EXTENSION_XML);
            return(sTempDocPath);
        }
Exemplo n.º 26
0
        public static void AddNewestIOFile(
            ContentURI uri, DirectoryInfo folder,
            ref int i, ref IDictionary <string, string> lstFilePaths)
        {
            //inputs and outputs don't have base NPV calcs and can be used directly without running new calculations
            FileInfo[] files        = folder.GetFiles();
            FileInfo   newestFile   = null;
            bool       bIsNewerFile = false;

            foreach (FileInfo file in files)
            {
                if (file.Extension == Helpers.GeneralHelpers.EXTENSION_XML)
                {
                    //rule2: use only the latest file calculated with that fileextension
                    //if this folder had more than one file with this extension,
                    //it could mean that an old calculation,
                    //from a previous calculator, was not deleted properly
                    i++;
                    if (newestFile != null)
                    {
                        bIsNewerFile
                            = FileStorageIO.File1IsNewer(
                                  uri, file.FullName, newestFile.FullName);
                        if (bIsNewerFile)
                        {
                            newestFile = file;
                        }
                    }
                    else
                    {
                        newestFile = file;
                    }
                }
            }
            if (newestFile != null)
            {
                AddFileToList(newestFile, i, ref lstFilePaths);
            }
        }
Exemplo n.º 27
0
 public void GetXmlFromFile(ContentURI uri,
                            string filePath, out XPathNavigator xPathNav)
 {
     xPathNav = null;
     if (FileStorageIO.URIAbsoluteExists(uri, filePath))
     {
         XmlDocument oSelectedDoc = new XmlDocument();
         XmlReader   reader
             = Helpers.FileStorageIO.GetXmlReader(uri, filePath);
         if (reader != null)
         {
             using (reader)
             {
                 oSelectedDoc.Load(reader);
             }
         }
         if (oSelectedDoc != null)
         {
             xPathNav = oSelectedDoc.CreateNavigator();
         }
     }
 }
Exemplo n.º 28
0
        public static void AddNewestFileWithFileExtension(
            ContentURI uri, DirectoryInfo folder,
            string fileExtension, IDictionary <string, string> lstFilePaths)
        {
            FileInfo[] files        = folder.GetFiles();
            FileInfo   newestFile   = null;
            bool       bIsNewerFile = false;

            foreach (FileInfo file in files)
            {
                if (file.FullName.EndsWith(fileExtension) &&
                    file.Extension == Helpers.GeneralHelpers.EXTENSION_XML)
                {
                    //use only the latest file calculated with that fileextension
                    //if this folder had more than one file with this extension,
                    //it could mean that an old calculation,
                    //from a previous calculator, was not deleted properly
                    if (newestFile != null)
                    {
                        bIsNewerFile
                            = FileStorageIO.File1IsNewer(
                                  uri, file.FullName, newestFile.FullName);
                        if (bIsNewerFile)
                        {
                            newestFile = file;
                        }
                    }
                    else
                    {
                        newestFile = file;
                    }
                }
            }
            if (newestFile != null)
            {
                int i = 0;
                AddFileToList(newestFile, i, ref lstFilePaths);
            }
        }
Exemplo n.º 29
0
        //gets paths to css, js, images in web root
        public static string GetWebContentFullPath(ContentURI uri,
                                                   string webSubfolder, string filename)
        {
            string sPathToContent = string.Empty;

            FileStorageIO.PLATFORM_TYPES ePlatform = FileStorageIO.GetPlatformType(uri);
            if (ePlatform == FileStorageIO.PLATFORM_TYPES.webserver)
            {
                sPathToContent = string.Format("{0}{1}{2}{3}",
                                               uri.URIDataManager.DefaultRootFullFilePath,
                                               webSubfolder, GeneralHelpers.FILE_PATH_DELIMITER,
                                               filename);
            }
            else if (ePlatform == FileStorageIO.PLATFORM_TYPES.azure)
            {
                //do not use the path to blob storage: DefaultRootWebStoragePath
                sPathToContent = string.Format("{0}{1}{2}{3}",
                                               uri.URIDataManager.DefaultWebDomain,
                                               webSubfolder, GeneralHelpers.WEBFILE_PATH_DELIMITER,
                                               filename);
            }
            return(sPathToContent);
        }
Exemplo n.º 30
0
        public static string AddDirectoryToDirectoryPath(string fromDirectoryPath, string toDirectoryPath)
        {
            string sFullDirectoryPath = toDirectoryPath;

            //deal with when absoluteuripath ends with a delimiter or file name
            if (Path.HasExtension(toDirectoryPath))
            {
                sFullDirectoryPath = GetDirectoryName(toDirectoryPath);
            }
            char[] cDelimiter         = FileStorageIO.GetCDelimiterForFileStorage(fromDirectoryPath);
            string sDelimiter         = FileStorageIO.GetDelimiterForFileStorage(fromDirectoryPath);
            string sLastDirectoryName = string.Empty;

            if (fromDirectoryPath.EndsWith(sDelimiter))
            {
                sLastDirectoryName = GeneralHelpers.GetSubstringFromEnd(
                    fromDirectoryPath, cDelimiter, 2);
            }
            else
            {
                sLastDirectoryName = GeneralHelpers.GetSubstringFromEnd(
                    fromDirectoryPath, cDelimiter, 1);
            }
            string sToDelimiter            = FileStorageIO.GetDelimiterForFileStorage(toDirectoryPath);
            string sLastDirectoryDelimited = string.Concat(sToDelimiter,
                                                           sLastDirectoryName, sToDelimiter);

            if (!sFullDirectoryPath.EndsWith(sLastDirectoryDelimited))
            {
                sFullDirectoryPath = Path.Combine(sFullDirectoryPath, sLastDirectoryName);
                if (!sFullDirectoryPath.EndsWith(sToDelimiter))
                {
                    sFullDirectoryPath = string.Concat(sFullDirectoryPath, sToDelimiter);
                }
            }
            return(sFullDirectoryPath);
        }