Ejemplo n.º 1
0
        /// <summary>
        /// GetContent with given details
        /// </summary>
        /// <param name="docUri"></param>
        /// <returns></returns>
        public object GetContent(string uri)
        {
            Logger.Info("Entering GetContent");
            MLReader mlReader = new MLReader();
            string   mlUrl    = ConfigurationManager.AppSettings["MarkLogicResourceURL"] + "content?name=content&rs:format=json&rs:uri=" + uri;
            object   results  = null;

            try
            {
                Logger.Debug("Logging for GetContent with mlUrl");
                results = mlReader.GetHttpContent <object>(mlUrl, "application/json");
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("401"))
                {
                    var error = new { responseCode = "401", message = "Error 401 - Unauthorized: Access is denied." };
                    Logger.Error("Error message for GetContentDal");
                    results = error;
                }
            }

            Logger.Info("Exitinging CreateContent");
            return(results);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// SearchContents with given details
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        public object SearchContents(string searchText, int pageNumber, int pageSize, string orderBy)
        {
            Logger.Info("Entering GetContentMasterData");
            MLReader mlReader = new MLReader();

            searchText = System.Web.HttpContext.Current.Server.UrlEncode(searchText);
            string mlUrl   = ConfigurationManager.AppSettings["MarkLogicResourceURL"] + "content?name=content&rs:format=json";
            object results = null;

            try
            {
                results = mlReader.GetHttpContent <object>(mlUrl, "application/json");
                Logger.Debug("Logging results for mlReader with json");
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("401"))
                {
                    var error = new { responseCode = "401", message = "Error 401 - Unauthorized: Access is denied." };
                    Logger.Error("Error Message for SearchContentsDal with mlUrl");
                    results = error;
                }
            }

            Logger.Info("Exitinging CreateContent");
            return(results);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// GetDictionary with given details 
 /// </summary>
 /// <param name="dictionaryType"></param>
 /// <param name="outputFormat"></param>
 /// <returns></returns>
 public object GetDictionary(string dictionaryType, string outputFormat)
 {
     Logger.Info("Entering GetDictionary");
 
     string mlUrl = ConfigurationManager.AppSettings["MarkLogicResourceURL"] + "dictionary?rs:dictionaryType=" + dictionaryType + "&rs:format=" + outputFormat + "&name=dictionary";
     
     MLReader mlReader = new MLReader();
     var results = mlReader.GetHttpContent<object>(mlUrl);
     Logger.Debug("Logging results for GetDictionary with mlUrl");
     Logger.Info("Exiting GetDictionary");
     return results;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// content with given details
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public object DeleteContent(string projUri)
        {
            Logger.Info("Entering DeleteProject");
            //Call ML and Put the project xml
            string   mlUrl    = ConfigurationManager.AppSettings["MarkLogicResourceURL"] + "content?name=content&rs:uri=" + projUri;
            MLReader mlReader = new MLReader();
            string   results  = mlReader.HttpInvoke(mlUrl, SupportedHttpMethods.DELETE, "application/json");

            Logger.Debug("Logging results for DeleteContent with mlUrl");
            Logger.Info("Exiting DeleteProject");
            return(mlReader.ConverttoJson <object>(results));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// CreateContent with given details
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public object UploadMetadata(string metadata)
        {
            Logger.Info("Entering UploadMetadata");

            string   mlUrl    = ConfigurationManager.AppSettings["MarkLogicResourceURL"] + "content?name=content";
            MLReader mlReader = new MLReader();
            string   results  = mlReader.HttpInvoke(mlUrl, SupportedHttpMethods.POST, "application/json", metadata);

            Logger.Debug("Logging results for UploadMetadata with mlUrl");
            Logger.Info("Exiting UploadMetadata");
            return(mlReader.ConverttoJson <object>(results));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// delete the Project with given details
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public object DeleteProject(string projUri)
        {
            Logger.Info("Entry DeleteProject");

            //Post it to MarkLogic
            string   mlUrl    = ConfigurationManager.AppSettings["MarkLogic_CRUD_URL"] + "project?name=project&rs:format=json&rs:uri=" + projUri;
            MLReader mlReader = new MLReader();
            string   results  = mlReader.HttpInvoke(mlUrl, SupportedHttpMethods.DELETE, "application/json");

            Logger.Debug("Logging Results for DeleteProject with mlUrl");
            Logger.Info("Exiting DeleteProject");
            return(mlReader.ConverttoJson <object>(results));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get project details with given details
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public object GetProjectDetails(string uri)
        {
            Logger.Info("Entering GetProjectDetails");

            MLReader mlReader = new MLReader();

            //get Marklogic url for CRUD operations
            string mlUrl   = ConfigurationManager.AppSettings["MarkLogic_CRUD_URL"] + "project?name=project&rs:uri=" + uri + "&rs:format=json";
            string results = mlReader.GetHttpContent(mlUrl, "application/json");

            Logger.Debug("Logging Results for GetProjectDetails with mlUrl");
            Logger.Info("Exiting GetProjectDetails");
            return(mlReader.ConverttoJson <object>(results));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// update the project with given details
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public object UpdateProject(string projXml, string projUri)
        {
            Logger.Info("Entering UpdateProject");
            //Call ML and Put the project xml

            //Post it to MarkLogic
            string   mlUrl    = ConfigurationManager.AppSettings["MarkLogic_CRUD_URL"] + "project?name=project&rs:format=json&rs:uri=" + projUri;
            MLReader mlReader = new MLReader();
            string   results  = mlReader.HttpInvoke(mlUrl, SupportedHttpMethods.PUT, "application/json", projXml);

            Logger.Debug("Logging Results for UpdateProject with mlUrl");
            Logger.Info("Exitinging UpdateProject");
            return(mlReader.ConverttoJson <object>(results));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Search Project for the given details
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        public object SearchProjects(string searchText, int pageNumber, int pageSize, string orderBy)
        {
            //Call ML and SearchProjects
            Logger.Info("Entering SearchProjects");
            JsonNetSerialization ser      = new JsonNetSerialization();
            MLReader             mlReader = new MLReader();

            searchText = System.Web.HttpContext.Current.Server.UrlEncode(searchText);
            //get Marklogic url for CRUD operations
            string mlUrl   = ConfigurationManager.AppSettings["MarkLogic_CRUD_URL"] + "project?name=project&rs:q=" + searchText + "&rs:format=json";
            string results = mlReader.GetHttpContent(mlUrl, "application/json");

            Logger.Debug("Logging Results for SearchProjects with pageNumber, pageSize in mlUrl");
            Logger.Info("Exiting SearchProjects");
            return(mlReader.ConverttoJson <object>(results));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// GetData for search data with given details
        /// </summary>
        /// <param name="orderBy"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="searchText"></param>
        /// <param name="searchType"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public object GetData(string orderBy, int pageNumber, int pageSize, string searchText, string searchType, string userName, string[] facets)
        {
            //Call ML and SearchProjects
            Logger.Info("Entering SearchData");

            MLReader mlReader = new MLReader();

            //get Marklogic url for CRUD operations
            pageNumber = ((pageNumber - 1) * pageSize) + 1;
            string facetsParam = string.Empty;

            if (searchText != string.Empty && searchText != null)
            {
                searchText = "" + searchText + "";
            }

            if (facets != null)
            {
                if (searchText != string.Empty && searchText != null)
                {
                    searchText = searchText + " AND ";
                }
                searchText = searchText + string.Join(" AND ", facets);
            }

            searchText = System.Web.HttpContext.Current.Server.UrlEncode(searchText);

            if (searchType == "all")
            {
                searchType = "search";
            }

            if (orderBy == null)
            {
                orderBy = "relevance";
            }

            string mlUrl   = ConfigurationManager.AppSettings["MarkLogic_CRUD_URL"] + searchType + "?name=" + searchType + "&rs:q=" + searchText + "&rs:format=json&rs:pageLength=" + pageSize + "&rs:start=" + pageNumber + "&rs:sort=" + orderBy;
            string results = mlReader.GetHttpContent(mlUrl, "application/json");

            Logger.Debug("Logging Results for GetData with mlUrl");
            Logger.Info("Exiting SearchData");
            return(mlReader.ConverttoJson <object>(results));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// DownloadContent with given details
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public HttpResponseMessage DownloadContent(string uri)
        {
            Logger.Info("Entering GetContent");
            MLReader mlReader = new MLReader();

            string mlUrl = ConfigurationManager.AppSettings["MarkLogicResourceURL"] + "file?name=file&rs:format=json&rs:uri=" + uploadFileLocation + uri;
            HttpResponseMessage results = null;

            try
            {
                results = mlReader.DownloadFile(mlUrl, "application/json", uri);
                Logger.Debug("Logging results for DownloadFile with mlReader uri");
            }
            catch (Exception ex)
            {
                Logger.Debug("Exception", ex);
            }

            Logger.Info("Exitinging CreateContent");
            return(results);
        }
Ejemplo n.º 12
0
        public object ValidateUser(Authentication authentication)
        {
            //Post it to MarkLogic
            object   results  = null;
            string   mlUrl    = ConfigurationManager.AppSettings["MarkLogicResourceURL"] + "login";
            MLReader mlReader = new MLReader();
            string   domain   = authentication.username.Split(new char[] { '@' })[1];

            if (domain != "" && domain.ToLower().ToString() == "macmillan.com")
            {
                //get base64 representaion of user name and password

                string userInfo = this.ConvertoBase64(authentication.username.Split(new char[] { '@' })[0] + ":" + authentication.password);

                Dictionary <string, string> requestHeader = new Dictionary <string, string>();
                requestHeader.Add("UserInfo", userInfo);


                try
                {
                    results = mlReader.GetHttpContent <object>(mlUrl, "application/json", requestHeader);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("401"))
                    {
                        var error = new { responseCode = "401", message = "Username or password is incorrect" };
                        results = error;
                    }
                }
            }
            else
            {
                var error = new { responseCode = "401", message = "Username or password is incorrect" };
                results = error;
            }

            return(results);
        }
Ejemplo n.º 13
0
 private void HTTPUpload(FileInfo file)
 {
     string   mlUrl    = ConfigurationManager.AppSettings["MarkLogicResourceURL"] + "file?name=file&rs:fileName=" + file.Name;
     MLReader mlReader = new MLReader();
     string   results  = mlReader.UploadFile(mlUrl, "image/jpeg", file.FullName);
 }