Beispiel #1
0
        public static string CreateCardDetailFile(CardDetailsFile f)
        {
            string result = "File created succesfully";

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(CardDetailsFile));
                string        path       = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\IssuerLicense";
                if (Directory.Exists(path))
                {
                    Console.WriteLine("That path exists already.");
                }
                else
                {
                    DirectoryInfo di = Directory.CreateDirectory(path);
                }

                using (TextWriter writer = new StreamWriter(path + @"\IssuerCard.merlic"))
                {
                    serializer.Serialize(writer, f);
                }
            }
            catch (Exception e)
            {
                result = e.ToString();
            }

            return(result);
        }
Beispiel #2
0
        //todo: Change this to accept a path for the file
        //       public static MernokAssetFile ReadMernokAssetFile(string filename)
        public static CardDetailsFile ReadCardDetailFile(string FileName)
        {
            //todo: add exception handling
            //Try Read the XML file
            XmlSerializer deserializer = new XmlSerializer(typeof(CardDetailsFile));
            string        appPath      = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
            //TextReader reader = new StreamReader(Environment.CurrentDirectory + @"\C2xxParameters.xml");
            //TextReader reader = new StreamReader(@"C:\MernokAssets\MernokAssetList.xml");
            TextReader reader = new StreamReader(FileName);//(Environment.CurrentDirectory + @"\C2xxParameters.xml");

            CardDetailContent = reader.ReadToEnd();
            reader            = new StringReader((string)CardDetailContent.Clone());
            object          obj = deserializer.Deserialize(reader);
            CardDetailsFile f   = (CardDetailsFile)obj;

            reader.Close();
            return(f);
        }
Beispiel #3
0
        public override void Update(ViewModelReturnData VMReturnData)
        {
            //Only update this view if visible

            if (VMReturnData.ProgramPromtView_Active)
            {
                this.View.Visibility = Visibility.Visible;

                if (VMReturnData.NewIssuerCard)
                {
                    ProgramPrompt = "Do you wish to save this card file?";
                }
                else
                {
                    ProgramPrompt = "Do you wish to Program this card?";
                }

                if (OkButtonPressed)
                {
                    OkButtonPressed = false;
                    VMReturnData.ProgramPromtView_Active = false;
                    if (!VMReturnData.NewIssuerCard)
                    {
                        if (VMReturnData.CardInfoWrite.WriteInfoToCard(VMReturnData.VMCardDetails, VMReturnData.CardType) == 100)
                        {
                            VMReturnData.CardProramed_done = true;
                            VMReturnData.App_datareset();
                        }
                        else
                        {
                            VMReturnData.CardProgramFail = true;
                            VMReturnData.NewCardWindow--;
                        }
                    }
                    else
                    {
                        CardDetailsFile cardDetailsFile = new CardDetailsFile();
                        cardDetailsFile.createdBy          = "N. Pretorius";
                        cardDetailsFile.dateCreated        = DateTime.Now;
                        cardDetailsFile.version            = 1;
                        VMReturnData.VMCardDetails.cardUID = VMReturnData.NewIssuerUID;
                        cardDetailsFile.FCardDetails       = VMReturnData.VMCardDetails;
                        CardDetailManager.CreateCardDetailFile(cardDetailsFile);

                        VMReturnData.CardProramed_done = true;
                        VMReturnData.App_datareset();
                    }
                }

                if (NoButtonPressed)
                {
                    NoButtonPressed = false;
                    VMReturnData.ProgramPromtView_Active = false;
                    VMReturnData.NewCardWindow--;
                }
            }
            else
            {
                this.View.Visibility = Visibility.Collapsed;
            }
        }
        public override void Update(ViewModelReturnData VMReturnData)
        {
            if (VMReturnData.NewCardIssuer_Active)
            {
                this.View.Visibility = Visibility.Visible;

                #region Navigationbar details
                VMReturnData.ViewTitle = "New Issuer Card";
                VMReturnData.SubTitle  = "New Issuer details";
                //VMReturnData.CurrentPageNumber = 1;
                //VMReturnData.TotalPageNumber = 4;
                VMReturnData.MenuButtonEnabled = Visibility.Collapsed;
                VMReturnData.HelpButtonEnabled = Visibility.Visible;
                #endregion

                if (IssuerFileCardBtnPressed)
                {
                    IssuerFileCardBtnPressed = false;
                    MernokPasswordFile mernokPasswordFile = MernokPasswordManager.ReadMernokPasswordFile(V);
                    OpenFileDialog     openFileDialog1    = new OpenFileDialog();
                    openFileDialog1.Filter = "License Files|*.merlic";
                    openFileDialog1.Title  = "Select a Mernok Licnese File";
                    if (openFileDialog1.ShowDialog() == true)
                    {
                        // Assign the cursor in the Stream to the Form's Cursor property.
                        Console.WriteLine(Path.GetFullPath(openFileDialog1.FileName));
                        LicenseFilePath            = Path.GetFullPath(openFileDialog1.FileName);
                        CardDetailsFile            = CardDetailManager.ReadCardDetailFile(LicenseFilePath);
                        VMReturnData.VMCardDetails = CardDetailsFile.FCardDetails;
                        VMReturnData.NewCardUID    = CardDetailsFile.FCardDetails.cardUID;
                    }

                    //
                }

                if (CardDetailsFile.FCardDetails == null)
                {
                    WarningMessageF = "Please select a license file.";
                    CardUidPresVis  = Visibility.Collapsed;
                }
                else
                {
                    CardUidPresVis = Visibility.Visible;
                }

                if (!VMReturnData.CardInField)
                {
                    if (CardDetailsFile.FCardDetails != null)
                    {
                        WarningMessageI = "Present RFID card with UID: " + VMReturnData.cardInfoRead.UIDtoString(CardDetailsFile.FCardDetails.cardUID);
                    }
                    MessageColour = Brushes.OrangeRed;
                }
                else if (CardDetailsFile.FCardDetails != null && CardDetailsFile.FCardDetails.cardUID == VMReturnData.UID)
                {
                    VMReturnData.VMCardDetails.IssuerUID = CardinFieldUID = VMReturnData.UID;
                    MernokPasswordFile mernokPasswordFile = MernokPasswordManager.ReadMernokPasswordFile(V);
                    bool password = true;// PasswordFinder.FindPasswordinFile(AdminPassword, mernokPasswordFile);
                    if (password)
                    {
                        PassColour = Brushes.GreenYellow;

                        string[] IssuerDetails = { "1", "piet", "1", "2" };    //PasswordDecriptor.PasswordToDetails(AdminPassword);
                        VMReturnData.VMCardDetails.EngineerName = IssuerDetails[3];
                        VMReturnData.VMCardDetails.EngineerUID  = UInt32.Parse(IssuerDetails[0]);
                        VMReturnData.NextButtonEnabled          = true;
                        WarningMessageI = "Password good, click next to continue";
                        MessageColour   = Brushes.White;
                    }
                    else
                    {
                        MessageColour = Brushes.OrangeRed;
                        PassColour    = Brushes.OrangeRed;
                        VMReturnData.NextButtonEnabled = false;
                        if (AdminPassword == "")
                        {
                            WarningMessageI = "Enter your password";
                        }
                        else
                        {
                            WarningMessageI = "Enter correct password";
                        }
                    }
                }
            }
            else
            {
                //View is not visible, do not update
                //Stop any animations on this vieModel
                this.View.Visibility = Visibility.Collapsed;
                AdminPassword        = "";
            }
        }