Beispiel #1
0
        /// <summary>
        /// Creates a file that contains business card item in this address book.
        /// </summary>
        /// <param name="name">Name of the new file. Unlike with CalDAV it is NOT equel to vCard UID.</param>
        /// <returns>The newly created file.</returns>
        /// <remarks></remarks>
        public async Task <IFileAsync> CreateFileAsync(string name)
        {
            // The actual business card file is created in datatbase in CardFile.Write call.
            string fileName = System.IO.Path.GetFileNameWithoutExtension(name);

            return(CardFile.CreateCardFile(Context, addressbookFolderId, fileName));
        }
Beispiel #2
0
        // Run button, read the cardfile & write it out as XML
        private void b_go_Click(object sender, EventArgs e)
        {
            string stsMsg = "File " + filename + " had a problem";             // status message

            rtb_Msg.Text = "Export pressed";
            try {
                FileInfo f           = new FileInfo(filename);                                        // card file file to read
                string   outPath     = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar; // path of file to be read
                string   outFileName = Path.GetFileNameWithoutExtension(filename);

                const string xmlext      = ".xml";
                string       xmlFilePath = outPath + outFileName + xmlext;
                Writer       wrtr        = new XmlWriter(xmlFilePath); // Destination of Xml produced

                bool         doTrace     = cbDoLogging.Checked;        // Logging?
                const string logext      = ".log";
                string       logFilePath = outPath + outFileName + logext;;

                CardFile cf = new CardFile(doTrace, logFilePath, wrtr);
                using (Stream inStrm = f.OpenRead()) {
                    cf.process(inStrm);
                }
                rtb_Msg.Text = "File " + xmlFilePath + " produced";
            } catch (ExnCardFileRdr ex) {
                ReportError(ex.Message, "Warning", stsMsg);
            } catch (Exception ex) when(ex is FileNotFoundException || ex is DirectoryNotFoundException)
            {
                ReportError(ex.Message, "Warning", stsMsg);
            } catch (Exception ex) {
                ReportError(ex.ToString(), "Error", stsMsg);
            }    //try
        }        //b_go
Beispiel #3
0
        /// <summary>
        /// Returns a list of address book files that correspont to the specified list of item paths.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method is called by the Engine during <b>addressbook-multiget</b> call.
        /// </para>
        /// <para>
        /// For each item from the <b>pathList</b> parameter return an item that corresponds to path or <b>null</b> if the item is not found.
        /// </para>
        /// </remarks>
        /// <param name="pathList">Addressbook files path list.</param>
        /// <param name="propNames">
        /// Properties requested by the client. You can use this as a hint about what properties will be called by
        /// the Engine for each item that are returned from this method.
        /// </param>
        /// <returns>List of address book files. Returns <b>null</b> for any item that is not found.</returns>
        public async Task <IEnumerable <ICardFileAsync> > MultiGetAsync(IEnumerable <string> pathList, IEnumerable <PropertyName> propNames)
        {
            // Get list of file names from path list.
            IEnumerable <string> fileNames = pathList.Select(a => System.IO.Path.GetFileNameWithoutExtension(a));

            return(await CardFile.LoadByFileNamesAsync(Context, fileNames, PropsToLoad.All));
        }
        /// <summary>
        /// Gets CardDAV items.
        /// </summary>
        /// <param name="path">Relative path requested.</param>
        /// <param name="context">Instance of <see cref="DavContext"/> class.</param>
        /// <returns>Object implementing various business card items or null if no object corresponding to path is found.</returns>
        public static async Task <IHierarchyItemAsync> GetCardDavItemAsync(DavContext context, string path)
        {
            // If this is [DAVLocation]/addressbooks - return folder that contains all addressbooks.
            if (path.Equals(AddressbooksRootFolder.AddressbooksRootFolderPath.Trim('/'), System.StringComparison.InvariantCultureIgnoreCase))
            {
                return(new AddressbooksRootFolder(context));
            }

            string[] segments = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            // If URL ends with .vcf - return address book file, which contains vCard.
            if (path.EndsWith(CardFile.Extension, System.StringComparison.InvariantCultureIgnoreCase))
            {
                string fileName = EncodeUtil.DecodeUrlPart(System.IO.Path.GetFileNameWithoutExtension(segments.Last()));
                return((await CardFile.LoadByFileNamesAsync(context, new[] { fileName }, PropsToLoad.All)).FirstOrDefault());
            }

            // If this is [DAVLocation]/addressbooks/[AddressbookFolderId]/ return address book.
            if (path.StartsWith(AddressbooksRootFolder.AddressbooksRootFolderPath.Trim('/'), System.StringComparison.InvariantCultureIgnoreCase))
            {
                Guid addressbookFolderId;
                if (Guid.TryParse(EncodeUtil.DecodeUrlPart(segments.Last()), out addressbookFolderId))

                {
                    return(await AddressbookFolder.LoadByIdAsync(context, addressbookFolderId));
                }
            }

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Retrieves children of this folder.
        /// </summary>
        /// <param name="propNames">List of properties to retrieve with the children. They will be queried by the engine later.</param>
        /// <returns>Children of the folder.</returns>
        public async Task <IEnumerable <IHierarchyItemAsync> > GetChildrenAsync(IList <PropertyName> propNames)
        {
            // Here we enumerate all business cards contained in this address book.
            // You can filter children items in this implementation and
            // return only items that you want to be available for this
            // particular user.

            // Typically only getcontenttype and getetag properties are requested in GetChildren call by CalDAV/CardDAV clients.
            // The iCalendar/vCard (calendar-data/address-data) is typically requested not in GetChildren, but in a separate multiget
            // report, in MultiGetAsync() method call, that follows this request.

            // Bynari submits PROPFIND without props - Engine will request getcontentlength

            IList <IHierarchyItemAsync> children = new List <IHierarchyItemAsync>();

            return(await CardFile.LoadByAddressbookFolderIdAsync(Context, addressbookFolderId, PropsToLoad.Minimum));
        }
Beispiel #6
0
        public override void Import(KeePassLib.PwDatabase pwStorage, System.IO.Stream sInput, IStatusLogger slLogger)
        {
            if (pwStorage == null)
            {
                throw new ArgumentNullException("CardFileFormatProvider.Import(): null PwDatabase argument received");
            }
            if (!pwStorage.IsOpen)
            {
                MessageBox.Show("You first need to open a database!", "CardFileFormatProvider");
                return;
            }
            if (sInput == null)
            {
                throw new ArgumentNullException("CardFileFormatProvider.Import(): null Stream argument received");
            }
            if (slLogger == null)
            {
                throw new ArgumentNullException("CardFileFormatProvider.Import(): null IStatusLogger argument received");
            }
            if (!(sInput.CanRead))
            {
                throw new ArgumentException("Input stream not readable");
            }
            try {
                KPWriter kpWriter = new KPWriter(pwStorage);                     // The plugin's Keepass Writer
                CardFile crdfile  = new CardFile(false, String.Empty, kpWriter); // The plugin's Importer, false = no logging

                slLogger.SetText("Importing Cardfile ...", LogStatusType.Info);
                crdfile.process(sInput);                   // read the cardfile & write to keepass

                m_Host.MainWindow.UpdateUI(false, null, true, m_Host.Database.RootGroup, true, null, true);
                slLogger.SetText("Importing Cardfile completed", LogStatusType.Info);
            } catch (ExnCardFileRdr ex) {
                reportError(ex.Message, "Warning", slLogger, LogStatusType.Warning);
            } catch (FileNotFoundException ex) {
                reportError(ex.Message, "Warning", slLogger, LogStatusType.Warning);
            } catch (DirectoryNotFoundException ex) {
                reportError(ex.Message, "Warning", slLogger, LogStatusType.Warning);
            } catch (Exception ex) {
                reportError(ex.ToString(), "Error", slLogger, LogStatusType.Error);
            }            //try
        }
Beispiel #7
0
        private void CardFileBtn_Click(object sender, System.EventArgs e)
        {
            CardFile form = new CardFile();

            form.Show();
        }