public Publisher GetById(PublisherId id) { using (var context = new ApplicationContext()) { var entity = LoadWithNoTracking(context, id); return(GetDomainResult(entity)); } }
public async Task ChangePublisher(Book a, PublisherId publisherId) { var book = await Context.Books.FindAsync(a.Id).ConfigureAwait(false); var publisher = await GetPublisherAsync(publisherId).ConfigureAwait(false); book.SetPublisher(publisher); await Context.SaveChangesAsync().ConfigureAwait(false); }
private static string PublisherIdToString(PublisherId publisherId, int payloadLength, INTV.Core.Utility.BinaryReader reader) { var publisher = string.Empty; var shouldReadMore = false; switch (publisherId) { case PublisherId.MattelElectronics: publisher = "Mattel Electronics"; break; case PublisherId.INTVCorp: publisher = "INTV Corporation"; break; case PublisherId.Imagic: publisher = "Imagic"; break; case PublisherId.Activision: publisher = "Activision"; break; case PublisherId.Atarisoft: publisher = "Atarisoft"; break; case PublisherId.Coleco: publisher = "Coleco"; break; case PublisherId.CBS: publisher = "CBS"; break; case PublisherId.ParkerBros: publisher = "Parker Brothers"; break; case PublisherId.Other: default: shouldReadMore = true; break; } var remainingPayload = payloadLength - sizeof(PublisherId); if (remainingPayload > 0) { var publisherData = reader.ParseStringFromMetadata((uint)remainingPayload, allowLineBreaks: false); if (shouldReadMore) { publisher = publisherData; } } return(publisher); }
/// <summary> /// Serves as a hash function for a particular type. /// </summary> /// <returns>A hash code for the current <see cref="T:System.Object" />.</returns> public override int GetHashCode() { return(Architecture.GetHashCode() ^ DisplayName?.GetHashCode() ?? 0 ^ InstallLocation?.GetHashCode() ?? 0 ^ PackageName?.GetHashCode() ?? 0 ^ PublisherId?.GetHashCode() ?? 0 ^ ResourceId?.GetHashCode() ?? 0 ^ Version.GetHashCode()); }
private PublisherEntity LoadWithNoTracking(ApplicationContext context, PublisherId id) { var entity = context.Publisher .AsNoTracking() .Include(p => p.PublisherAccounts) .ThenInclude(pa => pa.SocialAccount) .FirstOrDefault(p => p.Id == id.Value); return(entity); }
public static Task CreateInvalidPublisher() { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new BookOrganizer2DbContext(connectionString); var repository = new PublisherRepository(context); var publisherService = new PublisherService(repository); var publisherId = new PublisherId(SequentialGuid.NewSequentialGuid()); var command = new Commands.Create { Id = publisherId }; return(publisherService.Handle(command)); }
// DELETE public static Task RemovePublisher(PublisherId id) { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new BookOrganizer2DbContext(connectionString); var repository = new PublisherRepository(context); var publisherService = new PublisherService(repository); var command = new Commands.DeletePublisher { Id = id, }; return(publisherService.Handle(command)); }
public override string ToString() { var sb = new StringBuilder(); sb.Append("Key : "); sb.AppendLine(Key); sb.Append("Mod Hash : "); sb.AppendLine(Hash.ToString("x")); sb.Append("Mod PubId : "); sb.AppendLine(PublisherId.ToString()); sb.Append("Mod String: "); sb.AppendLine(Name); return(sb.ToString()); }
public static Task UpdatePublisherDescription(PublisherId id, string description) { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new BookOrganizer2DbContext(connectionString); var repository = new PublisherRepository(context); var publisherService = new PublisherService(repository); var command = new Commands.SetDescription() { Id = id, Description = description }; return(publisherService.Handle(command)); }
public static Task UpdatePublisherLogoPath(PublisherId id, string path) { var connectionString = ConnectivityService.GetConnectionString("TEMP"); var context = new BookOrganizer2DbContext(connectionString); var repository = new PublisherRepository(context); var publisherService = new PublisherService(repository); var command = new Commands.SetLogoPath { Id = id, LogoPath = path }; return(publisherService.Handle(command)); }
static void Main(string[] args) { PublisherId id = new PublisherId(Guid.Parse("6679C0E9-1C2C-4F99-9EB1-ED892225176B")); // John PublisherRepository repository = new PublisherRepository(); var publisher = repository.GetById(id); var account = publisher.AssignedSocialAccounts.FirstOrDefault(asa => asa.Email == "*****@*****.**"); publisher.ChangePublisherName("Derick"); publisher.ChangeAccountEmail(account, "*****@*****.**"); repository.Update(publisher); Console.ReadKey(); }
public virtual void Validate(ValidationResult result) { Title.ValidateRequired(result, nameof(Title)); Title.ValidateMaxLength(result, nameof(Title), 150); Category.ValidateRequired(result, nameof(Category)); DatePublished.ValidateRequired(result, nameof(DatePublished)); PublisherId.ValidateRequired(result, nameof(PublisherId)); foreach (var page in Pages) { page.Validate(result); } }
/// <summary> /// Decode the stream from decoder parameter and produce a Dataset /// </summary> /// <param name="binaryDecoder"></param> /// <param name="dataSetReaders"></param> /// <returns></returns> public void DecodeSubscribedDataSets(BinaryDecoder binaryDecoder, IList <DataSetReaderDataType> dataSetReaders) { if (dataSetReaders == null || dataSetReaders.Count == 0) { return; } try { List <DataSetReaderDataType> dataSetReadersFiltered = new List <DataSetReaderDataType>(); // 1. decode network message header (PublisherId & DataSetClassId) DecodeNetworkMessageHeader(binaryDecoder); //ignore network messages that are not dataSet messages if (m_uadpNetworkMessageType != UADPNetworkMessageType.DataSetMessage) { return; } /* 6.2.8.1 PublisherId * The parameter PublisherId defines the Publisher to receive NetworkMessages from. * If the value is null, the parameter shall be ignored and all received NetworkMessages pass the PublisherId filter. */ foreach (DataSetReaderDataType dataSetReader in dataSetReaders) { //check Enabled & publisher id if (dataSetReader.PublisherId.Value == null || (PublisherId != null && PublisherId.Equals(dataSetReader.PublisherId.Value))) { dataSetReadersFiltered.Add(dataSetReader); } } if (dataSetReadersFiltered.Count == 0) { return; } dataSetReaders = dataSetReadersFiltered; //continue filtering dataSetReadersFiltered = new List <DataSetReaderDataType>(); // 2. decode WriterGroupId DecodeGroupMessageHeader(binaryDecoder); /* 6.2.8.2 WriterGroupId * The parameter WriterGroupId with DataType UInt16 defines the identifier of the corresponding WriterGroup. * The default value 0 is defined as null value, and means this parameter shall be ignored.*/ foreach (DataSetReaderDataType dataSetReader in dataSetReaders) { //check WriterGroupId id if (dataSetReader.WriterGroupId == 0 || dataSetReader.WriterGroupId == WriterGroupId) { dataSetReadersFiltered.Add(dataSetReader); } } if (dataSetReadersFiltered.Count == 0) { return; } dataSetReaders = dataSetReadersFiltered; // 3. decode payload header DecodePayloadHeader(binaryDecoder); // 4. DecodeExtendedNetworkMessageHeader(binaryDecoder); // 5. DecodeSecurityHeader(binaryDecoder); //6.1 DecodePayloadSize(binaryDecoder); // the list of decode dataset messages for this network message List <UaDataSetMessage> dataSetMessages = new List <UaDataSetMessage>(); /* 6.2.8.3 DataSetWriterId * The parameter DataSetWriterId with DataType UInt16 defines the DataSet selected in the Publisher for the DataSetReader. * If the value is 0 (null), the parameter shall be ignored and all received DataSetMessages pass the DataSetWriterId filter.*/ foreach (DataSetReaderDataType dataSetReader in dataSetReaders) { List <UaDataSetMessage> uadpDataSetMessages = new List <UaDataSetMessage>(DataSetMessages); //if there is no information regarding dataSet in network message, add dummy datasetMessage to try decoding if (uadpDataSetMessages.Count == 0) { uadpDataSetMessages.Add(new UadpDataSetMessage()); } // 6.2 Decode payload into DataSets // Restore the encoded fields (into dataset for now) for each possible dataset reader foreach (UadpDataSetMessage uadpDataSetMessage in uadpDataSetMessages) { if (uadpDataSetMessage.DataSet != null) { continue; // this dataset message was already decoded } if (dataSetReader.DataSetWriterId == 0 || uadpDataSetMessage.DataSetWriterId == dataSetReader.DataSetWriterId) { //atempt to decode dataset message using the reader uadpDataSetMessage.DecodePossibleDataSetReader(binaryDecoder, dataSetReader); if (uadpDataSetMessage.DataSet != null) { dataSetMessages.Add(uadpDataSetMessage); } } } } if (m_uaDataSetMessages.Count == 0) { // set the list of dataset messages to the network message m_uaDataSetMessages.AddRange(dataSetMessages); } } catch (Exception ex) { // Unexpected exception in DecodeSubscribedDataSets Utils.Trace(ex, "UadpNetworkMessage.DecodeSubscribedDataSets"); } }
/// <summary> /// Decode the stream from decoder parameter and produce a Dataset /// </summary> /// <param name="jsonDecoder"></param> /// <param name="dataSetReaders"></param> /// <returns></returns> public void DecodeSubscribedDataSets(JsonDecoder jsonDecoder, IEnumerable <DataSetReaderDataType> dataSetReaders) { try { List <DataSetReaderDataType> dataSetReadersFiltered = new List <DataSetReaderDataType>(); // 1. decode network message header (PublisherId & DataSetClassId) DecodeNetworkMessageHeader(jsonDecoder); // ignore network messages that are not dataSet messages if (m_jsonNetworkMessageType != JSONNetworkMessageType.DataSetMessage) { return; } //* 6.2.8.1 PublisherId // The parameter PublisherId defines the Publisher to receive NetworkMessages from. // If the value is null, the parameter shall be ignored and all received NetworkMessages pass the PublisherId filter. */ foreach (DataSetReaderDataType dataSetReader in dataSetReaders) { if (dataSetReader.PublisherId == Variant.Null) { dataSetReadersFiltered.Add(dataSetReader); } // publisher id else if ((NetworkMessageContentMask & JsonNetworkMessageContentMask.PublisherId) != 0 && PublisherId != null && PublisherId.Equals(dataSetReader.PublisherId.Value.ToString())) { dataSetReadersFiltered.Add(dataSetReader); } } if (dataSetReadersFiltered.Count == 0) { return; } dataSetReaders = dataSetReadersFiltered; object messagesToken = null; List <object> messagesList = null; string messagesListName = string.Empty; if (jsonDecoder.ReadField(kFieldMessages, out messagesToken)) { messagesList = messagesToken as List <object>; if (messagesList == null) { // this is a SingleDataSetMessage encoded as the conteten of Messages jsonDecoder.PushStructure(kFieldMessages); messagesList = new List <object>(); } else { messagesListName = kFieldMessages; } } else if (jsonDecoder.ReadField(JsonDecoder.RootArrayName, out messagesToken)) { messagesList = messagesToken as List <object>; messagesListName = JsonDecoder.RootArrayName; } else { // this is a SingleDataSetMessage encoded as the conteten of json messagesList = new List <object>(); } if (messagesList != null) { // atempt decoding for each data set reader foreach (DataSetReaderDataType dataSetReader in dataSetReaders) { JsonDataSetReaderMessageDataType jsonMessageSettings = ExtensionObject.ToEncodeable(dataSetReader.MessageSettings) as JsonDataSetReaderMessageDataType; if (jsonMessageSettings == null) { // The reader MessageSettings is not set up corectly continue; } JsonNetworkMessageContentMask networkMessageContentMask = (JsonNetworkMessageContentMask)jsonMessageSettings.NetworkMessageContentMask; if ((networkMessageContentMask & NetworkMessageContentMask) != NetworkMessageContentMask) { // The reader MessageSettings.NetworkMessageContentMask is not set up corectly continue; } // initialize the dataset message JsonDataSetMessage jsonDataSetMessage = new JsonDataSetMessage(); jsonDataSetMessage.DataSetMessageContentMask = (JsonDataSetMessageContentMask)jsonMessageSettings.DataSetMessageContentMask; jsonDataSetMessage.SetFieldContentMask((DataSetFieldContentMask)dataSetReader.DataSetFieldContentMask); // set the flag that indicates if dataset message shall have a header jsonDataSetMessage.HasDataSetMessageHeader = (networkMessageContentMask & JsonNetworkMessageContentMask.DataSetMessageHeader) != 0; jsonDataSetMessage.DecodePossibleDataSetReader(jsonDecoder, messagesList.Count, messagesListName, dataSetReader); if (jsonDataSetMessage.DataSet != null) { m_uaDataSetMessages.Add(jsonDataSetMessage); } } } } catch (Exception ex) { // Unexpected exception in DecodeSubscribedDataSets Utils.Trace(ex, "JsonNetworkMessage.DecodeSubscribedDataSets"); } }
public ValueTask <Publisher> GetPublisherAsync(PublisherId publisherId) => Context.Publishers.FindAsync(publisherId);
public override string ToString() { return(PublisherId.ToString()); }