Esempio n. 1
0
        /// <summary> Saves the initial response in the LastOffline file. </summary>
        /// <param name="initialResponse"></param>
        internal void SaveInitialResponseInLastOfflineFile(String initialResponse)
        {
            String fileName = GetLastOfflineExecutionPropertiesFileName();
            String fileTime = HandleFiles.getFileTime(fileName);

            LastOfflineExecutionProperties[ConstInterface.INITIAL_RESPONSE] = initialResponse;

            LastOfflineExecutionProperties.WriteToXMLFile(fileName);
            HandleFiles.setFileTime(fileName, fileTime);
        }
Esempio n. 2
0
        /// <summary>
        /// Saves an indication of unsynchronized metadata in LastOffline to instruct client to start in connected mode next time
        /// </summary>
        internal void SaveUnsyncronizedMetadataFlagInLastOfflineFile()
        {
            String fileName = GetLastOfflineExecutionPropertiesFileName();
            String fileTime = HandleFiles.getFileTime(fileName);

            MgProperties offlineExecutionProps = LastOfflineExecutionProperties.Clone();

            offlineExecutionProps.Add(ConstInterface.MG_TAG_UNSYNCRONIZED_METADATA, "Y");

            String initialResponse = offlineExecutionProps[ConstInterface.INITIAL_RESPONSE];

            if (GetLastOfflineExecutionPropertyBool(ConstInterface.DISABLE_ENCRYPTION))
            {
                initialResponse = XMLConstants.CDATA_START + OSEnvironment.EolSeq + initialResponse + OSEnvironment.EolSeq + XMLConstants.CDATA_END;
                offlineExecutionProps[ConstInterface.INITIAL_RESPONSE] = initialResponse;
            }

            offlineExecutionProps.WriteToXMLFile(fileName);
            HandleFiles.setFileTime(fileName, fileTime);
        }
Esempio n. 3
0
        private String _cacheFolder; //absolute path of the cache folder

        /// <summary>
        /// Save 'content' into the cache folder, identified by 'url', and set the file's time to 'remote Time'.
        /// </summary>
        /// <param name="url">URL to a cached file, excluding the server-side time stamp, e.g. /MG1VAI3T_MP_0$$$_$_$_N02400$$$$G8FM01_.xml.</param>
        /// <param name="content">content to save for future access to the url.</param>
        /// <param name="remoteTime">modification time of the file on the server-side (for story#138618: remote time will be null).</param>
        public void PutFile(String url, byte[] content, String remoteTime)
        {
            lock (this)
            {
                try
                {
                    String localFilename = URLToLocalFileName(url);
                    bool   success       = HandleFiles.writeToFile(HandleFiles.getFile(localFilename), content, false, true, ClientManager.Instance.GetWriteClientCacheMaxRetryTime());
                    if (!success)
                    {
                        throw (new CacheManagerException(string.Format("Failed to save the file {0} in cache directory. Check log for details", localFilename)));
                    }
                    if (remoteTime != null)
                    {
                        HandleFiles.setFileTime(localFilename, remoteTime);
                    }
                }
                catch (Exception e)
                {
                    Misc.WriteStackTrace(e, Console.Error);
                    throw (e);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// commit modified sources to cache.
        /// </summary>
        internal void Commit()
        {
            Logger.Instance.WriteSupportToLog("Commit():>>>> ", true);

            bool success = true;

            // It is about to start committing the sources. So save the status. If process get terminated during commit,
            // in next execution, client will get to know the status of sources synchronization and take action accordingly.
            SourcesSyncStatus.InvalidSources = true;
            SourcesSyncStatus.SaveToFile();

            // Renames the temporary sources to original names.
            foreach (String url in _commitList)
            {
                String tempFileName               = BuildTemporarySourceFileName(GetFileNameFromURL(url));
                String tempSourceFileFullName     = PersistentOnlyCacheManager.GetInstance().URLToLocalFileName(tempFileName);
                String originalSourceFileFullName = PersistentOnlyCacheManager.GetInstance().URLToLocalFileName(GetFileNameFromURL(url));
                String remoteTime = GetRemoteTime(url);

                // check if source with remotetime exist
                if (IsFileExistWithRequestedTime(tempSourceFileFullName, remoteTime))
                {
                    Logger.Instance.WriteSupportToLog(String.Format("commit(): renaming {0}", tempFileName), true);

                    success = HandleFiles.renameFile(tempSourceFileFullName, originalSourceFileFullName);
                    if (!success)
                    {
                        break;
                    }

                    if (remoteTime != null)
                    {
                        HandleFiles.setFileTime(originalSourceFileFullName, remoteTime);
                    }

                    // record/register a cached file path + its local time:
                    OfflineRequiredMetadataCollection.Collect(url);
                }
            }

            if (!success)
            {
                String errorMessage;

                // sources commit failed
                // If tables were converted and committed, there structure won't match the sources
                if (SourcesSyncStatus.TablesIncompatibleWithDataSources == true)
                {
                    errorMessage = ClientManager.Instance.getMessageString(MsgInterface.RC_ERROR_INCOMPATIBLE_DATASOURCES);
                }
                else
                {
                    errorMessage = ClientManager.Instance.getMessageString(MsgInterface.RC_ERROR_INVALID_SOURCES);
                }

                throw new InvalidSourcesException(errorMessage, null);
            }

            // Commit is done successfully, clear the status.
            SourcesSyncStatus.Clear();

            Logger.Instance.WriteSupportToLog("Commit():<<<< ", true);
        }