public ApiList <Term> ParseFieldValue(string url, object fieldValue)
        {
            var terms = new ApiList <Term>();

            if (fieldValue != null)
            {
                Guid id;
                if (fieldValue is IEnumerable <object> )
                {
                    foreach (var term in ((IEnumerable <object>)fieldValue).Where(_ => _ != null).Select(t => ParseTerm(url, t)))
                    {
                        if (term != null)
                        {
                            terms.Add(term);
                        }
                    }
                }
                else
                {
                    var term = ParseTerm(url, fieldValue);
                    if (term != null)
                    {
                        terms.Add(term);
                    }
                }
            }
            return(terms);
        }
        private async void LoginButtonClick(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(UserText.Text) && !string.IsNullOrEmpty(PassText.Text))
            {
                var username       = UserText.Text.ToLower();
                var api            = BuildApi(username, PassText.Text);
                var sessionHandler = new FileSessionHandler {
                    FilePath = username.GetAccountPath(), InstaApi = api
                };

                api.SessionHandler = sessionHandler;
                var loginResult = await api.LoginAsync();

                if (loginResult.Succeeded)
                {
                    LoggedInUsers.Add(api.GetLoggedUser().LoggedInUser.UserName.ToLower());
                    ApiList.Add(api);
                    if (SessionsCombo.SelectedIndex == -1)
                    {
                        SessionsCombo.SelectedIndex = 0;
                    }
                    api.SessionHandler.Save();
                }
                else
                {
                    MessageBox.Show($"Error:\r\n{loginResult.Info.Message}\r\n\r\n" +
                                    $"Please check ChallengeExample for handling two factor or challenge..."
                                    , loginResult.Info.ResponseType.ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Beispiel #3
0
 public ApiList <SPView> List(SPList list)
 {
     using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl)))
     {
         SP.ViewCollection viewCollection = clientContext.ToList(list.Id).Views;
         var     views       = clientContext.LoadQuery(viewCollection.Include(SPView.InstanceQuery));
         SP.List splist      = clientContext.ToList(list.Id);
         var     fieldsQuery = clientContext.LoadQuery(splist.Fields.Include(
                                                           field => field.Title,
                                                           field => field.InternalName));
         clientContext.Load(splist,
                            _list => _list.ContentTypes.Include(ct => ct.Fields.SchemaXml),
                            _list => _list.SchemaXml);
         clientContext.ExecuteQuery();
         var spviewCollection = new ApiList <SPView>();
         var columns          = fieldsQuery.ToDictionary(item => item.InternalName, item => item.Title);
         foreach (var view in views)
         {
             if (!view.Hidden)
             {
                 spviewCollection.Add(new SPView(view, columns));
             }
         }
         return(spviewCollection);
     }
 }
 /// <summary>
 /// 加入
 /// </summary>
 /// <param name="api"></param>
 internal void Add(ApiItem api)
 {
     if (!ApiList.Contains(api))
     {
         ApiList.Add(api);
     }
     GlobalConfig.Add(api);
 }
        public static ApiList <SPList> ToApiList(this IEnumerable <SP.List> source, Guid siteId)
        {
            var apiList = new ApiList <SPList>();

            foreach (SP.List list in source)
            {
                apiList.Add(new SPList(list, siteId));
            }
            return(apiList);
        }
Beispiel #6
0
        public static void UpdateInternalUser(InternalApi.Entities.TEApiUser user, IEnumerable <string> fields)
        {
            IEnumerable <string> userFields = fields.ToList();
            var optUpdate = new UsersUpdateOptions {
                Id = Convert.ToInt32(user.Id)
            };

            try
            {
                var profileFieldList = new ApiList <ProfileField>();
                foreach (string fieldName in userFields)
                {
                    object fieldValue   = user[fieldName];
                    string propertyName = fieldName.Replace(" ", String.Empty);
                    if (UserUpdateOptionsProperties.ContainsKey(propertyName))
                    {
                        UserUpdateOptionsProperties[propertyName].SetValue(optUpdate, fieldValue, null);
                    }
                    else
                    {
                        profileFieldList.Add(new ProfileField
                        {
                            Label = GetFieldName(user.Profile, fieldName),
                            Value = fieldValue != null ? fieldValue.ToString() : null
                        });
                    }
                }

                optUpdate.ProfileFields = profileFieldList;

                var avatar = user[AvatarUrlField] as string;

                if (userFields.Contains(AvatarUrlField) && !string.IsNullOrEmpty(avatar))
                {
                    optUpdate.ExtendedAttributes = new List <ExtendedAttribute>
                    {
                        new ExtendedAttribute
                        {
                            Key   = "avatarUrl",
                            Value = avatar
                        }
                    };
                }

                PublicApi.Users.Update(optUpdate);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Could Not Update Internal User: {0}/{1}", user.Id, user.Email ?? string.Empty));
            }
        }
        public static void SetAttribute <T>(this ApiList <IExtendedAttribute> attributes, string name, T value)
        {
            IExtendedAttribute attribute = attributes.FirstOrDefault(f => f.Key == name);

            if (attribute == null)
            {
                attribute = new ExtendedAttribute()
                {
                    Key = name
                };
                attributes.Add(attribute);
            }

            attribute.Value = Convert.ToString(value);
        }
Beispiel #8
0
        private ApiList <Evolution.Extensibility.Api.Entities.Version1.UserProfileField> GetSamlProfileFields()
        {
            var samlProfileFields = new ApiList <Evolution.Extensibility.Api.Entities.Version1.UserProfileField>();
            var allProfileFields  = Apis.Get <IUserProfileFields>().List(new UserProfileFieldsListOptions()
            {
                PageSize = int.MaxValue
            });

            foreach (var profileField in allProfileFields)
            {
                if (profileField.Name.StartsWith(ProfileFieldPrefix, StringComparison.InvariantCultureIgnoreCase))
                {
                    samlProfileFields.Add(profileField);
                }
            }

            return(samlProfileFields);
        }
Beispiel #9
0
        /// <summary>
        /// Converts the users ProfileFields collection into something that can be saved, when you get a user profile field you get "lables" and "values"
        /// But when you save it you need to use "Names" and "Values", This class expects everyting to be the "Name" or Profile Field "Key"
        /// </summary>
        /// <param name="profileFields"></param>
        /// <returns></returns>
        private ApiList <ProfileField> ConvertTitlesToNames(ApiList <ProfileField> profileFields)
        {
            var cleanedProfileFields = new ApiList <ProfileField>();
            var allProfileFields     = Apis.Get <IUserProfileFields>().List(new UserProfileFieldsListOptions()
            {
                PageSize = int.MaxValue
            });

            foreach (var profileField in profileFields)
            {
                var fieldDefinition = allProfileFields.Where(i => i.Name == profileField.Label).First();
                if (fieldDefinition != null)
                {
                    cleanedProfileFields.Add(new ProfileField()
                    {
                        Label = fieldDefinition.Name, Value = profileField.Value
                    });
                }
            }

            return(cleanedProfileFields);
        }
Beispiel #10
0
        public void BaseString_FormData_Test()
        {
            var url = "https://test.example.com:443/api/v1/rest/level1/in-in/?ap=裕廊坊%20心邻坊";
            var expectedBaseString = "POST&https://test.example.com/api/v1/rest/level1/in-in/&ap=裕廊坊 心邻坊&auth_prefix_app_id=app-id-lpX54CVNltS0ye03v2mQc0b&auth_prefix_nonce=6584351262900708156&auth_prefix_signature_method=HMACSHA256&auth_prefix_timestamp=1502184161702&auth_prefix_version=1.0&param1=data1";

            var formList = new ApiList();

            formList.Add("param1", "data1");

            var baseString = ApiAuthorization.BaseString(
                "auth_prefix",
                SignatureMethod.HMACSHA256,
                "app-id-lpX54CVNltS0ye03v2mQc0b",
                new System.Uri(url),
                HttpMethod.POST,
                formList,
                "6584351262900708156",
                "1502184161702",
                "1.0"
                );

            Assert.AreEqual(expectedBaseString, baseString);
        }
Beispiel #11
0
        private ApiList <ProfileField> UpdatedProfileFields(Dictionary <string, string> usersSamlTokenProfileData, ApiList <ProfileField> currentProfileFields)
        {
            //get a list of user profile fields with the matching prefix
            var samlProfileFields    = GetSamlProfileFields();
            var updatedProfileFields = new ApiList <ProfileField>();

            bool hasChanges = false;

            foreach (var userProfileField in samlProfileFields)
            {
                try
                {
                    bool userHasField = false;
                    //this checks the current users profile fields against saml (ie remove or update)
                    foreach (var profileField in currentProfileFields.Where(i => i.Label == userProfileField.Name))
                    {
                        //check to see if its in the saml token based on userProfileField name
                        if (!usersSamlTokenProfileData.ContainsKey(userProfileField.Name) && !string.IsNullOrWhiteSpace(profileField.Value))
                        {
                            updatedProfileFields.Add(new ProfileField()
                            {
                                Label = userProfileField.Name, Value = ""
                            });
                            hasChanges = true;
                        }

                        if (usersSamlTokenProfileData.ContainsKey(userProfileField.Name) && profileField.Value != usersSamlTokenProfileData[userProfileField.Name])
                        {
                            updatedProfileFields.Add(new ProfileField()
                            {
                                Label = userProfileField.Name, Value = usersSamlTokenProfileData[userProfileField.Name]
                            });
                            hasChanges = true;
                        }

                        userHasField = true;
                    }

                    //this checks the saml data against the user (ie adding missing entries)
                    if (!userHasField && usersSamlTokenProfileData.ContainsKey(userProfileField.Name))
                    {
                        updatedProfileFields.Add(new ProfileField()
                        {
                            Label = userProfileField.Name, Value = usersSamlTokenProfileData[userProfileField.Name]
                        });
                        hasChanges = true;
                    }
                }
                catch (Exception ex)
                {
                    _eventLogApi.Write("ProfileAttributeManager Error UpdatedProfileFields: " + ex.Message + " : " + ex.StackTrace, new EventLogEntryWriteOptions()
                    {
                        Category = "SAML", EventId = 1, EventType = "Error"
                    });
                }
            }

            if (hasChanges)
            {
                return(updatedProfileFields);
            }
            else
            {
                return(null);
            }
        }
        public ApiList <SPListItem> List(SPList list,
                                         [Documentation(Name = "ViewFields", Type = typeof(List <string>)),
                                          Documentation(Name = "ViewQuery", Type = typeof(string))]
                                         IDictionary options)
        {
            if (list == null)
            {
                return(new ApiList <SPListItem>());
            }

            var cacheId   = string.Concat(SharePointListItemCacheId, string.Format("{0}_{1}", list.SPWebUrl, list.Id));
            var cacheList = (ApiList <SPListItem>)cacheService.Get(cacheId, CacheScope.Context | CacheScope.Process);

            if (cacheList == null)
            {
                using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl)))
                {
                    var sharepointList = clientContext.ToList(list.Id);
                    ListItemCollection listItemCollection;
                    if (options != null && options["ViewQuery"] != null)
                    {
                        var camlQuery = new CamlQuery
                        {
                            ViewXml = String.Format("<View><Query>{0}</Query></View>", options["ViewQuery"])
                        };
                        listItemCollection = sharepointList.GetItems(camlQuery);
                    }
                    else
                    {
                        listItemCollection = sharepointList.GetItems(CamlQuery.CreateAllItemsQuery());
                    }
                    IEnumerable <ListItem> items;
                    if (options != null && options["ViewFields"] != null)
                    {
                        var viewFields = (List <string>)options["ViewFields"];
                        items = clientContext.LoadQuery(listItemCollection.Include(CreateListItemLoadExpressions(viewFields)));
                    }
                    else
                    {
                        items = clientContext.LoadQuery(listItemCollection.Include(SPItemService.InstanceQuery));
                    }
                    var userItemCollection = clientContext.Web.SiteUserInfoList.GetItems(CamlQuery.CreateAllItemsQuery());
                    IEnumerable <SP.ListItem> userItems = clientContext.LoadQuery(
                        userItemCollection.Include(new Expression <Func <ListItem, object> >[] { item => item.Id, item => item["Picture"] }));

                    var fieldsQuery = clientContext.LoadQuery(sharepointList.Fields.Where(field => !field.Hidden && field.Group != "_Hidden"));
                    clientContext.ExecuteQuery();
                    var apiList = new ApiList <SPListItem>();
                    var fields  = fieldsQuery.ToList();

                    foreach (var item in items)
                    {
                        apiList.Add(new SPListItem(item, fields));
                    }

                    cacheService.Put(cacheId, apiList, CacheScope.Context | CacheScope.Process, new[] { GetTag(list.Id) }, CacheTimeOut);
                    return(apiList);
                }
            }

            return(cacheList);
        }
Beispiel #13
0
        private static void runTest(TestCase testCase)
        {
            var queryParam = new ApiList();

            foreach (var param in testCase.QueryParams)
            {
                queryParam.Add(param);
            }
            string queryString = queryParam.ToQueryString();

            LoggerManager.Logger.LogInformation($"Test Case {testCase.Name} started. Query string: {queryString}");
            Console.WriteLine($"Test Case {testCase.Name} started.");

            // base URL
            string baseUrl;
            //static string apiPath = "test/l2-eg/v1"; //according to "EDH_BIDWH_HPB_UAT_REST_Scenarios_Conditions_v1.0.xlsx", tab "WebService"
            //v1/entities
            //v1/entity/{uen}
            //v1/entity/{uen}/appointments
            string fullPath;

            switch (testCase.TestMethod)
            {
            case TestMethod.Entities:
                fullPath = $"{apiPath}/entities";
                break;

            case TestMethod.UENs:
                fullPath = $"{apiPath}/entity/{testCase.UEN}";
                break;

            case TestMethod.Appointments:
            default:
                fullPath = $"{apiPath}/entity/{testCase.UEN}/appointments";
                break;
            }

            if (string.IsNullOrEmpty(queryString))
            {
                baseUrl = $"https://{signingGateway}/{fullPath}";
            }
            else
            {
                baseUrl = $"https://{signingGateway}/{fullPath}?{queryString}";
            }

            // authorization header
            var authorizationHeader = ApiAuthorization.Token(realm, authPrefix, HttpMethod.GET, new Uri(baseUrl), appId, null, null, privateKey);

            //target base URL
            string targetBaseUrl;

            if (string.IsNullOrEmpty(queryString))
            {
                targetBaseUrl = $"https://{targetGatewayName}/{fullPath}";
            }
            else
            {
                targetBaseUrl = $"https://{targetGatewayName}/{fullPath}?{queryString}";
            }

            var result = ApiAuthorization.HttpRequest(new Uri(targetBaseUrl), authorizationHeader);

            LoggerManager.Logger.LogInformation($"Test Case {testCase.Name} ended with result: {result}");
            Console.WriteLine($"Test Case {testCase.Name} ended with result: {result}");
        }