示例#1
0
        private void GetHistoriesClick(object sender, EventArgs e)
        {
            var api = new RSM.Integration.S2.API();

            var results = api.Login(S2APIUser, S2APIPassword, S2APIUrl, false);

            if (results.Failed)
            {
                AssignView("Failed login!");
                return;
            }

            var session = results.Entity;

            var accessResult = api.GetAccessHistory(DateTime.Parse("01/01/2012"));

            if (accessResult.Failed)
            {
                AssignView("Failed access request!");
                return;
            }

            foreach (var access in accessResult.Entity)
            {
                var apiPerson = api.RetrievePerson(access.Person.ExternalId);
                if (apiPerson.Succeeded)
                {
                    access.Person = apiPerson.Entity;
                }

                var apiPortal = api.RetrievePortal(access.Portal.ExternalId);
                if (apiPortal.Succeeded)
                {
                    access.Portal = apiPortal.Entity;
                }

                var apiReader = api.RetrieveReader(access.Reader.ExternalId);
                if (apiReader.Succeeded)
                {
                    access.Reader = apiReader.Entity;
                }
            }

            var sb = new StringBuilder();

            foreach (var accessLog in accessResult.Entity)
            {
                sb.AppendFormat("{0} ({1}, {2})", accessLog.Person.ExternalId, accessLog.Person.LastName, accessLog.Person.FirstName);
                sb.AppendFormat(" | {0} ({1})", accessLog.Portal.ExternalId, accessLog.Portal.Name);
                sb.AppendFormat(" | {0} ({1})", accessLog.Reader.ExternalId, accessLog.Reader.Name);
                sb.AppendFormat(" | {0}", accessLog.Accessed);
                sb.Append(Environment.NewLine);
            }

            AssignView(sb.ToString());
        }
示例#2
0
        private void btnGetPeople_Click(object sender, EventArgs e)
        {
            var api = new RSM.Integration.S2.API();

            var results = api.Login(S2APIUser, S2APIPassword, S2APIUrl, false);

            if (results.Failed)
            {
                AssignView("Failed login!");
                return;
            }

            var session = results.Entity;

            var    sb      = new StringBuilder();
            string nextKey = null;

            var peopleResult = api.GetPeople(ref nextKey);

            if (peopleResult.Failed)
            {
                AssignView(string.Format("Failed people request!{0}{1}", Environment.NewLine, peopleResult.ToString()));
                return;
            }

            var imageShown = false;

            foreach (var person in peopleResult.Entity)
            {
                var apiPerson = api.RetrievePersonDetail(person.ExternalId, true);
                if (apiPerson.Succeeded)
                {
                    var detail = apiPerson.Entity;

                    sb.AppendFormat("{0} ({1}, {2})", detail.ExternalId, detail.LastName, detail.FirstName);
                    sb.AppendFormat(" | {0}", detail.Active ? "Active" : "Inactive");
                    sb.AppendFormat(" | last updated: {0}", detail.ExternalUpdated);
                    sb.AppendFormat(" | image: {0}", detail.Image != null);

                    if (detail.Image != null)
                    {
                        Image image;
                        try
                        {
                            using (var imageStream = new MemoryStream(detail.Image))
                            {
                                image = Image.FromStream(imageStream);
                            }
                            sb.Append(", image valid");

                            //display first valid image retreived
                            if (!imageShown)
                            {
                                AssignView("first image", image);
                                imageShown = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            sb.AppendFormat(", image invalid: {0}", ex.Message);
                        }
                    }

                    sb.Append(Environment.NewLine);
                }
                AssignView(sb.ToString());
            }
        }