Exemplo n.º 1
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);
        }