public override async Task InvokeAsync(HttpContext context)
        {
            try
            {
                if (!context.WebSockets.IsWebSocketRequest)
                {
                    return;
                }

                var authResult = await context.AuthenticateAsync(JwtBearerDefaults.AuthenticationScheme);

                var               isAuthenticated = authResult.Succeeded && authResult.Principal.Identity.IsAuthenticated;
                object            userId          = isAuthenticated ? authResult.Principal.Claims.SingleOrDefault(c => c.Type == "UserId")?.Value : Guid.NewGuid();
                string            userName        = isAuthenticated ? authResult.Principal.Claims.SingleOrDefault(c => c.Type == ClaimTypes.Name)?.Value : string.Empty;
                ConnectionAborted abortStatus     = ConnectionAborted.None;

                if (!isAuthenticated)
                {
                    abortStatus = ConnectionAborted.TokenExpiredOrInvalid;
                }
                else if (string.IsNullOrEmpty(userId.ToString()))
                {
                    abortStatus = ConnectionAborted.UserIdNotFound;
                }
                else if (string.IsNullOrEmpty(userName))
                {
                    abortStatus = ConnectionAborted.UserNameNotFound;
                }

                var info = new WSUserInfo()
                {
                    Id   = userId,
                    Name = userName
                };

                //Here you able to pass your own subclass instead of WSUserInfo. Note: If you bind your own subclass instead of WSUserInfo, all your Web Socket controllers should be use your passed subclass
                await InvokeWSAsync(context, info, abortStatus);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "An error on opening connection of WebSocket to the server");
            }
        }
Exemplo n.º 2
0
 public ChatController(WebSocketHub socketHub, WSUserInfo wsUserInfo, ILogger logger)
 {
     _socketHub  = socketHub;
     _wsUserInfo = wsUserInfo;
     _logger     = logger;
 }
 /// <summary>
 /// To connect new created WebSocket to the WebSocketManager's sockets list
 /// </summary>
 /// <param name="socket">New created socket</param>
 /// <param name="userInfo">Current User info</param>
 public override async Task OnConnectedAsync(System.Net.WebSockets.WebSocket socket, WSUserInfo userInfo)
 {
     await base.OnConnectedAsync(socket, userInfo);
 }
Exemplo n.º 4
0
        private DataTable BuildCVTaxonomy(string partnerRole)
        {
            TaxonomyService taxonomyService = new TaxonomyService();

            taxonomyService.SetConnectionInfo(base.taxonomyUrl, base.userId, base.userPassword, base.timeOut);

            WSUserInfo wsUserInfo = new WSUserInfo();

            wsUserInfo.userId   = base.userId;
            wsUserInfo.portalId = base.portalId;

            OracleUtil objOraUtil = new OracleUtil();

            wsUserInfo.disclosureLevels = objOraUtil.GetDisclosurelevel(partnerRole);

            WSCVRequest cvRequest = new WSCVRequest();

            cvRequest.taxoId = base.component_root_oid;           //COMPONENT_ROOT_OID;
            cvRequest.locale = DEFAULT_LANGUAGECODE;              // Release 8.7 Enhancement
            WSCVNode[] nodes = null;
            try
            {
                nodes = taxonomyService.retrieveCV(wsUserInfo, cvRequest);
            }
            catch (SoapException ex)
            {
                throw new TaxonomyException(3, TaxonomyException.ERROR_TYPE.INFORMATION, "Error While Retrieving Taxonomy", ex.Message, ex);
            }
            catch (System.Net.WebException ex)
            {
                throw new TaxonomyException(2, TaxonomyException.ERROR_TYPE.WARNING, "Error Connecting To Webservices", ex.Message, ex);
            }
            catch (Exception ex)
            {
                throw new TaxonomyException(1, TaxonomyException.ERROR_TYPE.WARNING, "Unexpected Error While Retrieving Taxonomy", ex.Message, ex);
            }

            if (nodes == null || nodes.Length == 0)
            {
                throw new TaxonomyException(4, TaxonomyException.ERROR_TYPE.INFORMATION, "Taxonomy Not Available For Given OID", "OID Node Is Empty");
            }

            DataTable retTaxonomy = CreateTaxonomyTable();

            for (int iCnt = 0; iCnt < nodes.Length; iCnt++)
            {
                DataRow row = retTaxonomy.NewRow();
                row["OID"]         = nodes[iCnt].oid;
                row["ParentID"]    = nodes[iCnt].parents[0];
                row["Description"] = nodes[iCnt].displayName;
                retTaxonomy.Rows.Add(row);
            }
            //sorting & storing...
            DataView dvSortedTaxonomy = new DataView(retTaxonomy);

            dvSortedTaxonomy.Sort = "Description";
            DataTable dtSortedTaxonomy = CreateTaxonomyTable();

            for (int iCnt = 0; iCnt < dvSortedTaxonomy.Count; iCnt++)
            {
                DataRow row = dtSortedTaxonomy.NewRow();
                row["OID"]         = dvSortedTaxonomy[iCnt]["OID"];
                row["ParentID"]    = dvSortedTaxonomy[iCnt]["ParentID"];
                row["Description"] = dvSortedTaxonomy[iCnt]["Description"];
                dtSortedTaxonomy.Rows.Add(row);
            }


            DateTime d          = DateTime.Now;
            DateTime d1         = new DateTime(d.Year, d.Month, d.Day, base.expiration_hrs, base.expiration_min, base.expiration_sec);
            long     expiration = (d1.Ticks - d.Ticks);

            if (expiration < 0)
            {
                expiration = TimeSpan.TicksPerDay + expiration;
            }
            expiration = expiration / TimeSpan.TicksPerSecond;
            int absoluteExpiration = Convert.ToInt32(expiration);
            int noSliding          = Cache.NoSlidingExpiration.Seconds;

            chTaxonomy.Insert("CSN_KM_TAXONOMY", "Taxonomy_CV", dtSortedTaxonomy, null, absoluteExpiration, noSliding);

            return(dtSortedTaxonomy);
        }
Exemplo n.º 5
0
        /// <summary>
        /// methods, which implement the computations and actions that can be
        /// performed by the class
        /// </summary>
        #region "### Private Methods  ###"

        private DataTable BuildTaxonomy(int oid, int level, string partnerRole)
        {
            TaxonomyService taxonomyService = new TaxonomyService();

            taxonomyService.SetConnectionInfo(base.taxonomyUrl, base.userId, base.userPassword, base.timeOut);

            WSUserInfo wsUserInfo = new WSUserInfo();

            wsUserInfo.userId   = base.userId;
            wsUserInfo.portalId = base.portalId;

            OracleUtil objOraUtil = new OracleUtil();

            // Release 8.7 Enhancement
            wsUserInfo.disclosureLevels = objOraUtil.GetDisclosurelevel(partnerRole);

            WSPMRequest pmRequest = new WSPMRequest();

            pmRequest.oid    = oid;
            pmRequest.locale = DEFAULT_LANGUAGECODE;

            WSPMNode[] nodes = null;
            try
            {
                nodes = taxonomyService.retrievePMSubtree(wsUserInfo, pmRequest);
            }
            catch (SoapException ex)
            {
                throw new TaxonomyException(3, TaxonomyException.ERROR_TYPE.INFORMATION, "Error While Retrieving Taxonomy", ex.Message, ex);
            }
            catch (System.Net.WebException ex)
            {
                throw new TaxonomyException(2, TaxonomyException.ERROR_TYPE.WARNING, "Error Connecting To Webservices", ex.Message, ex);
            }
            catch (Exception ex)
            {
                throw new TaxonomyException(1, TaxonomyException.ERROR_TYPE.WARNING, "Unexpected Error While Retrieving Taxonomy", ex.Message, ex);
            }

            if (nodes == null || nodes.Length == 0)
            {
                throw new TaxonomyException(4, TaxonomyException.ERROR_TYPE.INFORMATION, "Taxonomy Not Available For Given OID", "OID Node Is Empty");
            }

            DataTable retTaxonomy = CreateTaxonomyTable();

            for (int iCnt = 0; iCnt < nodes.Length; iCnt++)
            {
                if (nodes[iCnt].level == level)
                {
                    DataRow row = retTaxonomy.NewRow();
                    row["OID"]         = nodes[iCnt].oid;
                    row["ParentID"]    = oid;
                    row["Description"] = nodes[iCnt].displayName;
                    retTaxonomy.Rows.Add(row);
                }
            }
            // Sort taxonomy on description column
            DataView  dvSortedTaxonomy = new DataView(retTaxonomy, null, "Description", DataViewRowState.CurrentRows);
            DataTable dtSortedTaxonomy = CreateTaxonomyTable();

            for (int iCnt = 0; iCnt < dvSortedTaxonomy.Count; iCnt++)
            {
                DataRow row = dtSortedTaxonomy.NewRow();
                row["OID"]         = dvSortedTaxonomy[iCnt]["OID"];
                row["ParentID"]    = dvSortedTaxonomy[iCnt]["ParentID"];
                row["Description"] = dvSortedTaxonomy[iCnt]["Description"];
                dtSortedTaxonomy.Rows.Add(row);
            }

            if (oid == 0)
            {
                DateTime d          = DateTime.Now;
                DateTime d1         = new DateTime(d.Year, d.Month, d.Day, base.expiration_hrs, base.expiration_min, base.expiration_sec);
                long     expiration = (d1.Ticks - d.Ticks);
                if (expiration < 0)
                {
                    expiration = TimeSpan.TicksPerDay + expiration;
                }
                expiration = expiration / TimeSpan.TicksPerSecond;
                int absoluteExpiration = Convert.ToInt32(expiration);
                int noSliding          = Cache.NoSlidingExpiration.Seconds;

                chTaxonomy.Insert("CSN_KM_TAXONOMY", "Taxonomy_" + oid, dtSortedTaxonomy, null, absoluteExpiration, noSliding);
            }
            else
            {
                CacheDependency cDep = new CacheDependency(null, new string[] { "CSN_KM_TAXONOMY" + ":" + "Taxonomy_0" });
                chTaxonomy.Insert("CSN_KM_TAXONOMY", "Taxonomy_" + oid, dtSortedTaxonomy, cDep);
            }

            return(dtSortedTaxonomy);
        }