Ejemplo n.º 1
0
        internal bool CreateTestRelation(int tx1Index, int tx2Index, Pairing pairing)
        {
            if (IsInvalidTableIndex(tx1Index))
            {
                return(false);
            }
            if (IsInvalidTableIndex(tx2Index))
            {
                return(false);
            }

            var rx = new RelationX_RowX_RowX(Get <RelationXRoot>());

            rx.Pairing = pairing;
            rx.Initialize(NR, NR);

            var tx1 = Get <TableXRoot>().Items[tx1Index];
            var tx2 = Get <TableXRoot>().Items[tx2Index];

            Get <Relation_Store_ChildRelation>().SetLink(tx1, rx);
            Get <Relation_Store_ParentRelation>().SetLink(tx2, rx);

            for (int i = 0; i < NR; i++)
            {
                rx.SetLink(tx1.Items[i], tx2.Items[i]);
            }
            return(true);

            bool IsInvalidTableIndex(int txI) => (txI < 0) ? true : (txI < Get <TableXRoot>().Count) ? false : true;
        }
Ejemplo n.º 2
0
        public static byte[] decrypt(BFCText c, BFUserPrivateKey sk)
        {
            BFMasterPublicKey msk = sk.Param;
            Pairing           e   = msk.Pairing;

            //e(sQ,U), sQ is the user private key
            FieldElement temp = e.Compute(sk.Key, c.U);

            //sigma = V xor hash(temp)
            byte[] hash = BFUtil.HashToLength(temp.ToUByteArray(), c.V.Length); //This could fail

            byte[] sigma = BFUtil.XorTwoByteArrays(c.V, hash);

            hash = BFUtil.HashToLength(sigma, c.W.Length);

            byte[] m = BFUtil.XorTwoByteArrays(hash, c.W);

            //sigma||m
            byte[] toHash = new byte[sigma.Length + m.Length];
            Array.Copy(sigma, 0, toHash, 0, sigma.Length);
            Array.Copy(m, 0, toHash, sigma.Length, m.Length);

            //hash(sigma||m) to biginteger r;
            Field  field = e.Curve2.Field;
            BigInt r     = BFUtil.HashToField(toHash, field);

            if (c.U.Equals(e.Curve2.Multiply(msk.P, r)))
            {
                return(m);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
 public PairingTreeNode(Pairing p)
 {
     GetPairing = p;
     Nr         = p.TableNr;
     Player1    = p.Player1Name;
     Player2    = p.Player2Name;
 }
Ejemplo n.º 4
0
        private void Construct(Member init, Identity recv, World world, Pairing pairing)
        {
            Subject = $"{init.World.Name} - smallworld Connection";
            To(init);

            Write($@"
{feedbackRequest.Create(init, pairing)}

Hi {init.FirstName},

You have been paired with {recv.FirstName} for your next smallworld
connection. You have been selected as the initiator. **As the initiator,
it is your responsibility to send the first email to set up your meeting.**

Your partner’s contact information is below. We suggest providing three or
more times to connect in your initial email.  

{recv.FirstName} {recv.LastName}  
{recv.Email}

{personalMessage.Create(pairing)}

-The smallworld Team

{optOut.Create(init)}

Use the following link to leave/join your smallworld group at any time: [click here]({links.InvitePage(world)})
");
        }
        public override void Add(Pairing pairing)
        {
            pairing.World = World;
            World.Pairings.Add(pairing);

            base.Add(pairing);
        }
Ejemplo n.º 6
0
        public Task <Round> Handle(GetNextSwissRound request, CancellationToken cancellationToken)
        {
            _event = GetEvent(request);
            Round nextRound = GetNewRound();

            var playerSwissPairingArray = _event.ParticipatingPlayers.Select(player => new PlayerSwissPairing(player, GetNbOfWins(player))).ToArray();

            //First round is completely random
            if (nextRound.Number == 1)
            {
                //we have as many pairings as the number of players halved, rounded down
                return(Task.FromResult(HandleFirstRoundRandomly(nextRound, playerSwissPairingArray)));
            }

            while (!EveryPlayerIsPaired(nextRound, playerSwissPairingArray))
            {
                var player1 = GetUnpairedPlayerWithTheMostWin(nextRound, playerSwissPairingArray);
                player1.IsPaired = true;

                var player2 = GetNextOpposingPlayer(player1, nextRound, playerSwissPairingArray);
                player2.IsPaired = true;

                var nextPairing = new Pairing();
                nextPairing.Players = new List <Player>();
                nextPairing.Players.Add(player1.Player);
                nextPairing.Players.Add(player2.Player);

                nextRound.Pairings.Add(nextPairing);
            }

            return(Task.FromResult(nextRound));
        }
Ejemplo n.º 7
0
        private void buttonInsert_Click(object sender, EventArgs e)
        {
            try
            {
                List <Pairing> pairList = new List <Pairing>();

                for (int rows = 0; rows < dataGridViewPair.Rows.Count; rows++)
                {
                    // ID!!!
                    int   team1Id = (int)dataGridViewPair.Rows[rows].Cells["Team1Id"].Value;
                    Teams team1   = Teams.SelectTeam(team1Id);

                    int   team2Id = (int)dataGridViewPair.Rows[rows].Cells["Team2Id"].Value;
                    Teams team2   = Teams.SelectTeam(team2Id);

                    // >>>
                    double team1Score = (double)Convert.ToInt32(dataGridViewPair.Rows[rows].Cells["ScoreTeam1"].Value);

                    double team2Score = (double)Convert.ToInt32(dataGridViewPair.Rows[rows].Cells["ScoreTeam2"].Value);

                    int round = (int)dataGridViewPair.Rows[rows].Cells["Round"].Value;

                    Pairing pair = new Pairing(team1, team2, round, team1Score, team2Score);

                    pairList.Add(pair);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Fail");
            }
        }
Ejemplo n.º 8
0
 private void FormPairing_Load(object sender, EventArgs e)
 {
     listTeam = TournamentEntry.ReadTeam(FormMenu.selectedTournament);
     listPair = Pairing.GeneratePairing(listTeam);
     FormatDataGrid();
     AddPairToDataGrid();
 }
Ejemplo n.º 9
0
        private void Construct(Identity init, Identity recv, World world, Pairing pairing)
        {
            Subject = $"{world.Name} - smallworld Connection";
            To(recv);

            var member = recv as Member;

            Write($@"
{feedbackRequest.Create(member, pairing)}

Hi {recv.FirstName},

You have been paired with {init.FullName()} for your next smallworld
connection. {init.FirstName} has been selected as the initiator. Since
everyone is busy from time to time, we suggest contacting your partner
if you have not heard from them within 48 hours of the initial pairing email.

Your partner’s contact information is below. We suggest providing three or
more times to connect in your initial email.

{init.FirstName} {init.LastName}  
{init.Email}

{personalMessage.Create(pairing)}

-The smallworld Team

{optOut.Create(member)}

Use the following link to leave/join your smallworld group at any time: [click here]({links.InvitePage(world)})
");
        }
Ejemplo n.º 10
0
        public IActionResult CreatePairing(Guid worldId, [FromBody] PairingRequest request)
        {
            if (!worlds.Find(worldId, out var world))
            {
                return(NotFound());
            }

            if (!Permissions.ModifyWorld(world))
            {
                return(NotFound());
            }

            var pairings = worlds.Pairings(world);

            var pairing = new Pairing {
                IsComplete = false,
                Type       = PairingType.Auto,
                Date       = request.Date.ToUniversalTime(),
                Message    = request.Message,
            };

            pairings.Add(pairing);

            return(Ok(pairing));
        }
Ejemplo n.º 11
0
        private static IQueryable <Pair> GetQueryable(IServiceProvider provider, Pairing pairing)
        {
            var context = provider.GetRequiredService <IEntryRepository>();
            var entry   = context.Entry(pairing);

            return(entry.QueryRelation(w => w.Pairs));
        }
Ejemplo n.º 12
0
    public void SetResult(Pairing p, int stage)
    {
        RectTransform     r   = stage2a;
        List <RacePairUI> pui = pair_ui0;

        if (stage == 1)
        {
            pui = pair_ui1;
            r   = stage2b;
        }
        else if (stage == 2)
        {
            pui = pair_ui2;
            r   = stage2c;
        }

        foreach (RacePairUI ui in pui)
        {
            if (ui.racer1.text == p.name1)
            {
                ui.SetWinner(p.time1 < p.time2);
                ui.SetTimes(p.time1, p.time2);
            }
        }
    }
        /// <summary>
        /// Crate a Test Order Request
        /// </summary>
        public CreateOrderRequest CreateRequest(CreateOrderRequest.PaymentFlowEnum paymentFlow)
        {
            var phoneNumber = new PhoneNumber("string", true);
            var consumer    = new Consumer(phoneNumber, "Given Name", "Surname", "*****@*****.**");
            var billing     = new OrderAddress("AddressLine1", "AddressLine2", "Suburb", "Billing", "9999", "State");
            var shipping    = new OrderAddress("AddressLine1", "AddressLine2", "Suburb", "Shipping", "9999", "State");

            var item1 = new OrderItem("Decription1", "Name1", "SKU1", 1, 123, "Merchant 1");
            var item2 = new OrderItem("Decription1", "Name1", "SKU1", 1, 123, "Merchant 1");
            var items = new List <OrderItem>();

            items.Add(item1);
            items.Add(item2);

            string RedirectConfirmUrl = "https://orders.yourwebsite.com/confirm";
            string RedirectCancelUrl  = "https://orders.yourwebsite.com/cancel";

            var merchant = new Merchant(RedirectConfirmUrl, RedirectCancelUrl);

            string promotion1 = "Promotion1";
            string promotion2 = "Promotion2";
            var    promotions = new string[2];

            promotions[0] = promotion1;
            promotions[1] = promotion2;

            var pairing = new Pairing("Pairing Token");

            var createOrderRequest = new CreateOrderRequest(CreateOrderRequest.TypeEnum.Classic, 123, consumer, billing, shipping, "Description", items, merchant,
                                                            "Merchant Refernece", 123, 456, "Token1", promotions, pairing, paymentFlow, metaData);

            return(createOrderRequest);
        }
Ejemplo n.º 14
0
 public HandshakeMember(Element secret, string pseudonym, string role)
 {
     m_secret    = secret;
     m_pseudonym = pseudonym;
     m_role      = role;
     m_pairing   = new Pairing();
     Debug.Assert(m_pairing.isSymmetric());
 }
 public RacialPair(RacialPairIdentifier id, Pairing pairing, string pairingName, int tier, int regionId)
 {
     Id          = id;
     Pairing     = pairing;
     PairingName = pairingName;
     Tier        = tier;
     RegionId    = regionId;
 }
Ejemplo n.º 16
0
        public PairingPairRepository(IServiceProvider provider, Pairing pairing, IQueryable <Pair> src = null) : base(provider, src ?? GetQueryable(provider, pairing))
        {
            Pairing = pairing;

            Context.Entry(pairing)
            .LoadRelations(w => w.Pairs)
            .LoadRelations(w => w.World);
        }
Ejemplo n.º 17
0
 protected void ButtonOK_Click(object sender, EventArgs e)
 {
     OK = true;
     Pairing.ResetTableNr();
     foreach (var p in PremadePairing)
     {
         p.GetTableNr();
     }
 }
Ejemplo n.º 18
0
        public async Task GetWinners([FromBody] dynamic data, int?id)
        {
            string   winner          = data.Winner;
            var      winningArtefact = new Artefact();
            DateTime timeJudgement   = DateTime.ParseExact((string)data.TimeOfPairing, "dd/MM/yyyy, HH:mm:ss", CultureInfo.InvariantCulture);
            int      elapsedTime     = (int)data.ElapsedTime;
            string   comment         = data.Comment;
            var      user            = GetCurrentUserAsync().Result.Id;
            Pairing  pairing         = new Pairing
            {
                ExperimentId = (int)id,
                Experiment   = await _context.Experiment.FirstOrDefaultAsync(m => m.Id == id),
                JudgeLoginID = user
            };
            List <ArtefactPairing> pairOfScripts = new List <ArtefactPairing>();
            string   scriptOne   = data.ArtefactPairings["item1"];
            Artefact artefactOne = await _context.Artefact
                                   .FirstOrDefaultAsync(m => m.FilePath == scriptOne);

            ArtefactPairing one = new ArtefactPairing
            {
                ArtefactId = artefactOne.Id,
                PairingId  = pairing.Id,
                Artefact   = artefactOne
            };
            string   scriptTwo   = data.ArtefactPairings["item2"];
            Artefact artefactTwo = await _context.Artefact
                                   .FirstOrDefaultAsync(m => m.FilePath == scriptTwo);

            ArtefactPairing two = new ArtefactPairing
            {
                ArtefactId = artefactTwo.Id,
                PairingId  = pairing.Id,
                Artefact   = artefactTwo
            };

            if (artefactOne.FilePath == winner)
            {
                winningArtefact = artefactOne;
            }
            else
            {
                winningArtefact = artefactTwo;
            }
            pairOfScripts.Add(one);
            pairOfScripts.Add(two);
            pairing.ArtefactPairings = pairOfScripts;
            pairing.Winner           = winningArtefact;
            pairing.TimeOfPairing    = timeJudgement;
            pairing.ElapsedTime      = elapsedTime;
            pairing.Comment          = comment;
            if (ModelState.IsValid)
            {
                _context.Update(pairing);
                await _context.SaveChangesAsync();
            }
        }
Ejemplo n.º 19
0
        public void TestDropTable()
        {
            Db.CreateTable("newtable", Pairing.Of("name", "text"), Pairing.Of("number", "int")).Execute();
            Db.DropTable("newtable").Execute();

            var table = Db.Take("information_schema.tables").Where(Pairing.Of("table_name", "newtable")).Execute();

            Assert.AreEqual(0, table[0].Count);
        }
Ejemplo n.º 20
0
        internal void Preprocess(DoubleLinkedList <TokenLine> lines, string filename, IParserCallback cb, ArrayList pairings, params string[] defined)
        {
            this.pairings = new ArrayList();
            isdisabled    = false;

            condstack.Clear();
            regionstack.Clear();
            defines.Clear();
            foreach (string d in defined)
            {
                if (d != null)
                {
                    defines.Add(d, d);
                }
            }
            this.cb = cb;
            Preprocess(new PreprocessorTokenEnumerator(lines, filename, this));

            Set pp = new Set(pairings) & new Set(this.pairings);

            foreach (Pairing p in this.pairings)
            {
                if (pp.Contains(p))
                {
                    // we have to replace it here, else references wont point correctly
                    Pairing old = pp.Replace(p) as Pairing;
                    p.hidden = old.hidden;
                }
                else
                {
                    pp.Add(p);
                }
            }

            pairings.Clear();
            pairings.AddRange(pp);
            pairings.Sort();

            while (regionstack.Count > 0)
            {
                Region c = (Region)regionstack.Pop();
                c.start.Error = true;
                cb.Invoke(c.start);
                ServiceHost.Error.OutputErrors(new ActionResult("Region " + c.text + " not terminated", c.start));
            }

            while (condstack.Count > 0)
            {
                Conditional c = (Conditional)condstack.Pop();
                c.start.Error = true;
                cb.Invoke(c.start);
                ServiceHost.Error.OutputErrors(new ActionResult("Conditional " + c.text + " not terminated", c.start));
            }

            this.pairings.Clear();
            this.pairings = null;
        }
Ejemplo n.º 21
0
 public int AddAdminMessage(MessageModel messageModel)
 {
     return(_dataAccessService.ExecuteProcedureAsync("InsertAdminMessage", null,
                                                     Pairing.Of("@sender", messageModel.Sender),
                                                     Pairing.Of("@message", messageModel.Message),
                                                     Pairing.Of("@date", messageModel.Date),
                                                     Pairing.Of("@subject", messageModel.Subject)
                                                     ).Result);
 }
Ejemplo n.º 22
0
        void CreateTestTable()
        {
            Db.CreateTable("test", Pairing.Of("name", "text"), Pairing.Of("age", "int")).Execute();

            Db.Insert("test", Pairing.Of("name", "Marla"), Pairing.Of("age", 36)).Execute();
            Db.Insert("test", Pairing.Of("name", "Susan"), Pairing.Of("age", 100)).Execute();
            Db.Insert("test", Pairing.Of("name", "John"), Pairing.Of("age", 67)).Execute();
            Db.Insert("test", Pairing.Of("name", "Jenna"), Pairing.Of("age", 34)).Execute();
            Db.Insert("test", Pairing.Of("name", "RJ"), Pairing.Of("age", 29)).Execute();
        }
Ejemplo n.º 23
0
 public int AddComment(CommentModel commentModel)
 {
     return(_dataAccessService.ExecuteProcedureAsync("InsertComment", "commentId",
                                                     Pairing.Of("@content", commentModel.Content),
                                                     Pairing.Of("@userId", commentModel.UserId),
                                                     Pairing.Of("@datestamp", commentModel.DateStamp),
                                                     Pairing.Of("@eventId", commentModel.EventId),
                                                     Pairing.Of("@username", commentModel.UserName),
                                                     Pairing.Of("@parentId", commentModel.ParentCommentId)).Result);
 }
Ejemplo n.º 24
0
            public override bool Equals(object obj)
            {
                Pairing b = obj as Pairing;

                if (b == null)
                {
                    return(false);
                }
                return(b.text == text && b.start == start && b.end == end);
            }
Ejemplo n.º 25
0
            int IComparable.CompareTo(object obj)
            {
                Pairing b = obj as Pairing;

                if (b == null)
                {
                    return(-1);
                }
                return(start.LineNumber.CompareTo(b.start.LineNumber));
            }
Ejemplo n.º 26
0
        public async Task <IEnumerable <Pairing> > GetPairingAsync(int id, int interval)
        {
            var pairings = new List <Pairing>();

            if (string.IsNullOrEmpty(this.options?.Value?.Url?.Pairings))
            {
                return(pairings);
            }

            var url    = string.Format(this.options.Value.Url.Pairings, id, interval, DateTime.Now.Millisecond);
            var result = await this.restConnector.GetAsync(url);

            if (string.IsNullOrWhiteSpace(result))
            {
                return(pairings);
            }

            if (result.Contains("["))
            {
                result = result.Substring(result.IndexOf("["));
            }
            if (result.Contains("]"))
            {
                result = result.Substring(0, result.LastIndexOf("]") + 1);
            }
            result = result.Replace("\n", "");
            var resultArray = JsonConvert.DeserializeObject <string[][]>(result);

            if (resultArray != null)
            {
                resultArray.ToList().ForEach(
                    value =>
                {
                    if (value.Length != 7)
                    {
                        return;
                    }

                    var pairing = new Pairing()
                    {
                        Timestamp = long.Parse(value[0]) - 7 * 60 * 60 * 1000,
                        Low       = double.Parse(value[1]),
                        High      = double.Parse(value[2]),
                        Current   = double.Parse(value[3]),
                        Volume    = double.Parse(value[4]),
                        Open      = double.Parse(value[5]),
                        Close     = double.Parse(value[6])
                    };
                    pairings.Add(pairing);
                }
                    );
            }

            return(pairings);
        }
Ejemplo n.º 27
0
        public string Create(Pairing pairing)
        {
            if (pairing?.Message == null)
            {
                return("");
            }

            return($@"Below is a personalized message from your community administrator:

{pairing.Message}");
        }
Ejemplo n.º 28
0
 public virtual RacialPair GetByPair(Pairing pair, int tier)
 {
     foreach (var racialPair in RacialPairList)
     {
         if ((racialPair.Pairing == pair) && (racialPair.Tier == tier))
         {
             return(racialPair);
         }
     }
     return(null);
 }
Ejemplo n.º 29
0
        public IActionResult CreateManualPairings(Guid worldId, [FromBody] ManualPairingRequest request)
        {
            var value = worlds
                        .Include(w => w.Members)
                        .Include(w => w.Pairs)
                        .Find(worldId);

            if (!value.Exists(out var world))
            {
                return(NotFound());
            }

            if (!Permissions.ModifyWorld(world))
            {
                return(NotFound());
            }

            var pairings = worlds.Pairings(world);

            if (request.Pairs == null || !request.Pairs.Any())
            {
                return(BadRequest());
            }

            var pairing = new Pairing {
                IsComplete = false,
                Type       = PairingType.Manual,
                Date       = request.Date.ToUniversalTime(),
                Message    = request.Message,
                Pairs      = new HashSet <Pair>()
            };

            pairings.Add(pairing);

            var pairs = pairings.Pairs(pairing);

            foreach (var src in request.Pairs)
            {
                var pair = new Pair {
                    Initiator = world.Members.FirstOrDefault(m => m.Guid == src.Initiator),
                    Receiver  = world.Members.FirstOrDefault(m => m.Guid == src.Receiver),
                    Outcome   = PairOutcome.Unknown
                };

                if (pair.Initiator == null || pair.Receiver == null || pair.Initiator == pair.Receiver)
                {
                    return(BadRequest());
                }

                pairs.Add(pair);
            }

            return(Ok(pairing));
        }
Ejemplo n.º 30
0
 public void SetResult(Pairing p)
 {
     foreach (RacePairUI ui in pair_ui)
     {
         if (ui.racer1.text == p.name1)
         {
             ui.SetWinner(p.time1 < p.time2);
             ui.SetTimes(p.time1, p.time2);
         }
     }
 }
Ejemplo n.º 31
0
 internal static int MatchesInPairing(Pairing p1, Pairing p2)
 {
     int matchCount = 0;
     foreach (Player pl1 in p1.Participants)
     {
         foreach (Player pl2 in p2.Participants)
         {
             if (pl1 == pl2)
             {
                 ++matchCount;
             }
         }
     }
     return matchCount;
 }
        private Pairing buildXPathRef(DataGridViewRow row)
        {
            Pairing pairing = new Pairing();
            string pred = (string)row.Cells["Predicate"].Value;
            TagData td;
            string newXPath;

            if (row.Cells["Questions"].Value is RepeatPosition)
            {
                if (pred.Equals("first"))
                {
                    newXPath = "position()=1";
                    pairing.titleText = "If first entry in repeat";
                }
                else if (pred.Equals("not first"))
                {
                    newXPath = "position()&gt;1";
                    pairing.titleText = "If not the first entry in repeat";
                }
                else if (pred.Equals("second"))
                {
                    newXPath = "position()=2";
                    pairing.titleText = "If second entry in repeat";
                }
                else if (pred.Equals("second last"))
                {
                    newXPath = "position()=last()-1";
                    pairing.titleText = "If second last entry in repeat";

                }
                else if (pred.Equals("last"))
                {
                    newXPath = "position()=last()";
                    pairing.titleText = "If last entry in repeat";
                }
                else if (pred.Equals("not last"))
                {
                    newXPath = "position()!=last()";
                    pairing.titleText = "If not the last entry in repeat";
                }
                else
                {
                    log.Error("unexpected predicate " + pred);
                    return null;
                }
                // No point making this a condition

                //condition result = conditionsHelper.setup(xpathExisting.dataBinding.storeItemID,
                //    newXPath, xpathExisting.dataBinding.prefixMappings, false);

                xpathsXpath xpathEntry = xppe.setup("", model.answersPart.Id, newXPath, null, false);
                //xpathEntry.questionID = q.id;
                xpathEntry.dataBinding.prefixMappings = "xmlns:oda='http://opendope.org/answers'";
                //xpathEntry.type = dataType;
                xppe.save();

                //td = new TagData("");
                //td.set("od:RptPosCon", xpathEntry.id);
                //cc.Tag = td.asQueryString();

                //cc.Title = titleText;
                //cc.SetPlaceholderText(null, null, "Type the text that'll appear between repeated items.");
                //// that'll only be displayed if the cc is not being wrapped around existing content :-)

                //// Don't :
                //// ContentControlNewConditionCheck variableRelocator = new ContentControlNewConditionCheck();
                //// variableRelocator.checkAnswerAncestry(xpathExisting.id);

                //postconditionsMet = true;

                pairing.xpathEntry = xpathEntry;

                return pairing;

            }

            string val = null;
            object o = row.Cells["Value"].Value;
            if (o is string)
            {
                val = (string)o;
            }
            else
            {
                //responseFixed
                val = ((responseFixedItem)o).value;
            }

            xpathsXpath xpathExisting;

            question q;
            if (row.Cells["Questions"].Value is RepeatCount)
            {

                q = ((RepeatCount)row.Cells["Questions"].Value).Repeat;

                xpathExisting = xppe.getXPathByQuestionID(q.id);

                if (pred.Equals("="))
                {
                    newXPath = "count(" + xpathExisting.dataBinding.xpath + ")=" + val;
                    pairing.titleText = "If Repeat " + q.text + " has " + val;
                }
                else if (pred.Equals(">"))
                {
                    newXPath = "count(" + xpathExisting.dataBinding.xpath + ")>" + val;
                    pairing.titleText = "If Repeat " + q.text + " > " + val;
                }
                else if (pred.Equals(">="))
                {
                    newXPath = "count(" + xpathExisting.dataBinding.xpath + ")>=" + val;
                    pairing.titleText = "If Repeat " + q.text + " >= " + val;
                }
                else if (pred.Equals("<"))
                {
                    newXPath = "count(" + xpathExisting.dataBinding.xpath + ")<" + val;
                    pairing.titleText = "If Repeat " + q.text + " < " + val;

                }
                else if (pred.Equals("<="))
                {
                    newXPath = "count(" + xpathExisting.dataBinding.xpath + ")<=" + val;
                    pairing.titleText = "If Repeat " + q.text + " <= " + val;
                }
                else
                {
                    log.Error("unexpected predicate " + pred);
                    return null;
                }

            }
            else
            {

                q = ((question)row.Cells["Questions"].Value);
                xpathExisting = xppe.getXPathByQuestionID(q.id);

                if (xpathExisting.type.Equals("boolean"))
                {

                    // done this way, since XPath spec says the boolean value of a string is true,
                    // if it is not empty!

                    newXPath = "string(" + xpathExisting.dataBinding.xpath + ")='" + val + "'";
                    pairing.titleText = "If '" + val + "' for Q: " + q.text;

                }
                else if (xpathExisting.type.Equals("string"))
                {
                    if (pred.Equals("equals"))
                    {
                        newXPath = "string(" + xpathExisting.dataBinding.xpath + ")='" + val + "'";
                        pairing.titleText = "If '" + val + "' for Q: " + q.text;

                    }
                    else if (pred.Equals("is not"))
                    {
                        newXPath = "string(" + xpathExisting.dataBinding.xpath + ")!='" + val + "'";
                        pairing.titleText = "If NOT '" + val + "' for Q: " + q.text;
                    }
                    else if (pred.Equals("starts-with"))
                    {
                        newXPath = "starts-with(string(" + xpathExisting.dataBinding.xpath + "), '" + val + "')";
                        pairing.titleText = "If starts-with '" + val + "' for Q: " + q.text;

                    }
                    else if (pred.Equals("contains"))
                    {
                        newXPath = "contains(string(" + xpathExisting.dataBinding.xpath + "), '" + val + "')";
                        pairing.titleText = "If contains '" + val + "' for Q: " + q.text;
                    }
                    else
                    {
                        log.Error("unexpected predicate " + pred);
                        return null;
                    }
                }
                else if (xpathExisting.type.Equals("decimal")
                  || xpathExisting.type.Equals("integer")
                  || xpathExisting.type.Equals("positiveInteger")
                  || xpathExisting.type.Equals("nonPositiveInteger")
                  || xpathExisting.type.Equals("negativeInteger")
                  || xpathExisting.type.Equals("nonNegativeInteger")
                  )
                {
                    if (pred.Equals("="))
                    {
                        newXPath = "number(" + xpathExisting.dataBinding.xpath + ")=" + val;
                        pairing.titleText = "If '" + val + "' for Q: " + q.text;
                    }
                    else if (pred.Equals(">"))
                    {
                        newXPath = "number(" + xpathExisting.dataBinding.xpath + ")>" + val;
                        pairing.titleText = "If >" + val + " for Q: " + q.text;
                    }
                    else if (pred.Equals(">="))
                    {
                        newXPath = "number(" + xpathExisting.dataBinding.xpath + ")>=" + val;
                        pairing.titleText = "If >=" + val + " for Q: " + q.text;
                    }
                    else if (pred.Equals("<"))
                    {
                        newXPath = "number(" + xpathExisting.dataBinding.xpath + ")<" + val;
                        pairing.titleText = "If <" + val + " for Q: " + q.text;

                    }
                    else if (pred.Equals("<="))
                    {
                        newXPath = "number(" + xpathExisting.dataBinding.xpath + ")<=" + val;
                        pairing.titleText = "If <=" + val + " for Q: " + q.text;
                    }
                    else
                    {
                        log.Error("unexpected predicate " + pred);
                        return null;
                    }

                }
                else if (xpathExisting.type.Equals("date"))
                {
                    // Requires XPath 2.0

                    if (pred.Equals("equals"))
                    {
                        newXPath = "xs:date(" + xpathExisting.dataBinding.xpath + ") = xs:date('" + val + "')";
                        pairing.titleText = "If '" + val + "' for Q: " + q.text;
                    }
                    else if (pred.Equals("is before"))
                    {
                        newXPath = "xs:date(" + xpathExisting.dataBinding.xpath + ") < xs:date('" + val + "')";
                        pairing.titleText = "If before '" + val + "' for Q: " + q.text;
                    }
                    else if (pred.Equals("is after"))
                    {
                        newXPath = "xs:date(" + xpathExisting.dataBinding.xpath + ") > xs:date('" + val + "')";
                        pairing.titleText = "If after '" + val + "' for Q: " + q.text;
                    }
                    else
                    {
                        log.Error("unexpected predicate " + pred);
                        return null;
                    }

                }
                else
                {
                    log.Error("Unexpected data type " + xpathExisting.type);
                    return null;
                }
            }

            // Drop any trailing "/" from a Condition XPath
            if (newXPath.EndsWith("/"))
            {
                newXPath = newXPath.Substring(0, newXPath.Length - 1);
            }
            log.Debug("Creating condition using XPath:" + newXPath);

            xpathsXpath xpath = xppe.setup("cond", xpathExisting.dataBinding.storeItemID,
                newXPath, xpathExisting.dataBinding.prefixMappings, false);
            xppe.save();

            pairing.xpathEntry = xpath;

            return pairing;
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Gets the duty changes.
        /// </summary>
        /// <returns>the duty changes.</returns>
        private static List<PairingDutyChange> GetDutyChanges()
        {
            DateTime startDate = new DateTime(2011, 1, 1);
            DateTime endDate = startDate.AddHours(10);
            Pairing pairing = new Pairing
                {
                    Id = 7,
                    StartDate = startDate,
                    EndDate = endDate,
                    Label = "XYZ",
                    Port = new Port { IataCode = "SYD" },
                    ToPort = new Port { IataCode = "BNE" }
                };

            List<PairingDutyChange> dutyChanges = new List<PairingDutyChange>
                {
                    new PairingDutyChange
                    {
                        Id = 5,
                        Pairing = pairing,
                        AlarmAt = startDate.AddDays(-4),
                        Notify = true,
                        HideUntil = startDate.AddDays(-5),
                        PublicComment = "Duty changed.",
                    }
                };

            dutyChanges[0].PairingDutyChangeEmployees.AddRange(
                   new List<PairingDutyChangeEmployee>
                   {
                        new PairingDutyChangeEmployee { Id = 1, EmployeeId = 1, PairingDutyChangeId = 5 },
                        new PairingDutyChangeEmployee { Id = 2, EmployeeId = 2, PairingDutyChangeId = 5 }
                   });

            return dutyChanges;
        }