예제 #1
0
        public async Task PutDirectoryAsync(Profile profile, string directory, SharingHandler <ISharingDirectorySender> handler)
        {
            if (profile == null || handler == null || !(profile is NotifyClientProfile receiver))
            {
                throw new ArgumentNullException();
            }
            var directoryInfo = new DirectoryInfo(directory);

            if (!directoryInfo.Exists)
            {
                throw new DirectoryNotFoundException("Directory not found!");
            }
            var packet = new { name = directoryInfo.Name };

            _ = await this.network.ConnectAsync("link.sharing.directory", packet, receiver.GetTcpEndPoint(), async stream =>
            {
                var result = await stream.ReadBlockWithHeaderAsync(this.settings.TcpBufferLimits, this.cancellationToken);
                var data   = new Token(this.generator, result);
                if (data["status"].As <string>() != "wait")
                {
                    throw new NetworkException(NetworkError.InvalidData);
                }
                using (var sender = new DirectorySender(this.context, receiver, stream, directoryInfo.FullName))
                {
                    await this.dispatcher.InvokeAsync(() => handler.Invoke(sender));
                    await sender.LoopAsync();
                }
                return(new Unit());
            }, this.cancellationToken);
        }
예제 #2
0
        private static Content GetSharingGroupByUrlParameter(NameValueCollection parameters)
        {
            var sharingGuid = parameters?[Constants.SharingUrlParameterName];

            return(string.IsNullOrEmpty(sharingGuid)
                ? null
                : SharingHandler.GetSharingGroupBySharingId(sharingGuid));
        }
        private Content GetSharingGroupByUrlParameter()
        {
            var sharingGuid = _httpContext?.Request.Query[Constants.SharingUrlParameterName];

            return(string.IsNullOrEmpty(sharingGuid)
                ? null
                : SharingHandler.GetSharingGroupBySharingId(sharingGuid));
        }
예제 #4
0
        private static void ExportDataPath(XmlWriter writer, string sharingData)
        {
            // Convert all ids to path in case of identity properties
            // to let other repository instances import sharing data.

            var sharingItems = SharingHandler.Deserialize(sharingData);
            var settings     = new JsonSerializerSettings
            {
                Converters            = { new IdToPathConverter() },
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                DateFormatHandling    = DateFormatHandling.IsoDateFormat,
                Formatting            = Formatting.Indented
            };

            writer.WriteString(JsonConvert.SerializeObject(sharingItems, settings));
        }
        internal MembershipExtension GetSharingExtension(string contextValue)
        {
            // check the url first
            var sharingGroup = GetSharingGroupByUrlParameter()?.ContentHandler as Group;

            // check the context param next
            if (sharingGroup == null && contextValue != null)
            {
                sharingGroup = SharingHandler.GetSharingGroupBySharingId(contextValue)?.ContentHandler as Group;
            }

            if (sharingGroup == null)
            {
                return(MembershipExtension.Placeholder);
            }

            var sharedNode = sharingGroup.GetReference <GenericContent>(Constants.SharedContentFieldName);

            // Check if the related shared content exists.
            if (sharedNode == null)
            {
                // Invalid sharing group: no related content. Delete the group and move on.
                SnTrace.Security.Write($"SharingMembershipExtender: Deleting orphaned sharing group {sharingGroup.Id} ({sharingGroup.Path}).");

                sharingGroup.ForceDelete();
                sharingGroup = null;
            }

            // If found and the content is not in the Trash, return a new extension collection
            // containing the sharing group.
            if ((sharingGroup?.ContentType.IsInstaceOfOrDerivedFrom(Constants.SharingGroupTypeName) ?? false) &&
                !TrashBin.IsInTrash(sharedNode))
            {
                return(new MembershipExtension(new[] { sharingGroup.Id }));
            }

            return(MembershipExtension.Placeholder);
        }