本文整理汇总了C#中ICatalog.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ICatalog.Add方法的具体用法?C# ICatalog.Add怎么用?C# ICatalog.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICatalog
的用法示例。
在下文中一共展示了ICatalog.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCommand
public void ExecuteCommand(ICatalog catalog, ICommand command, StringBuilder sb)
{
switch (command.Type)
{
case Commands.AddBook:
catalog.Add(new CatalogContent(ContentTypes.Book, command.Parameters));
sb.AppendLine("Book added");
break;
case Commands.AddMovie:
catalog.Add(new CatalogContent(ContentTypes.Movie, command.Parameters));
sb.AppendLine("Movie added");
break;
case Commands.AddSong:
catalog.Add(new CatalogContent(ContentTypes.Song, command.Parameters));
sb.AppendLine("Song added");
break;
case Commands.AddApplication:
catalog.Add(new CatalogContent(ContentTypes.Application, command.Parameters));
sb.AppendLine("Application added");
break;
case Commands.Update:
UpdateCommand(catalog, command, sb);
break;
case Commands.Find:
FindCommand(command, catalog, sb);
break;
default:
throw new InvalidOperationException("Unknown command!");
}
}
示例2: ExecuteCommand
public void ExecuteCommand(ICatalog catalog, ICommand cmd, StringBuilder sb)
{
switch (cmd.Type)
{
case CommandType.AddBook:
catalog.Add(new ContentItem(ContentItemType.Book, cmd.Parameters));
sb.AppendLine("Book added");
break;
case CommandType.AddMovie:
catalog.Add(new ContentItem(ContentItemType.Movie, cmd.Parameters));
sb.AppendLine("Movie added");
break;
case CommandType.AddSong:
catalog.Add(new ContentItem(ContentItemType.Song, cmd.Parameters));
sb.AppendLine("Song added");
break;
case CommandType.AddApplication:
catalog.Add(new ContentItem(ContentItemType.Application, cmd.Parameters));
sb.AppendLine("Application added");
break;
case CommandType.Update:
if (cmd.Parameters.Length != 2)
{
throw new FormatException("Format exception");
}
var updatedItems = catalog.UpdateContent(cmd.Parameters[0], cmd.Parameters[1]);
sb.AppendLine(String.Format("{0} items updated", updatedItems));
break;
case CommandType.Find:
{
if (cmd.Parameters.Length != 2)
{
Console.WriteLine("Invalid params!");
throw new Exception("Invalid number of parameters!");
}
int numberOfElementsToList = int.Parse(cmd.Parameters[1]);
IEnumerable<IContent> foundContent = catalog.GetListContent(cmd.Parameters[0], numberOfElementsToList);
if (foundContent.Count() == 0)
{
sb.AppendLine("No items found");
}
else
{
foreach (IContent content in foundContent)
{
sb.AppendLine(content.TextRepresentation);
}
}
}
break;
default:
{
throw new InvalidCastException("Unknown command!");
}
}
}
示例3: ExecuteCommand
public void ExecuteCommand(ICatalog catalog, ICommand command, StringBuilder output)
{
switch (command.Type)
{
case CommandType.AddBook:
var book = new ContentItem(ContentItemType.Book, command.Parameters);
catalog.Add(book);
output.AppendLine("Book Added");
break;
case CommandType.AddMovie:
var movie = new ContentItem(ContentItemType.Movie, command.Parameters);
catalog.Add(movie);
output.AppendLine("Movie added");
break;
case CommandType.AddSong:
var song = new ContentItem(ContentItemType.Song, command.Parameters);
catalog.Add(song);
output.AppendLine("Song added");
break;
case CommandType.AddApplication:
var application = new ContentItem(ContentItemType.Application, command.Parameters);
catalog.Add(application);
output.AppendLine("Application added");
break;
case CommandType.Update:
ProcessUpdateCommand(catalog, command, output);
break;
case CommandType.Find:
ProcessFindCommand(catalog, command, output);
break;
default:
throw new InvalidOperationException("Unknown command!");
}
}
示例4: ExecuteCommand
public void ExecuteCommand(ICatalog catalog, ICommand commmand, StringBuilder output)
{
switch (commmand.Type)
{
case CommandType.AddBook:
{
catalog.Add(new Content(ContentType.Book, commmand.Parameters));
output.AppendLine("Book added");
break;
}
case CommandType.AddMovie:
{
catalog.Add(new Content(ContentType.Movie, commmand.Parameters));
output.AppendLine("Movie added");
break;
}
case CommandType.AddSong:
{
catalog.Add(new Content(ContentType.Song, commmand.Parameters));
output.AppendLine("Song added");
break;
}
case CommandType.AddApplication:
{
catalog.Add(new Content(ContentType.Application, commmand.Parameters));
output.AppendLine("Application added");
break;
}
case CommandType.Update:
{
if (commmand.Parameters.Length != 2)
{
throw new FormatException("Invalid parameteres count.");
}
int itemsUpdated = catalog.UpdateContent(commmand.Parameters[0], commmand.Parameters[1]);
string updatedInfo = String.Format("{0} items updated", itemsUpdated);
output.AppendLine(updatedInfo);
break;
}
case CommandType.Find:
{
if (commmand.Parameters.Length != 2)
{
throw new Exception("Invalid number of parameters!");
}
int numberOfElementsToList = int.Parse(commmand.Parameters[1]);
FindContent(catalog, commmand, output, numberOfElementsToList);
break;
}
default:
{
throw new ArgumentException("Unknown command type.");
}
}
}
示例5: ExecuteCommand
public void ExecuteCommand(ICatalog contentCatalog, ICommand command, StringBuilder output)
{
switch (command.Type)
{
case CommandType.AddBook:
contentCatalog.Add(new ContentItem(ContentType.Book, command.Parameters));
output.AppendLine("Book Added");
break;
case CommandType.AddMovie:
contentCatalog.Add(new ContentItem(ContentType.Movie, command.Parameters));
output.AppendLine("Movie added");
break;
case CommandType.AddSong:
contentCatalog.Add(new ContentItem(ContentType.Song, command.Parameters));
output.AppendLine("Song added");
break;
case CommandType.AddApplication:
contentCatalog.Add(new ContentItem(ContentType.Application, command.Parameters));
output.AppendLine("Application added");
break;
case CommandType.Update:
if (command.Parameters.Length != 2)
{
throw new FormatException("Invalid number of Parameters!");
}
string message = string.Format("{0} items updated", contentCatalog.UpdateContent(command.Parameters[0], command.Parameters[1]));
output.AppendLine(message);
break;
case CommandType.Find:
if (command.Parameters.Length != 2)
{
throw new FormatException("Invalid number of parameters!");
}
int numberOfElementsToList = int.Parse(command.Parameters[1]);
IEnumerable<IContent> foundContent = contentCatalog.GetListContent(command.Parameters[0], numberOfElementsToList);
if (foundContent.Count() == 0)
{
output.AppendLine("No items found");
}
else
{
foreach (IContent content in foundContent)
{
output.AppendLine(content.TextRepresentation);
}
}
break;
default:
throw new ArgumentException("Unknown command!");
}
}
示例6: ExecuteCommand
public void ExecuteCommand(ICatalog contentCatalog, ICommand command, StringBuilder output)
{
switch (command.Type)
{
case Commands.AddBook:
{
contentCatalog.Add(new Content(Contents.Book, command.Parameters));
output.AppendLine("Book Added");
}
break;
case Commands.AddMovie:
{
contentCatalog.Add(new Content(Contents.Movie, command.Parameters));
output.AppendLine("Movie added");
}
break;
case Commands.AddSong:
{
contentCatalog.Add(new Content(Contents.Song, command.Parameters));
output.AppendLine("Song added");
}
break;
case Commands.AddApplication:
{
contentCatalog.Add(new Content(Contents.Application, command.Parameters));
output.AppendLine("Application added");
}
break;
case Commands.Update:
{
UpdateItem(contentCatalog, command, output);
}
break;
case Commands.Find:
{
FindItem(contentCatalog, command, output);
}
break;
default:
{
throw new ArgumentException("Unknown command!");
}
}
}
示例7: ProcessAddCommand
private static void ProcessAddCommand(
ICatalog catalog,
ContentType contentType,
string[] parameters,
StringBuilder output)
{
IContent contentItem = new ContentItem(contentType, parameters);
catalog.Add(contentItem);
output.AppendFormat("{0} added{1}", contentType, Environment.NewLine);
}
示例8: ExecuteCommand
public void ExecuteCommand(ICatalog catalog, ICommand cmd, StringBuilder output)
{
switch (cmd.Type)
{
case CommandType.AddBook:
catalog.Add(new Content(ContentType.Book, cmd.Parameters));
output.AppendLine("Book added");
break;
case CommandType.AddMovie:
var item = new Content(ContentType.Movie, cmd.Parameters);
catalog.Add(item);
output.AppendLine("Movie added");
break;
case CommandType.AddSong:
catalog.Add(new Content(ContentType.Song, cmd.Parameters));
output.AppendLine("Song added");
break;
case CommandType.AddApplication:
catalog.Add(new Content(ContentType.Application, cmd.Parameters));
output.AppendLine("Application added");
break;
case CommandType.Update:
ProcessUpdateCommand(catalog, cmd, output);
break;
case CommandType.Find:
ProcessFindCommand(catalog, cmd, output);
break;
default:
throw new ArgumentException("Unknown command!");
}
}
示例9: ExecuteCommand
public void ExecuteCommand(ICatalog catalog, ICommandParser commandParser, StringBuilder stringBuilder)
{
switch (commandParser.Type)
{
case Command.AddBook:
{
catalog.Add(new Content(CatalogType.Book, commandParser.Parameters));
stringBuilder.AppendLine("Book added");
}
break;
case Command.AddMovie:
{
catalog.Add(new Content(CatalogType.Movie, commandParser.Parameters));
stringBuilder.AppendLine("Movie added");
}
break;
case Command.AddSong:
{
catalog.Add(new Content(CatalogType.Song, commandParser.Parameters));
stringBuilder.AppendLine("Song added");
}
break;
case Command.AddApplication:
{
catalog.Add(new Content(CatalogType.Application, commandParser.Parameters));
stringBuilder.AppendLine("Application added");
}
break;
case Command.Update:
{
if (commandParser.Parameters.Length != 2)
{
throw new FormatException("Invalid Parameters!");
}
stringBuilder.AppendLine(
string.Format(
"{0} items updated",
catalog.UpdateContent(commandParser.Parameters[0], commandParser.Parameters[1])));
}
break;
case Command.Find:
{
if (commandParser.Parameters.Length != 2)
{
Console.WriteLine("Invalid params!");
throw new Exception("Invalid number of parameters!");
}
var numberOfElementsToList = int.Parse(commandParser.Parameters[1]);
var foundContent = catalog.GetListContent(commandParser.Parameters[0], numberOfElementsToList);
var enumerable = foundContent as IContent[] ?? foundContent.ToArray();
if (!enumerable.Any())
{
stringBuilder.AppendLine("No items found");
}
else
{
foreach (var content in enumerable)
{
stringBuilder.AppendLine(content.ToString());
}
}
}
break;
default:
{
throw new InvalidCastException("Unknown command!");
}
}
}
示例10: Add
private void Add(ContentType contentType, ICommand command, ICatalog contentCatalog, StringBuilder output)
{
IContent currentBook = new Content(contentType, command.Parameters);
contentCatalog.Add(currentBook);
output.AppendLine(contentType + " added");
}
示例11: ExecuteCommand
public void ExecuteCommand(ICatalog contCat, ICommand command, StringBuilder output)
{
switch (command.Type)
{
case ContentCommand.AddBook:
contCat.Add(new Content(ContentType.Book, command.Parameters));
output.AppendLine("Book Added");
break;
case ContentCommand.AddMovie:
contCat.Add(new Content(ContentType.Movie, command.Parameters));
output.AppendLine("Movie added");
break;
case ContentCommand.AddSong:
contCat.Add(new Content(ContentType.Song, command.Parameters));
output.AppendLine("Song added");
break;
case ContentCommand.AddApplication:
contCat.Add(new Content(ContentType.Application, command.Parameters));
output.AppendLine("Application added");
break;
case ContentCommand.Update:
ProcessUpdateCommand(command, contCat, output);
break;
case ContentCommand.Find:
ProcessFindCommand(command, contCat, output);
break;
default:
throw new ArgumentException("Invalid command!");
}
}
示例12: ExecuteCommandAddApplication
private void ExecuteCommandAddApplication(ICommand command, ICatalog catalog, StringBuilder sb)
{
var application = new Content(ContentType.Application, command.Parameters);
catalog.Add(application);
sb.AppendLine("Application added");
}
示例13: AddContent
private void AddContent(ContentType type, ICatalog catalog, ICommand command, StringBuilder result)
{
catalog.Add(new Content(type, command.Parameters));
string updateSring = String.Format("{0} added", type.ToString());
this.UpdateResult(result, updateSring);
}
示例14: AddSongCommand
private static void AddSongCommand(ICatalog catalog, ICommand command, StringBuilder output)
{
catalog.Add(new Content(ContentTypes.Song, command.Parameters));
output.AppendLine("Song added");
}
示例15: ExecuteCommand
public void ExecuteCommand(ICatalog contCat, ICommand c, StringBuilder sb)
{
switch (c.Type)
{
case CommandTypes.AddBook:
{
contCat.Add(new CatalogItem(ContentType.Kniga, c.Parameters)
);sb.AppendLine("Books Added");
}break;
case CommandTypes.AddMovie:
{
contCat.Add(new CatalogItem(ContentType.Film, c.Parameters));
sb.AppendLine("Movie added");
}
break;
case CommandTypes.AddSong:
{
contCat.Add(new CatalogItem(ContentType.Muzika, c.Parameters));
sb.Append("Song added");
}
break;
case CommandTypes.AddApplication:
{
contCat.Add(new CatalogItem(ContentType.Prilozenie, c.Parameters));
sb.AppendLine("Application added");
}
break;
case CommandTypes.Update:
{
if (c.Parameters.Length == 2)
{
}
else
{
throw new FormatException("невалидни параметри!");
}
sb.AppendLine(String.Format("{0} items updated", contCat.UpdateContent(c.Parameters[0], c.Parameters[1]) - 1));
}
break;
case CommandTypes.Find:
{
if (c.Parameters.Length != 2)
{
Console.WriteLine("Invalid params!");
throw new Exception("Invalid number of parameters!");
}
Int32 numberOfElementsToList = Int32.Parse(c.Parameters[1]);
IEnumerable<IContent> foundContent = contCat.GetListContent(c.Parameters[0], numberOfElementsToList);
if (foundContent.Count() == 0)
{
sb.AppendLine("No items found");
}
else
{
foreach (IContent content in foundContent)
{
sb.AppendLine(content.TextRepresentation);
}
}
}
break;
default:
{
throw new InvalidCastException("Unknown command!");
}
}
}