Пример #1
0
        public async Task ApplyTo(DataCollection collection, bool final = false)
        {
            foreach (var item in _removed.ToArray())
            {
                collection.RemoveFile(item.Model.Name);
            }

            foreach (var item in _added.ToArray())
            {
                var fs = _streams[item].Item2;
                if (final)
                {
                    using (fs)
                    {
                        await collection.AddFile(item.Model.Name, fs);
                    }
                }
                else
                {
                    await collection.AddFile(item.Model.Name, fs);

                    fs.Position = 0;
                }
            }

            foreach (var item in _renamed.ToArray())
            {
                await collection.RenameFile(item.Item1, item.Item2);
            }

            if (final)
            {
                _added.Clear();
                _removed.Clear();
                _renamed.Clear();
            }
        }
Пример #2
0
        private static async Task InheritContent(SIDocument doc, SIDocument doc2, Question question)
        {
            foreach (var atom in question.Scenario)
            {
                if (atom.Type == AtomTypes.Text || atom.Type == AtomTypes.Oral)
                {
                    continue;
                }

                var link = doc2.GetLink(atom);
                if (link.GetStream != null)
                {
                    DataCollection collection = null;
                    switch (atom.Type)
                    {
                    case AtomTypes.Video:
                        collection = doc.Video;
                        break;

                    case AtomTypes.Audio:
                        collection = doc.Audio;
                        break;

                    case AtomTypes.Image:
                        collection = doc.Images;
                        break;
                    }

                    if (collection != null)
                    {
                        using (var stream = link.GetStream().Stream)
                        {
                            await collection.AddFile(link.Uri, stream);
                        }
                    }
                }
            }
        }
Пример #3
0
        public async Task Commit(DataCollection collection)
        {
            foreach (var item in _removed.ToArray())
            {
                collection.RemoveFile(item.Model.Name);
                item.PropertyChanged -= Named_PropertyChanged;
                _removed.Remove(item);
            }

            foreach (var item in _added.ToArray())
            {
                try
                {
                    using (var fs = _streams[item].Item2)
                    {
                        await collection.AddFile(item.Model.Name, fs);
                    }
                }
                catch (Exception exc)
                {
                    OnError(exc);
                }

                _added.Remove(item);
                _streams.Remove(item);
            }

            foreach (var item in _renamed.ToArray())
            {
                await collection.RenameFile(item.Item1, item.Item2);

                _renamed.Remove(item);
            }

            HasPendingChanges = false;
        }