Exemple #1
0
        public void MongoConnectionCanUpdateMultipleData()
        {
            Member member1 = InsertMember();
            Member member2 = InsertMember();

            string newId = $"new card id {Guid.NewGuid()}";

            AbstractData.Update <Member, string>(_mongoConnection, member => true, member => member.CardId, newId);

            IOrderedEnumerable <Member> readMembers = AbstractData.Read <Member>(_mongoConnection, member => true).OrderBy(member => member.Id);

            Assert.IsTrue(readMembers.All(member => member.CardId == newId));
        }
        private void createCombinedPdf_noFoldouts(
            IOrderedEnumerable<CockleFilePdf> files_no_foldouts,
            TypeOfCombinedPdf typeOfCombinedPdf,
            bool centerPdf = false)
        {
            CAcroApp app = new AcroApp();           // Acrobat
            CAcroPDDoc doc = new AcroPDDoc();       // First document
            CAcroPDDoc docToAdd = new AcroPDDoc();  // Next documents

            try
            {
                int numPages = 0, numPagesToAdd = 0;
                foreach (var f in files_no_foldouts)
                {
                    if (f.Rank == 0) // both 0
                    {
                        doc.Open(f.FullName);
                        numPages = doc.GetNumPages();
                    }
                    else if (f.Rank != 0 && numPages == 0)
                    {
                        doc.Open(f.FullName);
                        numPages = doc.GetNumPages();
                    }
                    else
                    {
                        if (!docToAdd.Open(f.FullName)) { break; }
                        numPagesToAdd = docToAdd.GetNumPages();
                        if (!doc.InsertPages(numPages - 1, docToAdd, 0, numPagesToAdd, 0)) { break; }
                        if (!docToAdd.Close()) { break; }
                        numPages = doc.GetNumPages();
                    }
                }
                doc.Save(1, CombinedPdfFilename);
                doc.Close();
                // use reflection to center the pdf
                if (centerPdf)
                {
                    var opened = doc.Open(CombinedPdfFilename);
                    if (opened)
                    {
                        object js_object = doc.GetJSObject();
                        Type js_type = js_object.GetType();
                        object[] js_param = { };
                        string script_name = string.Empty;
                        int? cover_length = null;
                        if (typeOfCombinedPdf == TypeOfCombinedPdf.Appendix
                            && files_no_foldouts.All(x => x.CoverLength == null))
                        {
                            script_name = Models.Utilities.AcrobatJS.Javascripts
                                [Models.Utilities.LocalJavascripts.center_letter_no_cover];
                        }
                        else if (files_no_foldouts.All(x => x.CoverLength == null))
                        {
                            script_name = Models.Utilities.AcrobatJS.Javascripts
                                [Models.Utilities.LocalJavascripts.center_letter_no_cover];
                        }
                        else
                        {
                            cover_length = files_no_foldouts.Where(x => x.FileType == SourceFileTypeEnum.Cover).FirstOrDefault().CoverLength;
                            switch (cover_length)
                            {
                                case 48:
                                default:
                                    script_name = Models.Utilities.AcrobatJS.Javascripts
                                        [Models.Utilities.LocalJavascripts.center_letter_48pica];
                                    break;
                                case 49:
                                    script_name = Models.Utilities.AcrobatJS.Javascripts
                                        [Models.Utilities.LocalJavascripts.center_letter_49pica];
                                    break;
                                case 50:
                                    script_name = Models.Utilities.AcrobatJS.Javascripts
                                        [Models.Utilities.LocalJavascripts.center_letter_50pica];
                                    break;
                                case 51:
                                    script_name = Models.Utilities.AcrobatJS.Javascripts
                                        [Models.Utilities.LocalJavascripts.center_letter_51pica];
                                    break;
                            }
                        }

                        js_type.InvokeMember(script_name,
                            System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance,
                            null, js_object, js_param);
                        // test that the file exists
                        doc.Save(1, CombinedPdfFilename);
                    }
                    else
                    {
                        throw new Exception("Could not center pdf.");
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                doc.Close();
                app.CloseAllDocs();
                app.Exit();

                doc = null;
                docToAdd = null;
                app = null;

                GC.Collect();
            }
        }