Beispiel #1
0
        public void Optimize_PredecessorQueryCanRunOnGraph()
        {
            var userWithName = Given <PassengerName> .Match(passengerName =>
                                                            passengerName.passenger.user);

            var pipeline = userWithName.Pipeline;

            pipeline.CanRunOnGraph.Should().BeTrue();

            var passenger     = new Passenger(new Airline("IA"), new User("--- PUBLIC KEY ---"));
            var passengerName = new PassengerName(passenger, "George", new PassengerName[0]);

            var collector = new Collector(SerializerCache.Empty);
            var reference = collector.Serialize(passengerName);
            var graph     = collector.Graph;

            var references = pipeline
                             .Execute(reference, graph)
                             .Select(p => p.GetElement("user"))
                             .OfType <SimpleElement>()
                             .Select(e => e.FactReference)
                             .ToImmutableList();
            var userReference = references.Should().ContainSingle().Subject;

            var emitter = new Emitter(graph, DeserializerCache.Empty);
            var user    = emitter.Deserialize <User>(userReference);

            user.publicKey.Should().Be("--- PUBLIC KEY ---");
        }
 private void btnnew_Click(System.Object sender, System.EventArgs e)
 {
     clear();
     PassengerNo.Enabled      = true;
     PassengerName.Enabled    = true;
     PassengerAddress.Enabled = true;
     PassengerCity.Enabled    = true;
     PassengerContact.Enabled = true;
     PassengerName.Focus();
     con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Bus_System;Integrated Security=True");
     con.Open();
     cmd = new SqlCommand("Select max(Pno) From Passenger", con);
     dr  = cmd.ExecuteReader();
     dr.Read();
     if ((!object.ReferenceEquals(dr[0], DBNull.Value)))
     {
         t = Convert.ToInt32(dr[0]) + 1;
     }
     else
     {
         t = 1;
     }
     PassengerNo.Text = t.ToString();
     dr.Close();
     con.Close();
     btnsave.Enabled          = true;
     btnpassengerfind.Enabled = false;
     btnnew.Enabled           = false;
     f = 5;
 }
Beispiel #3
0
        public void HashMultiplePredecessorList()
        {
            var passenger = new Passenger(
                new Airline("IA"),
                new User("---PUBLIC KEY---")
                );
            var first = new PassengerName(
                passenger,
                "Charles Rane",
                new PassengerName[0]
                );
            var middle = Enumerable.Range(1, 10)
                         .Select(id => new PassengerName(
                                     passenger,
                                     $"Charley Rane {id}",
                                     new PassengerName[] { first }
                                     ))
                         .ToArray();
            var last = new PassengerName(
                passenger,
                "Charley Rane",
                middle
                );
            var hash = ComputeHash(last);

            hash.Should().Be("4Os8M2Tt7+lCEe6WQ6iAJwQ/wbmK6CTLqwF8DCS6Bc4tgXE268BanI0sHDeSYhbKYbSDAyRzarMkrciveBoDTQ==");
        }
Beispiel #4
0
        public void Optimization_CacheTypeSerializers()
        {
            var passenger  = new Passenger(new Airline("IA"), new User("--- PUBLIC KEY ---"));
            var firstName  = new PassengerName(passenger, "George", new PassengerName[0]);
            var secondName = new PassengerName(passenger, "Jorge", new PassengerName[] { firstName });

            var serializerCache = SerializerCache.Empty;
            var collector       = new Collector(serializerCache);
            var result          = collector.Serialize(secondName);

            collector.SerializerCache.TypeCount.Should().Be(4);
        }
Beispiel #5
0
        public void Optimization_LimitVisits()
        {
            var passenger  = new Passenger(new Airline("IA"), new User("--- PUBLIC KEY ---"));
            var firstName  = new PassengerName(passenger, "George", new PassengerName[0]);
            var secondName = new PassengerName(passenger, "Jorge", new PassengerName[] { firstName });

            var collector  = new Collector(SerializerCache.Empty);
            var result     = collector.Serialize(secondName);
            int factVisits = collector.FactVisitsCount;

            factVisits.Should().Be(5);
        }
Beispiel #6
0
        public void SerializeRoundTripMultiplePredecessors()
        {
            var passenger  = new Passenger(new Airline("IA"), new User("--- PUBLIC KEY ---"));
            var firstName  = new PassengerName(passenger, "George", new PassengerName[0]);
            var secondName = new PassengerName(passenger, "Jorge", new PassengerName[] { firstName });

            var graph     = Serialize(secondName);
            var roundTrip = Deserialize <PassengerName>(graph, graph.Last);

            roundTrip.prior.Should().ContainSingle().Which
            .value.Should().Be("George");
        }
Beispiel #7
0
        public void SerializeMultiplePredecessors()
        {
            var passenger  = new Passenger(new Airline("IA"), new User("--- PUBLIC KEY ---"));
            var firstName  = new PassengerName(passenger, "George", new PassengerName[0]);
            var secondName = new PassengerName(passenger, "Jorge", new PassengerName[] { firstName });

            var graph = Serialize(secondName);
            var fact  = graph.GetFact(graph.Last);

            fact.Predecessors.Where(p => p.Role == "prior").Should().ContainSingle().Which
            .Should().BeOfType <PredecessorMultiple>();
        }
 public void clear()
 {
     PassengerNo.Clear();
     PassengerName.Clear();
     PassengerAddress.Clear();
     PassengerCity.Clear();
     PassengerContact.Clear();
     PassengerNo.Enabled      = true;
     PassengerName.Enabled    = false;
     PassengerAddress.Enabled = false;
     PassengerCity.Enabled    = false;
     PassengerContact.Enabled = false;
 }
Beispiel #9
0
        public void Optimization_ReuseObjects()
        {
            var passenger  = new Passenger(new Airline("IA"), new User("--- PUBLIC KEY ---"));
            var firstName  = new PassengerName(passenger, "George", new PassengerName[0]);
            var secondName = new PassengerName(passenger, "Jorge", new PassengerName[] { firstName });

            var collector = new Collector(SerializerCache.Empty);
            var result    = collector.Serialize(secondName);

            var emitter      = new Emitter(collector.Graph, DeserializerCache.Empty);
            var deserialized = emitter.Deserialize <PassengerName>(result);

            deserialized.passenger.Should().BeSameAs(deserialized.prior[0].passenger);
        }
Beispiel #10
0
        public void HashEmptyPredecessorList()
        {
            var fact = new PassengerName(
                new Passenger(
                    new Airline("IA"),
                    new User("---PUBLIC KEY---")
                    ),
                "Charles Rane",
                new PassengerName[0]
                );
            var hash = ComputeHash(fact);

            hash.Should().Be("GsMMA/8Nv401P6RXvugFYzYCemGehnXSFZuaKNcoVFoXKmxzMJkpqI9rs/SRlKHZlnRP1QsBxFWKFt6143OpYA==");
        }
Beispiel #11
0
        public void Optimization_DetectsCycles()
        {
            var passenger  = new Passenger(new Airline("IA"), new User("--- PUBLIC KEY ---"));
            var firstName  = new PassengerName(passenger, "George", new PassengerName[0]);
            var prior      = new PassengerName[] { firstName };
            var secondName = new PassengerName(passenger, "Jorge", prior);

            // You have to really want to do this
            prior[0] = secondName;

            var    collector = new Collector(SerializerCache.Empty);
            Action serialize = () => collector.Serialize(secondName);

            serialize.Should().Throw <ArgumentException>()
            .WithMessage("Jinaga cannot serialize a fact containing a cycle");
        }
Beispiel #12
0
        public async Task Optimization_RunPipelineOnGraph()
        {
            var userWithName = Given <PassengerName> .Match(passengerName =>
                                                            passengerName.passenger.user);

            var pipeline      = userWithName.Pipeline;
            var passenger     = new Passenger(new Airline("IA"), new User("--- PUBLIC KEY ---"));
            var passengerName = new PassengerName(passenger, "George", new PassengerName[0]);

            // This instance does not contain the facts.
            var j     = JinagaTest.Create();
            var users = await j.Query(passengerName, userWithName);

            // But the graph does.
            users.Should().ContainSingle().Which
            .publicKey.Should().Be("--- PUBLIC KEY ---");
        }
Beispiel #13
0
        public void HashSinglePredecessorList()
        {
            var passenger = new Passenger(
                new Airline("IA"),
                new User("---PUBLIC KEY---")
                );
            var first = new PassengerName(
                passenger,
                "Charles Rane",
                new PassengerName[0]
                );
            var second = new PassengerName(
                passenger,
                "Charley Rane",
                new PassengerName[] { first }
                );
            var hash = ComputeHash(second);

            hash.Should().Be("BYLtR7XddbhchlyBdGdrnRHGkPsDecynDjLHFvqtKH7zug46ymxNDpPC4QNb+T14Bhzs8M1F3VfCnlgzinNHPg==");
        }
Beispiel #14
0
 public void FormControls(string CLR)
 {
     if (CLR == "CLR")
     {
         PassengerNo.Clear();
         PassengerName.Clear();
         PassengerAddress.Clear();
         PassengerCity.Clear();
         PassengerContact.Clear();
         PassengerNo.Enabled      = false;
         PassengerName.Enabled    = false;
         PassengerAddress.Enabled = false;
         PassengerCity.Enabled    = false;
         PassengerContact.Enabled = false;
         btnsave.Enabled          = false;
         btnedit.Enabled          = false;
         btndelete.Enabled        = false;
         btnadd.Enabled           = true;
         btnfind.Enabled          = true;
         Left1.Enabled            = false;
         Right1.Enabled           = false;
     }
     if (CLR == "Save")
     {
         btnsave.Enabled          = true;
         btnadd.Enabled           = false;
         btnfind.Enabled          = false;
         btndelete.Enabled        = false;
         btnedit.Enabled          = false;
         PassengerName.Enabled    = true;
         PassengerAddress.Enabled = true;
         PassengerCity.Enabled    = true;
         PassengerContact.Enabled = true;
         PassengerName.Focus();
     }
 }
Beispiel #15
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (AgentNumericCode != null)
         {
             hashCode = hashCode * 59 + AgentNumericCode.GetHashCode();
         }
         if (Code != null)
         {
             hashCode = hashCode * 59 + Code.GetHashCode();
         }
         if (FlightDate != null)
         {
             hashCode = hashCode * 59 + FlightDate.GetHashCode();
         }
         if (FlightLegs != null)
         {
             hashCode = hashCode * 59 + FlightLegs.GetHashCode();
         }
         if (InvoiceNumber != null)
         {
             hashCode = hashCode * 59 + InvoiceNumber.GetHashCode();
         }
         if (IsETicket != null)
         {
             hashCode = hashCode * 59 + IsETicket.GetHashCode();
         }
         if (IsRegisteredCustomer != null)
         {
             hashCode = hashCode * 59 + IsRegisteredCustomer.GetHashCode();
         }
         if (IsRestrictedTicket != null)
         {
             hashCode = hashCode * 59 + IsRestrictedTicket.GetHashCode();
         }
         if (IsThirdParty != null)
         {
             hashCode = hashCode * 59 + IsThirdParty.GetHashCode();
         }
         if (IssueDate != null)
         {
             hashCode = hashCode * 59 + IssueDate.GetHashCode();
         }
         if (MerchantCustomerId != null)
         {
             hashCode = hashCode * 59 + MerchantCustomerId.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (PassengerName != null)
         {
             hashCode = hashCode * 59 + PassengerName.GetHashCode();
         }
         if (Passengers != null)
         {
             hashCode = hashCode * 59 + Passengers.GetHashCode();
         }
         if (PlaceOfIssue != null)
         {
             hashCode = hashCode * 59 + PlaceOfIssue.GetHashCode();
         }
         if (Pnr != null)
         {
             hashCode = hashCode * 59 + Pnr.GetHashCode();
         }
         if (PointOfSale != null)
         {
             hashCode = hashCode * 59 + PointOfSale.GetHashCode();
         }
         if (PosCityCode != null)
         {
             hashCode = hashCode * 59 + PosCityCode.GetHashCode();
         }
         if (TicketDeliveryMethod != null)
         {
             hashCode = hashCode * 59 + TicketDeliveryMethod.GetHashCode();
         }
         if (TicketNumber != null)
         {
             hashCode = hashCode * 59 + TicketNumber.GetHashCode();
         }
         if (TotalFare != null)
         {
             hashCode = hashCode * 59 + TotalFare.GetHashCode();
         }
         if (TotalFee != null)
         {
             hashCode = hashCode * 59 + TotalFee.GetHashCode();
         }
         if (TotalTaxes != null)
         {
             hashCode = hashCode * 59 + TotalTaxes.GetHashCode();
         }
         if (TravelAgencyName != null)
         {
             hashCode = hashCode * 59 + TravelAgencyName.GetHashCode();
         }
         return(hashCode);
     }
 }
Beispiel #16
0
        /// <summary>
        /// Returns true if AirlineData instances are equal
        /// </summary>
        /// <param name="other">Instance of AirlineData to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(AirlineData other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     AgentNumericCode == other.AgentNumericCode ||
                     AgentNumericCode != null &&
                     AgentNumericCode.Equals(other.AgentNumericCode)
                     ) &&
                 (
                     Code == other.Code ||
                     Code != null &&
                     Code.Equals(other.Code)
                 ) &&
                 (
                     FlightDate == other.FlightDate ||
                     FlightDate != null &&
                     FlightDate.Equals(other.FlightDate)
                 ) &&
                 (
                     FlightLegs == other.FlightLegs ||
                     FlightLegs != null &&
                     FlightLegs.SequenceEqual(other.FlightLegs)
                 ) &&
                 (
                     InvoiceNumber == other.InvoiceNumber ||
                     InvoiceNumber != null &&
                     InvoiceNumber.Equals(other.InvoiceNumber)
                 ) &&
                 (
                     IsETicket == other.IsETicket ||
                     IsETicket != null &&
                     IsETicket.Equals(other.IsETicket)
                 ) &&
                 (
                     IsRegisteredCustomer == other.IsRegisteredCustomer ||
                     IsRegisteredCustomer != null &&
                     IsRegisteredCustomer.Equals(other.IsRegisteredCustomer)
                 ) &&
                 (
                     IsRestrictedTicket == other.IsRestrictedTicket ||
                     IsRestrictedTicket != null &&
                     IsRestrictedTicket.Equals(other.IsRestrictedTicket)
                 ) &&
                 (
                     IsThirdParty == other.IsThirdParty ||
                     IsThirdParty != null &&
                     IsThirdParty.Equals(other.IsThirdParty)
                 ) &&
                 (
                     IssueDate == other.IssueDate ||
                     IssueDate != null &&
                     IssueDate.Equals(other.IssueDate)
                 ) &&
                 (
                     MerchantCustomerId == other.MerchantCustomerId ||
                     MerchantCustomerId != null &&
                     MerchantCustomerId.Equals(other.MerchantCustomerId)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     PassengerName == other.PassengerName ||
                     PassengerName != null &&
                     PassengerName.Equals(other.PassengerName)
                 ) &&
                 (
                     Passengers == other.Passengers ||
                     Passengers != null &&
                     Passengers.SequenceEqual(other.Passengers)
                 ) &&
                 (
                     PlaceOfIssue == other.PlaceOfIssue ||
                     PlaceOfIssue != null &&
                     PlaceOfIssue.Equals(other.PlaceOfIssue)
                 ) &&
                 (
                     Pnr == other.Pnr ||
                     Pnr != null &&
                     Pnr.Equals(other.Pnr)
                 ) &&
                 (
                     PointOfSale == other.PointOfSale ||
                     PointOfSale != null &&
                     PointOfSale.Equals(other.PointOfSale)
                 ) &&
                 (
                     PosCityCode == other.PosCityCode ||
                     PosCityCode != null &&
                     PosCityCode.Equals(other.PosCityCode)
                 ) &&
                 (
                     TicketDeliveryMethod == other.TicketDeliveryMethod ||
                     TicketDeliveryMethod != null &&
                     TicketDeliveryMethod.Equals(other.TicketDeliveryMethod)
                 ) &&
                 (
                     TicketNumber == other.TicketNumber ||
                     TicketNumber != null &&
                     TicketNumber.Equals(other.TicketNumber)
                 ) &&
                 (
                     TotalFare == other.TotalFare ||
                     TotalFare != null &&
                     TotalFare.Equals(other.TotalFare)
                 ) &&
                 (
                     TotalFee == other.TotalFee ||
                     TotalFee != null &&
                     TotalFee.Equals(other.TotalFee)
                 ) &&
                 (
                     TotalTaxes == other.TotalTaxes ||
                     TotalTaxes != null &&
                     TotalTaxes.Equals(other.TotalTaxes)
                 ) &&
                 (
                     TravelAgencyName == other.TravelAgencyName ||
                     TravelAgencyName != null &&
                     TravelAgencyName.Equals(other.TravelAgencyName)
                 ));
        }