Beispiel #1
0
    void RemoveTip()
    {
        if (checkTip == true)
        {
            imageTip.gameObject.SetActive(false);
            checkTip = false;
        }

        switch (gametype)
        {
        case 1:
            MG.GetComponent <mathGame> ().AdditionTiles();
            break;

        case 2:
            MG.GetComponent <mathGame> ().SubtractionTiles();
            break;

        case 3:
            MG.GetComponent <mathGame> ().MultiplicationTiles();
            break;

        case 4:
            MG.GetComponent <mathGame> ().DivisionTiles();
            break;

        default:
            Debug.Log("No game type selected");
            break;
        }
    }
Beispiel #2
0
 async Task Responce_Connect4_Play(string Msg, MessageEventArgs e)
 {
     if (Connect4Games.Where(x => !x.Finished).Any(x => x.Players.Any(y => e.User == y)))
     {
         var      Column = int.Parse(e.Message.RawText.Substring(2, 1));
         MainGame MG;
         if ((MG = Connect4.Play(e.User, Column)) != null)
         {
             if (MG.Players[MG._Turn].IsBot)
             {
                 Connect4.Play(MG.Players[MG._Turn], MG.PlayAI());
             }
         }
         else
         {
             (await e.Channel.SendMessage("It's not your turn, " + e.User.Mention)).Timed(40);
             WriteLine("Command Error: It is not the user's turn");
         }
     }
     else
     {
         (await e.Channel.SendMessage(":anger: You are not in a Connect 4 Game")).Timed(40);
         WriteLine("Command Error: User is not in a Connect 4 game");
         return;
     }
 }
Beispiel #3
0
 // Start is called before the first frame update
 void Start()
 {
     DashImg.color = Color.green;
     RecImg.color  = Color.green;
     mG            = GameObject.FindGameObjectWithTag("Player").GetComponent <MG>();
     aG            = GameObject.FindGameObjectWithTag("Graphic").GetComponent <AnimatorGus>();
 }
Beispiel #4
0
    //void ShowDestroyButton(Vec2 pt)
    //{
    //    var ui = UIManager.Instance.ShowTopUI("InBattleUI/SelectUnitUI", true) as SelectUnitUI;
    //    ui.Pos = pt;
    //    ui.Choices = new string[] { "DestroyBuilding" };
    //    ui.ChoicesName = new string[] { "回收" };
    //    ui.Refresh();
    //    ui.OnChoiceSel = (toType) =>
    //    {
    //        ShowReDestroySel(pt);
    //    };
    //}

    void ShowBuildAccessory(Vec2 pt)
    {
        var ui = UIManager.Instance.ShowTopUI("InBattleUI/SelectUnitUI", true) as SelectUnitUI;

        ui.Pos         = pt;
        ui.Choices     = new string[] { "Accessory", /* "DestroyBuilding" */ };
        ui.ChoicesName = new string[] { "+1 仓库", /* "回收" */ };
        ui.Refresh();
        ui.OnChoiceSel = (toType) =>
        {
            if (toType == "Accessory")
            {
                if (u.Room.FindNextAccessoryPos(u, "Accessory") == Vec2.Zero)
                {
                    AddTip("无法建造更多仓库");
                    return;
                }
                else if (!MG.CheckResourceRequirementAndTip(toType))
                {
                    return;
                }

                var conn = GameCore.Instance.ServerConnection;
                var buff = conn.Send2Srv("ConstructAccessory");
                buff.Write(U.UID);
                buff.Write("Accessory");
                conn.End(buff);
            }
            //else if (toType == "DestroyBuilding")
            //{
            //    ShowReDestroySel(pt);
            //}
        };
    }
Beispiel #5
0
        public override void HandleMessage(int fromId, Msg msg)
        {
            switch (msg.Type)
            {
            case MsgType.Commit:
                // collect commitments from parties
                Commitment = ((CommitMsg)msg).Commitment;
                break;

            case MsgType.Share:
                // collect shares from parties

                var swMsg = msg as ShareWitnessMsg <BigZp>;
                if (PolyCommit != null && Commitment != null &&
                    !PolyCommit.VerifyEval(Commitment, new BigZp(Prime, DstQuorum.GetPositionOf(Me.Id) + 1), swMsg.Share, swMsg.Witness))
                {
                    // broadcast an accusation against the i-th party.
                    throw new NotImplementedException();
                }
                else if (PolyCommit != null && Commitment == null)
                {
                    Console.Write("No commitment received from" + fromId);
                }

                IsCompleted = true;
                Result      = new Share <BigZp>(swMsg.Share, false);
                break;
            }
        }
Beispiel #6
0
 // Update is called once per frame
 void Update()
 {
     if (MG.trig)
     {
         MG.moveCheck();
         MG.trig = false;
     }
 }
Beispiel #7
0
 // Start is called before the first frame update
 public static void T(int i, int j, int k, GameObject prefab)
 {
     MG.spawn(i, j, k, prefab);
     MG.spawn(i, j, k - 1, prefab);
     MG.spawn(i, j, k + 1, prefab);
     MG.spawn(i, j - 1, k, prefab);
     //promenliva prashta -1
 }
 // Start is called before the first frame update
 void Start()
 {
     mg    = GetComponentInParent <MG>();
     anim  = GetComponent <Animator>();
     speed = mg.speed;
     anim.SetBool("BasicAttack", true);
     canWalk = true;
 }
 public void Dispose()
 {
     disposedValue            = true;
     img.Dispose(); img       = null;
     map.Dispose(); map       = null;
     Players.Clear(); Players = null;
     MG.Dispose(); MG         = null;
     recording = null;
 }
Beispiel #10
0
        public static MG GenerateCommitment(int numShares, BigZp[] coeffs, BigInteger prime, ref MG[] witnesses, PolyCommit polyCommit)
        {
            var iz = new BigZp[numShares];
            for (int i = 0; i < numShares; i++)
            {
                iz[i] = new BigZp(prime, new BigInteger(i + 1));
            }

            byte[] proof = null;
            MG commitment = polyCommit.Commit(coeffs, iz, ref witnesses, ref proof, false);

            return commitment;
        }
Beispiel #11
0
    void ShowSels(Vec2 pt)
    {
        var ui = UIManager.Instance.ShowTopUI("InBattleUI/SelectUnitUI", true) as SelectUnitUI;

        ui.Pos     = pt;
        ui.Choices = u.UnitType == "Base" ?
                     (new string[] { "CrystalMachine" }).Concat(u.cfg.ReconstructTo).ToArray() :
                     new string[] { "CrystalMachine" };

        ui.ChoicesName = ui.Choices.ToArray((i, t, skipAct) =>
        {
            var ccfg = t == "CrystalMachine" ?
                       UnitConfiguration.GetDefaultConfig("CrystalMachine") :
                       UnitConfiguration.GetDefaultConfig(t);

            return(ccfg.DisplayName);
        });
        ui.Refresh();
        ui.OnChoiceSel = (toType) =>
        {
            var unitType = toType == "CrystalMachine" ? "CrystalMachine" : toType;
            if (!U.BuildingCompleted ||
                !MG.CheckPrerequisitesAndTip(unitType) ||
                !MG.CheckResourceRequirementAndTip(unitType))
            {
                return;
            }

            if (toType == "CrystalMachine")
            {
                if (U.Room.FindNextCrystalMachinePos(U) == Vec2.Zero)
                {
                    AddTip("没有多余的矿机位置");
                    return;
                }

                var conn = GameCore.Instance.ServerConnection;
                var buff = conn.Send2Srv("ConstructCrystalMachine");
                buff.Write(U.UID);
                conn.End(buff);
            }
            else // 升级基地
            {
                var conn = GameCore.Instance.ServerConnection;
                var buff = conn.Send2Srv("ReconstructBuilding");
                buff.Write(U.UID);
                buff.Write(toType);
                conn.End(buff);
            }
        };
    }
Beispiel #12
0
        private void Reshare(BigZp secret)
        {
            Debug.Assert(Prime == secret.Prime);

            IList <BigZp> coeffs = null;

            var shares = BigShamirSharing.Share(secret, FinalShareCount, NewPolyDeg, out coeffs);

            MG[] witnesses  = null;
            MG   commitment = null;

            if (PolyCommit != null)
            {
                commitment = BigShamirSharing.GenerateCommitment(FinalShareCount, coeffs.ToArray(), Prime, ref witnesses, (Quorums[TO] as ByzantineQuorum).PolyCommit);

                // fake random generation round
                for (int i = 0; i < Quorums[TO].Size; i++)
                {
                    NetSimulator.FakeMulticast(Quorums[TO].Size, secret.Size);
                }
                // fake commitment and challenge response
                NetSimulator.FakeMulticast(Quorums[TO].Size, secret.Size);
                NetSimulator.FakeMulticast(Quorums[TO].Size, secret.Size);
            }
            else
            {
                witnesses = new MG[FinalShareCount];
            }

            QuorumBroadcast(new CommitMsg(commitment), TO);

            // create the share messages
            if (PolyCommit != null)
            {
                Debug.Assert(PolyCommit.VerifyEval(commitment, new BigZp(Prime, 2), shares[1], witnesses[1]));
            }
            Debug.Assert(BigShamirSharing.Recombine(shares, NewPolyDeg, Prime) == secret);

            int numSent = 0;

            //int delay = (PolyCommit != null) ? 1 : 0;
            foreach (var toMember in Quorums[TO].Members)
            {
                for (int i = 0; i < FinalSharesPerParty; i++)
                {
                    Send(toMember, new ShareWitnessMsg <BigZp>(shares[numSent], witnesses[numSent]));
                    numSent++;
                }
            }
        }
Beispiel #13
0
        public static MG GenerateCommitment(int numShares, BigZp[] coeffs, BigInteger prime, ref MG[] witnesses, PolyCommit polyCommit)
        {
            var iz = new BigZp[numShares];

            for (int i = 0; i < numShares; i++)
            {
                iz[i] = new BigZp(prime, new BigInteger(i + 1));
            }

            byte[] proof      = null;
            MG     commitment = polyCommit.Commit(coeffs, iz, ref witnesses, ref proof, false);

            return(commitment);
        }
Beispiel #14
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("w"))
        {
            T(1, 9, 3, prefab[0]);
            MG.updater();
        }
        if (Input.GetKeyDown("space"))
        {
            // Destroy(GameObject.Find("0"));

            /* DesmeObject.FindWithTag(MG.grid[1, 2, 3].tag));
             * Debug.Log(GameObject.Find(MG.grid[1, 2, 3].name));*/
            /*MG.movedown();
            *  MG.updater(); */
        }
    }
Beispiel #15
0
    // 点击生产单位
    public override void OnClick(Vec2 pt, Vector3 wp)
    {
        if (inReplay)
        {
            return;
        }

        if (U.Player != GameCore.Instance.MePlayer)
        {
            base.OnClick(pt, wp);
            return;
        }

        if (null != MG)
        {
            MG.UPSUI.Hide();
        }

        if (IsExampleUnit)
        {
            return;
        }

        if (u.InDestroying)
        {
            return;
        }
        else if (!U.BuildingCompleted)
        {
            ShowCancelSel(pt);
        }
        else if (U.cfg.ReconstructTo != null)
        {
            ShowLevelUpSel(U.cfg.ReconstructTo, pt);
        }
        else if (u.UnitType == "Barrack" || u.UnitType == "Factory" || u.UnitType == "Airport")
        {
            ShowBuildAccessory(pt);
        }
        else
        {
            // ShowDestroyButton(pt);
            MG.OnClick(pt, wp);
        }
    }
Beispiel #16
0
        public void Share(BigZp secret)
        {
            Debug.Assert(Prime == secret.Prime);
            IList <BigZp> coeffs = null;

            int polyDegree = (int)Math.Ceiling(DstQuorum.Size / 3.0) - 1;

            // generate a random polynomial
            var shares = BigShamirSharing.Share(secret, DstQuorum.Size, PolyDegree, out coeffs);

            MG[] witnesses  = null;
            MG   commitment = null;

            if (PolyCommit != null)
            {
                commitment = BigShamirSharing.GenerateCommitment(DstQuorum.Size, coeffs.ToArray(), Prime, ref witnesses, PolyCommit);
            }
            else
            {
                witnesses = new MG[DstQuorum.Size];
            }

            Multicast(new CommitMsg(commitment), DstQuorum.Members);

            // create share messages
            var shareMsgs = new ShareWitnessMsg <BigZp> [DstQuorum.Size];

            for (int i = 0; i < DstQuorum.Size; i++)
            {
                shareMsgs[i] = new ShareWitnessMsg <BigZp>(shares[i], witnesses[i]);
            }

            if (PolyCommit != null)
            {
                Debug.Assert(PolyCommit.VerifyEval(commitment, new BigZp(Prime, 2), shareMsgs[1].Share, shareMsgs[1].Witness));
            }
            Debug.Assert(BigShamirSharing.Recombine(shares, PolyDegree, Prime) == secret);

            // send the i-th share message to the i-th party
            Send(shareMsgs, DstQuorum.Members);
        }
Beispiel #17
0
    void ShowLevelUpSel(string[] newTypes, Vec2 pt)
    {
        // var btns = new string[newTypes.Length + 1];
        // newTypes.CopyTo(btns, 0);
        // btns[newTypes.Length] = "DestroyBuilding";
        var btns = newTypes;

        var ui = UIManager.Instance.ShowTopUI("InBattleUI/SelectUnitUI", true) as SelectUnitUI;

        ui.Pos         = pt;
        ui.Choices     = btns;
        ui.ChoicesName = btns.ToArray((i, t, skipAct) =>
        {
            //if (t == "DestroyBuilding")
            //    return "回收";

            var ccfg = UnitConfiguration.GetDefaultConfig(t);
            return(ccfg.DisplayName);
        });
        ui.Refresh();
        ui.OnChoiceSel = (toType) =>
        {
            if (toType == "DestroyBuilding")
            {
                ShowReDestroySel(pt);
            }
            else if (!U.BuildingCompleted || !MG.CheckPrerequisitesAndTip(toType) || !MG.CheckResourceRequirementAndTip(toType))
            {
                return;
            }
            else
            {
                var conn = GameCore.Instance.ServerConnection;
                var buff = conn.Send2Srv("ReconstructBuilding");
                buff.Write(U.UID);
                buff.Write(toType);
                conn.End(buff);
            }
        };
    }
Beispiel #18
0
    IEnumerator AttackCycle()
    {
        IsAttacking = true;
        while (CanAttack)
        {
            if (IsShooting == false)
            {
                foreach (ShockWaveAttack SWA in ShockWaves)
                {
                    SWA.StartAttackCycle();
                }

                foreach (MachineGun MG in Guns)
                {
                    MG.StopShooting();
                }
            }

            else
            {
                foreach (MachineGun MG in Guns)
                {
                    MG.StartShooting();
                }

                foreach (ShockWaveAttack SWA in ShockWaves)
                {
                    SWA.StopAttackingCycle();
                }
            }

            yield return(new WaitForSeconds(WaitBetweenAttacks));

            IsShooting = !IsShooting;
        }

        IsAttacking = false;
    }
Beispiel #19
0
    void ShowBaseConstructionSel(Vec2 pt)
    {
        var ui = UIManager.Instance.ShowTopUI("InBattleUI/SelectUnitUI", true) as SelectUnitUI;

        ui.Pos         = pt;
        ui.Choices     = new string[] { "Base" };
        ui.ChoicesName = new string[] { "基地" };

        ui.Refresh();
        ui.OnChoiceSel = (toType) =>
        {
            if (!MG.CheckPrerequisitesAndTip(toType) || !MG.CheckResourceRequirementAndTip(toType))
            {
                return;
            }

            var conn = GameCore.Instance.ServerConnection;
            var buff = conn.Send2Srv("ConstructBuilding");
            buff.Write(toType);
            buff.Write(U.Pos);
            conn.End(buff);
        };
    }
Beispiel #20
0
    void OnTriggerEnter(Collider other)
    {
        if (other.transform.position.z > transform.position.z + 0.1f)
        {
            if (other.tag == "Wrong")
            {
                isWrong = true;

                if (canProduceSound == 1)
                {
                    audioSource.clip = incorrectSound;
                    audioSource.Play();
                }
                //errorFinder.text = ("Reached");
                GetComponent <score> ().OnWrongAnswer(gametype);
            }
            else if (other.tag == "Right")
            {
                if (canProduceSound == 1)
                {
                    audioSource.clip = correctSound;
                    audioSource.Play();
                }

                switch (gametype)
                {
                case 1:
                    MG.GetComponent <mathGame> ().AdditionTiles();

                    if (PlayerPrefs.GetFloat(currentplayer + "_Addexp") == 0)
                    {
                        exp = (int)experience;
                    }
                    else
                    {
                        exp = ((int)PlayerPrefs.GetFloat(currentplayer + "_Addexp") + (int)experience);
                    }

                    PlayerPrefs.SetFloat(currentplayer + "_Addexp", exp);
                    break;

                case 2:
                    MG.GetComponent <mathGame> ().SubtractionTiles();

                    if (PlayerPrefs.GetFloat(currentplayer + "_Addexp") == 0)
                    {
                        exp = (int)experience;
                    }
                    else
                    {
                        exp = ((int)PlayerPrefs.GetFloat(currentplayer + "_Subtractexp") + (int)experience);
                    }

                    PlayerPrefs.SetFloat(currentplayer + "_Subtractexp", exp);
                    break;

                case 3:
                    MG.GetComponent <mathGame> ().MultiplicationTiles();

                    if (PlayerPrefs.GetFloat(currentplayer + "_Addexp") == 0)
                    {
                        exp = (int)experience;
                    }
                    else
                    {
                        exp = ((int)PlayerPrefs.GetFloat(currentplayer + "_Multiplyexp") + (int)experience);
                    }


                    PlayerPrefs.SetFloat(currentplayer + "_Multiplyexp", exp);
                    break;

                case 4:
                    MG.GetComponent <mathGame> ().DivisionTiles();

                    if (PlayerPrefs.GetFloat(currentplayer + "_Addexp") == 0)
                    {
                        exp = (int)experience;
                    }
                    else
                    {
                        exp = ((int)PlayerPrefs.GetFloat(currentplayer + "_Divideexp") + (int)experience);
                    }


                    PlayerPrefs.SetFloat(currentplayer + "_Divideexp", exp);
                    break;

                default:
                    Debug.Log("No game type selected");
                    break;
                }
            }
        }
    }
Beispiel #21
0
 // Start is called before the first frame update
 void Start()
 {
     mg    = GetComponentInParent <MG>();
     anim  = GetComponent <Animator>();
     speed = mg.speed;
 }
Beispiel #22
0
        void ProcessDecodedMessage(int msgFunction, int msgPayloadLength, byte[] msgPayload)
        {
            int numLed, etatLed, IRGauche, IRCentre, IRDroite, MG, MD;

            switch ((Functions)msgFunction)
            {
            case Functions.LEDS:
                numLed  = msgPayload[0];
                etatLed = msgPayload[1];
                if (numLed == 1)
                {
                    if (etatLed == 1)
                    {
                        CheckBoxLed1.IsChecked = true;
                    }
                    else
                    {
                        CheckBoxLed1.IsChecked = false;
                    }
                }
                else if (numLed == 2)
                {
                    if (etatLed == 1)
                    {
                        CheckBoxLed2.IsChecked = true;
                    }
                    else
                    {
                        CheckBoxLed2.IsChecked = false;
                    }
                }
                else if (numLed == 3)
                {
                    if (etatLed == 1)
                    {
                        CheckBoxLed3.IsChecked = true;
                    }
                    else
                    {
                        CheckBoxLed3.IsChecked = false;
                    }
                }
                break;

            case Functions.telemetres:
                IRDroite = msgPayload[0];
                IRCentre = msgPayload[1];
                IRGauche = msgPayload[2];
                TextBoxTelemetres.Text = "IR Gauche:" + IRGauche.ToString() + "cm\n\r" + "IR Centre:" + IRCentre.ToString() + "cm\n\r" + "IR Droite:" + IRDroite.ToString() + "cm";
                break;

            case Functions.moteurs:
                MG = msgPayload[0];
                MD = msgPayload[1];
                TextBoxMoteurs.Text = "Vitesse Gauche:" + MG.ToString() + "%\n\r" + "Vitesse Droite:" + MD.ToString() + "%\n\r";
                break;

            case Functions.message:
                TextBoxReception.Text += Encoding.UTF8.GetString(msgPayload, 0, msgPayload.Length) + "\n";
                break;

            case Functions.RobotState:
                int instant = (((int)msgPayload[1]) << 24) + (((int)msgPayload[2]) << 16) + (((int)msgPayload[3]) << 8) + (((int)msgPayload[4]));
                RtbReception.Text = ((StateRobot)(msgPayload[0])).ToString() + "\n\rTemps: " + instant.ToString() + " ms";
                break;

            case Functions.Clavier:
                textBoxPilotage.Text = "Instruction reçue: " + ((StateRobot)msgPayload[0]).ToString();
                break;
            }
        }
Beispiel #23
0
        private int method5(List <double[][]>[] rgbList, int chr)
        {
            List <double> subDiff = new List <double>();

            List <double[][]> MR, MG, MB;
            List <double[][]> SR, SG, SB;

            int listSize   = rgbList[0].Count;
            int windowSize = Math.Min(Global.maxWidth, listSize);
            int result     = 0;
            int minWidth   = 40;

            switch (chr)
            {
            case 0:
                // 4:4:4
                for (int i = minWidth; i < windowSize; i++)
                {
                    MR = rgbList[0].Take(listSize - i).ToList();
                    MG = rgbList[1].Take(listSize - i).ToList();
                    MB = rgbList[2].Take(listSize - i).ToList();

                    SR = rgbList[0].Skip(i).ToList();
                    SG = rgbList[1].Skip(i).ToList();
                    SB = rgbList[2].Skip(i).ToList();

                    subDiff.Add(UBDiffSum(MR, MG, MB, SR, SG, SB));

                    MR.Clear();
                    MG.Clear();
                    MB.Clear();
                    SR.Clear();
                    SG.Clear();
                    SB.Clear();
                }
                result = subDiff.IndexOf(subDiff.Min()) + minWidth;
                break;

            case 1:
                // 4:4:0
                for (int i = minWidth; i < windowSize; i++)
                {
                    MR = rgbList[0].Where((item, index) => index % 2 != 0).Take(listSize / 2 - i).ToList();
                    MG = rgbList[1].Where((item, index) => index % 2 != 0).Take(listSize / 2 - i).ToList();
                    MB = rgbList[2].Where((item, index) => index % 2 != 0).Take(listSize / 2 - i).ToList();

                    SR = rgbList[0].Skip(2 * i).Where((item, index) => index % 2 == 0).ToList();
                    SG = rgbList[1].Skip(2 * i).Where((item, index) => index % 2 == 0).ToList();
                    SB = rgbList[2].Skip(2 * i).Where((item, index) => index % 2 == 0).ToList();

                    subDiff.Add(UBDiffSum(MR, MG, MB, SR, SG, SB));

                    MR.Clear();
                    MG.Clear();
                    MB.Clear();
                    SR.Clear();
                    SG.Clear();
                    SB.Clear();
                }
                result = subDiff.IndexOf(subDiff.Min()) + minWidth;
                break;

            case 2:
                // 4:2:2
                for (int i = minWidth; i < windowSize; i += 2)
                {
                    MR = rgbList[0].Take(listSize - i).ToList();
                    MG = rgbList[1].Take(listSize - i).ToList();
                    MB = rgbList[2].Take(listSize - i).ToList();

                    SR = rgbList[0].Skip(i).ToList();
                    SG = rgbList[1].Skip(i).ToList();
                    SB = rgbList[2].Skip(i).ToList();

                    subDiff.Add(UBDiffSum(MR, MG, MB, SR, SG, SB));

                    MR.Clear();
                    MG.Clear();
                    MB.Clear();
                    SR.Clear();
                    SG.Clear();
                    SB.Clear();
                }
                result = subDiff.IndexOf(subDiff.Min()) + minWidth / 2;
                break;

            case 3:
                //4:2:0
                for (int i = minWidth; i < windowSize; i += 2)
                {
                    MR = rgbList[0].Where((item, index) => index % 4 == 2 || index % 4 == 3).Take(listSize / 2 - i).ToList();
                    MG = rgbList[1].Where((item, index) => index % 4 == 2 || index % 4 == 3).Take(listSize / 2 - i).ToList();
                    MB = rgbList[2].Where((item, index) => index % 4 == 2 || index % 4 == 3).Take(listSize / 2 - i).ToList();

                    SR = rgbList[0].Skip(2 * i).Where((item, index) => index % 4 == 0 || index % 4 == 1).ToList();
                    SG = rgbList[1].Skip(2 * i).Where((item, index) => index % 4 == 0 || index % 4 == 1).ToList();
                    SB = rgbList[2].Skip(2 * i).Where((item, index) => index % 4 == 0 || index % 4 == 1).ToList();

                    subDiff.Add(UBDiffSum(MR, MG, MB, SR, SG, SB));

                    MR.Clear();
                    MG.Clear();
                    MB.Clear();
                    SR.Clear();
                    SG.Clear();
                    SB.Clear();
                }
                result = subDiff.IndexOf(subDiff.Min()) + minWidth / 2;
                break;
            }

            return(result);
        }
Beispiel #24
0
 public ShareWitnessMsg(T share, MG witness)
     : base(share)
 {
     Witness = witness;
 }
Beispiel #25
0
        protected override void ProcessRecord()
        {
            this.SetOptions();
            this.SetScope(Server);
            this.SetManagementPath(Identity);
            ManagementObject wmiRecord = this.Get();

            WmiRecordClass WmiRecordClassName = (WmiRecordClass)Enum.Parse(typeof(WmiRecordClass), (String)wmiRecord.Properties["__CLASS"].Value);
            String         NewPath            = String.Empty;

            #region Parameter Set validation
            Boolean Terminate = false;
            switch (ParameterSetName)
            {
            case "PS0": break;

            case "PS1":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_AType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_AAAAType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_WKSType)
                {
                    Terminate = true;
                }
                break;

            case "PS2":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_CNAMEType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_MBType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_MDType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_MFType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_NSType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_PTRType)
                {
                    Terminate = true;
                }
                break;

            case "PS3":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_MGType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_MRType)
                {
                    Terminate = true;
                }
                break;

            case "PS4":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_TXTType)
                {
                    Terminate = true;
                }
                break;

            case "PS5":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_HINFOType)
                {
                    Terminate = true;
                }
                break;

            case "PS6":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_ISDNType)
                {
                    Terminate = true;
                }
                break;

            case "PS7":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_MINFOType)
                {
                    Terminate = true;
                }
                break;

            case "PS8":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_NXTType)
                {
                    Terminate = true;
                }
                break;

            case "PS9":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_RPType)
                {
                    Terminate = true;
                }
                break;

            case "PS10":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_AFSDBType)
                {
                    Terminate = true;
                }
                break;

            case "PS11":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_MXType &
                    WmiRecordClassName != WmiRecordClass.MicrosoftDNS_RTType)
                {
                    Terminate = true;
                }
                break;

            case "PS12":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_X25Type)
                {
                    Terminate = true;
                }
                break;

            case "PS13":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_SOAType)
                {
                    Terminate = true;
                }
                break;

            case "PS14":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_SRVType)
                {
                    Terminate = true;
                }
                break;

            case "PS15":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_WINSType)
                {
                    Terminate = true;
                }
                break;

            case "PS16":
                if (WmiRecordClassName != WmiRecordClass.MicrosoftDNS_WINSRType)
                {
                    Terminate = true;
                }
                break;
            }

            if (Terminate)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new PSInvalidOperationException("InvalidParameterSetForRecordType"),
                        "InvalidOperation",
                        ErrorCategory.InvalidOperation,
                        typeof(ManagementCmdlet)));
            }
            #endregion

            if (ShouldProcess((String)wmiRecord.Properties["TextRepresentation"].Value))
            {
                switch (WmiRecordClassName)
                {
                case WmiRecordClass.MicrosoftDNS_AType:
                    A ARecord = new A(wmiRecord, Server);
                    NewPath = ARecord.Modify(TTL, Address.ToString());
                    break;

                case WmiRecordClass.MicrosoftDNS_AAAAType:
                    AAAA AAAARecord = new AAAA(wmiRecord, Server);
                    NewPath = AAAARecord.Modify(TTL, Address.ToString());
                    break;

                case WmiRecordClass.MicrosoftDNS_AFSDBType:
                    AFSDB AFSDBRecord = new AFSDB(wmiRecord, Server);
                    NewPath = AFSDBRecord.Modify(TTL, SubType, TargetName);
                    break;

                case WmiRecordClass.MicrosoftDNS_CNAMEType:
                    CNAME CNAMERecord = new CNAME(wmiRecord, Server);
                    NewPath = CNAMERecord.Modify(TTL, Hostname);
                    break;

                case WmiRecordClass.MicrosoftDNS_HINFOType:
                    HINFO HINFORecord = new HINFO(wmiRecord, Server);
                    NewPath = HINFORecord.Modify(TTL, CPU, OS);
                    break;

                case WmiRecordClass.MicrosoftDNS_ISDNType:
                    ISDN ISDNRecord = new ISDN(wmiRecord, Server);
                    NewPath = ISDNRecord.Modify(TTL, ISDNNumber, SubAddress);
                    break;

                case WmiRecordClass.MicrosoftDNS_MBType:
                    MB MBRecord = new MB(wmiRecord, Server);
                    NewPath = MBRecord.Modify(TTL, Hostname);
                    break;

                case WmiRecordClass.MicrosoftDNS_MDType:
                    MD MDRecord = new MD(wmiRecord, Server);
                    NewPath = MDRecord.Modify(TTL, Hostname);
                    break;

                case WmiRecordClass.MicrosoftDNS_MFType:
                    MF MFRecord = new MF(wmiRecord, Server);
                    NewPath = MFRecord.Modify(TTL, Hostname);
                    break;

                case WmiRecordClass.MicrosoftDNS_MGType:
                    MG MGRecord = new MG(wmiRecord, Server);
                    NewPath = MGRecord.Modify(TTL, MailboxName);
                    break;

                case WmiRecordClass.MicrosoftDNS_MINFOType:
                    MINFO MINFORecord = new MINFO(wmiRecord, Server);
                    NewPath = MINFORecord.Modify(TTL, ResponsibleMailbox, ErrorMailbox);
                    break;

                case WmiRecordClass.MicrosoftDNS_MRType:
                    MR MRRecord = new MR(wmiRecord, Server);
                    NewPath = MRRecord.Modify(TTL, MailboxName);
                    break;

                case WmiRecordClass.MicrosoftDNS_MXType:
                    MX MXRecord = new MX(wmiRecord, Server);
                    NewPath = MXRecord.Modify(TTL, Preference, TargetName);
                    break;

                case WmiRecordClass.MicrosoftDNS_NSType:
                    NS NSRecord = new NS(wmiRecord, Server);
                    NewPath = NSRecord.Modify(TTL, Hostname);
                    break;

                case WmiRecordClass.MicrosoftDNS_NXTType:
                    NXT NXTRecord = new NXT(wmiRecord, Server);
                    NewPath = NXTRecord.Modify(TTL, NextDomainName, Types);
                    break;

                case WmiRecordClass.MicrosoftDNS_PTRType:
                    PTR PTRRecord = new PTR(wmiRecord, Server);
                    NewPath = PTRRecord.Modify(TTL, Hostname);
                    break;

                case WmiRecordClass.MicrosoftDNS_RPType:
                    RP RPRecord = new RP(wmiRecord, Server);
                    NewPath = RPRecord.Modify(TTL, ResponsibleMailbox, TXTDomainName);
                    break;

                case WmiRecordClass.MicrosoftDNS_RTType:
                    RT RTRecord = new RT(wmiRecord, Server);
                    NewPath = RTRecord.Modify(TTL, Preference, TargetName);
                    break;

                case WmiRecordClass.MicrosoftDNS_SOAType:
                    SOA SOARecord = new SOA(wmiRecord, Server);
                    NewPath = SOARecord.Modify(TTL, SerialNumber,
                                               SOAServer, ResponsibleMailbox, RefreshInterval,
                                               RetryDelay, ExpireLimit, MinimumTTL);
                    break;

                case WmiRecordClass.MicrosoftDNS_SRVType:
                    SRV SRVRecord = new SRV(wmiRecord, Server);
                    NewPath = SRVRecord.Modify(TTL, Priority, Weight, Port, TargetName);
                    break;

                case WmiRecordClass.MicrosoftDNS_TXTType:
                    TXT TXTRecord = new TXT(wmiRecord, Server);
                    NewPath = TXTRecord.Modify(TTL, Text);
                    break;

                case WmiRecordClass.MicrosoftDNS_WINSType:
                    WINS WINSRecord = new WINS(wmiRecord, Server);
                    NewPath = WINSRecord.Modify(TTL, MappingFlag, LookupTimeout,
                                                CacheTimeout, String.Join(" ", WinsServers));
                    break;

                case WmiRecordClass.MicrosoftDNS_WINSRType:
                    WINSR WINSRRecord = new WINSR(wmiRecord, Server);
                    NewPath = WINSRRecord.Modify(TTL, MappingFlag, LookupTimeout,
                                                 CacheTimeout, ResultDomain);
                    break;

                case WmiRecordClass.MicrosoftDNS_WKSType:
                    WKS WKSRecord = new WKS(wmiRecord, Server);
                    NewPath = WKSRecord.Modify(Address, TTL, IPProtocol, String.Join(" ", Services));
                    break;

                case WmiRecordClass.MicrosoftDNS_X25Type:
                    X25 X25Record = new X25(wmiRecord, Server);
                    NewPath = X25Record.Modify(TTL, PSDNAddress);
                    break;

                default:
                    ThrowTerminatingError(
                        new ErrorRecord(
                            new PSNotSupportedException("Unsupported Record Type"),
                            "RecordModificationNotSupported",
                            ErrorCategory.NotImplemented,
                            typeof(ManagementCmdlet)));
                    break;
                }

                if (PassThru)
                {
                    this.SetManagementPath(NewPath);
                    wmiRecord = this.Get();

                    WriteRecord(wmiRecord);
                }
            }
        }
 private Video CopyVideoData(MG.DataModels.Video data)
 {
     return new Video()
     {
         ImageUrl = data.ImageUrl,
         Intro = data.Desc,
         Name = data.Title,
         PlayCount = data.PlayCount,
         VideoId = data.Id
     };
 }
Beispiel #27
0
        private Video CopyVideoData(MG.DataModels.Video source)
        {
            Video video = new Video();
            video.Name = source.Title;
            video.VideoId = source.Id;
            video.ImageUrl = source.ImageUrl;
            video.Intro = source.Desc;

            return video;
        }
Beispiel #28
0
 public CommitMsg(MG commitment)
 {
     Type       = MsgType.Commit;
     Commitment = commitment;
 }
Beispiel #29
0
 public CommitMsg(MG commitment)
 {
     Type = MsgType.Commit;
     Commitment = commitment;
 }