Пример #1
0
        /// <summary>
        /// The create from json.
        /// </summary>
        /// <param name="serializedSubscription">
        /// The serialized subscription.
        /// </param>
        /// <returns>
        /// The <see cref="MamChannelSubscription"/>.
        /// </returns>
        public MamChannelSubscription CreateFromJson(string serializedSubscription)
        {
            var unserializedSubscriptionData = JsonConvert.DeserializeObject <dynamic>(serializedSubscription);

            var channelSubscription = new MamChannelSubscription(this.Repository, this.Parser, this.Mask);

            var nextRootValue = (string)unserializedSubscriptionData.NextRoot.Value;

            if (nextRootValue == null)
            {
                channelSubscription.Init(
                    new Hash((string)unserializedSubscriptionData.MessageRoot.Value),
                    (Mode)unserializedSubscriptionData.Mode,
                    new TryteString((string)unserializedSubscriptionData.Key.Value));
            }
            else
            {
                channelSubscription.Init(
                    new Hash((string)unserializedSubscriptionData.MessageRoot.Value),
                    (Mode)unserializedSubscriptionData.Mode,
                    new TryteString((string)unserializedSubscriptionData.Key.Value),
                    new Hash(nextRootValue));
            }



            return(channelSubscription);
        }
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="root">
        /// The message root.
        /// </param>
        /// <param name="mode">
        /// The mode.
        /// </param>
        /// <param name="channelKey">
        /// The channel key.
        /// </param>
        /// <returns>
        /// The <see cref="MamChannelSubscription"/>.
        /// </returns>
        public MamChannelSubscription Create(Hash root, Mode mode, TryteString channelKey = null)
        {
            var channelSubscription = new MamChannelSubscription(this.Repository, this.Parser, this.Mask);

            channelSubscription.Init(root, mode, channelKey);

            return(channelSubscription);
        }
Пример #3
0
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="root">
        /// The message root.
        /// </param>
        /// <param name="mode">
        /// The mode.
        /// </param>
        /// <param name="channelKey">
        /// The channel key.
        /// </param>
        /// <returns>
        /// The <see cref="MamChannelSubscription"/>.
        /// </returns>
        public MamChannelSubscription Create(Hash root, Mode mode, string channelKey = null, bool keyIsTrytes = false)
        {
            var channelSubscription = new MamChannelSubscription(this.Repository, this.Parser, this.Mask);

            channelSubscription.Init(
                root,
                mode,
                channelKey != null ? keyIsTrytes ? new TryteString(channelKey) : TryteString.FromAsciiString(channelKey) : Hash.Empty);

            return(channelSubscription);
        }