Beispiel #1
0
        public void DetermineSequence()
        {
            try
            {
                // Find the newest chunk
                ChunkIndex?newestChunkIndex = FindNewestChunkIndex();
                if (newestChunkIndex == null)
                {
                    CurrentSequence = null;
                }
                else
                {
                    Logger.Instance.Trace(this, "Newest chunk: {0}", newestChunkIndex.Value);

                    int?currentSequence = CurrentSequence;
                    if (!currentSequence.HasValue || currentSequence.Value != newestChunkIndex?.numberOfChunks)
                    {
                        // Sequence has changed. Delete contacts
                        Logger.Instance.Trace(this, "Rechunked, deleting contacts");
                        ClearContacts();

                        // Determine new sequence
                        if (newestChunkIndex == null)
                        {
                            using (IStorageItem index = GetIndexItem())
                            {
                                if (index != null)
                                {
                                    index.Delete();
                                }
                            }
                        }
                        else
                        {
                            int numberOfChunks = newestChunkIndex.Value.numberOfChunks;
                            using (IStorageItem index = GetIndexItem())
                            {
                                index.SetUserProperty(PROP_CURRENT_SEQUENCE, numberOfChunks);
                                index.SetUserProperty(PROP_LAST_PROCESSED, CreateChunkStateString(numberOfChunks));
                                index.Save();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Instance.Trace(this, "Exception determining sequence: {0}", e);
                // Delete the index item
                using (IStorageItem index = GetIndexItem())
                    index?.Delete();
                return;
            }
            Logger.Instance.Trace(this, "Current sequence: {0}", CurrentSequence);
        }
Beispiel #2
0
        private void SetChunkStateString(ChunkIndex index, string partState)
        {
            using (IStorageItem item = GetIndexItem())
            {
                string   state = item.GetUserProperty <string>(PROP_LAST_PROCESSED);
                string[] parts;
                if (string.IsNullOrEmpty(state))
                {
                    parts = new string[index.numberOfChunks];
                }
                else
                {
                    parts = state.Split(';');
                }
                if (parts.Length != index.numberOfChunks)
                {
                    Logger.Instance.Error(this, "Wrong number of chunks, got {0}, expected {1}: {2}",
                                          parts.Length, index.numberOfChunks, state);
                }
                parts[index.chunk] = partState;
                string combined = string.Join(";", parts);

                item.SetUserProperty(PROP_LAST_PROCESSED, combined);
                item.Save();
            }
        }