private async Task LoadImages(int?homeImageId, int?visitorImageId)
        {
            try
            {
                if (homeImageId != null)
                {
                    var img1 = await RestUtils.GetImage(homeImageId);

                    if (!string.IsNullOrEmpty(img1.ImageUrl))
                    {
                        img_home.Source = img1.ImageUrl;
                    }
                }

                if (visitorImageId != null)
                {
                    var img2 = await RestUtils.GetImage(visitorImageId);

                    if (!string.IsNullOrEmpty(img2.ImageUrl))
                    {
                        img_visitor.Source = img2.ImageUrl;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #2
0
        private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                InstrumentFamilyProviderBase provider = InstrumentManager.Instance.GetInstrumentFamilyProvider(user);
                if (provider != null)
                {
                    IEnumerable <InstrumentFamily> instrumentFams = provider.Get();
                    JArray jinstrumentFams = Jsonifier.ToJson(instrumentFams);
                    if (jinstrumentFams != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jinstrumentFams.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, JsonOpStatus.Failed);
            }
            catch
            {
                RestUtils.Push(context.Response, JsonOpStatus.Failed);
                return;
            }
        }
Example #3
0
        public async Task <(bool success, string failureMessage)> RegisterAsync(string userName, string mobile, string email, string password)
        {
            var url = GetCliUrl(RestUrlRegister);

            return(await RestUtils.PostAsync(url, new RegisterRequest
            {
                UserName = userName,
                Mobile = mobile,
                Email = email,
                Password = password
            }));

            //var client = new RestClient(CloudUtils.Api.GetCliUrl(RestUrlRegister)) { Timeout = -1 };
            //var request = new RestRequest(Method.POST);
            //request.AddHeader("Content-Type", "application/json");
            //request.AddParameter("application/json", TranslateUtils.JsonSerialize(new RegisterRequest
            //{
            //    UserName = userName,
            //    Mobile = mobile,
            //    Email = email,
            //    Password = password
            //}), ParameterType.RequestBody);
            //var response = client.Execute(request);

            //return response.IsSuccessful ? (true, null) : (false, StringUtils.Trim(response.Content, '"'));
        }
Example #4
0
        private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                if (provider != null)
                {
                    IEnumerable <OrganizationAliasScheme> schemes = provider.Get();
                    JArray jschemes = Jsonifier.ToJson(schemes);
                    if (jschemes != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jschemes.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
        }
        public static InlineCollectionRepresentation Create(IOidStrategy oidStrategy, HttpRequest req, PropertyContextFacade propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags, bool asTableColumn)
        {
            var collectionRepresentationStrategy = AbstractCollectionRepresentationStrategy.GetStrategy(asTableColumn, true, oidStrategy, req, propertyContext, flags);

            var size = collectionRepresentationStrategy.GetSize();

            if (size != null)
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Size, size));
            }

            var value = collectionRepresentationStrategy.GetValue();

            if (value != null)
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, value));
            }

            var actions = collectionRepresentationStrategy.GetActions();

            if (actions.Any())
            {
                var members = RestUtils.CreateMap(actions.ToDictionary(m => m.Id, m => (object)m));
                optionals.Add(new OptionalProperty(JsonPropertyNames.Members, members));
            }

            return(optionals.Any()
                ? CreateWithOptionals <InlineCollectionRepresentation>(new object[] { oidStrategy, collectionRepresentationStrategy }, optionals)
                : new InlineCollectionRepresentation(oidStrategy, collectionRepresentationStrategy));
        }
        public virtual LinkRepresentation[] GetLinks(bool inline)
        {
            var tempLinks = new List <LinkRepresentation>();

            if (!inline)
            {
                tempLinks.Add(CreateUpLink());
                tempLinks.Add(CreateSelfLink());
            }
            else if (!propertyContext.Target.IsTransient)
            {
                if (propertyContext.Property.IsCollection && !propertyContext.Property.IsEager(propertyContext.Target))
                {
                    tempLinks.Add(CreateCollectionValueLink());
                }
                tempLinks.Add(CreateDetailsLink());
            }

            if (RestUtils.IsAttachment(propertyContext.Specification))
            {
                tempLinks.Add(CreateAttachmentLink());
            }

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(CreateDescribedByLink());
            }

            return(tempLinks.ToArray());
        }
Example #7
0
        private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                InstrumentProviderBase provider = InstrumentManager.Instance.GetInstrumentProvider(user);
                InstrumentKnownArchetypeProviderBase archProvider = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(user);
                if (provider != null)
                {
                    IEnumerable <Instrument> instruments = provider.Get();
                    JArray jinstruments = new JArray();
                    foreach (Instrument inst in instruments)
                    {
                        IArchetype arch = archProvider.Get(inst.Identity);
                        if (arch != null)
                        {
                            string archetypeString = archProvider.GetArchetypeType(arch.Identity);
                            switch (archetypeString)
                            {
                            case "SimpleTrapDredge":
                                jinstruments.Add(Jsonifier.ToJson(inst, arch as SimpleTrapDredge));
                                break;

                            case "StandardMeshNet":
                                jinstruments.Add(Jsonifier.ToJson(inst, arch as StandardMeshNet));
                                break;

                            case "StandardPlanktonNet":
                                jinstruments.Add(Jsonifier.ToJson(inst, arch as StandardPlanktonNet));
                                break;

                            case "WingedBagNet":
                                jinstruments.Add(Jsonifier.ToJson(inst, arch as WingedBagNet));
                                break;
                            }
                        }
                        else  //instrument has no archetype
                        {
                            jinstruments.Add(Jsonifier.ToJson(inst));
                        }
                    }

                    if (jinstruments != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jinstruments.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, JsonOpStatus.Failed);
            }
            catch
            {
                RestUtils.Push(context.Response, JsonOpStatus.Failed);
                return;
            }
        }
Example #8
0
        private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                PersonProvider provider = PersonManager.Instance.GetProvider(user);
                if (provider != null)
                {
                    IEnumerable <Person> persons = provider.Get();
                    JArray jpersons = new JArray();
                    jpersons = Jsonifier.ToJson(persons);

                    if (jpersons != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jpersons.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, JsonOpStatus.Failed);
            }
            catch
            {
                RestUtils.Push(context.Response, JsonOpStatus.Failed);
                return;
            }
        }
Example #9
0
        private static void RemoveInstance(CompoundIdentity cid, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                InstrumentKnownArchetypeProviderBase archProvider = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(user);
                if (cid != null && archProvider != null)
                {
                    bool result = archProvider.Delete(cid);

                    if (result == true)
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
                    }
                    else
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    return;
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                return;
            }
        }
        private LinkRepresentation CreatePromptLink(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter)
        {
            var opts = new List <OptionalProperty>();

            var parameterContext = new ParameterContextSurface {
                Action    = parameter.Action,
                Target    = nakedObject,
                Parameter = parameter
            };

            if (parameter.IsAutoCompleteEnabled)
            {
                var arguments  = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.XRoSearchTerm, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))));
                var extensions = new OptionalProperty(JsonPropertyNames.Extensions, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.MinLength, parameter.AutoCompleteMinLength())));

                opts.Add(arguments);
                opts.Add(extensions);
            }
            else
            {
                Tuple <string, INakedObjectSpecificationSurface>[] parms = parameter.GetChoicesParameters();
                OptionalProperty[] args = parms.Select(tuple => RestUtils.CreateArgumentProperty(req, tuple, Flags)).ToArray();
                var arguments           = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args));
                opts.Add(arguments);
            }

            return(LinkRepresentation.Create(new PromptRelType(new UriMtHelper(req, parameterContext)), Flags, opts.ToArray()));
        }
Example #11
0
        private IDictionary <string, object> GetCustomPropertyExtensions()
        {
            if (CustomExtensions == null)
            {
                AddChoicesCustomExtension();

                var mask = PropertyContext.Property.Mask;

                if (!string.IsNullOrWhiteSpace(mask))
                {
                    AddCustomExtension(JsonPropertyNames.CustomMask, mask);
                }

                var multipleLines = PropertyContext.Property.NumberOfLines;

                if (multipleLines > 1)
                {
                    AddCustomExtension(JsonPropertyNames.CustomMultipleLines, multipleLines);
                }

                if (PropertyContext.Property.NotNavigable)
                {
                    AddCustomExtension(JsonPropertyNames.CustomNotNavigable, true);
                }

                if (PropertyContext.Property.IsFindMenuEnabled)
                {
                    AddCustomExtension(JsonPropertyNames.CustomFindMenu, true);
                }

                CustomExtensions = RestUtils.AddRangeExtension(PropertyContext.Property, CustomExtensions);
            }

            return(CustomExtensions);
        }
        public static ParameterRepresentation Create(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter, RestControlFlags flags)
        {
            var optionals = new List <OptionalProperty>();

            if (parameter.IsChoicesEnabled && !parameter.GetChoicesParameters().Any())
            {
                INakedObjectSurface[] choices = parameter.GetChoices(nakedObject, null);
                object[] choicesArray         = choices.Select(c => RestUtils.GetChoiceValue(req, c, parameter, flags)).ToArray();
                optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
            }

            if (parameter.DefaultTypeIsExplicit(nakedObject))
            {
                INakedObjectSurface defaultNakedObject = parameter.GetDefault(nakedObject);
                if (defaultNakedObject != null)
                {
                    string title        = defaultNakedObject.TitleString();
                    object value        = RestUtils.ObjectToPredefinedType(defaultNakedObject.Object);
                    var    isValue      = defaultNakedObject.Specification.IsParseable() || (defaultNakedObject.Specification.IsCollection() && defaultNakedObject.ElementSpecification.IsParseable());
                    object defaultValue = isValue ? value : CreateDefaultLinks(req, parameter, defaultNakedObject, title, flags);

                    optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue));
                }
            }

            if (optionals.Count == 0)
            {
                return(new ParameterRepresentation(req, nakedObject, parameter, flags));
            }
            return(CreateWithOptionals <ParameterRepresentation>(new object[] { req, nakedObject, parameter, flags }, optionals));
        }
Example #13
0
        private static void GetForUser(HttpContext context, UserSecurityContext ctx)
        {
            IUserAffiliationProvider prov = UserAffiliationManager.Instance.GetProvider(ctx);

            if (prov != null)
            {
                IEnumerable <CompoundIdentity> ids = null;
                ids = prov.GetIds(ctx.User);
                if (ids != null)
                {
                    JArray orgs = JsonUtils.ToJson(ids);
                    if (orgs != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, orgs);
                        return;
                    }
                }
                else
                {
                    RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    return;
                }
            }
            RestUtils.Push(context.Response, JsonOpStatus.Failed);
        }
Example #14
0
        private static void Get(HttpContext context, UserSecurityContext ctx, JObject body)
        {
            IUserAffiliationProvider prov = UserAffiliationManager.Instance.GetProvider(ctx);

            if (prov != null)
            {
                CompoundIdentity orgId = JsonUtils.ToId(body[JsonUtils.OwnerId]);
                if (orgId == null)
                {
                    Guid userId = JsonUtils.ToGuid(body[userId]);
                    IEnumerable <CompoundIdentity> ids = null;
                    if (Guid.Empty.Equals(userId) || userId.Equals(ctx.Identity))
                    {
                        //this is for self
                        ids = prov.GetIds(ctx.User);
                    }
                    else
                    {
                        //this is for other
                        IIdentityProvider idp = IdentityManager.Instance.GetProvider(ctx);
                        if (idp != null)
                        {
                            IUserIdentity uid = idp.Get(userId); //make sure this is a valid user
                            if (uid != null)
                            {
                                ids = prov.GetIds(uid);
                            }
                        }
                    }

                    if (ids != null)
                    {
                        JArray orgs = JsonUtils.ToJson(ids);
                        if (orgs != null)
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Ok, orgs);
                            return;
                        }
                    }
                }
                else //we're searching by org rather than by user
                {
                    IOrganizationProvider oProv = OrganizationManager.Instance.GetOrganizationProvider(ctx);
                    if (oProv != null)
                    {
                        Organization org = oProv.Get(orgId);
                        if (org != null)
                        {
                            JArray uids = JsonUtils.ToJson(prov.GetIds(org));
                            if (uids != null)
                            {
                                RestUtils.Push(context.Response, JsonOpStatus.Ok, uids);
                                return;
                            }
                        }
                    }
                }
                RestUtils.Push(context.Response, JsonOpStatus.Failed);
            }
        }
        protected static object GetPropertyValue(IOidStrategy oidStrategy, HttpRequestMessage req, IAssociationFacade property, IObjectFacade target, RestControlFlags flags, bool valueOnly = false)
        {
            IObjectFacade valueNakedObject = property.GetValue(target);
            string        title            = RestUtils.SafeGetTitle(property, valueNakedObject);

            if (valueNakedObject == null)
            {
                return(null);
            }
            if (property.Specification.IsParseable || property.Specification.IsCollection)
            {
                return(RestUtils.ObjectToPredefinedType(valueNakedObject.GetDomainObject()));
            }

            if (valueOnly)
            {
                return(RefValueRepresentation.Create(oidStrategy, new ValueRelType(property, new UriMtHelper(oidStrategy, req, valueNakedObject)), flags));
            }

            var helper    = new UriMtHelper(oidStrategy, req, property.IsInline ? target : valueNakedObject);
            var optionals = new List <OptionalProperty> {
                new OptionalProperty(JsonPropertyNames.Title, title)
            };

            if (property.IsEager(target))
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, ObjectRepresentation.Create(oidStrategy, valueNakedObject, req, flags)));
            }

            return(LinkRepresentation.Create(oidStrategy, new ValueRelType(property, helper), flags, optionals.ToArray()));
        }
Example #16
0
        private static void GetForAllTypes(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                InstrumentKnownArchetypeProviderBase provider = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(user);
                if (provider != null)
                {
                    IEnumerable <Tuple <CompoundIdentity, CompoundIdentity> > archetypes = provider.GetInstrumentTypeKnownArchetypes();
                    JArray jarchetypes = Jsonifier.ToJson(archetypes);

                    if (jarchetypes != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jarchetypes.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, JsonOpStatus.Failed);
            }
            catch
            {
                RestUtils.Push(context.Response, JsonOpStatus.Failed);
                return;
            }
        }
Example #17
0
        public async Task <(bool success, string failureMessage)> LoginAsync(string account, string password)
        {
            var url = GetCliUrl(RestUrlLogin);

            var(success, result, _) = await RestUtils.PostAsync <LoginRequest, LoginResult>(url,
                                                                                            new LoginRequest
            {
                Account      = account,
                Password     = AuthUtils.Md5ByString(password),
                IsPersistent = true
            });

            if (!success)
            {
                return(false, "your account or password was incorrect");
            }

            var status = new ConfigStatus
            {
                UserName    = result.UserName,
                AccessToken = result.AccessToken
            };

            await _configService.SaveStatusAsync(status);

            return(true, null);
        }
Example #18
0
        private static void GetByType(CompoundIdentity typeid, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                InstrumentKnownArchetypeProviderBase provider = InstrumentManager.Instance.GetInstrumentKnownArchetypeProvider(user);
                if (provider != null)
                {
                    IEnumerable <CompoundIdentity> archetypes_ids = provider.ArchetypesForInstrumentType(typeid);
                    if (archetypes_ids != null && archetypes_ids.Any())
                    {
                        JArray jarchetypes_ids = JsonUtils.ToJson(archetypes_ids);
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jarchetypes_ids.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, JsonOpStatus.Failed);
            }
            catch
            {
                RestUtils.Push(context.Response, JsonOpStatus.Failed);
                return;
            }
        }
Example #19
0
        private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                ProjectProviderBase provider = ProjectManager.Instance.GetProvider(user);
                if (provider != null)
                {
                    IEnumerable <Project> projects = provider.Get();
                    JArray arr_projects            = Jsonifier.ToJson(projects);
                    if (arr_projects != null)
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, arr_projects.ToString()));
                    }
                    else
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, "[]"));
                    }
                    return;
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
        }
Example #20
0
        private static void GetByOrg(CompoundIdentity org_id, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                OrganizationAliasProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasProvider(user);
                Organization org = OrganizationManager.Instance.GetOrganizationProvider(user).Get(org_id);
                if (org != null && provider != null)
                {
                    IEnumerable <OrganizationAlias> aliases = provider.Get(org);
                    JArray jaliases = Jsonifier.ToJson(aliases);
                    if (jaliases != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jaliases.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
        }
Example #21
0
        private static void GetOrgAndName(CompoundIdentity orgid, string name, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                Organization org = OrganizationManager.Instance.GetOrganizationProvider(user).Get(orgid);
                if (org != null && provider != null)
                {
                    IEnumerable <OrganizationAliasScheme> schemes = provider.Get(org, name);
                    JArray jschemes = Jsonifier.ToJson(schemes);
                    if (jschemes != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jschemes.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
        }
Example #22
0
        public static ParameterRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, IActionParameterFacade parameter, RestControlFlags flags)
        {
            var optionals = new List <OptionalProperty>();

            if (parameter.IsChoicesEnabled != Choices.NotEnabled && !parameter.GetChoicesParameters().Any())
            {
                IObjectFacade[] choices      = parameter.GetChoices(objectFacade, null);
                object[]        choicesArray = choices.Select(c => RestUtils.GetChoiceValue(oidStrategy, req, c, parameter, flags)).ToArray();
                optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
            }

            var adapter = new FieldFacadeAdapter(parameter);

            // include default value for for nonnullable boolean so we can distinguish from nullable on client
            if (parameter.DefaultTypeIsExplicit(objectFacade) || (parameter.Specification.IsBoolean && !parameter.IsNullable))
            {
                IObjectFacade defaultNakedObject = parameter.GetDefault(objectFacade);
                if (defaultNakedObject != null)
                {
                    string title        = defaultNakedObject.TitleString;
                    object value        = RestUtils.ObjectToPredefinedType(defaultNakedObject.Object, true);
                    var    isValue      = defaultNakedObject.Specification.IsParseable || (defaultNakedObject.Specification.IsCollection && defaultNakedObject.ElementSpecification.IsParseable);
                    object defaultValue = isValue ? value : CreateDefaultLinks(oidStrategy, req, adapter, parameter.Action, defaultNakedObject, title, flags);

                    optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue));
                }
            }


            if (optionals.Count == 0)
            {
                return(new ParameterRepresentation(oidStrategy, req, objectFacade, adapter, flags));
            }
            return(CreateWithOptionals <ParameterRepresentation>(new object[] { oidStrategy, req, objectFacade, adapter, flags }, optionals));
        }
Example #23
0
        private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                FieldTripProviderBase provider = FieldActivityManager.Instance.GetFieldTripProvider(user);
                if (provider != null)
                {
                    IEnumerable <FieldTrip> trips = provider.Get();
                    JArray jtrips = Jsonifier.ToJson(trips);
                    if (jtrips != null)
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jtrips.ToString()));
                    }
                    else
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, "[]"));
                    }
                    return;
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                return;
            }
        }
Example #24
0
        public static ParameterRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade objectFacade, IAssociationFacade assoc, ActionContextFacade actionContext, RestControlFlags flags)
        {
            var optionals = new List <OptionalProperty>();

            if (assoc.IsChoicesEnabled != Choices.NotEnabled && !assoc.GetChoicesParameters().Any())
            {
                IObjectFacade[] choices      = assoc.GetChoices(objectFacade, null);
                object[]        choicesArray = choices.Select(c => RestUtils.GetChoiceValue(oidStrategy, req, c, assoc, flags)).ToArray();
                optionals.Add(new OptionalProperty(JsonPropertyNames.Choices, choicesArray));
            }

            var adapter = new FieldFacadeAdapter(assoc);

            IObjectFacade defaultNakedObject = assoc.GetValue(objectFacade);

            if (defaultNakedObject != null)
            {
                string title        = defaultNakedObject.TitleString;
                object value        = RestUtils.ObjectToPredefinedType(defaultNakedObject.Object, true);
                var    isValue      = defaultNakedObject.Specification.IsParseable || (defaultNakedObject.Specification.IsCollection && defaultNakedObject.ElementSpecification.IsParseable);
                object defaultValue = isValue ? value : CreateDefaultLinks(oidStrategy, req, adapter, actionContext.Action, defaultNakedObject, title, flags);

                optionals.Add(new OptionalProperty(JsonPropertyNames.Default, defaultValue));
            }

            if (optionals.Count == 0)
            {
                return(new ParameterRepresentation(oidStrategy, req, objectFacade, adapter, flags));
            }
            return(CreateWithOptionals <ParameterRepresentation>(new object[] { oidStrategy, req, objectFacade, adapter, flags }, optionals));
        }
Example #25
0
        private static void GetIds(HashSet <CompoundIdentity> ids, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                if (ids.Count == 0)
                {
                    RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    return;
                }

                InstrumentFamilyProviderBase provider = InstrumentManager.Instance.GetInstrumentFamilyProvider(user);
                if (provider != null)
                {
                    JArray jinstrumentFamilies = Jsonifier.ToJson(provider.Get(ids));
                    if (jinstrumentFamilies != null)
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jinstrumentFamilies.ToString()));
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
        }
Example #26
0
        private void Create(HttpResponse response, CancellationToken cancel)
        {
            ModuleRuntimeSession sess = Prov.Create();

            response.Headers[Session.SessionIdName] = sess.SessionId.ToString();
            RestUtils.Push(response, RestUtils.JsonOpStatus(JsonOpStatus.Ok));
        }
Example #27
0
        private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                TaxaUnitTypeProviderBase provider = TaxonomyManager.Instance.GetTaxaUnitTypeProvider(user);
                if (provider != null)
                {
                    IEnumerable <TaxaUnitType> unitTypes = provider.Get();
                    JArray junittypes = Jsonifier.ToJson(unitTypes);
                    if (junittypes != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, junittypes.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, JsonOpStatus.Failed);
            }
            catch
            {
                RestUtils.Push(context.Response, JsonOpStatus.Failed);
                return;
            }
        }
Example #28
0
        private static void GetNonLivingTaxa(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            //This is a workaround until lists of observables can be abstracted out of taxonomy
            try
            {
                Guid ds = Guid.Empty;
                Guid id = Guid.Empty;
                Guid.TryParse("e578ca70-6cec-4961-bb43-14fd45f455bd", out ds);
                Guid.TryParse("237f8c0a-dc5f-4104-a0b8-dbb5a7c73aa2", out id);
                CompoundIdentity nonLivingTaxonomy = new CompoundIdentity(ds, id);

                TaxaUnitProviderBase provider = TaxonomyManager.Instance.GetTaxaUnitProvider(user);
                if (provider != null)
                {
                    IEnumerable <TaxaUnit> units = provider.GetByTaxonomy(nonLivingTaxonomy);
                    JArray junits = Jsonifier.ToJson(units);
                    if (junits != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, junits.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                    return;
                }

                RestUtils.Push(context.Response, JsonOpStatus.Failed);
            }
            catch
            {
                RestUtils.Push(context.Response, JsonOpStatus.Failed);
                return;
            }
        }
Example #29
0
        private static void GetIds(HashSet <CompoundIdentity> ids, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            if (ids.Count == 0)
            {
                RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                return;
            }

            try
            {
                SampleEventProviderBase provider = FieldActivityManager.Instance.GetSampleEventProvider(user);
                if (provider != null)
                {
                    IEnumerable <SamplingEvent> events = provider.Get(ids);
                    JArray jevents = Jsonifier.ToJson(events);

                    if (jevents != null)
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jevents.ToString()));
                    }
                    else
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, "[]"));
                    }
                    return;
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                return;
            }
        }
        public (bool success, string failureMessage) PluginUnPublish(string pluginId)
        {
            var status = _configService.Status;

            if (status == null || string.IsNullOrEmpty(status.UserName) || string.IsNullOrEmpty(status.AccessToken))
            {
                return(false, "you have not logged in");
            }

            var url = CloudUtils.Api.GetCliUrl(RestUrlPluginUnPublish);

            return(RestUtils.Post(url, new PluginUnPublishRequest
            {
                PluginId = pluginId
            }, status.AccessToken));

            //var client = new RestClient(CloudUtils.Api.GetCliUrl(RestUrlPluginUnPublish)) { Timeout = -1 };
            //var request = new RestRequest(Method.POST);
            //request.AddHeader("Content-Type", "application/json");
            //request.AddHeader("Authorization", $"Bearer {status.AccessToken}");
            //request.AddParameter("application/json", TranslateUtils.JsonSerialize(new PluginUnPublishRequest
            //{
            //    PluginId = pluginId
            //}), ParameterType.RequestBody);
            //var response = client.Execute(request);
            //if (!response.IsSuccessful)
            //{
            //    return (false, StringUtils.Trim(response.Content, '"'));
            //}

            //return (true, null);
        }