Ejemplo n.º 1
0
        public ProjectState WithRemovedHostDocument(HostDocument hostDocument)
        {
            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            if (!Documents.ContainsKey(hostDocument.FilePath))
            {
                return(this);
            }

            var documents = new Dictionary <string, DocumentState>(FilePathComparer.Instance);

            foreach (var kvp in Documents)
            {
                documents.Add(kvp.Key, kvp.Value);
            }

            documents.Remove(hostDocument.FilePath);

            var difference = ProjectDifference.DocumentRemoved;
            var state      = new ProjectState(this, difference, HostProject, WorkspaceProject, documents);

            return(state);
        }
Ejemplo n.º 2
0
        public ProjectState WithChangedHostDocument(HostDocument hostDocument, Func <Task <TextAndVersion> > loader)
        {
            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            if (!Documents.ContainsKey(hostDocument.FilePath))
            {
                return(this);
            }

            var documents = new Dictionary <string, DocumentState>(FilePathComparer.Instance);

            foreach (var kvp in Documents)
            {
                documents.Add(kvp.Key, kvp.Value);
            }

            if (documents.TryGetValue(hostDocument.FilePath, out var document))
            {
                documents[hostDocument.FilePath] = document.WithTextLoader(loader);
            }

            var state = new ProjectState(this, ProjectDifference.DocumentChanged, HostProject, WorkspaceProject, documents);

            return(state);
        }
Ejemplo n.º 3
0
        public ProjectState WithRemovedHostDocument(HostDocument hostDocument)
        {
            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            if (!Documents.ContainsKey(hostDocument.FilePath))
            {
                return(this);
            }

            var documents = Documents.Remove(hostDocument.FilePath);

            // First check if the updated document is an import - it's important that this happens
            // before updating the imports map.
            if (ImportsToRelatedDocuments.TryGetValue(hostDocument.TargetPath, out var relatedDocuments))
            {
                foreach (var relatedDocument in relatedDocuments)
                {
                    documents = documents.SetItem(relatedDocument, documents[relatedDocument].WithImportsChange());
                }
            }

            // Compute the effect on the import map
            var importTargetPaths         = GetImportDocumentTargetPaths(hostDocument.TargetPath);
            var importsToRelatedDocuments = RemoveFromImportsToRelatedDocuments(ImportsToRelatedDocuments, hostDocument, importTargetPaths);

            var state = new ProjectState(this, ProjectDifference.DocumentRemoved, HostProject, ProjectWorkspaceState, documents, importsToRelatedDocuments);

            return(state);
        }
Ejemplo n.º 4
0
        public ProjectState WithAddedHostDocument(HostDocument hostDocument, Func <Task <TextAndVersion> > loader)
        {
            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            if (loader == null)
            {
                throw new ArgumentNullException(nameof(loader));
            }

            // Ignore attempts to 'add' a document with different data, we only
            // care about one, so it might as well be the one we have.
            if (Documents.ContainsKey(hostDocument.FilePath))
            {
                return(this);
            }

            var documents = new Dictionary <string, DocumentState>(FilePathComparer.Instance);

            foreach (var kvp in Documents)
            {
                documents.Add(kvp.Key, kvp.Value);
            }

            documents.Add(hostDocument.FilePath, DocumentState.Create(Services, hostDocument, loader));

            var difference = ProjectDifference.DocumentAdded;
            var state      = new ProjectState(this, difference, HostProject, WorkspaceProject, documents);

            return(state);
        }
Ejemplo n.º 5
0
 public Document GetDocument(GetDocument documentInfo)
 {
     return(new Document()
     {
         Id = documentInfo.Id,
         RawJsonValue = Documents.ContainsKey(documentInfo.Id) ? Documents[documentInfo.Id] : null,
     });
 }
        public async Task <IEnumerable <Document> > ListAsync(string container)
        {
            if (!Documents.ContainsKey(container))
            {
                Documents[container] = (await DataSource.ListAsync(container).ConfigureAwait(false)).ToDictionary(d => d.Id, d => d);
            }

            return(Documents[container].Values.ToList().AsReadOnly());
        }
Ejemplo n.º 7
0
        public Task UpdateAsync(string container, string id, Document document)
        {
            if (!Documents.ContainsKey(container))
            {
                Documents[container] = new Dictionary <string, Document>();
            }

            Documents[container][id] = document;

            return(Task.CompletedTask);
        }
Ejemplo n.º 8
0
        public Task DeleteAsync(string container, string id)
        {
            if (!Documents.ContainsKey(container))
            {
                return(Task.CompletedTask);
            }

            Documents[container].Remove(id);

            return(Task.CompletedTask);
        }
        public async Task DeleteAsync(string container, string id)
        {
            if (!Documents.ContainsKey(container))
            {
                Documents[container] = (await DataSource.ListAsync(container).ConfigureAwait(false)).ToDictionary(d => d.Id, d => d);
            }

            await DataSource.DeleteAsync(container, id).ConfigureAwait(false);

            Documents[container].Remove(id);
        }
        public async Task UpdateAsync(string container, string id, Document document)
        {
            if (!Documents.ContainsKey(container))
            {
                Documents[container] = (await DataSource.ListAsync(container).ConfigureAwait(false)).ToDictionary(d => d.Id, d => d);
            }

            await DataSource.UpdateAsync(container, id, document).ConfigureAwait(false);

            Documents[container][id] = document;
        }
Ejemplo n.º 11
0
        public Task Create(string container, Document document)
        {
            if (!Documents.ContainsKey(container))
            {
                Documents[container] = new Dictionary <string, Document>();
            }

            Documents[container][document.Id] = document;

            return(Task.CompletedTask);
        }
        public async Task Create(string container, Document document)
        {
            await DataSource.CreateDocumentAsync(container, document).ConfigureAwait(false);

            if (!Documents.ContainsKey(container))
            {
                Documents[container] = (await DataSource.ListAsync(container).ConfigureAwait(false)).ToDictionary(d => d.Id, d => d);
            }

            Documents[container][document.Id] = document;
        }
Ejemplo n.º 13
0
        public bool UploadDocument(DocumentMetaData meta, object content)
        {
            if (!Documents.ContainsKey(meta.Name))
            {
                var newDocument = DocumentFactory.CreateDocument(meta.Name);
                syncManager.SetContent(newDocument, content);
                Documents[meta.Name] = newDocument;

                return(true);
            }

            return(false);
        }
        public async Task <Document> GetAsync(string container, string id)
        {
            if (!Documents.ContainsKey(container))
            {
                Documents[container] = (await DataSource.ListAsync(container).ConfigureAwait(false)).ToDictionary(d => d.Id, d => d);
            }

            if (!Documents[container].ContainsKey(id))
            {
                return(null);
            }

            return(Documents[container][id]);
        }
Ejemplo n.º 15
0
        public Task <Document> GetAsync(string container, string id)
        {
            if (!Documents.ContainsKey(container))
            {
                return(Task.FromResult <Document>(null));
            }

            if (!Documents[container].ContainsKey(id))
            {
                return(Task.FromResult <Document>(null));
            }

            return(Task.FromResult(Documents[container][id]));
        }
        /// <summary>
        /// Returns list of documents which have at least 1 similar term to passed document
        ///
        /// Usually this method is needed for getting list of docs for which we need perform tf-idf recalculations
        /// </summary>
        public List <Document> GetRelatedDocuments(Document document)
        {
            return(document.Tokens
                   .SelectMany(t =>
            {
                var tokenContext = _keyValueStorage.Get <TokenContext>(_tokenContextCacheKey(t))
                                   ?? new TokenContext();

                return tokenContext.DocumentIds;
            })
                   // Take unique document ids (because document can appear in multiply tokens)
                   .Distinct()
                   .Where(x => x != document.Id && Documents.ContainsKey(x))
                   .Select(x => Documents[x])
                   .ToList());
        }
Ejemplo n.º 17
0
        public bool CreateDocument(DocumentMetaData document)
        {
            if (!Documents.ContainsKey(document.Name))
            {
                var newInstance = DocumentFactory.CreateDocument(document.Name);
                Documents[document.Name] = newInstance;

                var to = Clients.Where(c => c.Key != document.ClientId);
                Parallel.ForEach(to, c => c.Value.Client.NotifyDocumentCreated(document.Name));

                return(true);
            }

            else
            {
                return(false);
            }
        }
Ejemplo n.º 18
0
        private void ProcessMessage(OTMessage message)
        {
            foreach (var o in message.Content)
            {
                if (!Documents.ContainsKey(o.DocumentName))
                {
                    continue;
                }

                var operationContext = Documents[o.DocumentName];
                Transform(o, operationContext);
                Execute(o, operationContext);

                operationContext.ServerMessages++;

                o.ExecutedAt     = DateTime.Now;
                o.ClientMessages = this.clientMessages;
                o.ServerMessages = this.serverMessages;

                operationContext.Log.Add(o);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        ///		Trata el evento de cierre de un documento
        /// </summary>
        private bool TreatEventCloseForm(DockLayoutDocument document)
        {
            bool canClose = true;

            // Si es un documento, antes de cerrar se pregunta a la ventana principal
            if (document.Type == DockLayoutDocument.DocumentType.Document)
            {
                ClosingEventArgs args = new ClosingEventArgs(document);

                // Llama al manejador de eventos
                Closing?.Invoke(this, args);
                // Si no se ha cancelado, se puede cerrar
                canClose = !args.Cancel;
            }
            // Si se debe cerrar, se quita del diccionario
            if (canClose && Documents.ContainsKey(document.Id))
            {
                Documents.Remove(document.Id);
            }
            // Devuelve el valor que indica si se puede cerrar el documento
            return(canClose);
        }
Ejemplo n.º 20
0
        public ProjectState WithAddedHostDocument(HostDocument hostDocument, Func <Task <TextAndVersion> > loader)
        {
            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            if (loader == null)
            {
                throw new ArgumentNullException(nameof(loader));
            }

            // Ignore attempts to 'add' a document with different data, we only
            // care about one, so it might as well be the one we have.
            if (Documents.ContainsKey(hostDocument.FilePath))
            {
                return(this);
            }

            var documents = Documents.Add(hostDocument.FilePath, DocumentState.Create(Services, hostDocument, loader));

            // Compute the effect on the import map
            var importTargetPaths         = GetImportDocumentTargetPaths(hostDocument.TargetPath);
            var importsToRelatedDocuments = AddToImportsToRelatedDocuments(ImportsToRelatedDocuments, hostDocument, importTargetPaths);

            // Now check if the updated document is an import - it's important this this happens after
            // updating the imports map.
            if (importsToRelatedDocuments.TryGetValue(hostDocument.TargetPath, out var relatedDocuments))
            {
                foreach (var relatedDocument in relatedDocuments)
                {
                    documents = documents.SetItem(relatedDocument, documents[relatedDocument].WithImportsChange());
                }
            }

            var state = new ProjectState(this, ProjectDifference.DocumentAdded, HostProject, ProjectWorkspaceState, documents, importsToRelatedDocuments);

            return(state);
        }
Ejemplo n.º 21
0
 public bool OpenDocument(DocumentMetaData document)
 {
     return(Documents.ContainsKey(document.Name));
 }
Ejemplo n.º 22
0
 /// <summary>
 ///		Comprueba si existe un  documento
 /// </summary>
 private bool ExistsDocument(string windowID)
 {
     return(Documents.ContainsKey(windowID));
 }