Ejemplo n.º 1
0
/// <summary>
/// Returns the list of logs for the specified protocol.
/// </summary>
        public TrillianLog[] GetLogs(string protocol)
        {
            string logDir = Path.Combine(_profileDir, Path.Combine("Logs", protocol));

            if (!Directory.Exists(logDir))
            {
                return new TrillianLog[] {}
            }
            ;

            string[] fileNames = Directory.GetFiles(logDir);
            var      result    = new TrillianLog[fileNames.Length];

            for (int i = 0; i < fileNames.Length; i++)
            {
                result[i] = new TrillianLog(Path.Combine(logDir, fileNames[i]));
            }
            return(result);
        }
Ejemplo n.º 2
0
        /**
         * Imports a single Trillian log.
         */

        private void ImportLog(string protocol, TrillianLog log, IResource selfAccount)
        {
            // For ICQ, the first session does not contain the nickname of the correspondent.
            // Thus, to avoid creating number-only contacts, we buffer messages until we
            // get a real nick, then create the contact and account, process the messages from
            // the buffer and continue parsing normally.
            ArrayList messageBuffer = new ArrayList();

            IResource correspondentAcct = FindTrillianAccount(protocol, log.GetName());

            if (correspondentAcct != null)
            {
                // GetIntProp() returns 0 if the property was not defined
                int lastImportOffset = correspondentAcct.GetIntProp(_propLastImportOffset);

                // If the log size is less than the last import offset, it means that the
                // log was truncated. Redo import from start.
                if (lastImportOffset > log.Size)
                {
                    lastImportOffset = 0;
                }
                if (lastImportOffset == log.Size)
                {
                    // the log is already completely imported
                    return;
                }
                log.Seek(lastImportOffset);
            }

            while (true)
            {
                TrillianLogMessage msg = log.ReadNextMessage();
                if (msg == null)
                {
                    break;
                }

                if (correspondentAcct == null)
                {
                    int foo;
                    if (protocol == "ICQ" && Int32.TryParse(log.CurCorrespondentName, out foo))
                    {
                        messageBuffer.Add(msg);
                        continue;
                    }
                    correspondentAcct = FindOrCreateTrillianAccount(protocol, log.GetName(),
                                                                    log.CurCorrespondentName);

                    ImportFromBuffer(messageBuffer, selfAccount, correspondentAcct);
                    messageBuffer.Clear();
                }

                IResource fromAccount = msg.Incoming ? correspondentAcct : selfAccount;
                IResource toAccount   = msg.Incoming ? selfAccount : correspondentAcct;

                IResource conversation = _convManager.Update(msg.Text, msg.Time, fromAccount, toAccount);

                // Request text indexing of the conversation. Repeated indexing requests
                // will be merged, so there is no harm in requesting to index the same
                // conversation multiple times.
                if (conversation != null)
                {
                    _environment.TextIndexManager.QueryIndexing(conversation.Id);
                }
            }

            if (correspondentAcct == null && messageBuffer.Count > 0)
            {
                // no nickname until end of log => process messages accumulated in the buffer
                correspondentAcct = FindOrCreateTrillianAccount(protocol, log.GetName(), null);
                ImportFromBuffer(messageBuffer, selfAccount, correspondentAcct);
            }
            correspondentAcct.SetProp(_propLastImportOffset, log.Size);
        }