コード例 #1
0
ファイル: ExtendStreamItem.cs プロジェクト: deke/lokad-cqrs
 public static void ReadInto(this IStreamItem stream, Action <Stream> reader)
 {
     using (var read = stream.OpenRead())
     {
         reader(read);
     }
 }
コード例 #2
0
        public static Exception ContainerNotFound(IStreamItem item, Exception inner = null)
        {
            var message = string.Format(CultureInfo.InvariantCulture, "Storage container was not found for: '{0}'.",
                                        item.FullPath);

            return(new StreamContainerNotFoundException(message, inner));
        }
コード例 #3
0
ファイル: ExtendStreamItem.cs プロジェクト: deke/lokad-cqrs
 /// <summary>
 /// Performs the write operation, ensuring that the condition is met.
 /// </summary>
 /// <param name="stream"> </param>
 /// <param name="writer">The writer.</param>
 /// <returns>number of bytes written</returns>
 public static void Write(this IStreamItem stream, Action <Stream> writer)
 {
     using (var file = stream.OpenWrite())
     {
         writer(file);
     }
 }
コード例 #4
0
ファイル: ExtendStreamItem.cs プロジェクト: deke/lokad-cqrs
 /// <summary>
 /// Attempts to read the storage item.
 /// </summary>
 /// <param name="stream"> </param>
 /// <param name="reader">The reader.</param>
 /// <exception cref="StreamItemNotFoundException">if the item does not exist.</exception>
 /// <exception cref="StreamContainerNotFoundException">if the container for the item does not exist</exception>
 public static T ReadInto <T>(this IStreamItem stream, Func <Stream, T> reader)
 {
     using (var read = stream.OpenRead())
     {
         return(reader(read));
     }
 }
コード例 #5
0
ファイル: ExtendStreamItem.cs プロジェクト: deke/lokad-cqrs
 public static void WriteText(this IStreamItem item, string text, Encoding encoding)
 {
     item.Write(s =>
     {
         using (var writer = new StreamWriter(s, encoding))
         {
             writer.Write(text);
         }
     });
 }
コード例 #6
0
ファイル: ExtendStreamItem.cs プロジェクト: deke/lokad-cqrs
 public static string ReadText(this IStreamItem item)
 {
     return(item.ReadInto(stream =>
     {
         using (var reader = new StreamReader(stream))
         {
             return reader.ReadToEnd();
         }
     }));
 }
コード例 #7
0
        protected void ShouldHaveBytes(IStreamItem streamingItem, byte[] bytes)
        {
            byte[] actualBytes = null;

            using (var ms = new MemoryStream())
            {
                streamingItem.ReadInto((stream) =>
                {
                    stream.CopyTo(ms);
                    actualBytes = ms.ToArray();
                });
            }
            Assert.AreEqual(bytes, actualBytes);
        }
コード例 #8
0
        protected void ShouldHaveGuid(IStreamItem streamingItem, Guid g)
        {
            var  set    = false;
            Guid actual = Guid.Empty;

            streamingItem.ReadInto((stream) =>
            {
                var b = new byte[16];
                stream.Read(b, 0, 16);
                actual = new Guid(b);
                set    = true;
            });

            Assert.AreEqual(g, actual);


            set = true;

            Assert.IsTrue(set);
        }
コード例 #9
0
        public static IStreamItem ChooseStream(List <IStreamItem> streams)
        {
            Console.WriteLine("{0,-10}{1,-17}{2,-6}{3,-15}", "StreamID", "Type", "SN", "Model");
            //Print basic information for the user to select the stream they want
            foreach (IStreamItem stream in streams)
            {
                Console.WriteLine("{0,-10}{1,-17}{2,-6}{3,-15}", stream.StreamId, stream.CodecType, stream.DeviceSerialNumber, stream.ProductModel);
            }
            Console.WriteLine("\n");

            //User selects a stream
            Console.WriteLine("Choose a stream to view:");

            uint chosen_stream_id = 0;

            while (true)
            {
                try
                {
                    chosen_stream_id = Convert.ToUInt32(Console.ReadLine());
                }
                catch (System.Exception e)
                {
                    Console.WriteLine(e.Message);
                    continue;
                }

                IStreamItem chosen_stream = streams.Find(x => x.StreamId == chosen_stream_id);

                if (chosen_stream != null)
                {
                    Console.WriteLine("The selected m_streams device serial number was " + chosen_stream.DeviceSerialNumber);
                    return(chosen_stream);
                }
                else
                {
                    Console.WriteLine("Stream not found");
                }
            }
        }
コード例 #10
0
        private string DynamicStreamCheck(IStreamItem cachedStream, ISerie serie)
        {
            var title          = serie.Title;
            var progress       = serie.Progress;
            var correctedTitle = title.Replace(" ", cachedStream.WhitespaceReplacement);

            var hasTitle   = cachedStream.Website.Contains("{0}");
            var hasSeason  = cachedStream.Website.Contains("{1}");
            var hasEpisode = cachedStream.Website.Contains("{2}");

            if (!hasTitle && !hasSeason && !hasEpisode)
            {
                return(string.Empty);
            }
            if (hasTitle && !hasSeason && !hasEpisode)
            {
                return(string.Format(cachedStream.Website, correctedTitle));
            }
            if (hasTitle && hasSeason && !hasEpisode)
            {
                return(string.Format(cachedStream.Website, correctedTitle, progress.Season));
            }
            if (hasTitle && hasEpisode && !hasSeason)
            {
                var stream = cachedStream.Website.Replace("{2}", "{1}");
                if (this.IsValidUrl(string.Format(stream, correctedTitle, progress.CurrentEpisode)))
                {
                    return(string.Format(stream, correctedTitle, this.GetNextEpisode(progress)));
                }
            }

            if (this.IsValidUrl(string.Format(cachedStream.Website, correctedTitle, progress.Season, progress.CurrentEpisode)))
            {
                return(string.Format(cachedStream.Website, correctedTitle, progress.Season, this.GetNextEpisode(progress)));
            }

            return(string.Empty);
        }
コード例 #11
0
        private string DynamicStreamCheck(IStreamItem cachedStream, ISerie serie)
        {
            var title = serie.Title;
            var progress = serie.Progress;
            var correctedTitle = title.Replace(" ", cachedStream.WhitespaceReplacement);

            var hasTitle = cachedStream.Website.Contains("{0}");
            var hasSeason = cachedStream.Website.Contains("{1}");
            var hasEpisode = cachedStream.Website.Contains("{2}");

            if (!hasTitle && !hasSeason && !hasEpisode)
            {
                return string.Empty;
            }
            if (hasTitle && !hasSeason && !hasEpisode)
            {
                return string.Format(cachedStream.Website, correctedTitle);
            }
            if (hasTitle && hasSeason && !hasEpisode)
            {
                return string.Format(cachedStream.Website, correctedTitle, progress.Season);
            }
            if (hasTitle && hasEpisode && !hasSeason)
            {
                var stream = cachedStream.Website.Replace("{2}", "{1}");
                if (this.IsValidUrl(string.Format(stream, correctedTitle, progress.CurrentEpisode)))
                {
                    return string.Format(stream, correctedTitle, this.GetNextEpisode(progress));
                }
            }

            if (this.IsValidUrl(string.Format(cachedStream.Website, correctedTitle, progress.Season, progress.CurrentEpisode)))
            {
                return string.Format(cachedStream.Website, correctedTitle, progress.Season, this.GetNextEpisode(progress));
            }

            return string.Empty;
        }
コード例 #12
0
 public static Exception ItemNotFound(IStreamItem item, Exception inner = null)
 {
     var message = string.Format(CultureInfo.InvariantCulture, "Storage item was not found: '{0}'.",
         item.FullPath);
     return new StreamItemNotFoundException(message, inner);
 }
コード例 #13
0
 protected void TryToRead(IStreamItem item)
 {
     item.ReadInto((stream) => stream.Read(new byte[1], 0, 1));
 }
コード例 #14
0
 protected void Write(IStreamItem streamingItem, byte[] bytes)
 {
     streamingItem.Write(stream => stream.Write(bytes, 0, bytes.Length));
 }
コード例 #15
0
 protected void Write(IStreamItem streamingItem, Guid g)
 {
     streamingItem.Write(stream => stream.Write(g.ToByteArray(), 0, 16));
 }
コード例 #16
0
 public void SetUp()
 {
     TestContainer = GetContainer("tc-" + Guid.NewGuid().ToString().ToLowerInvariant());
     TestItem      = TestContainer.GetItem(Guid.NewGuid().ToString().ToLowerInvariant());
 }