Exemplo n.º 1
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value != null)
     {
         return(RTFUtils.StripMarkup(value as string));
     }
     return(value);
 }
        protected override void GetDetailText(BioLinkDataObject model, TextTableBuilder builder)
        {
            var refmodel = model as Reference;

            builder.Add("Type", refmodel.RefType);
            builder.Add("Title", RTFUtils.StripMarkup(refmodel.Title));
            builder.Add("Author", refmodel.Author);
            builder.Add("Year", refmodel.YearOfPub);
            builder.Add("Journal", refmodel.JournalName);
        }
        private void EditComment()
        {
            string oldComment = RTFUtils.StripMarkup(Model.Comment);

            InputBox.Show(this.FindParentWindow(), "Enter comment", "Enter a comment", oldComment, (newcomment) => {
                if (oldComment != newcomment)
                {
                    Model.Comment = newcomment;
                }
            });
        }
Exemplo n.º 4
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string rtf = RTFUtils.filter(value as string, true, false, "b", "i", "sub", "super", "strike", "ul", "ulnone", "nosupersub");

            if (rtf != null && (!rtf.StartsWith(@"{{\rtf") && (!rtf.StartsWith(@"{\rtf"))))
            {
                rtf = string.Format(@"{{\rtf1\ansi\ansicpg1252\deff0\deftab720 {{\fonttbl{{\f0\fswiss Arial;}}}} \plain\f0\fs18 {0} }}", rtf);
            }

            return(rtf);
        }
        public DataMatrix GetAssociatesForTaxa(int regionID, bool stripRTF, params int[] taxonIds)
        {
            var strTaxonIDS = taxonIds.Join(",");

            var formatters = new Dictionary <String, ColumnDataFormatter>();

            if (stripRTF)
            {
                formatters["Notes"] = (value, reader) => RTFUtils.StripMarkup(value as String);
            }

            return(StoredProcDataMatrix("spAssociatesListForTaxon", formatters, _P("intPoliticalRegionID", regionID), _P("vchrBiotaID", strTaxonIDS)));
        }
        public bool ImportMultimediaLink(List <XMLImportMultimediaLink> items)
        {
            bool ok = true;

            foreach (XMLImportMultimediaLink item in items)
            {
                ImportObject(item, "spXMLImportMultimediaLink", _P("GUID", item.GUID));
                if (item.ID < 0)
                {
                    ok = false;
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(item.Caption))
                    {
                        try {
                            XMLImportMultimediaLink item1 = item;
                            Command((con, cmd) => {
                                cmd.CommandText = "UPDATE tblMultimediaLink SET vchrCaption = @vchrCaption WHERE intMultimediaLinkID = @linkid";
                                cmd.Parameters.Add(_P("@vchrCaption", item1.Caption));
                                cmd.Parameters.Add(_P("@linkid", item1.ID));
                                cmd.ExecuteNonQuery();
                            });
                        } catch (Exception ex) {
                            Logger.Debug("Failed to insert caption for multimedia link id {0}. Probably due to the size of the caption exceeding the size of the table column. Will trim and try again. {1}.", item.ID, ex.Message);
                            try {
                                // first strip off any rtf...
                                var caption = RTFUtils.StripMarkup(item.Caption);
                                if (caption.Length > 255)
                                {
                                    caption = caption.Truncate(255);
                                }
                                XMLImportMultimediaLink item1 = item;
                                Command((con, cmd) => {
                                    cmd.CommandText = "UPDATE tblMultimediaLink SET vchrCaption = @vchrCaption WHERE intMultimediaLinkID = @linkid";
                                    cmd.Parameters.Add(_P("@vchrCaption", caption));
                                    cmd.Parameters.Add(_P("@linkid", item1.ID));
                                    cmd.ExecuteNonQuery();
                                });
                            } catch (Exception ex2) {
                                Logger.Debug("Failed to insert shortened caption for multimedia link id {0} again!. Probably due to the size of the caption exceeding the size of the table column. Giving up! {1}. ", item.ID, ex2.Message);
                            }
                        }
                    }
                }
            }
            return(ok);
        }
        /// <summary>
        /// Compares two strings by stripping away any RTF formatting so that just textual content is compared.
        /// This is necessary because the RTF text box will add a bunch of RTF fluff to field values even if no actual formatting is used,
        /// and this will trigger a change when logically there isn't one.
        /// </summary>
        /// <param name="current"></param>
        /// <param name="newval"></param>
        /// <returns></returns>
        private bool CompareIgnoringFormatting(string current, string newval)
        {
            if (current == null)
            {
                current = "";
            }

            if (newval == null)
            {
                newval = "";
            }

            // basic tests first
            if (current == newval)
            {
                return(false);
            }

            string lhs = RTFUtils.StripMarkup(current);
            string rhs = RTFUtils.StripMarkup(newval);

            return(!lhs.Trim().Equals(rhs.Trim()));
        }
        protected override System.Windows.FrameworkElement GetDetailContent(BioLinkDataObject model)
        {
            var vm   = ViewModel as MultimediaLinkViewModel;
            var grid = new Grid {
                Margin = new Thickness(3)
            };

            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength()
            });
            grid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength()
            });

            if (vm != null && !string.IsNullOrWhiteSpace(vm.TempFilename))
            {
                var img = new Image {
                    SnapsToDevicePixels = true, UseLayoutRounding = true, Stretch = System.Windows.Media.Stretch.None
                };
                img.Source = GraphicsUtils.GenerateThumbnail(vm.TempFilename, 300);
                grid.Children.Add(img);
            }

            var builder = new TextTableBuilder();

            builder.Add("Type", vm.MultimediaType);
            builder.Add("Caption", RTFUtils.StripMarkup(vm.Caption));

            var details = builder.GetAsContent();

            Grid.SetRow(details, 1);

            grid.Children.Add(details);

            return(grid);
        }
Exemplo n.º 9
0
        public override DataMatrix ExtractReportData(IProgressObserver progress)
        {
            var matrix = new DataMatrix();

            var service = new SupportService(User);

            matrix.Columns.Add(new MatrixColumn {
                Name = IntraCategoryIdColumnName, IsHidden = true
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "RefID", IsHidden = true
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "RefCode"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "RefType"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "LinkPage"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "LinkQualification"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "LinkQualificationRTF", IsHidden = true
            });

            matrix.Columns.Add(new MatrixColumn {
                Name = "Title"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Author"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "BookTitle"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Edition"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Editor"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "StartPage"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "EndPage"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "ActualDate"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "ISBN"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "ISSN"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalID", IsHidden = true
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "PartNo"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Place"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Possess"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Publisher"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "RefType"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Series"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "Source"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "FullText"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "FullRTF", IsHidden = true
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalAbbrevName"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalAbbrevName2"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalAlias"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalFullName"
            });
            matrix.Columns.Add(new MatrixColumn {
                Name = "JournalNotes"
            });

            var reflinks = SelectReferences(progress);

            progress.ProgressMessage("Preparing view model...");
            foreach (RefLink link in reflinks)
            {
                if (Options.HonourIncludeInReportsFlag)
                {
                    if (!link.UseInReport.HasValue || !link.UseInReport.Value)
                    {
                        // skip this one as it hasn't got the use in reports flag set.
                        continue;
                    }
                }

                var reference = service.GetReference(link.RefID);
                if (reference != null)
                {
                    int i   = 0;
                    var row = matrix.AddRow();
                    row[i++] = link.IntraCatID.Value;
                    row[i++] = link.RefID;
                    row[i++] = reference.RefCode;
                    row[i++] = link.RefLinkType;
                    row[i++] = link.RefPage;
                    row[i++] = RTFUtils.StripMarkup(link.RefQual);
                    row[i++] = link.RefQual;


                    row[i++] = RTFUtils.StripMarkup(reference.Title);
                    row[i++] = reference.Author;
                    row[i++] = RTFUtils.StripMarkup(reference.BookTitle);
                    row[i++] = reference.Edition;
                    row[i++] = reference.Editor;
                    row[i++] = reference.StartPage;
                    row[i++] = reference.EndPage;
                    row[i++] = SupportService.FormatDate(reference.ActualDate, "yyyy-MM-dd");
                    row[i++] = reference.ISBN;
                    row[i++] = reference.ISSN;
                    row[i++] = reference.JournalID;
                    row[i++] = reference.PartNo;
                    row[i++] = reference.Place;
                    row[i++] = reference.Possess;
                    row[i++] = reference.Publisher;
                    row[i++] = reference.RefType;
                    row[i++] = reference.Series;
                    row[i++] = reference.Source;
                    row[i++] = reference.FullText;
                    row[i++] = reference.FullRTF;

                    if (reference.JournalID.HasValue && reference.JournalID.Value > 0)
                    {
                        var journal = service.GetJournal(reference.JournalID.Value);
                        row[i++] = journal.AbbrevName;
                        row[i++] = journal.AbbrevName2;
                        row[i++] = journal.Alias;
                        row[i++] = journal.FullName;
                        row[i++] = journal.Notes;
                    }
                }
            }

            progress.ProgressMessage("");

            return(matrix);
        }
        protected string SubstitutePlaceHolder(string key, Loan loan, IEnumerable <LoanMaterial> material, IEnumerable <Trait> traits, Contact originator, Contact requestor, Contact receiver)
        {
            var sb = new StringBuilder();

            // Special placeholders

            switch (key.ToLower())
            {
            case "totalspecimencount":
                return(CountTotalSpecimens(material) + "");
            }

            if (key.Contains('('))
            {
                // group...
                var collectionName = key.Substring(0, key.IndexOf('('));
                var fieldstr       = key.Substring(key.IndexOf('(') + 1);
                var fields         = fieldstr.Substring(0, fieldstr.Length - 1).Split(',');

                List <object> collection = null;
                if (collectionName.Equals("material", StringComparison.CurrentCultureIgnoreCase))
                {
                    collection = new List <object>(material);
                }
                else if (collectionName.Equals("trait", StringComparison.CurrentCultureIgnoreCase))
                {
                    collection = new List <object>(traits);
                }

                if (collection != null)
                {
                    foreach (Object obj in collection)
                    {
                        int i = 0;
                        foreach (string field in fields)
                        {
                            var value = GetPropertyValue(obj, field);
                            if (!string.IsNullOrEmpty(value))
                            {
                                sb.Append(RTFUtils.EscapeUnicode(value));
                            }
                            sb.Append(++i < fields.Length ? ", " : String.Format(". {0}", NewLineSequence));
                        }
                    }
                }
            }
            else if (key.Contains("."))
            {
                // is a property of a linked object (currently just the three different contacts attached to the loan)
                // e.g. receiver.EMail
                var bits = key.Split('.');

                if (bits.Length > 0)
                {
                    Object srcObject = null;
                    switch (bits[0].ToLower())
                    {
                    case "receiver":
                        srcObject = receiver;
                        break;

                    case "requestor":
                        srcObject = requestor;
                        break;

                    case "originator":
                        srcObject = originator;
                        break;
                    }

                    if (srcObject != null)
                    {
                        var value = GetPropertyValue(srcObject, bits[1]);
                        if (!string.IsNullOrEmpty(value))
                        {
                            sb.Append(RTFUtils.EscapeUnicode(value));
                        }
                    }
                }
            }
            else
            {
                // single value from the Loan model...
                var value = GetPropertyValue(loan, key);
                if (!string.IsNullOrEmpty(value))
                {
                    sb.Append(RTFUtils.EscapeUnicode(value));
                }
            }
            return(sb.ToString());
        }
Exemplo n.º 11
0
        public DataMatrix RunDwcQuery(BioLinkService service, String whereClause)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            TextReader inputStream = new StreamReader(assembly.GetManifestResourceStream("BioLink.Data.scripts.DarwinCoreReportTemplate.txt"));
            string     sql         = inputStream.ReadToEnd();

            // Now we need do substitutions
            var values = new Dictionary <String, String>();

            values["InstitutionCode"] = "";
            values["CollectionCode"]  = "";
            values["where"]           = whereClause;

            sql = StringUtils.SubstitutePlaceholders(sql, values);

            var formatters = new Dictionary <String, ColumnDataFormatter>();

            formatters["occurrenceRemarks"] = (value, reader) => RTFUtils.StripMarkup(value as String);
            formatters["dateIdentified"]    = (value, reader) => {
                var d = value as DateTime?;
                if (d != null)
                {
                    return(d.Value.ToString("yyyy-MM-dd"));
                }

                return(value);
            };

            formatters["eventDate"] = (value, reader) => {
                var rangeStr = value as String;
                if (rangeStr != null)
                {
                    var   bits = rangeStr.Split('/');
                    var   sb = new StringBuilder();
                    Int32 date1 = 0, date2 = 0;
                    if (bits.Length > 1)
                    {
                        Int32.TryParse(bits[0], out date1);
                        Int32.TryParse(bits[1], out date2);
                    }
                    else
                    {
                        if (bits.Length == 1)
                        {
                            Int32.TryParse(bits[0], out date1);
                        }
                    }

                    if (date1 > 0)
                    {
                        sb.Append(DateUtils.FormatBLDate("yyyy-MM-dd", date1));
                        if (date2 > 0)
                        {
                            sb.Append("/").Append(DateUtils.FormatBLDate("yyyy-MM-dd", date2));
                        }
                    }
                    else if (date2 > 0)
                    {
                        sb.Append(DateUtils.FormatBLDate("yyyy-MM-dd", date2));
                    }
                    return(sb.ToString());
                }
                return(value);
            };

            return(service.SQLReaderDataMatrix(sql, formatters, null));
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     return(RTFUtils.StripMarkup(value as string));
 }
        public System.Windows.FrameworkElement ConstructView(IBioLinkReport report, DataMatrix reportData, IProgressObserver progress)
        {
            var options = (report as ReferenceLinksReport).Options;

            var viewer = new RTFReportViewer {
                ReportName = report.Name
            };
            var rtf = new RTFReportBuilder();

            rtf.AppendFullHeader();
            rtf.ReportHeading(options.BibliographyTitle);

            var idx      = 1;
            var colIndex = reportData.IndexOf("RefID");

            var refIds = new List <Int32>();

            for (var i = 0; i < reportData.Rows.Count; ++i)
            {
                refIds.Add(i);
            }

            int sortColumnIdx = reportData.IndexOf(options.SortColumn);
            int refTypeIndex  = reportData.IndexOf("RefType");

            refIds.Sort((idx1, idx2) => {
                // If grouping, first check the ref type
                if (options.GroupByReferenceType)
                {
                    var refType1 = reportData.Rows[idx1][refTypeIndex] as String;
                    var refType2 = reportData.Rows[idx2][refTypeIndex] as String;
                    if (!refType1.Equals(refType2))
                    {
                        return(String.Compare(refType1, refType2, true));
                    }
                }

                // then by the nominated sort column
                var objVal1 = reportData.Rows[idx1][sortColumnIdx];
                var objVal2 = reportData.Rows[idx2][sortColumnIdx];
                var val1    = RTFUtils.StripMarkup(objVal1 == null ? "" : objVal1.ToString());
                var val2    = RTFUtils.StripMarkup(objVal2 == null ? "" : objVal2.ToString());

                if (options.SortAscending)
                {
                    return(String.Compare((String)val1, (String)val2, true));
                }
                else
                {
                    return(String.Compare((String)val2, (String)val1, true));
                }
            });


            var lastRefType = "";

            String[] allowedKeywords = { "b", "i", "sub", "super", "strike", "ul", "ulnone", "nosupersub" };
            foreach (var rowIdx in refIds)
            {
                var row = reportData.Rows[rowIdx];

                if (options.GroupByReferenceType)
                {
                    var refType = row["RefType"] as String;
                    if (!String.Equals(refType, lastRefType, StringComparison.CurrentCultureIgnoreCase))
                    {
                        rtf.Par();
                        rtf.Append(@" \pard\fs24\b\f1 ");
                        rtf.Append(refType);
                        rtf.Append(@" \b0");
                        rtf.Par();
                        lastRefType = refType;
                    }
                }

                rtf.Par();
                rtf.Append(@" \pard\fs20\f1 ");
                if (options.BibliographyIndexStyle != BibliographyIndexStyle.None)
                {
                    rtf.Append("[");
                    switch (options.BibliographyIndexStyle)
                    {
                    case BibliographyIndexStyle.Number:
                        rtf.Append(idx);
                        break;

                    case BibliographyIndexStyle.RefCode:
                        rtf.Append(row["RefCode"]);
                        break;
                    }
                    rtf.Append("] ");
                }
                idx++;

                var fullRTF = RTFUtils.filter(row["FullRTF"] as string, true, false, allowedKeywords);
                rtf.Append(fullRTF);

                var bits = new List <String>();
                if (!String.IsNullOrWhiteSpace(row["LinkPage"] as String))
                {
                    bits.Add(String.Format("page {0}", row["LinkPage"] as String));
                }

                if (options.IncludeQualification)
                {
                    var qual = row["LinkQualificationRTF"] as string;
                    if (!String.IsNullOrEmpty(qual))
                    {
                        bits.Add(RTFUtils.filter(qual, true, true, allowedKeywords).Trim());
                    }
                }

                if (bits.Count > 0)
                {
                    rtf.Append(" (").Append(bits.Join("; ").Trim()).Append(")");
                }

                rtf.Par();
            }

            Console.WriteLine(rtf.RTF);

            viewer.rtf.Rtf = rtf.RTF;

            return(viewer);
        }