Пример #1
0
                } // end UISettingPanel

                public void DoBeforeEntering() {
                    stuffArray = new UICell[4];
                    cellArray = new UICell[ConstConfig.GRID_COUNT];
                    blueprintPack = SceneManager.mainCharacter.pack.GetItemPack(ConstConfig.PRINT);
                    gameObject = ObjectTool.InstantiateGo("ForgePanelUI", ResourcesTool.LoadPrefabUI(id), SceneManager.mainCanvas.rectTransform);
                    rectTransform = gameObject.GetComponent<RectTransform>();
                    rectTransform.sizeDelta = SceneManager.mainCanvas.sizeDelta;
                    buleprint = rectTransform.Find("Blueprint/Print").gameObject.AddComponent<UICell>();
                    for (int i = 0; i < cellArray.Length; i++) {
                        cellArray[i] = rectTransform.Find("GridPanel/Grids/Grid_" + i).gameObject.AddComponent<UICell>();
                        string itemID = blueprintPack.GetItemIDForGrid(i);
                        IItemInfo info = Configs.itemConfig.GetItemInfo(itemID);
                        if (null == info) {
                            cellArray[i].HideItem();
                            continue;
                        } // end 
                        int id = i;
                        cellArray[i].AddAction(delegate () { OnSelectedGrid(id); });
                        cellArray[i].SetUIItem(ResourcesTool.LoadSprite(info.spritepath), 0);
                    } // end for
                    for (int i = 0; i < stuffArray.Length; i++) {
                        stuffArray[i] = rectTransform.Find("Blueprint/Stuff_" + i).gameObject.AddComponent<UICell>();
                        stuffArray[i].gameObject.SetActive(false);
                    } // end for
                    rectTransform.Find("ForgeBtn").gameObject.AddComponent<UIButtonNormal>().AddListener(delegate () { OnClickForgeBtn(); });
                    rectTransform.Find("CloseBtn").gameObject.AddComponent<UIButtonNormal>().AddListener(delegate () { OnClickCloseBtn(); }, "ui_close");
                } // end DoBeforeEntering
Пример #2
0
        private byte[] ReadOneFrame(IPack pack, bool isFinish)
        {
            byte[] result = new byte[100];
            int    pos    = 0;
            byte   before = 0;

            while (Box.ReadBytes(result, pos++, 1) == 1)
            {
                if (before == 0x0D && (result[pos - 1] == 0x0A))
                {
                    break;
                }
                before = result[pos - 1];
            }

            if (before == 0x0D && result[pos - 1] == 0x0A)
            {
                // break normal
                result = pack.Unpack(result, 0, pos);
            }
            else
            {
                result = null;
            }
            FinishExecute(isFinish);
            return(result);
        }
Пример #3
0
 public AbstractECU(ICommbox commbox)
 {
     this.commbox       = commbox;
     this.protocol      = null;
     this.pack          = new NoPack();
     stopReadDataStream = false;
 }
Пример #4
0
        static void Main(string[] args)
        {
            List <IPack> products = new List <IPack>();

            Console.WriteLine("Enter total number of order");
            int a = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                Console.WriteLine("Enter the type of product:A,B,C or D");
                string type = Console.ReadLine();
                IPack  p    = ProductFactory.GetProduct(type);
                if (p != null)
                {
                    products.Add(p);
                }
            }

            var distinctProducts = products.GroupBy(x => x.ProductType)
                                   .Select(g => g.First())
                                   .ToList();

            decimal totalPrice = ProductFactory.GetTotalPrice(distinctProducts);

            Console.WriteLine(totalPrice);
            Console.ReadLine();
        }
        /// <summary>
        /// Requests the error detailes for a the specified processed pack.
        /// </summary>
        /// <param name="pack">The pack to get the error detailes for.</param>
        /// <param name="errorType">On successful return the type of error that occurred during input.</param>
        /// <param name="errorText">On successful return the additional text of the error that occurred during input.</param>
        /// <returns>
        ///   <c>true</c> if the specified pack had an error during input;<c>false</c> otherwise.
        /// </returns>
        bool IInitiateInputRequest.GetProcessedPackError(IPack pack, out InputErrorType errorType, out string errorText)
        {
            errorType = InputErrorType.None;
            errorText = string.Empty;

            if (pack == null)
            {
                return(false);
            }

            if ((pack is Pack) == false)
            {
                return(false);
            }

            var error = ((Pack)pack).Error;

            if (error == null)
            {
                return(false);
            }

            if (Enum.TryParse <InputErrorType>(error.Type, out errorType) == false)
            {
                errorType = InputErrorType.Rejected;
            }

            errorText = TextConverter.UnescapeInvalidXmlChars(error.Text);
            return(true);
        }
Пример #6
0
        public virtual void OnAfterInstallPack(IPack pack)
        {
            var script = String.Format(@"update [{0}].[DBVersion] 
                                            set [InstallationFinished] = getdate() 
                                          where [Major] = @major
                                            and [Minor] = @minor
                                            and [Build] = @build
                                            and [Revision] = @revision", Settings.ServiceSchema);

            using (var conn = new SqlConnection(Settings.ConnectionString))
                using (var cmd = new SqlCommand(Regex.Replace(script, @"\s+", " "), conn))
                {
                    conn.Open();
                    conn.ChangeDatabase(Settings.Database);

                    cmd.Parameters.Add(new SqlParameter("@major", pack.Version.Major));
                    cmd.Parameters.Add(new SqlParameter("@minor", pack.Version.Minor));
                    cmd.Parameters.Add(new SqlParameter("@build", pack.Version.Build));
                    cmd.Parameters.Add(new SqlParameter("@revision", pack.Version.Revision));

                    cmd.ExecuteNonQuery();
                };

            var args = new AfterPackInstallEventArgs()
            {
                Pack = pack
            };

            if (AfterPackInstall != null)
            {
                AfterPackInstall(this, args);
            }
            ;
        }
Пример #7
0
        private byte[] ReadOneFrame(IPack pack, bool isFinish)
        {
            byte[] result = new byte[100];
            int pos = 0;
            byte before = 0;
            while (Box.ReadBytes(result, pos++, 1) == 1)
            {
                if (before == 0x0D && (result[pos - 1] == 0x0A))
                {
                    break;
                }
                before = result[pos - 1];
            }

            if (before == 0x0D && result[pos - 1] == 0x0A)
            {
                // break normal
                result = pack.Unpack(result, 0, pos);
            }
            else
            {
                result = null;
            }
            FinishExecute(isFinish);
            return result;
        }
Пример #8
0
 public AbstractECU(ICommbox commbox)
 {
     this.commbox = commbox;
     this.protocol = null;
     this.pack = new NoPack();
     stopReadDataStream = false;
 }
Пример #9
0
        /// <inheritdoc />
        public void CreatePack(IPack pack)
        {
            PackDto packDto = PackDto.ToDto(pack);

            this.Context.Packs.Add(packDto);
            int count = this.Context.SaveChanges();

            if (count != 1)
            {
                throw new ApplicationException($"Unexpectedly created {count} rows");
            }
        }
Пример #10
0
        public void LoadPack(IPack <IFrenchSuitedCard> packOfCards)
        {
            var cards = packOfCards.GetCards();

            _clubsStackModel    = new StackModel(cards.Where(x => x.Suit == Suit.Clubs));
            _diamondsStackModel = new StackModel(cards.Where(x => x.Suit == Suit.Diamonds));
            _heartsStackModel   = new StackModel(cards.Where(x => x.Suit == Suit.Hearts));
            _spadesStackModel   = new StackModel(cards.Where(x => x.Suit == Suit.Spades));

            _clubsStackPresenter    = new StackPresenter(_clubsStackModel, stackViewClubs);
            _diamondsStackPresenter = new StackPresenter(_diamondsStackModel, stackViewDiamonds);
            _heartsStackPresenter   = new StackPresenter(_heartsStackModel, stackViewHearts);
            _spadesStackPresenter   = new StackPresenter(_spadesStackModel, stackViewSpades);
        }
Пример #11
0
        /// <summary>
        /// Convert domain object to DTO.
        /// </summary>
        /// <param name="pack">Pack.</param>
        /// <returns>Pack DTO.</returns>
        public static PackDto ToDto(IPack pack)
        {
            if (pack == null)
            {
                throw new ArgumentNullException(nameof(pack));
            }

            return(new PackDto(
                       id: pack.Id,
                       packColourId: pack.PackColour.Id,
                       setId: pack.Set.Id,
                       enteredService: pack.EnteredService,
                       boardNumber: pack.BoardNumber));
        }
Пример #12
0
                } // end LoseItem

                private void SwitchPack(string name) {
                    LoseItem();
                    packName = name;
                    currentPack = SceneManager.mainCharacter.pack.GetItemPack(name);
                    for (int i = 0; i < gridArray.Length; i++) {
                        string itemID = currentPack.GetItemIDForGrid(i);
                        IItemInfo info = Configs.itemConfig.GetItemInfo(itemID);
                        if (null == info) {
                            gridArray[i].HideItem();
                            continue;
                        } // end 
                        int count = currentPack.GetCountForGrid(i);
                        gridArray[i].SetUIItem(ResourcesTool.LoadSprite(info.spritepath), count);
                    } // end for
                } // end SwitchPack
Пример #13
0
        public byte[] ReadOneFrame(IPack pack)
        {
            byte[] buff = new byte[128];
            int i;
            for (i = 0; i < buff.Length; i++)
            {
                if (Box.ReadBytes(buff, i, 1) != 1)
                    break;
            }

            if (i < 5 || i > 11)
            {
                return null;
            }

            return pack.Unpack(buff, 0, i);
        }
Пример #14
0
        public byte[] SendAndRecv(byte[] data, int offset, int count, IPack pack)
        {
            int times = 3;

            while (times-- != 0)
            {
                if (protocol.SendFrames(data, offset, count, pack) != count)
                {
                    continue;
                }
                byte[] result = protocol.ReadFrames(pack);
                if (result == null)
                {
                    continue;
                }
                return(result);
            }
            return(null);
        }
Пример #15
0
        public byte[] ReadOneFrame(IPack pack)
        {
            byte[] buff = new byte[128];
            int    i;

            for (i = 0; i < buff.Length; i++)
            {
                if (Box.ReadBytes(buff, i, 1) != 1)
                {
                    break;
                }
            }

            if (i < 5 || i > 11)
            {
                return(null);
            }

            return(pack.Unpack(buff, 0, i));
        }
        public void Test_ScenarioA()
        {
            List <IPack> products = new List <IPack>();
            int          a        = Convert.ToInt32("3");
            //"Enter the type of product:A,B,C or D");
            IPack p = ProductFactory.GetProduct("A");

            products.Add(p);
            p = ProductFactory.GetProduct("B");
            products.Add(p);
            p = ProductFactory.GetProduct("C");
            products.Add(p);

            var distinctProducts = products.GroupBy(x => x.ProductType)
                                   .Select(g => g.First())
                                   .ToList();
            decimal totalPrice = ProductFactory.GetTotalPrice(distinctProducts);

            Assert.AreEqual(totalPrice, 100);
            Assert.Pass();
        }
Пример #17
0
        public byte[] ReadFrames(IPack pack)
        {
            byte[] buff = new byte[128];
            int    i;

            for (i = 0; i < buff.Length; i++)
            {
                if (Box.ReadBytes(buff, i, 1) != 1)
                {
                    break;
                }
            }

            if (i < 5)
            {
                FinishExecute(true);
                return(null);
            }

            List <byte> result = new List <byte>();
            int         j      = 3;
            int         k      = 0;

            while (j < i) // Multi Frame
            {
                if ((buff[k] == buff[j]) &&
                    (buff[k + 1] == buff[j + 1]) &&
                    (buff[k + 2] == buff[j + 2]))
                {
                    result.AddRange(pack.Unpack(buff, k, j - k));
                    k = j;
                }
                j++;
            }

            result.AddRange(pack.Unpack(buff, k, j - k)); // Add last frame or it's a single frame
            FinishExecute(true);

            return(result.ToArray());
        }
Пример #18
0
        public byte[] ReadFrames(IPack pack)
        {
            byte[] buff = new byte[128];
            int i;
            for (i = 0; i < buff.Length; i++)
            {
                if (Box.ReadBytes(buff, i, 1) != 1)
                    break;
            }

            if (i < 5)
            {
                FinishExecute(true);
                return null;
            }

            List<byte> result = new List<byte>();
            int j = 3;
            int k = 0;

            while (j < i) // Multi Frame
            {
                if ((buff[k] == buff[j]) &&
                    (buff[k + 1] == buff[j + 1]) &&
                    (buff[k + 2] == buff[j + 2]))
                {
                    result.AddRange(pack.Unpack(buff, k, j - k));
                    k = j;
                }
                j++;
            }

            result.AddRange(pack.Unpack(buff, k, j - k)); // Add last frame or it's a single frame
            FinishExecute(true);

            return result.ToArray();
        }
Пример #19
0
 public int SendFrames(byte[] data, int offset, int count, IPack pack)
 {
     return func.SendOneFrame(data, offset, count, pack, true);
 }
Пример #20
0
 public byte[] ReadOneFrame(IPack pack)
 {
     return(ReadOneFrame(pack, true));
 }
Пример #21
0
 public Deck(IPack <T> pack)
 {
     Pack = pack;
 }
Пример #22
0
                } // end GetWearInfo

                public bool PackItem(string id, int count) {
                    IPack pack = GetItemPack(Configs.itemConfig.GetItemType(id));
                    if (null == pack) return false;
                    // end if
                    return pack.PackItem(id, count);
                } // end PackItems
Пример #23
0
 public bool SetKeepLink(byte[] data, int offset, int count, IPack pack)
 {
     byte[] buff = pack.Pack(data, offset, count);
     return(func.SetKeepLink(buff, 0, buff.Length));
 }
Пример #24
0
 public bool SetKeepLink(byte[] data, int offset, int count, IPack pack)
 {
     byte[] buff = pack.Pack(data, offset, count);
     return func.SetKeepLink(buff, 0, buff.Length);
 }
Пример #25
0
 public byte[] SendAndRecv(byte[] data, int offset, int count, IPack pack)
 {
     return func.SendAndRecv(data, offset, count, pack);
 }
Пример #26
0
 public bool SetKeepLink(byte[] data, int offset, int count, IPack pack)
 {
     byte[] packData = pack.Pack(data, offset, count);
     return(func.SetKeepLink(packData, 0, packData.Length));
 }
Пример #27
0
 public byte[] ReadOneFrame(IPack pack)
 {
     return ReadOneFrame(pack, true);
 }
Пример #28
0
 public int SendFrames(byte[] data, int offset, int count, IPack pack)
 {
     return(func.SendOneFrame(data, offset, count, pack, true));
 }
Пример #29
0
        private byte[] ReadOneFrame(IPack pack, bool isFinish)
        {
            byte[] temp        = new byte[3];
            byte[] result      = new byte[255];
            int    frameLength = 0;
            int    length      = 0;
            byte   checksum    = 0;
            int    i;

            length = Box.ReadBytes(temp, 0, temp.Length);

            if (length <= 0)
            {
                FinishExecute(isFinish);
                return(null);
            }

            if (temp[1] == options.SourceAddress)
            {
                if (temp[0] == 0x80)
                {
                    byte[] b = new byte[1];
                    length = Box.ReadBytes(b, 0, 1);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return(null);
                    }

                    length = Convert.ToInt32(b[0]);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return(null);
                    }

                    Array.Copy(temp, 0, result, 0, temp.Length);
                    frameLength += temp.Length;
                    Array.Copy(b, 0, result, frameLength, 1);
                    ++frameLength;
                    length       = Box.ReadBytes(result, KWPPack.KWP80_HEADER_LENGTH, length + KWPPack.KWP_CHECKSUM_LENGTH);
                    frameLength += length;
                }
                else
                {
                    length = Convert.ToInt32(temp[0] - 0x80);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return(null);
                    }

                    Array.Copy(temp, 0, result, 0, temp.Length);
                    frameLength += temp.Length;
                    length       = Box.ReadBytes(result, temp.Length, length + KWPPack.KWP_CHECKSUM_LENGTH);
                    frameLength += length;
                }
            }
            else
            {
                if (temp[0] == 0x00)
                {
                    length = Convert.ToInt32(temp[1]);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return(null);
                    }
                    Array.Copy(temp, 0, result, 0, temp.Length);
                    frameLength += temp.Length;
                    length       = Box.ReadBytes(result, temp.Length, length);
                    frameLength += length;
                }
                else
                {
                    length = Convert.ToInt32(temp[0]);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return(null);
                    }

                    Array.Copy(temp, 0, result, 0, temp.Length);
                    frameLength += temp.Length;
                    length       = Box.ReadBytes(result, temp.Length, length - KWPPack.KWP_CHECKSUM_LENGTH);
                    frameLength += length;
                }
            }

            FinishExecute(isFinish);
            if (frameLength <= 0)
            {
                return(null);
            }

            for (i = 0; i < frameLength - 1; i++)
            {
                checksum += result[i];
            }

            if (checksum != result[frameLength - 1])
            {
                return(null);
            }

            return(pack.Unpack(result, 0, frameLength));
        }
Пример #30
0
 public static DirectoryInfo GetPackDir(this DirectoryInfo packageCacheDir, IPack pack)
 {
     return(packageCacheDir.GetPackDir(pack.Id, pack.Version));
 }
Пример #31
0
        private byte[] ReadOneFrame(IPack pack, bool isFinish)
        {
            byte[] temp = new byte[3];
            byte[] result = new byte[255];
            int frameLength = 0;
            int length = 0;
            byte checksum = 0;
            int i;

            length = Box.ReadBytes(temp, 0, temp.Length);

            if (length <= 0)
            {
                FinishExecute(isFinish);
                return null;
            }

            if (temp[1] == options.SourceAddress)
            {
                if (temp[0] == 0x80)
                {
                    byte[] b = new byte[1];
                    length = Box.ReadBytes(b, 0, 1);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return null;
                    }

                    length = Convert.ToInt32(b[0]);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return null;
                    }

                    Array.Copy(temp, 0, result, 0, temp.Length);
                    frameLength += temp.Length;
                    Array.Copy(b, 0, result, frameLength, 1);
                    ++frameLength;
                    length = Box.ReadBytes(result, KWPPack.KWP80_HEADER_LENGTH, length + KWPPack.KWP_CHECKSUM_LENGTH);
                    frameLength += length;
                }
                else
                {
                    length = Convert.ToInt32(temp[0] - 0x80);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return null;
                    }

                    Array.Copy(temp, 0, result, 0, temp.Length);
                    frameLength += temp.Length;
                    length = Box.ReadBytes(result, temp.Length, length + KWPPack.KWP_CHECKSUM_LENGTH);
                    frameLength += length;
                }
            }
            else
            {
                if (temp[0] == 0x00)
                {
                    length = Convert.ToInt32(temp[1]);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return null;
                    }
                    Array.Copy(temp, 0, result, 0, temp.Length);
                    frameLength += temp.Length;
                    length = Box.ReadBytes(result, temp.Length, length);
                    frameLength += length;
                }
                else
                {
                    length = Convert.ToInt32(temp[0]);
                    if (length <= 0)
                    {
                        FinishExecute(isFinish);
                        return null;
                    }

                    Array.Copy(temp, 0, result, 0, temp.Length);
                    frameLength += temp.Length;
                    length = Box.ReadBytes(result, temp.Length, length - KWPPack.KWP_CHECKSUM_LENGTH);
                    frameLength += length;
                }
            }

            FinishExecute(isFinish);
            if (frameLength <= 0)
            {
                return null;
            }

            for (i = 0; i < frameLength - 1; i++)
            {
                checksum += result[i];
            }

            if (checksum != result[frameLength - 1])
            {
                return null;
            }

            return pack.Unpack(result, 0, frameLength);
        }
Пример #32
0
 public byte[] ReadFrames(IPack pack)
 {
     return ReadOneFrame(pack);
 }
Пример #33
0
 public byte[] ReadFrames(IPack pack)
 {
     return(ReadOneFrame(pack));
 }
Пример #34
0
 public bool SetKeepLink(byte[] data, int offset, int count, IPack pack)
 {
     byte[] packData = pack.Pack(data, offset, count);
     return func.SetKeepLink(packData, 0, packData.Length);
 }
Пример #35
0
 public byte[] SendAndRecv(byte[] data, int offset, int count, IPack pack)
 {
     return(func.SendAndRecv(data, offset, count, pack));
 }