Пример #1
0
        private IEnumerator _Shuffle(ILogic logic, int level)
        {
            btn_Start.enabled   = false;
            btn_Restart.enabled = false;

            Random rnd             = new Random();
            int    lastValShuffled = -1;

            for (int i = 0; i < level; i++)
            {
                yield return(new WaitForSeconds(SpeedShuffle));

                List <IChip> adjCellsCoords = new List <IChip>();
                foreach (var cell in logic.EmptyCell.GetAdjacentCells(AdjacementCount.Cells4))
                {
                    if (_CheckPosition(cell) && _logicGame.Field[cell.PosY, cell.PosX].Value != lastValShuffled)
                    {
                        adjCellsCoords.Add(cell);
                    }
                }

                IChip rndCoord = adjCellsCoords[rnd.Next(0, adjCellsCoords.Count)];
                IChip tempCh   = _logicGame.Field[rndCoord.PosY, rndCoord.PosX];

                lastValShuffled = tempCh.Value;
                _logicGame.MoveChip(tempCh);
                _SwapPos(_chipsInScene[tempCh.Value - 1].transform, _emptyCellPos.transform);
                SoundManager.ShufflePlay();
            }

            btn_Start.enabled   = true;
            btn_Restart.enabled = true;
            _isGameReady        = true;
            SoundManager.StartingPlay();
        }
Пример #2
0
        public bool ReconnectOnCard()
        {
            if (insertedChip == null)
            {
                return(false);
            }

            bool ret = false;

            try
            {
                readerUnit.Disconnect();
                ret = readerUnit.Connect();
                if (ret)
                {
                    insertedChip = readerUnit.GetSingleChip();
                }
            }
            catch (COMException)
            {
                ret = false;
            }

            if (!ret)
            {
                ResetCard();
            }

            return(ret);
        }
Пример #3
0
        protected DokanError EraseCard()
        {
            try
            {
                IChip chip = rfidListener.GetChip();
                if (chip == null)
                {
                    return(DokanError.ErrorNotReady);
                }

                IStorageCardService storage = chip.GetService(CardServiceType.CST_STORAGE) as IStorageCardService;
                if (storage != null)
                {
                    storage.Erase();
                    ResetCache();
                    return(DokanError.ErrorSuccess);
                }
                else
                {
                    return(DokanError.ErrorNotImplemented);
                }
            }
            catch (Exception ex)
            {
                log.Error("DeleteDirectory error", ex);
                rfidListener.ResetCard();
                return(DokanError.ErrorError);
            }
        }
Пример #4
0
        public bool MoveChip(IChip chipCoord)
        {
            if (chipCoord.Value == 0)
            {
                return(false);
            }

            //Проверка находятся ли координаты в одной строке или столбце с пустой ячейкой
            if (chipCoord.PosX != _emptyCell.PosX &&
                chipCoord.PosY != _emptyCell.PosY)
            {
                return(false);
            }

            //Проверка является ли пустая ячейка соседней
            if (Math.Abs(chipCoord.PosX - _emptyCell.PosX) != 1 &&
                Math.Abs(chipCoord.PosY - _emptyCell.PosY) != 1)
            {
                return(false);
            }

            IChip oldChipPos = chipCoord.CreateClone();

            _field[_emptyCell.PosY, _emptyCell.PosX] = _field[chipCoord.PosY, chipCoord.PosX];
            _field[_emptyCell.PosY, _emptyCell.PosX].SetPosition(_emptyCell);

            _field[oldChipPos.PosY, oldChipPos.PosX] = _emptyCell;
            _emptyCell.SetPosition(oldChipPos);

            return(true);
        }
Пример #5
0
 public void ResetCard()
 {
     waitRemoval.Set();
     insertedChip = null;
     if (driver != null)
     {
         driver.ResetCache();
     }
 }
Пример #6
0
        public DokanError GetDiskFreeSpace(out long free, out long total, out long used, DokanFileInfo info)
        {
            log.Info("GetDiskFreeSpace call");

            free  = 0;
            total = 0;
            used  = 0;

            try
            {
                IChip chip = rfidListener.GetChip();
                if (chip == null)
                {
                    return(DokanError.ErrorNotReady);
                }

                if (chip.Type == "Mifare1K")
                {
                    free  = 0;
                    total = 32 + (15 * 3 * 16);
                    used  = total;
                }
                else if (chip.Type == "Mifare4K")
                {
                    free  = 0;
                    total = 32 + (30 * 48) + (8 * 240);
                    used  = total;
                }
                else if (chip.Type == "DESFire" || chip.Type == "DESFireEV1")
                {
                    free  = 0;
                    total = 0;
                    used  = 0;

                    IDESFireEV1Commands cmd = chip.Commands as IDESFireEV1Commands;
                    if (cmd != null)
                    {
                        try
                        {
                            free = cmd.GetFreeMemory() / 1024;
                            DESFireCardVersion version = cmd.GetVersion();
                            total = ((long)(version.softwareStorageSize / 4)) * 1024;
                            used  = total - free;
                        }
                        catch (COMException) { }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("GetDiskFreeSpace error", ex);
                return(DokanError.ErrorError);
            }

            return(DokanError.ErrorSuccess);
        }
Пример #7
0
        // Injecting the dependency into a single method, for use by that method.
        // Could have injected the dependency in constructor itself which is more common, but the requirement mentions a chip installation method
        public void installChip(IChip pluggedChip)
        {
            this.chip = pluggedChip;

            Console.WriteLine("\nInstalling Chip: " + pluggedChip.GetType().Name);

            InstalledChips.Add(pluggedChip.GetType());

            TotalUniqueChipsIntalled = InstalledChips.Count;
        }
Пример #8
0
        public void ResetField()
        {
            for (int y = 0; y < _sizeY; y++)
            {
                for (int x = 0; x < _sizeX; x++)
                {
                    _field[y, x] = _etalonField[y, x].CreateClone();
                }
            }

            _emptyCell = _field[_sizeY - 1, _sizeX - 1];
        }
Пример #9
0
        public override DokanError OpenDirectory(string fileName, DokanFileInfo info)
        {
            log.Info(String.Format("OpenDirectory call - {0}", fileName));

            IChip chip = rfidListener.GetChip();

            if (chip == null)
            {
                return(DokanError.ErrorNotReady);
            }

            if (!CheckDirectoryPath(fileName))
            {
                log.Error("Path not found");
                return(DokanError.ErrorPathNotFound);
            }

            return(DokanError.ErrorSuccess);
        }
Пример #10
0
        protected DokanError PopulateCSNFiles(IList <FileInformation> files)
        {
            log.Info("PopulateCSNFiles call");

            IChip chip = rfidListener.GetChip();

            if (chip == null)
            {
                return(DokanError.ErrorNotReady);
            }

            FileInformation csnFile = new FileInformation();

            csnFile.Attributes   = FileAttributes.Directory;
            csnFile.FileName     = chip.ChipIdentifier;
            csnFile.CreationTime = csnFile.LastWriteTime = csnFile.LastAccessTime = rfidListener.GetChipInsertionDate();
            csnFile.Length       = 0;
            files.Add(csnFile);
            return(DokanError.ErrorSuccess);
        }
Пример #11
0
        public bool OnClickChip(Transform sender, IChip dataChip)
        {
            if (!_isGameReady || !_logicGame.MoveChip(dataChip))
            {
                return(false);
            }

            _SwapPos(sender.transform, _emptyCellPos.transform);
            Steps();
            SoundManager.ShufflePlay();

            if (_logicGame.CheckWin())
            {
                StopCoroutine(_timerRoutine);
                _isGameReady = false;
                WinWindow.ShowWin();
                SoundManager.SuccessPlay();
            }

            return(true);
        }
Пример #12
0
        public void InitField(int sizeX, int sizeY)
        {
            _sizeX = sizeX;
            _sizeY = sizeY;
            _field = new IChip[_sizeY, _sizeX];

            int value = 0;

            for (int y = 0; y < _sizeY; y++)
            {
                for (int x = 0; x < _sizeX; x++)
                {
                    IChip newChep = new Chip(x, y);
                    newChep.Value = (++value != _field.Length) ? value : 0;
                    _field[y, x]  = newChep;
                }
            }

            _emptyCell = new Chip(sizeX - 1, sizeY - 1);
            _InitEtalonField(_field);
        }
Пример #13
0
        public override DokanError FindFiles(string fileName, out IList <FileInformation> files, DokanFileInfo info)
        {
            log.Info(String.Format("FindFiles call - {0}", fileName));

            files = new List <FileInformation>();

            IChip chip = rfidListener.GetChip();

            if (chip == null)
            {
                return(DokanError.ErrorNotReady);
            }

            if (fileName == "\\")
            {
                if (nfcConfig.CSNAsRoot)
                {
                    return(PopulateCSNFiles(files));
                }

                return(PopulateNDEFFiles(files));
            }
            else
            {
                log.Info("Subdir");

                if (!nfcConfig.CSNAsRoot)
                {
                    return(DokanError.ErrorPathNotFound);
                }

                if (fileName != chip.ChipIdentifier)
                {
                    return(DokanError.ErrorPathNotFound);
                }

                return(PopulateNDEFFiles(files, fileName));
            }
        }
Пример #14
0
        protected bool CheckDirectoryPath(string fileName)
        {
            if (fileName == "\\")
            {
                return(true);
            }

            IChip chip = rfidListener.GetChip();

            if (chip != null)
            {
                if (nfcConfig.CSNAsRoot)
                {
                    if (fileName == chip.ChipIdentifier)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #15
0
 public bool EqualsCoord(IChip coord)
 {
     return(currentX == coord.PosX && currentY == coord.PosY);
 }
Пример #16
0
 public void SetPosition(IChip newCoord)
 {
     currentX = newCoord.PosX;
     currentY = newCoord.PosY;
 }
Пример #17
0
        protected void Listen()
        {
            IsRunning         = true;
            waitRemoval       = new AutoResetEvent(false);
            insertedChip      = null;
            chipInsertionDate = null;

            log.Info(String.Format("Listening on {0} reader {1}...", readerProviderName, readerUnitName));

            readerProvider = DokanNFCConfig.CreateReaderProviderFromName(readerProviderName);
            readerUnit     = DokanNFCConfig.CreateReaderUnitFromName(readerProvider, readerUnitName);

            if (readerProvider != null && readerUnit != null)
            {
                if (readerUnit.ConnectToReader())
                {
                    DokanNFCConfig config = DokanNFCConfig.GetSingletonInstance();
                    switch (config.Mode)
                    {
                    case DisplayMode.RawRFID:
                        break;

                    case DisplayMode.NFC:
                        driver = new NFCDokanRFIDDriver(this);
                        break;
                    }

                    if (driver != null)
                    {
                        string mountPoint = config.MountPoint;
                        if (String.IsNullOrEmpty(mountPoint))
                        {
                            string[] mountPoints = DokanNFCConfig.GetAvailableMountPoints();
                            if (mountPoints.Length > 0)
                            {
                                mountPoint = mountPoints[0];
                            }
                        }

                        if (!String.IsNullOrEmpty(mountPoint))
                        {
                            DokanOptions options = DokanOptions.FixedDrive;
                            if (config.AlwaysMounted)
                            {
                                Mount(mountPoint, options);
                            }
                            else
                            {
                                options |= DokanOptions.RemovableDrive;
                            }
                            do
                            {
                                if (readerUnit.WaitInsertion(500))
                                {
                                    Thread.Sleep(400);
                                    chipInsertionDate = DateTime.Now;
                                    log.Info("Card inserted.");
                                    if (readerUnit.Connect())
                                    {
                                        insertedChip = readerUnit.GetSingleChip();
                                        if (insertedChip != null)
                                        {
                                            log.Info(String.Format("Chip type `{0}`", insertedChip.Type));
                                            if (!config.AlwaysMounted)
                                            {
                                                Mount(mountPoint, options);
                                            }

                                            RemovalChecker();
                                            while (!waitRemoval.WaitOne(500) && IsRunning)
                                            {
                                                ;
                                            }
                                            log.Info("Card removed.");

                                            if (!config.AlwaysMounted)
                                            {
                                                Unmount(mountPoint);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        log.Error("Cannot connect to the card.");
                                    }
                                    chipInsertionDate = null;
                                }
                            } while (IsRunning);

                            if (config.AlwaysMounted)
                            {
                                Unmount(mountPoint);
                            }
                        }
                        else
                        {
                            log.Error("No mount point.");
                        }
                    }
                    else
                    {
                        log.Error("No matching file system driver to mount.");
                    }
                    readerUnit.DisconnectFromReader();
                }
                else
                {
                    log.Error("Cannot connect to the reader.");
                }

                GC.KeepAlive(readerUnit);
                GC.KeepAlive(readerProvider);
            }
            else
            {
                log.Error("Error in RFID reader resource allocation.");
            }
        }
Пример #18
0
 //Возвращает true, если проверяемые координаты находятся в границах массива
 private bool _CheckPosition(IChip coord)
 {
     return(_CheckPosition(coord.PosX, coord.PosY));
 }
Пример #19
0
 public void ResetCard()
 {
     waitRemoval.Set();
     insertedChip = null;
     if (driver != null)
     {
         driver.ResetCache();
     }
 }
        /// <summary>
        /// 取得したチップを元にスポイト動作をする
        /// </summary>
        public void SpoilChip(DrawState drawState, IChip chip)
        {
            switch (drawState)
            {
                case DrawState.MapChip:
                    MapChipPalletViewModel.PalletSelect(chip.ID);
                    MapChipPalletViewModel.DrawMapState.Set(chip.ID);
                    ObjectChipPalletViewModel.SelectCancel();
                    _current = MapChipPalletViewModel;
                    break;

                case DrawState.ObjChip:
                    ObjectChipPalletViewModel.PalletSelect(chip.ID);
                    ObjectChipPalletViewModel.DrawObjectState.SpoilObject(chip as ObjectChip);
                    MapChipPalletViewModel.SelectCancel();
                    _current = ObjectChipPalletViewModel;
                    break;

                case DrawState.Empty:
                    //何もしない
                    break;
                default:
                    throw new ArgumentOutOfRangeException("drawState");
            }
        }
Пример #21
0
        protected void Listen()
        {
            IsRunning = true;
            waitRemoval = new AutoResetEvent(false);
            insertedChip = null;
            chipInsertionDate = null;

            log.Info(String.Format("Listening on {0} reader {1}...", readerProviderName, readerUnitName));

            readerProvider = DokanNFCConfig.CreateReaderProviderFromName(readerProviderName);
            readerUnit = DokanNFCConfig.CreateReaderUnitFromName(readerProvider, readerUnitName);

            if (readerProvider != null && readerUnit != null)
            {
                if (readerUnit.ConnectToReader())
                {
                    DokanNFCConfig config = DokanNFCConfig.GetSingletonInstance();
                    switch (config.Mode)
                    {
                        case DisplayMode.RawRFID:
                            break;
                        case DisplayMode.NFC:
                            driver = new NFCDokanRFIDDriver(this);
                            break;
                    }

                    if (driver != null)
                    {
                        string mountPoint = config.MountPoint;
                        if (String.IsNullOrEmpty(mountPoint))
                        {
                            string[] mountPoints = DokanNFCConfig.GetAvailableMountPoints();
                            if (mountPoints.Length > 0)
                            {
                                mountPoint = mountPoints[0];
                            }
                        }

                        if (!String.IsNullOrEmpty(mountPoint))
                        {
                            DokanOptions options = DokanOptions.FixedDrive;
                            if (config.AlwaysMounted)
                            {
                                Mount(mountPoint, options);
                            }
                            else
                            {
                                options |= DokanOptions.RemovableDrive;
                            }
                            do
                            {
                                if (readerUnit.WaitInsertion(500))
                                {
                                    Thread.Sleep(400);
                                    chipInsertionDate = DateTime.Now;
                                    log.Info("Card inserted.");
                                    if (readerUnit.Connect())
                                    {
                                        insertedChip = readerUnit.GetSingleChip();
                                        if (insertedChip != null)
                                        {
                                            log.Info(String.Format("Chip type `{0}`", insertedChip.Type));
                                            if (!config.AlwaysMounted)
                                            {
                                                Mount(mountPoint, options);
                                            }

                                            RemovalChecker();
                                            while (!waitRemoval.WaitOne(500) && IsRunning) ;
                                            log.Info("Card removed.");

                                            if (!config.AlwaysMounted)
                                            {
                                                Unmount(mountPoint);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        log.Error("Cannot connect to the card.");
                                    }
                                    chipInsertionDate = null;
                                }
                            } while (IsRunning);

                            if (config.AlwaysMounted)
                            {
                                Unmount(mountPoint);
                            }
                        }
                        else
                        {
                            log.Error("No mount point.");
                        }
                    }
                    else
                    {
                        log.Error("No matching file system driver to mount.");
                    }
                    readerUnit.DisconnectFromReader();
                }
                else
                {
                    log.Error("Cannot connect to the reader.");
                }

                GC.KeepAlive(readerUnit);
                GC.KeepAlive(readerProvider);
            }
            else
            {
                log.Error("Error in RFID reader resource allocation.");
            }
        }
Пример #22
0
        protected DokanError WritePayload(byte[] payload, string extension)
        {
            // Make sure the chip is still here
            if (!rfidListener.ReconnectOnCard())
            {
                log.Error("Card reconnection failed");
                return(DokanError.ErrorNotReady);
            }

            IChip        chip = rfidListener.GetChip();
            ICardService svc  = chip.GetService(CardServiceType.CST_NFC_TAG);
            IDESFireEV1NFCTag4CardService nfcsvc = svc as IDESFireEV1NFCTag4CardService;

            if (nfcsvc == null)
            {
                log.Error("No NFC service.");
                // If no NFC service for this chip, we must fail
                return(DokanError.ErrorNotReady);
            }

            try
            {
                IStorageCardService storage = chip.GetService(CardServiceType.CST_STORAGE) as IStorageCardService;
                if (storage != null)
                {
                    storage.Erase();
                }
                nfcsvc.CreateNFCApplication(1, null);

                NdefMessage ndef = new NdefMessage();
                switch (extension)
                {
                case "txt":
                    log.Info("Adding Text Record");
                    ndef.AddRawTextRecord(payload);
                    break;

                case "url":
                    string lnk    = Encoding.UTF8.GetString(payload);
                    int    urlpos = lnk.IndexOf("URL=");
                    if (urlpos > -1)
                    {
                        urlpos += 4;
                        int end = lnk.IndexOf(Environment.NewLine, urlpos);
                        if (end < 0)
                        {
                            end = lnk.Length - urlpos;
                        }
                        else
                        {
                            end -= urlpos;
                        }
                        string url = lnk.Substring(urlpos, end).Trim();
                        log.Info(String.Format("Adding Uri Record `{0}`", url));
                        ndef.AddUriRecord(url, UriType.NO_PREFIX);
                    }
                    else
                    {
                        log.Warn("Cannot found URL on link file content.");
                    }
                    break;

                default:
                    string mime = System.Web.MimeMapping.GetMimeMapping("dummy." + extension);
                    log.Info(String.Format("Adding Mime Record `{0}`", mime));
                    ndef.AddMimeMediaRecord(mime, Encoding.ASCII.GetString(payload));       // This shouldn't be a string here
                    break;
                }
                nfcsvc.WriteNDEFFile(ndef);

                ResetCache();
            }
            catch (COMException ex)
            {
                log.Info("NDEF write error", ex);
            }

            return(DokanError.ErrorSuccess);
        }
Пример #23
0
        protected DokanError ReadPayload(out byte[] payload, out string extension)
        {
            payload   = null;
            extension = String.Empty;

            // Make sure the chip is still here
            if (!rfidListener.ReconnectOnCard())
            {
                log.Error("Card reconnection failed");
                return(DokanError.ErrorNotReady);
            }

            IChip        chip = rfidListener.GetChip();
            ICardService svc  = chip.GetService(CardServiceType.CST_NFC_TAG);
            IDESFireEV1NFCTag4CardService nfcsvc = svc as IDESFireEV1NFCTag4CardService;

            if (nfcsvc == null)
            {
                log.Error("No NFC service.");
                // If no NFC service for this chip, we must fail
                return(DokanError.ErrorNotReady);
            }

            try
            {
                NdefMessage ndef = nfcsvc.ReadNDEFFile();
                if (ndef != null)
                {
                    if (ndef.GetRecordCount() > 0)
                    {
                        // For now, only support for one Ndef record per card
                        object[] records = ndef.Records as object[];
                        if (records != null)
                        {
                            INdefRecord record     = records[0] as INdefRecord;
                            object      payloadobj = record.Payload;
                            if (payloadobj != null)
                            {
                                payload = payloadobj as byte[];
                                payload = ParsePayload(record, payload, out extension);
                            }
                            else
                            {
                                log.Error("Bad record payload");
                            }
                        }
                    }
                    else
                    {
                        log.Info("No NDEF record in the message");
                    }
                }
                else
                {
                    log.Info("No NDEF message on this card");
                }
            }
            catch (COMException ex)
            {
                log.Info("NDEF read error", ex);
            }

            return(DokanError.ErrorSuccess);
        }
Пример #24
0
        public override DokanError CreateFile(string fileName, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
        {
            log.Info(String.Format("CreateFile call - {0}", fileName));

            IChip chip = rfidListener.GetChip();

            if (chip == null)
            {
                return(DokanError.ErrorNotReady);
            }

            info.Context = new RFIDContext();

            if (fileName == "\\" || (attributes & FileAttributes.Directory) != 0)
            {
                if (!CheckDirectoryPath(fileName))
                {
                    log.Error("Path not found");
                    return(DokanError.ErrorFileNotFound);
                }

                return(DokanError.ErrorSuccess);
            }
            else
            {
                bool exists = false;
                lock (cacheFiles)
                {
                    if (!CacheExists(fileName))
                    {
                        if (CacheCount() > 0)
                        {
                            log.Error("Cache already initialized and cannot found file");
                            return(DokanError.ErrorFileNotFound);
                        }

                        DokanError payloadRet = ReadAndCachePayload(nfcConfig.CSNAsRoot ? "\\" + chip.ChipIdentifier : String.Empty);
                        if (payloadRet == DokanError.ErrorSuccess)
                        {
                            exists = CacheExists(fileName);
                        }
                        else
                        {
                            return(payloadRet);
                        }
                    }
                    else
                    {
                        exists = true;
                    }
                }

                log.Info(String.Format("Exists? {0}", exists));

                switch (mode)
                {
                case FileMode.Open:
                {
                    log.Info("FileMode Open");
                    if (exists)
                    {
                        return(DokanError.ErrorSuccess);
                    }
                    else
                    {
                        log.Error("File not found.");
                        return(DokanError.ErrorFileNotFound);
                    }
                }

                case FileMode.CreateNew:
                {
                    log.Info("FileMode CreateNew");
                    if (exists)
                    {
                        return(DokanError.ErrorAlreadyExists);
                    }

                    InitCache(fileName);
                    return(DokanError.ErrorSuccess);
                }

                case FileMode.Create:
                {
                    log.Info("FileMode Create");
                    InitCache(fileName);
                    return(DokanError.ErrorSuccess);
                }

                case FileMode.OpenOrCreate:
                {
                    log.Info("FileMode OpenOrCreate");
                    if (!exists)
                    {
                        InitCache(fileName);
                    }
                    return(DokanError.ErrorSuccess);
                }

                case FileMode.Truncate:
                {
                    log.Info("FileMode Truncate");
                    if (!exists)
                    {
                        return(DokanError.ErrorFileNotFound);
                    }

                    InitCache(fileName);
                    return(DokanError.ErrorSuccess);
                }

                case FileMode.Append:
                {
                    log.Info("FileMode Append");
                    if (!exists)
                    {
                        return(DokanError.ErrorFileNotFound);
                    }

                    return(DokanError.ErrorSuccess);
                }

                default:
                {
                    log.Error(String.Format("Error unknown FileMode {0}", mode));
                    return(DokanError.ErrorError);
                }
                }
            }
        }
Пример #25
0
        public bool ReconnectOnCard()
        {
            if (insertedChip == null)
                return false;

            bool ret = false;
            try
            {
                readerUnit.Disconnect();
                ret = readerUnit.Connect();
                if (ret)
                {
                    insertedChip = readerUnit.GetSingleChip();
                }
            }
            catch (COMException)
            {
                ret = false;
            }

            if (!ret)
            {
                ResetCard();
            }

            return ret;
        }
Пример #26
0
 public void AcceptChip(IChip chip)
 {
     container = chip;
     hs.Add(container.ChipName());
 }