예제 #1
0
        public static void EditMagazine(MagazineView mag, string[] selectedCourses, MagazineService db, HttpPostedFileBase File = null)
        {
            if (selectedCourses == null)
            {
                selectedCourses = new string[] { };
            }
            if (File != null)
            {
                mag.ImageMimeType = File.ContentType;
                mag.ImageData     = new byte[File.ContentLength];
                File.InputStream.Read(mag.ImageData, 0, File.ContentLength);
            }
            WriterService ws = new WriterService();
            var           selectedCoursesHS = new HashSet <string>(selectedCourses);


            var allwriter = db.GetAllArticle();
            var newwriter = new List <ArticleView>();

            mag.Articles = new List <ArticleView>();

            foreach (var t in allwriter)
            {
                if (selectedCoursesHS.Contains(t.id.ToString()))
                {
                    mag.Articles.Add(t);
                }
            }



            db.Update(mag);
        }
예제 #2
0
        public static void EditBook(BookView book, string[] selectedCourses, BookService db, HttpPostedFileBase Image = null)
        {
            if (selectedCourses == null)
            {
                selectedCourses = new string[] { };
            }
            if (Image != null)
            {
                book.ImageMimeType = Image.ContentType;
                book.ImageData     = new byte[Image.ContentLength];
                Image.InputStream.Read(book.ImageData, 0, Image.ContentLength);
            }

            WriterService ws = new WriterService();
            var           selectedCoursesHS = new HashSet <string>(selectedCourses);


            var allwriter = db.GetAllWriter();
            var newwriter = new List <WriterView>();

            book.Writers = new List <WriterView>();

            foreach (var t in allwriter)
            {
                if (selectedCoursesHS.Contains(t.id.ToString()))
                {
                    book.Writers.Add(t);
                }
            }



            db.Update(book);
        }
예제 #3
0
        private WriterService CreateWriterService()
        {
            var authorId = Guid.Parse(User.Identity.GetUserId());
            var Service  = new WriterService(authorId);

            return(Service);
        }
예제 #4
0
        public IHttpActionResult Get(int id)
        {
            WriterService writerService = CreateWriterService();
            var           writer        = writerService.GetWriterById(id);

            return(Ok(writer));
        }
예제 #5
0
        public IHttpActionResult Get()
        {
            WriterService writerService = CreateWriterService();
            var           writers       = writerService.GetWriters();

            return(Ok(writers));
        }
예제 #6
0
        static void Main(string[] args)
        {
            const string fileName = @"C:\Users\MRMacDonnell\Desktop\NotepadDocs\SavingsCalc.csv";
            bool         inUse    = false;

            do
            {
                try
                {
                    if (!File.Exists(fileName))
                    {
                        File.Create(fileName).Dispose();
                    }
                    var writerService = new WriterService(fileName);

                    var interestCalculator = new CalculateInterestService(writerService);
                    var header             = string.Join(",", "Timestamp", "Expected Value", "Interest Value", "InterestRate", "Payment/Check",
                                                         "Estimated Income", "Estimated Yearly Interest");
                    var footer = string.Join(",", "My Age", "Final Result");

                    writerService.LogInformation(header);
                    var startDate = new DateTime(2018, 6, 30);
                    interestCalculator.CalculateInterestByMonths(4030.02m, 0.0175m, 250, 500, startDate);
                    //writerService.LogInformation(footer);
                    writerService.DisposeWriter();
                    inUse = false;
                }
                catch (Exception ex)
                {
                    inUse = true;
                    Console.WriteLine(ex);
                    Thread.Sleep(10000);
                }
            }while (inUse);
        }
예제 #7
0
        public void Call(WriterService writerService, string outputFilePath)
        {
            service = writerService;

            outputStream = File.Create(outputFilePath);

            new Thread(WriterWorkerStart).Start();
        }
    public static void Main(string[] args)
    {
        var s = new WriterService(new WriterA());

        s.Write("Hello!");
        WriterService.WithA().Write("Hello again!");
        WriterService.WithB().Write("And again!");
    }
예제 #9
0
 public BooksController(DatabaseContext context, BookService bookService, WriterService writerService, PublisherService publisherService, AuthorService authorService)
 {
     _context          = context;
     _bookService      = bookService;
     _writerService    = writerService;
     _publisherService = publisherService;
     _authorService    = authorService;
 }
 public ScriptGenerationService(
     IServiceProvider prov,
     IOptions <MoldsterModuleOptions> opt,
     IOutputWriter output) : base(output)
 {
     _store  = new InstanceStore <object>(prov);
     _opts   = opt.Value;
     _writer = new WriterService();
 }
예제 #11
0
 public ScriptModelMappingService(
     IMoldProvider mold,
     IPathsService paths,
     IConfigUnit unit,
     IOutputWriter output) : base(output)
 {
     _writer   = new WriterService();
     _molds    = mold;
     _paths    = paths;
     this.unit = unit;
 }
예제 #12
0
        public ActionResult GetWriter([FromRoute] Guid idWriter)
        {
            var writer = WriterService.ShowWriter(idWriter);

            if (writer == null)
            {
                return(NotFound());
            }

            return(Ok(writer));
        }
예제 #13
0
        public ActionResult <Writer> PutWriter([FromRoute] Guid idWriter, Writer writer)
        {
            if (idWriter != writer.Id)
            {
                return(BadRequest());
            }

            WriterService.UpdateWriter(idWriter, writer);

            return(Ok(writer));
        }
예제 #14
0
        private static void Main()
        {
            var writerType = ConfigurationManager.AppSettings["MessageWriter"];

            var writer = new WriterService().GetWriter(writerType);

            var repository = new ConsoleMessageRepository(writer);

            repository.WriteMessage();

            System.Console.ReadLine();
        }
예제 #15
0
 public LocalizationService(
     IMoldProvider molds,
     IConfigUnit unit,
     IPathsService paths,
     IUIFileNameService names,
     IOutputWriter output) : base(output)
 {
     _writer    = new WriterService();
     _paths     = paths;
     this.names = names;
     _molds     = molds;
     _unit      = unit;
 }
예제 #16
0
        public ActionResult <Writer> DeleteWriter([FromRoute] Guid idWriter)
        {
            var writer = WriterService.ShowWriter(idWriter);

            if (writer == null)
            {
                return(NotFound());
            }

            WriterService.DeleteWriter(idWriter);

            return(NoContent());
        }
예제 #17
0
        public BundlingService(

            IPathsService paths,
            IMoldProvider molds,
            IDataService data,
            IUIFileNameService names,
            IOutputWriter output) : base(output)
        {
            _paths  = paths;
            _writer = new WriterService();
            _molds  = molds;
            _data   = data;
            _names  = names;
        }
예제 #18
0
        private void button1_Click(object sender, EventArgs e)
        {
            WriterService writerService = new WriterService();
            BookService   bookService   = new BookService();
            int           ID            = Convert.ToInt32(textBox1.Text);

            dataGridView1.DataSource = bookService.GetAllBook(ID);

            //WriterDTO writerDTO = new WriterDTO();
            //BookDTO bookDTO = new BookDTO();
            ////writerDTO.Name = textBox1.Text;
            ////writerDTO.Surname = textBox2.Text;
            //bookDTO.Name = textBox1.Text;
            //bookDTO.ReleaseDate = DateTime.Today;
            ////writerService.Adding(writerDTO);
            //bookService.Adding(bookDTO);
        }
예제 #19
0
        public void RemoveWriter_ShouldRemoveWriter()
        {
            // Arrange
            var mock = new Mock <IWriterRepository>();

            mock.Setup(a => a.ContainsId(It.IsAny <int>())).Returns(true);
            var writerService = new WriterService(mock.Object);
            var Id            = 12;

            // Act
            writerService.RemoveWriter(Id);

            // Assert
            mock.Verify(a => a.Remove(It.IsAny <WriterEntity>()));
            mock.Verify(a => a.Save());
            mock.Verify(a => a.GetById(Id));
        }
        private void WriterInitialization(CompressionMode operationType,
                                          string outputFilePath)
        {
            BaseWriterLogic logic;

            if (operationType == CompressionMode.Compress)
            {
                logic = new CompressWriterLogic();
            }
            else
            {
                logic = new DecompressWriterLogic();
            }

            var service = new WriterService(queue, monitor);

            logic.Call(service, outputFilePath);
        }
예제 #21
0
        public ActionResult Index(string Id)
        {
            // ID = User name.
            var userName = Id;

            if (!ValidationService.ValidateWriterName(userName).Validated)
            {
                SessionService.AddMessage(HttpContext.Session, "Your name was invalid.");
                return(View());
            }

            var writer = WriterService.Create(userName);

            ApplicationService.AddWriter(writer);
            HttpContext.Session.SetString(SessionVariables.UserId, writer.Identifier.ToString());

            return(RedirectToAction("Start"));
        }
예제 #22
0
파일: StoryHub.cs 프로젝트: abc/Storyteller
        public void SubmitFragment(string fragment)
        {
            var writer = WriterService.GetWriterFromConnection(Context.ConnectionId);
            var room   = RoomService.GetRoomFromConnection(Context.ConnectionId);

            if ((writer == null) || (room == null))
            {
                throw new InvalidOperationException();
            }

            if (!string.IsNullOrWhiteSpace(fragment))
            {
                RoomService.RegisterFragment(room, writer, fragment);
            }

            // Notify the other users of the new fragment.
            Clients.Group("room-" + room.Code).SendAsync("newFragment", fragment);
        }
예제 #23
0
        public void GetAllWriter_ShouldGetAllWriter()
        {
            // Arrange
            var mock = new Mock <IWriterRepository>();
            // var listEntity = new Fixture().Create<IEnumerable<BookEntity>>();
            var listEntity = new List <WriterEntity>();

            mock.Setup(a => a.ContainsId(It.IsAny <int>())).Returns(true);
            mock.Setup(a => a.GetAll()).Returns(listEntity);
            var writerService = new WriterService(mock.Object);
            var Id            = 12;

            // Act
            var resylt = writerService.GetAllWriter();

            // Assert
            mock.Verify(a => a.GetAll());
            Assert.AreEqual(resylt, listEntity);
        }
예제 #24
0
파일: StoryHub.cs 프로젝트: abc/Storyteller
        public void JoinRoom(string writerId, string roomCode)
        {
            // Find the writer and the room.
            WriterService.LinkWriterToConnection(writerId, Context.ConnectionId);
            RoomService.LinkRoomToConnection(roomCode, Context.ConnectionId);

            var writer = ApplicationService.FindWriter(writerId);
            var room   = ApplicationService.FindRoom(roomCode);

            // Add the user to the room.
            Groups.AddToGroupAsync(Context.ConnectionId, "room-" + roomCode);

            room.AbsentWriters.RemoveAll(w => w.Identifier == writer.Identifier);
            room.PresentWriters.Add(writer);

            // Notify other users in the room that the user joined.
            Clients.Group("room-" + roomCode).SendAsync("userJoined", room);
            Clients.Client(Context.ConnectionId).SendAsync("welcome", room);
        }
예제 #25
0
        public void GetWriterById_ShouldGetWriterById()
        {
            // Arrange
            var Id           = 12;
            var mock         = new Mock <IWriterRepository>();
            var writerEntity = new WriterEntity {
                Id = Id
            };

            mock.Setup(a => a.GetById(It.IsAny <int>())).Returns(writerEntity);
            mock.Setup(a => a.ContainsId(It.IsAny <int>())).Returns(true);
            var writerService = new WriterService(mock.Object);

            // Act
            var resylt = writerService.GetWriterById(Id);

            // Assert
            mock.Verify(a => a.GetById(Id));
            Assert.AreEqual(resylt, writerEntity);
        }
예제 #26
0
파일: StoryHub.cs 프로젝트: abc/Storyteller
        public override Task OnDisconnectedAsync(Exception exception)
        {
            // Find the writer and the room.
            var writer = WriterService.GetWriterFromConnection(Context.ConnectionId);
            var room   = RoomService.GetRoomFromConnection(Context.ConnectionId);

            if ((writer != null) || (room != null))
            {
                // Remove the user from the room.
                Groups.RemoveFromGroupAsync(Context.ConnectionId, "room" + room.Code);

                room.PresentWriters.RemoveAll(w => w.Identifier == writer.Identifier);
                room.AbsentWriters.Add(writer);

                // Notify other users in the room that the user left.
                Clients.Group("room-" + room.Code).SendAsync("userLeft", room);
            }

            return(base.OnDisconnectedAsync(exception));
        }
예제 #27
0
파일: StoryHub.cs 프로젝트: abc/Storyteller
        public void LeaveRoom()
        {
            // Find the writer and the room.
            var writer = WriterService.GetWriterFromConnection(Context.ConnectionId);
            var room   = RoomService.GetRoomFromConnection(Context.ConnectionId);

            if ((writer == null) || (room == null))
            {
                throw new InvalidOperationException();
            }

            // Remove the user from the room.
            Groups.RemoveFromGroupAsync(Context.ConnectionId, "room" + room.Code);

            room.PresentWriters.RemoveAll(w => w.Identifier == writer.Identifier);
            room.AbsentWriters.Add(writer);

            // Notify other users in the room that the user left.
            Clients.Group("room-" + room.Code).SendAsync("userLeft", room);
        }
예제 #28
0
        /// <summary>
        /// Creates or updates a given file resource in the file system.
        /// </summary>
        /// <param name="virtualFilePath">The qualified path of the file to be created.</param>
        /// <param name="input">A stream that provides the file's contents.</param>
        /// <param name="overwrite">Whether an existing file should be overwritten
        /// or not. If this parameter is false and the file already exists, a
        /// <see cref="ResourceOverwriteException"/> is thrown.</param>
        /// <param name="resourceLength">The length of the resource to be uploaded in bytes.</param>
        /// <param name="contentType">The content type of the uploaded resource.</param>
        /// <exception cref="ResourceAccessException">In case of invalid or prohibited
        /// resource access.</exception>
        /// <exception cref="ResourceOverwriteException">If a file already exists at the
        /// specified location, and the <paramref name="overwrite"/> flag was not set.</exception>
        /// <exception cref="ArgumentNullException">If any of the parameters is a null reference.</exception>
        public override VirtualFileInfo WriteFile(string virtualFilePath, Stream input, bool overwrite, long resourceLength,
                                                  string contentType)
        {
            var fileContract = SecureFunc(FileSystemTask.StreamedFileUploadRequest,
                                          () =>
            {
                WriteFileDataContract contract = new WriteFileDataContract
                {
                    Data           = input,
                    Overwrite      = overwrite,
                    FilePath       = virtualFilePath,
                    ResourceLength = resourceLength,
                    ContentType    = contentType
                };
                return(WriterService.WriteFile(contract));
            },
                                          () =>
                                          String.Format("Could not write data for file [{0}] to file system.", virtualFilePath));

            return(fileContract.FileInfo);
        }
예제 #29
0
파일: StoryHub.cs 프로젝트: abc/Storyteller
        public void CastVote(string fragmentId)
        {
            var writer = WriterService.GetWriterFromConnection(Context.ConnectionId);
            var room   = RoomService.GetRoomFromConnection(Context.ConnectionId);

            if ((writer == null) || (room == null))
            {
                throw new InvalidOperationException();
            }

            if (!string.IsNullOrWhiteSpace(fragmentId))
            {
                var fragment = room.FrameFragments.Where(f => f.Identifier.ToString() == fragmentId).Single();
                if (fragment.Author.Identifier != writer.Identifier)
                {
                    // Refuse to register votes for fragments the user wrote themselves.
                    RoomService.RegisterVote(room, writer, fragmentId);
                }
            }

            // Notify the other users of the cast vote.
            Clients.Group("room-" + room.Code).SendAsync("voteCast", writer.Identifier, fragmentId);
        }
예제 #30
0
파일: StoryHub.cs 프로젝트: abc/Storyteller
        public void StartGame()
        {
            var writer = WriterService.GetWriterFromConnection(Context.ConnectionId);
            var room   = RoomService.GetRoomFromConnection(Context.ConnectionId);

            if ((writer == null) || (room == null))
            {
                throw new InvalidOperationException();
            }

            if (room.Owner.Identifier != writer.Identifier)
            {
                throw new InvalidOperationException();
            }

            if (room.Started)
            {
                throw new InvalidOperationException();
            }

            room.Start();
            Clients.Group("room-" + room.Code).SendAsync("gameStarted", room);
        }