コード例 #1
0
ファイル: Program.cs プロジェクト: Lesssnik/Labs
 static void Main(string[] args)
 {
     UserInfoServiceClient client = new UserInfoServiceClient();
     Console.WriteLine("Число пользователей: " + client.GetUsersCount());
     Console.WriteLine("Число тестов, созданных пользователем Admin: " + client.GetUserTestsCount("Admin"));
     Console.ReadKey();
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: pcyin/RumorDetection
        private void button1_Click(object sender, EventArgs e)
        {
            string[] temp = textBox1.Text.Split('/');

            ContentCrawlServiceClient contentClient = new ContentCrawlServiceClient();
            UserInfoServiceClient infoClient = new UserInfoServiceClient();
            var contentInfo = contentClient.GetContentCrawlResult(temp[3] + '|' + temp[4]);
            var userInfo = infoClient.GetUserInfo(temp[3]);

            StringBuilder sb = new StringBuilder();
            sb.Append("1:").Append(contentInfo.Sentiment).Append(" ");   //sentiment
            sb.Append("2:").Append(contentInfo.HasImg ? "1" : "0").Append(" ");   //HasImg ? "1" : "0"
            sb.Append("3:").Append(contentInfo.HasUrl ? "1" : "0").Append(" ");   //HasUrl ? "1" : "0"
            sb.Append("4:").Append(userInfo.FanNum).Append(" ");    //fans
            sb.Append("5:").Append(userInfo.WeiboNum).Append(" ");    //weibo
            sb.Append("6:").Append(userInfo.Credit).Append(" ");    //credit
            sb.Append("7:").Append(getLocVal(userInfo.Location)).Append(" "); //userLoc
            sb.Append("8:").Append(userInfo.Level).Append(" ");    //level
            sb.Append("9:").Append(userInfo.IsVerified).Append(" ");    //verified
            sb.Append("10:").Append(contentInfo.CommentEval).Append(" ");  //comval
            vector.Text = sb.ToString();
            /*List<string> newsList = sim.BiggestFiveTitle(weiboDataList[4]);
            foreach(string str in newsList)
            {
                news.Text += str + '\n';
            }*/
        }
コード例 #3
0
ファイル: ServiceHelper.cs プロジェクト: pcyin/RumorDetection
        public static void GetServiceInfo(string url, out ContentCrawlResult contentInfo, out UserInfo userInfo)
        {
            string[] temp = url.Split('/');

            ContentCrawlServiceClient contentClient = new ContentCrawlServiceClient();
            UserInfoServiceClient infoClient = new UserInfoServiceClient();
            var contentTask = Task.Factory.StartNew<ContentCrawlResult>(() => {
                return contentClient.GetContentCrawlResult(temp[3] + '|' + temp[4]);
            });
            var userTask = Task.Factory.StartNew<UserInfo>(() => {
                return infoClient.GetUserInfo(temp[3]);
            });

            contentInfo = contentTask.Result;//contentClient.GetContentCrawlResult(temp[3] + '|' + temp[4]);
            userInfo = userTask.Result; //infoClient.GetUserInfo(temp[3]);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: sunzhong0201/WCF-
        static void Main(string[] args)
        {
            //客户端调用服务器端服务方式1 :通过微软的svcutil 工具生成配置+代理类client
            UserInfoServiceClient userinfoClient = new UserInfoServiceClient();
            int      result   = userinfoClient.Add(1, 2);
            UserInfo userinfo = userinfoClient.GetUserInfo();

            Console.WriteLine(userinfo.userName);



            OrderInfoServiceClient orderInfoClient = new OrderInfoServiceClient();
            int orderResult = orderInfoClient.Add();

            Console.WriteLine("orderinfo:" + orderResult);
            Console.ReadKey();
        }
コード例 #5
0
ファイル: UserInfo.cs プロジェクト: montakan29/TestGit
        public static UserDetails GetUserDetails(string uuid)
        {
            var userDetails = new UserDetails();
            using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
            {
                var userResp = uisCilent.GetUserInfoReq2(new UserInfoReq
                {
                    uuid = uuid,
                    fields = new[]
                    {
                        "UserId",
                        "EmailAddress",
                        "LocationAccountId"
                    }
                });

                if (!userResp.OperationSuccessful)
                {
                    ALogger.LogWarn("STOpsConsole-GetTopLocationScope - Failed response with {0} - {1}",
                        userResp.ResponseCode,
                        userResp.ResponseMessage);
                    return null;
                }

                var userID = userResp.UserInfo.UserDetails.First(x => x.Key == "UserId").Value;
                var email = userResp.UserInfo.UserDetails.First(x => x.Key == "EmailAddress").Value;
                userDetails.UserID = userID;
                userDetails.Email = email;
                var locAccID = userResp.UserInfo.UserDetails.First(x => x.Key == "LocationAccountId").Value;

                if (string.IsNullOrEmpty(locAccID)) return userDetails;

                var locResp = uisCilent.GetLocation(new LocationInfoRequest
                {
                    LocationAccountId = locAccID
                });
                if (locResp != null)
                {
                    userDetails.Country = locResp.Country;
                }
                return userDetails;
            }
        }
コード例 #6
0
ファイル: AaaUser.cs プロジェクト: montakan29/TestGit
        public void SetUser(string uuid)
        {
            using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local,RouterAddresses.Local.RequestReply))
            {
                var locResp = uisCilent.GetUserInfoReq2(new UserInfoReq
                {
                    uuid = uuid,
                    fields = new List<string>
                    {
                        "LocationAccountId",
                        "EmailAddress",
                        "UserId",
                        "FullName",
                        "AccountName",
                        "NearestLegalEntityId",
                        "UltimateParentId"
                    }
                });

                if (!locResp.OperationSuccessful)
                {
                    Logger.LogWarn("STOpsConsole-AaaUser - Failed response with {0} - {1}", locResp.ResponseCode,
                        locResp.ResponseMessage);
                    return;
                }

                UUID = uuid;
                LocationAccountId = locResp.UserInfo.UserDetails.First(x => x.Key == "LocationAccountId").Value;
                EmailAddress = locResp.UserInfo.UserDetails.First(x => x.Key == "EmailAddress").Value;
                UserId = locResp.UserInfo.UserDetails.First(x => x.Key == "UserId").Value;
                FullName = locResp.UserInfo.UserDetails.First(x => x.Key == "FullName").Value;
                CompanyName = locResp.UserInfo.UserDetails.First(x => x.Key == "AccountName").Value;
                NearestLegalEntityId = locResp.UserInfo.UserDetails.First(x => x.Key == "NearestLegalEntityId").Value;
                UltimateParentId = locResp.UserInfo.UserDetails.First(x => x.Key == "UltimateParentId").Value;
            }
        }
コード例 #7
0
ファイル: Permission.cs プロジェクト: montakan29/TestGit
        public static PermissionSetting GetUserPermission(IAaaUser user)
        {
            try
            {
                var permission = GetUserPermissionFromCache(user.UUID);
                if (permission == null)
                {
                    var req = new UserPreferencesReq
                    {
                        uuid = user.UUID,
                        preferences = new List<preference>(1) { new preference { dactName = "APP.SYSTEMTEST.PERMISSION", prefName = "APP.SYSTEMTEST.PERMISSION" } }
                    };

                    using (var userInfoServiceclient = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
                    {
                        var svcResp = userInfoServiceclient.GetUserPreferencesReq(req);
                        if (svcResp != null)
                        {
                            var setting = svcResp.preferences.FirstOrDefault().value;
                            //setting = @"{""writeaccess"": [
                            //                                    """"
                            //                                ],
                            //                                ""readaccess"": [
                            //                                    """"
                            //                                ]
                            //                            }";

                            permission = JsonConvert.DeserializeObject<PermissionSetting>(setting);
                            AddUserPermissionToCache(user.UUID, permission);
                            return permission;
                        }
                        return new PermissionSetting();
                    }
                }
                return permission;

            }
            catch (Exception ex)
            {
                _Logger.LogError("STOpsConsole-Error getting user preference from UserInfoService: {0}", ex.Message);
                return new PermissionSetting();
            }
        }
コード例 #8
0
ファイル: Permission.cs プロジェクト: montakan29/TestGit
        public static string GetUserInScopeAaaDetails(string userUuid, string searchUuid)
        {
            try
            {
                using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
                {
                    var response = uisCilent.GetUserScope(new CheckUserScopeRequest
                    {
                        LoginUUID = userUuid,
                        CheckLocationUUID = new List<string> { searchUuid },
                        LocationID = null,
                        AAAServiceCode = "CPAP_SNAPIN_MANAGE_ST_IRS"
                    });

                    if (!response.Success)
                    {
                        _Logger.LogWarn("STOpsConsole-IsUserInScopeAaa - Failed response with {0}", response.Message);
                        return "{}";
                    }

                    var isUserInScope = "user:"******" search:"+searchUuid;
                    var scopeList = new List<string>();

                    foreach (var scope in response.UserScope)
                    {
                        isUserInScope += "("+scope.locationAccountIdField+"_"+scope.isInScopeField+")";
                        scopeList.Add(String.Format("{{\"location\":\"{0}\",\"isInScope\":\"{1}\"}}",
                        scope.locationAccountIdField,
                        scope.isInScopeField
                        )); 
                    }
                    _Logger.LogDebug("STOpsConsole-IsUserInScopeAaa: {0} - {1}", userUuid, isUserInScope);

                    var jsonresp = String.Format("{{\"user\":\"{0}\",\"search\":\"{1}\",\"scope\":[{2}]}}",
                                userUuid,
                                searchUuid,
                                string.Join(",", scopeList)
                                );
                    return jsonresp;
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError("STOpsConsole-Error get user scope from AAA service: {0}", ex.Message);
                return "{}";
            }
        }
コード例 #9
0
ファイル: Permission.cs プロジェクト: montakan29/TestGit
        private static bool IsUserInScopeAaa(string userUuid, string searchUuid)
        {
            try
            {
                using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
                {
                    var response = uisCilent.GetUserScope(new CheckUserScopeRequest
                    {
                        LoginUUID = userUuid,
                        CheckLocationUUID = new List<string> { searchUuid },
                        LocationID = null,
                        AAAServiceCode = "CPAP_SNAPIN_MANAGE_ST_IRS"
                    });

                    if (!response.Success)
                    {
                        _Logger.LogWarn("STOpsConsole-IsUserInScopeAaa - Failed response with {0}", response.Message);
                        return false;
                    }

                    var isUserInScope = false;
                    foreach (var scope in response.UserScope)
                    {
                        isUserInScope |= scope.isInScopeField;
                    }

                    _Logger.LogDebug("STOpsConsole-IsUserInScopeAaa: {0} - {1}", userUuid, isUserInScope);

                    return isUserInScope;
                }
            }
            catch (Exception ex)
            {
                _Logger.LogError("STOpsConsole-Error get user scope from AAA service: {0}", ex.Message);
                return false;
            }
        }
コード例 #10
0
ファイル: Permission.cs プロジェクト: montakan29/TestGit
        internal static KeyValuePair<FindLocationFilter, string> GetTopLocationScope(IAaaUser user)
        {
            var key = default(KeyValuePair<FindLocationFilter, string>);
            
            try
            {
                var locationScope = GetLocationScopeFromCache(user.UUID);

                if (locationScope == null)
                {
                    using (
                        var uisCilent = new UserInfoServiceClient(RouterBindings.Local,
                            RouterAddresses.Local.RequestReply))
                    {
                        var locResp = uisCilent.GetUserInfoReq2(new UserInfoReq
                        {
                            uuid = user.UUID,
                            fields = new List<string>
                            {
                                "LocationAccountId",
                                "NearestLegalEntityId",
                                "UltimateParentId"
                            }
                        });

                        if (!locResp.OperationSuccessful)
                        {
                            _Logger.LogWarn("STOpsConsole-GetTopLocationScope - Failed response with {0} - {1}", locResp.ResponseCode,
                                locResp.ResponseMessage);
                            return key;
                        }

                        var locs = new Dictionary<string, string>();

                        locs.Add("lo",locResp.UserInfo.UserDetails.First(x => x.Key == "LocationAccountId").Value);
                        locs.Add("le",locResp.UserInfo.UserDetails.First(x => x.Key == "NearestLegalEntityId").Value);
                        locs.Add("up",locResp.UserInfo.UserDetails.First(x => x.Key == "UltimateParentId").Value);

                        var response = uisCilent.GetUserScope(new CheckUserScopeRequest
                        {
                            LoginUUID = user.UUID,
                            CheckLocationUUID = null,
                            LocationID = new List<string> { locs["up"], locs["le"], locs["lo"] },
                            AAAServiceCode = "CPAP_SNAPIN_MANAGE_ST_IRS"
                        });

                        if (!response.Success)
                        {
                            _Logger.LogWarn("STOpsConsole-GetTopLocationScope - Failed response with {0}", response.Message);
                            return key;
                        }

                        foreach (var scope in response.UserScope)
                        {
                            if (locs["up"] == scope.locationAccountIdField && scope.isInScopeField)
                            {
                                key = new KeyValuePair<FindLocationFilter, string>(FindLocationFilter.ULT, locs["up"]);
                                break;
                            }
                            if (locs["le"] == scope.locationAccountIdField && scope.isInScopeField)
                            {
                                key = new KeyValuePair<FindLocationFilter, string>(FindLocationFilter.LGL, locs["le"]);
                                break;
                            }
                            if (locs["lo"] == scope.locationAccountIdField && scope.isInScopeField)
                            {
                                key = new KeyValuePair<FindLocationFilter, string>(FindLocationFilter.LOC, locs["lo"]);
                                break;
                            }
                        }

                        AddLocationScopeToCache(user.UUID, new LocationScope
                        {
                            TopLocationScope = key
                        });
                    }
                }
                else
                {
                    key = locationScope.TopLocationScope;
                }

                _Logger.LogInfo("STOpsConsole-GetTopLocationScope - User {0}, Key {1}, Value {2}", user.UUID, key.Key.ToString(), key.Value);
                return key;
            }
            catch (Exception ex)
            {
                _Logger.LogError("STOpsConsole-GetTopLocationScope: Error get user scope from AAA service: {0}", ex.Message);
                return key;
            }

        }
コード例 #11
0
ファイル: Permission.cs プロジェクト: montakan29/TestGit
        internal static bool IsLocationInScope(IAaaUser user, string searchLocationID)
        {
            if (IsUserInternal(user)) return true;
            //location xx is hardcoded for getting min interval
            if (string.Compare(user.LocationAccountId, searchLocationID, true) == 0 || searchLocationID == "xx") return true;

            if (string.IsNullOrEmpty(user.LocationAccountId) || string.IsNullOrEmpty(searchLocationID))
            {
                _Logger.LogWarn("STOpsConsole-IsLocationInScope - empty location user {0}, [User-{1}/Search-{2}]", user.UUID, user.LocationAccountId,searchLocationID);
                return false;
            }

            using (var uisCilent = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
            {
                var locs = new List<LocationInfoRequest>();
                locs.Add(new LocationInfoRequest { LocationAccountId = searchLocationID });
                locs.Add(new LocationInfoRequest { LocationAccountId = user.LocationAccountId });
                var locResp = uisCilent.GetLocations(locs);
                var userULT = locResp.Where(x => x.LocationId == user.LocationAccountId).Select(y => y.UltimateParentId).SingleOrDefault();
                var srchULT = locResp.Where(x => x.LocationId == searchLocationID).Select(y => y.UltimateParentId).SingleOrDefault();

                if (string.Compare(userULT, srchULT, true) == 0)
                {
                    _Logger.LogInfo("STOpsConsole-IsLocationInScope - ULT location matched for user {0}, [User-{1}:{3}/Search-{2}:{4}]", 
                        user.UUID, user.LocationAccountId, searchLocationID,userULT,srchULT);
                    return true;
                }

                _Logger.LogInfo("STOpsConsole-IsLocationInScope - ULT location not matched for user {0}, [User-{1}:{3}/Search-{2}:{4}]",
                        user.UUID, user.LocationAccountId, searchLocationID, userULT, srchULT);
            }
            return false;
        }
コード例 #12
0
        private string FindMachineInstall(FindMachineInstallRequest req, IAaaUser aaaUser, ILogger logger)
        {
            IDictionary<string, FindUserEntity> userDetailDic = new Dictionary<string, FindUserEntity>();
            req.Product = "est";
            var findUserReq = new FindUserRequest
            {
                Filter = FindUserFilter.All,
                SearchString = req.SearchString,
            };


            // For external user, the auto suggest will only show the users under the user's location scope
            var canOnlySeeYourOwnAccount = false;
            if (!Permission.IsUserInternal(aaaUser))
            {
                var scope = Permission.GetTopLocationScope(aaaUser);
                if (!scope.Equals(default(KeyValuePair<FindLocationFilter, string>)))
                {
                    findUserReq.LocationScope = scope;
                }
                else if (aaaUser.UserId.Contains(req.SearchString) ||
                        aaaUser.EmailAddress.Contains(req.SearchString) ||
                        aaaUser.UUID.Contains(req.SearchString) ||
                        aaaUser.FullName.Contains(req.SearchString))
                {
                    canOnlySeeYourOwnAccount = true;
                }
                else
                {
                    logger.LogWarn("STOpsConsole - FindMachineInstall - external user {0} has no eligible scope.", aaaUser.UserId);
                    return "{ \"items\":[]}";
                }
            }

            using (var userInfoServiceclient = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
            {
                var svcResp = userInfoServiceclient.FindUser(findUserReq);

                if (svcResp == null || svcResp.Users.Count == 0)
                {
                    return "{ \"items\":[]}";
                }

                var machInstReq = new MachInstInfoRequest
                {
                    uuids = new List<string>(),
                    filter = req.Filter,
                    product = req.Product
                };

                //If user can see only his own account due to the scope. Will filter out the list of find user.
                if (canOnlySeeYourOwnAccount)
                {
                    var user = svcResp.Users.SingleOrDefault(x => x.Uuid == aaaUser.UUID);
                    if (user != null)
                    {
                        userDetailDic[user.Uuid] = user;
                        machInstReq.uuids.Add(user.Uuid);
                    }
                    else
                    {
                        return "{ \"items\":[]}";
                    }
                }
                else
                {
                    foreach (FindUserEntity user in svcResp.Users)
                    {
                        userDetailDic[user.Uuid] = user;
                        machInstReq.uuids.Add(user.Uuid);
                    }
                }

                FindMachInstResponse findMachInstResponse = new FindMachInstResponse() { Items = new List<FindMachInstInfoItem>() };
                using (var opsConsoleServiceClient = new OpsConsoleServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
                {
                    MachInstInfoResponse machInstResp = opsConsoleServiceClient.GetMachineInstallInfo(machInstReq);
                    foreach (MachInstInfoItem machInsInfo in machInstResp.Items)
                    {

                        FindMachInstInfoItem findMachInstInfoItem = new FindMachInstInfoItem
                        {
                            UUID = machInsInfo.uuid,
                            FirstName = userDetailDic[machInsInfo.uuid].FirstName,
                            LastName = userDetailDic[machInsInfo.uuid].LastName,
                            EmailAddress = userDetailDic[machInsInfo.uuid].Email
                            //MachInstInfoList = machInsInfo.machInstInfoList
                        };
                        findMachInstResponse.Items.Add(findMachInstInfoItem);
                        findMachInstResponse.Product = machInstResp.product;

                    }
                }
                return JsonConvert.SerializeObject(findMachInstResponse) ?? "{}";
            }
        }
コード例 #13
0
        public string FindUser(string query, string body, IAppServerServices services)
        {
            var logger = services.Logger;
            try
            {
                // Load the incoming request into the request params object (for easy passing to the half dozen functions that need the parameters)
                var req = JsonConvert.DeserializeObject<FindUserRequest>(body);
                req.Filter = FindUserFilter.All;

                using (var userInfoServiceclient = new UserInfoServiceClient(RouterBindings.Local, RouterAddresses.Local.RequestReply))
                {
                    var svcResp = userInfoServiceclient.FindUser(req);

                    return (svcResp == null) ? "{ \"Users\":[]}" : JsonConvert.SerializeObject(svcResp);
                }
            }
            catch (Exception ex)
            {
                logger.LogError("STOpsConsole - FindUser - Caught exception: " + ex.Message);
                return "{ }";
            }
        }
コード例 #14
0
 static void Main(string[] args)
 {
     UserInfoServiceClient clinet = new UserInfoServiceClient();
     Console.WriteLine(clinet.Add(1, 5));
     //Console.ReadKey();
 }