Esempio n. 1
0
        /// <summary>
        /// Funkcija koja daje određeni model kamere
        /// </summary>
        /// <param name="category">Kategorija kamere</param>
        /// <returns>Objekt IFotoaparat-a</returns>
        private IFotoaparat GetCamera(string category)
        {
            string directoryLocation = DirectoryLocator.GetDirectory("Cameras", Directory.GetCurrentDirectory(), 0, 3);

            if (string.Equals(directoryLocation, "ERROR"))
            {
                Console.WriteLine("Ne može se pronaći direktorij s kamerama!");
            }

            string[]           files      = Directory.GetFiles(directoryLocation);
            List <IFotoaparat> cameraList = new List <IFotoaparat>();

            foreach (string file in files)
            {
                XmlTextReader reader = new XmlTextReader(file);
                while (reader.Read())
                {
                    if (XmlNodeType.Element == reader.NodeType)
                    {
                        reader.MoveToAttribute("type");
                        string elementType = reader.Value;
                        if (string.Equals(elementType, category))
                        {
                            CameraFactory cameraFactory;
                            if (string.Equals(category, "DSLR"))
                            {
                                cameraFactory = new CreatorDSLR();
                            }
                            else if (string.Equals(category, "MILC"))
                            {
                                cameraFactory = new CreatorMILC();
                            }
                            else
                            {
                                cameraFactory = new CreatorCompact();
                            }

                            IFotoaparat newCamera = cameraFactory.Create();
                            for (int attInd = 0; attInd < reader.AttributeCount; attInd++)
                            {
                                reader.MoveToAttribute(attInd);
                                newCamera.SetValue(reader.Name, reader.Value);
                            }
                            cameraList.Add(newCamera);
                        }
                    }
                }
            }

            Randomizer rnd         = Randomizer.GetInstance();
            int        cameraIndex = rnd.GetNumber(0, cameraList.Count);

            return(cameraList[cameraIndex]);
        }
        /// <summary>
        /// Funkcija koja daje određeni model kamere
        /// </summary>
        /// <param name="category">Kategorija kamere</param>
        /// <returns>Objekt IFotoaparat-a</returns>
        private IFotoaparat GetCamera(string category)
        {
            string directoryLocation = DirectoryLocator.GetDirectory("Cameras", Directory.GetCurrentDirectory(), 0, 3);
            if (string.Equals(directoryLocation, "ERROR"))
            {
                Console.WriteLine("Ne može se pronaći direktorij s kamerama!");
            }

            string[] files = Directory.GetFiles(directoryLocation);
            List<IFotoaparat> cameraList = new List<IFotoaparat>();

            foreach (string file in files)
            {
                XmlTextReader reader = new XmlTextReader(file);
                while (reader.Read())
                {
                    if (XmlNodeType.Element == reader.NodeType)
                    {
                        reader.MoveToAttribute("type");
                        string elementType = reader.Value;
                        if (string.Equals(elementType, category))
                        {
                            CameraFactory cameraFactory;
                            if (string.Equals(category, "DSLR"))
                                cameraFactory = new CreatorDSLR();
                            else if (string.Equals(category, "MILC"))
                                cameraFactory = new CreatorMILC();
                            else
                                cameraFactory = new CreatorCompact();

                            IFotoaparat newCamera = cameraFactory.Create();
                            for (int attInd = 0; attInd < reader.AttributeCount; attInd++)
                            {
                                reader.MoveToAttribute(attInd);
                                newCamera.SetValue(reader.Name, reader.Value);
                            }
                            cameraList.Add(newCamera);
                        }
                    }
                }
            }

            Randomizer rnd = Randomizer.GetInstance();
            int cameraIndex = rnd.GetNumber(0, cameraList.Count);
            return cameraList[cameraIndex];
        }