/// <summary>
        ///
        /// </summary>
        /// <param name="storageId"></param>
        /// <param name="couchConnector"></param>
        /// <param name="doc"></param>
        /// <param name="errorMessage"></param>
        /// <param name="liteFetch"> </param>
        /// <returns></returns>
        public static bool GetDocument(
            string storageId,
            SecuredCouchConnector couchConnector,
            out Document doc,
            out string errorMessage,
            bool liteFetch = false)
        {
            //Set defaults for outgoing params
            doc          = null;
            errorMessage = string.Empty;

            if (!string.IsNullOrEmpty(storageId) &&
                couchConnector != null)
            {
                doc = new Document_Couch(storageId);
                var    dStorage = new DocStorage_CouchDB();
                string errCode, errTxt;
                if (dStorage.SecuredGetDocument(couchConnector, ref doc, out errCode, out errTxt, liteFetch))
                {
                    return(true);
                }
                errorMessage = "Could not retrieve document: " + errCode + " " + errTxt;
                return(false);
            }

            errorMessage = "Could not retrieve document";
            return(false);
        }
Esempio n. 2
0
        public bool getDocumentByID(string id)
        {
            var      dStorage = new DocStorage_CouchDB();
            Document doc      = new Document_Couch(id);
            var      errCode  = string.Empty;
            var      errTxt   = string.Empty;

            byte[]     fileData;
            FileStream fStream           = null;
            var        CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec);

            dStorage.SecuredGetDocument(CouchConnectorObj, ref doc, out errCode, out errTxt);

            if (CouchConnectorObj.Error)
            {
                Console.WriteLine(errTxt);
                return(false);
            }
            else
            {
                Console.WriteLine(string.Format("Got Doc '{0}'  from db '{1}' by userID '{2}'", doc.FileId, dbName, userid));
                doc.GetSourceData(out fileData);
                if (fileData != null)
                {
                    fStream = File.Create(Directory.GetCurrentDirectory() + "//" + doc.FileId + ".pdf");
                    fStream.Write(fileData, 0, fileData.Length);
                    Console.WriteLine("written to file :" + Directory.GetCurrentDirectory() + "//" + doc.FileId + ".pdf");
                    fStream.Flush();
                    fStream.Close();
                }
                return(true);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="fileId"></param>
        /// <param name="couchConnector"></param>
        /// <param name="overrideDoc"></param>
        /// <param name="fileType"></param>
        /// <param name="docMetaData"></param>
        /// <param name="couchDocObj"></param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        public static bool StoreDocument(
            string fileName,
            string fileId,
            SecuredCouchConnector couchConnector,
            bool overrideDoc,
            Document.DocTypeNames fileType,
            Dictionary <string, string> docMetaData,
            out Document couchDocObj,
            out string errorMessage)
        {
            couchDocObj  = null;
            errorMessage = string.Empty;

            if (string.IsNullOrEmpty(fileName) ||
                !System.IO.File.Exists(fileName) ||
                string.IsNullOrEmpty(fileId) ||
                couchConnector == null)
            {
                errorMessage = "Input parameters are invalid";
                return(false);
            }

            var sErrCode = string.Empty;
            var sErrText = string.Empty;

            try
            {
                byte[] fileBytes    = File.ReadAllBytes(fileName);
                int    lastSlashIdx = fileName.LastIndexOf('\\');
                if (lastSlashIdx == -1)
                {
                    errorMessage = "Absolute file name is invalid.";
                    return(false);
                }

                string fName = fileName.Substring(lastSlashIdx + 1);
                couchDocObj = new Document_Couch(fileName, fName, fileType);
                if (couchDocObj.SetSourceData(fileBytes, fileId, overrideDoc))
                {
                    if (CollectionUtilities.isNotEmpty(docMetaData))
                    {
                        foreach (string key in docMetaData.Keys)
                        {
                            if (key == null)
                            {
                                continue;
                            }
                            string val;
                            if (docMetaData.TryGetValue(key, out val))
                            {
                                couchDocObj.SetPropertyData(key, val);
                            }
                        }
                    }
                    var dStorage = new DocStorage_CouchDB();
                    if (dStorage.SecuredAddDocument(couchConnector, ref couchDocObj, out sErrCode, out sErrText))
                    {
                        errorMessage = sErrText;
                        return(true);
                    }
                    errorMessage = sErrText;
                    return(false);
                }
            }
            catch (Exception eX)
            {
                errorMessage = "Exception occurred while storing document: " + eX.Message + " (" + sErrCode + ", " +
                               sErrText + ")";
            }
            return(false);
        }