Esempio n. 1
0
        // internal, and taking bookFolder (which is always this.BookFolderName in production) for ease of testing.
        internal TeamCollectionMessage MakeLockFailedMessageFromException(Exception e, string bookFolder)
        {
            var msgId      = "TeamCollection.CheckoutError";
            var msgEnglish = "Bloom was not able to check out \"{0}\".";
            var syncAgent  = "";            // becomes SyncAgent for longer versions of message that need it

            if (e is FolderTeamCollection.CannotLockException cannotLockException)
            {
                var msgTryAgain = LocalizationManager.GetString("Common.TryAgainOrRestart",
                                                                "Please try again later. If the problem continues, restart your computer.");
                msgId = null;                 // this branch uses a 3-part message which can't be relocalized later.
                string part2;
                if (cannotLockException.SyncAgent != "Unknown")
                {
                    part2 = string.Format(LocalizationManager.GetString("TeamCollection.AgentSynchronizing",
                                                                        "Some other program may be busy with it. This may just be {0} synchronizing the file."), cannotLockException.SyncAgent);
                }
                else
                {
                    part2 = LocalizationManager.GetString("TeamCollection.SomethingSynchronizing",
                                                          "Some other program may be busy with it. This may just be something synchronizing the file.");
                }
                msgEnglish += " " + part2 + " " + msgTryAgain;
            }

            var msg = new TeamCollectionMessage(MessageAndMilestoneType.Error, msgId, msgEnglish,
                                                Path.GetFileName(bookFolder), syncAgent);

            return(msg);
        }
Esempio n. 2
0
        public void WriteMessage(MessageAndMilestoneType messageType, string l10nId, string message, string param0 = "", string param1 = "")
        {
            if (IsRedundantMessage(messageType, l10nId, message, param0, param1))
            {
                return;
            }
            var msg = new TeamCollectionMessage(messageType, l10nId, message, param0, param1);

            WriteMessage(msg);
        }
        public static TeamCollectionMessage FromPersistedForm(string form)
        {
            var parts  = form.Split('\t');
            var result = new TeamCollectionMessage();

            if (parts.Length < 2)
            {
                return(null);
            }
            if (DateTime.TryParse(parts[0], out var when))
            {
                result.When = when;
            }
            else
            {
                return(null);
            }

            if (Enum.TryParse(parts[1], out MessageAndMilestoneType messageType))
            {
                result.MessageType = messageType;
            }
            else
            {
                return(null);
            }

            // Probably overkill; if it has more than two it probably has them all.
            if (parts.Length > 5)
            {
                result.Param1 = parts[5];
            }

            if (parts.Length > 4)
            {
                result.Param0 = parts[4];
            }

            if (parts.Length > 3)
            {
                result.RawEnglishMessageTemplate = parts[3];
            }

            if (parts.Length > 2)
            {
                result.L10NId = parts[2];
            }
            return(result);
        }
Esempio n. 4
0
        public void WriteMessage(TeamCollectionMessage message)
        {
            Messages.Add(message);
            SIL.Reporting.Logger.WriteEvent(message.TextForDisplay);
            TeamCollectionManager.RaiseTeamCollectionStatusChanged();
            // Using Environment.NewLine here means the format of the file will be appropriate for the
            // computer we are running on. It's possible a shared collection might be used by both
            // Linux and Windows. But that's OK, because .NET line reading accepts either line
            // break on either platform.
            var toPersist = message.ToPersistedForm + Environment.NewLine;

            // There ought to be a RobustFile.AppendAllText, but there isn't.
            // However, as this promises to close the file each call, it should be pretty reliable.
            RetryUtility.Retry(() => File.AppendAllText(_logFilePath, toPersist));
        }
 public void MakeDisconnected(TeamCollectionMessage message, string repoDescription)
 {
     CurrentCollection = null;
     // This will show the TC icon in error state, and if the dialog is shown it will have this one message.
     CurrentCollectionEvenIfDisconnected = new DisconnectedTeamCollection(this, _localCollectionFolder, repoDescription);
     CurrentCollectionEvenIfDisconnected.SocketServer = SocketServer;
     CurrentCollectionEvenIfDisconnected.TCManager    = this;
     CurrentCollectionEvenIfDisconnected.MessageLog.WriteMessage(message);
     CurrentCollectionEvenIfDisconnected.MessageLog.WriteMessage(MessageAndMilestoneType.Error, "TeamCollection.OperatingDisconnected", "When you have resolved this problem, please click \"Reload Collection\". Until then, your Team Collection will operate in \"Disconnected\" mode.",
                                                                 null, null);
     // This is normally ensured by pushing an Error message into the log. But in this case,
     // before the user gets a chance to open the dialog, we will run SyncAtStartup, push a Reloaded
     // milestone into the log, and thus suppress it. If we're disconnected, whatever gets in the
     // message log, we want to offer Reload...after all, the message says to use it.
     MessageLog.NextTeamCollectionDialogShouldForceReloadButton = true;
 }
Esempio n. 6
0
        // TeamCollection has its own set of message types. Here we convert them to standard
        // progress messages so we can reuse existing UI controls.
        private BloomWebSocketProgressEvent ProgressMessageFromTeamCollectionLogEntry(TeamCollectionMessage entry)
        {
            switch (entry.MessageType)
            {
            case MessageAndMilestoneType.Error:
            case MessageAndMilestoneType.ErrorNoReload:
            case MessageAndMilestoneType.ClobberPending:
                return(new BloomWebSocketProgressEvent(kWebSocketContext, ProgressKind.Error, entry.TextForDisplay));

            default:
                return(new BloomWebSocketProgressEvent(kWebSocketContext, ProgressKind.Progress, entry.TextForDisplay));
            }
        }