Ejemplo n.º 1
0
        /// <summary>
        /// Shares on store.
        /// </summary>
        /// <param name="identifier">Identifier.</param>
        /// <param name="type">Type.</param>
        /// <param name="users">Users.</param>
        /// <param name="communities">Communities.</param>
        public static void ShareOnStore(string origin, string identifier, string type, string visibility, List <string> users = null, List <ThematicCommunity> communities = null)
        {
            var shareInput = new StoreShareRequest {
                origin     = origin,
                type       = type,
                identifier = identifier,
                visibility = visibility
            };

            if (users != null)
            {
                shareInput.users = new List <StoreShareUser>();
                foreach (var usr in users)
                {
                    shareInput.users.Add(new StoreShareUser {
                        username = usr
                    });
                }
            }
            if (communities != null)
            {
                shareInput.communities = new List <StoreShareCommunity>();
                foreach (var c in communities)
                {
                    var cUsers  = c.GetUsers();
                    var scUsers = new List <StoreShareUser>();
                    foreach (var usr in cUsers)
                    {
                        if (!c.IsUserPending(usr.Id))
                        {
                            if (string.IsNullOrEmpty(usr.TerradueCloudUsername))
                            {
                                usr.LoadCloudUsername();
                            }
                            if (!string.IsNullOrEmpty(usr.TerradueCloudUsername))
                            {
                                scUsers.Add(new StoreShareUser {
                                    username = usr.TerradueCloudUsername
                                });
                            }
                        }
                    }
                    shareInput.communities.Add(new StoreShareCommunity {
                        identifier = c.Identifier, users = scUsers
                    });
                }
            }
            var payload = JsonSerializer.SerializeToString <StoreShareRequest>(shareInput);

            ShareRequest shareRequest = ShareRequest.LoadFromJsonString(payload, new ArtifactoryBaseUrl(dataGatewayBaseUrl, dataGatewayApikey));

            shareRequest.ExecuteAsync(new System.Threading.CancellationToken());
        }
Ejemplo n.º 2
0
        internal static ShareRequest LoadFromJsonString(string payload, ArtifactoryBaseUrl storeBaseUrl)
        {
            JsonSerializer serializer = new JsonSerializer();

            serializer.ContractResolver  = new CamelCasePropertyNamesContractResolver();
            serializer.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;

            ShareRequest shareRequest = (ShareRequest)serializer.Deserialize(new StringReader(payload), typeof(ShareRequest));

            shareRequest.storeBaseUrl = storeBaseUrl;

            return(shareRequest);
        }