/// <summary> /// </summary> /// <param name="completeCachedFileRetrievalURL">complete cached file retrieval request (including the server-side time stamp), /// e.g. http://[server]/[requester]?CTX=&CACHE=My Application_DbhDataIds.xml|31/07/2013%2020:15:15</param> /// <returns>true if the requested cached file ('completeCachedFileRetrievalURL') exists in the local cache folder.</returns> internal bool IsCompleteCacheRequestURLExistsLocally(string completeCachedFileRetrievalURL) { string cachedFileServerFileName; string cachedFileLocalFileName; CompleteCacheRequestURLToFileNames(completeCachedFileRetrievalURL, out cachedFileServerFileName, out cachedFileLocalFileName); return(HandleFiles.isExists(cachedFileLocalFileName)); }
///<summary> /// check that content exists in the cache folder for 'url'. ///</summary> /// <param name="url">URL to a cached file, excluding the server-side time stamp, e.g. /MG1VAI3T_MP_0$$$_$_$_N02400$$$$G8FM01_.xml.</param> ///<returns>true if content exists for 'url'.</returns> public bool IsExists(string url) { bool contentFound = false; lock (this) { String localFilename = URLToLocalFileName(url); contentFound = HandleFiles.isExists(localFilename); } return(contentFound); }
/// <summary> /// record an offline-required metadata + its local time /// </summary> /// <param name="requestedURL">complete cache file retrieval request to an offline-required metadata, /// e.g. http://[server]/[requester]?CTX=&CACHE=MG1VAI3T_MP_0$$$_$_$_N02400$$$$G8FM01_.xml|31/07/2013%2020:15:15</param> internal void Collect(string requestedURL) { if (Enabled) { string cachedFileServerFileName; string cachedFileLocalFileName; PersistentOnlyCacheManager.GetInstance().CompleteCacheRequestURLToFileNames(requestedURL, out cachedFileServerFileName, out cachedFileLocalFileName); Debug.Assert(HandleFiles.isExists(cachedFileLocalFileName)); CollectedMetadata[cachedFileServerFileName] = HandleFiles.getFileTime(cachedFileLocalFileName); } }
/// <summary> /// get content from the cache /// </summary> /// <param name="url">URL to a cached file, excluding the server-side time stamp, e.g. /MG1VAI3T_MP_0$$$_$_$_N02400$$$$G8FM01_.xml.</param> public byte[] GetFile(String url) { lock (this) { byte[] content = null; String localFilename = URLToLocalFileName(url); if (HandleFiles.isExists(localFilename)) { content = HandleFiles.readToByteArray(localFilename, ""); } return(content); } }
internal SourcesSyncStatus() { TablesIncompatibleWithDataSources = false; InvalidSources = false; String cachFoldername = CacheUtils.GetCacheFolderName(); String fileName = ClientManager.Instance.getAppName() + "_SourcesSyncStatus"; StatusFileName = cachFoldername + "\\" + fileName; // Read the synchronization status of sources in previous execution, if exist. // If file does not exist, this means in previous execution sources were synchronized without any failure. if (HandleFiles.isExists(StatusFileName)) { ReadFromFile(); } }
/// <summary> /// Retrieve a file from the server to the client's default folder. /// In case the file wasn't modified since last retrieved, it will not be downloaded from the server /// and will not be copied to the client's default folder. /// </summary> /// <param name="serverFileName">file name, as known in the server's file system.</param> /// <param name="currTask">the current executing task.</param> /// <returns>true if the file was found on the client's default folder.</returns> internal bool CopyToDefaultFolder(string serverFileName, Task currTask) { Debug.Assert(currTask != null); string clientFileName = (serverFileName.Substring(serverFileName.LastIndexOf('\\') + 1)); string cachedFileName = GetLocalFileName(serverFileName, currTask, false); if (!String.IsNullOrEmpty(cachedFileName)) { // if the file was modified since last retrieved, copy it from the client's cache to the client's default folder if (HandleFiles.getFileTime(cachedFileName) != HandleFiles.getFileTime(clientFileName)) { HandleFiles.copy(cachedFileName, clientFileName, true, false); } } return(HandleFiles.isExists(clientFileName)); }
/// <summary> /// checks file exist with specified remote time. /// when remote time is null, then check only file is exist or not /// otherwise check if source with remotetime exist /// </summary> /// <param name="fileFullName">Full name of the file</param> /// <param name="remoteTime">last modification time of the file (for story#138618: remote time will be null)</param> /// <returns></returns> private bool IsFileExistWithRequestedTime(String fileFullName, String remoteTime) { bool isFileExist = HandleFiles.isExists(fileFullName); try { if (isFileExist && remoteTime != null) { String localTime = HandleFiles.getFileTime(fileFullName); if (!HandleFiles.equals(localTime, remoteTime)) { isFileExist = false; } } } catch (Exception exception) { Logger.Instance.WriteExceptionToLog(exception.Message); throw; } return(isFileExist); }
/// <summary> Creates (on the disk) the executable used the launch the application after /// the current executable exits /// </summary> /// <returns> path to the newly created executable </returns> private static string CreateRCSpawnerAssembly() { String asmName = getSpawnerAssemblyPath(); if (HandleFiles.isExists(asmName)) { HandleFiles.deleteFile(asmName); } // Get the assmbly code from the resource Byte[] asmBuf; #if PocketPC asmBuf = RichClient.Properties.Resources.MgxpaRIAMobile_spawner; #else asmBuf = RichClient.Properties.Resources.MgxpaRIA_spawner; #endif // Write the assembly code to the file BinaryWriter bw = new BinaryWriter(File.Open(asmName, FileMode.Create)); bw.Write(asmBuf); bw.Close(); return(asmName); }
/// <summary>convert the file path on the server's file system or the url to the file name in the client's cached folder.</summary> /// <param name="serverFilename">a file name in the Server's file system.</param> /// <param name="task"></param> /// <param name="refreshClientCopy"></param> /// <returns>file name in the local file system.</returns> internal override string GetLocalFileName(string serverFilename, Task task, bool refreshClientCopy) { string localFileName = String.Empty; if (!String.IsNullOrEmpty(serverFilename)) { if (Misc.isWebURL(serverFilename, ClientManager.Instance.getEnvironment().ForwardSlashUsage)) { localFileName = CacheUtils.URLToLocalFileName(serverFilename); } else { localFileName = CacheUtils.ServerFileToLocalFileName(serverFilename); } if (!HandleFiles.isExists(localFileName)) { localFileName = String.Empty; //TODO: Kaushal. Raise InAccessibleServer event. } } return(localFileName); }