Example #1
0
        public IPartViewJunction GetParts()
        {
            var conjunction = new PartViewJunction()
            {
                Type = JunctionType.Conjunction, Builder = _builderFactory
            };

            foreach (var part in Parts)
            {
                if (part.GetParameter() != null)
                {
                    conjunction.Add(part);
                }
            }
            return(conjunction);
        }
Example #2
0
 public IPartView Restore(PartViewDTO dto)
 {
     if (!String.IsNullOrEmpty(dto.JunctionType))
     {
         var junc = new PartViewJunction();
         junc.Type = dto.JunctionType.Equals(JunctionType.Conjunction.ToString()) ? JunctionType.Conjunction : JunctionType.Disjunction;
         foreach (var j in dto.JunctionPartViews)
         {
             junc.Add(this.Restore(j));
         }
         return(junc);
     }
     else
     {
         var part = new PartViewNodeImpl();
         part.SelectedPath    = _pathAssembler.Restore(dto.Path);
         part.SelectedBuilder = _builderAssembler.Restore(dto.Builder);
         part.Values          = dto.Values;
         part.Parser          = _parserAssembler.Restore(dto.Parser);
         return(part);
     }
 }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dto"></param>
        /// <exception cref="Standalone.Core.Serialization.Assemblers.SearchDocumentRestoreException">Thrown if the project details cannot be matched to the assemblers project instance.</exception>
        /// <returns></returns>
        public SearchDocument Restore(SearchDocumentDTO dto)
        {
            var doc = new SearchDocument()
            {
                Project = new ProjectDetails()
                {
                    FileHint = dto.Project.FileHint,
                    Id       = dto.Project.Id,
                    Version  = (dto.Project.Version == null ? null : new System.Version(dto.Project.Version))
                },
                SearchType = dto.SearchType
            };

            // verify project before continuing
            var errors = new StringBuilder();

            if (!_project.Id.Equals(doc.Project.Id))
            {
                errors.AppendLine("This search document was saved for a different project.");
            }
            int compare = 0;

            if ((doc.Project.Version == null && _project.Version != null) || (doc.Project.Version != null && _project.Version == null))
            {
                errors.AppendLine("This search document was saved for a different version of the project.");
            }
            else if (!(doc.Project.Version == null && _project.Version == null))
            {
                compare = doc.Project.Version.CompareTo(_project.Version);
            }
            if (compare != 0)
            {
                errors.AppendLine(compare > 0 ? "The search document was saved for a newer version of the project." : "The search document was saved for an older version of the project.");
            }
            if (errors.Length > 0)
            {
                throw new SearchDocumentRestoreException(errors.ToString());
            }

            // if the project was OK, try to restore the subject
            if (dto.SubjectIndex >= 0 && dto.SubjectIndex < _project.Configuration.Count)
            {
                doc.Subject = _project.Configuration[dto.SubjectIndex];
            }
            else
            {
                throw new SearchDocumentRestoreException(String.Format("Search index {0} does not exist in the project.", dto.SubjectIndex));
            }

            // now restore output/parts
            if (dto.Outputs != null)
            {
                doc.Outputs = new List <IFieldPath>();
                foreach (var f in dto.Outputs)
                {
                    doc.Outputs.Add(_pathAssembler.Restore(f));
                }
            }

            if (dto.Parts != null)
            {
                var parts = _partAssembler.Restore(dto.Parts);
                if (parts is IPartViewNode)
                {
                    parts = new PartViewJunction(JunctionType.Conjunction)
                    {
                        parts
                    }
                }
                ;
                doc.Parts = (IPartViewJunction)parts;
            }

            return(doc);
        }