Example #1
0
        /// <summary>
        /// Get the load balance server data.
        /// </summary>
        /// <returns></returns>
        public static Nequeo.Net.Data.context GetLoadBalanceServer()
        {
            try
            {
                string xmlValidationMessage = string.Empty;

                // Get the xml file location and
                // the xsd file schema.
                string xml = Helper.LoadBalanceServerXmlPath;
                string xsd = Nequeo.Net.Properties.Resources.LoadBalanceServer;

                // Validate the filter xml file.
                if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                {
                    throw new Exception("Xml validation. " + xmlValidationMessage);
                }

                // Deserialise the xml file into
                // the log directory list object
                GeneralSerialisation    serial   = new GeneralSerialisation();
                Nequeo.Net.Data.context loadData =
                    ((Nequeo.Net.Data.context)serial.Deserialise(typeof(Nequeo.Net.Data.context), xml));

                // Return the load balance data.
                return(loadData);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        /// <summary>
        /// Save the client service context data.
        /// </summary>
        /// <param name="context">The client service data to save.</param>
        public static void SaveClientServiceData(Nequeo.Xml.Authorisation.Communication.Data.contextService context)
        {
            lock (_lockObject)
            {
                try
                {
                    string xmlValidationMessage = string.Empty;

                    // Get the xml file location and
                    // the xsd file schema.
                    string xml = (String.IsNullOrEmpty(ClientServiceReader.ClientServiceXmlPath) ? Helper.ClientServiceXmlPath : ClientServiceReader.ClientServiceXmlPath);
                    string xsd = Nequeo.Xml.Authorisation.Properties.Resources.ClientServiceProvider;

                    // Deserialise the xml file into
                    // the log directory list object
                    GeneralSerialisation serial = new GeneralSerialisation();
                    bool authData = serial.Serialise(context, typeof(Nequeo.Xml.Authorisation.Communication.Data.contextService), xml);

                    // Validate the filter xml file.
                    if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                    {
                        throw new Exception("Xml validation. " + xmlValidationMessage);
                    }
                }
                catch { }
            }
        }
        /// <summary>
        /// Load the client service context data.
        /// </summary>
        /// <returns>The collection of communication data.</returns>
        public static Nequeo.Xml.Authorisation.Communication.Data.contextService LoadClientServiceData()
        {
            try
            {
                string xmlValidationMessage = string.Empty;

                // Get the xml file location and
                // the xsd file schema.
                string xml = (String.IsNullOrEmpty(ClientServiceReader.ClientServiceXmlPath) ? Helper.ClientServiceXmlPath : ClientServiceReader.ClientServiceXmlPath);
                string xsd = Nequeo.Xml.Authorisation.Properties.Resources.ClientServiceProvider;

                // Validate the filter xml file.
                if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                {
                    throw new Exception("Xml validation. " + xmlValidationMessage);
                }

                // Deserialise the xml file into
                // the log directory list object
                GeneralSerialisation serial = new GeneralSerialisation();
                Nequeo.Xml.Authorisation.Communication.Data.contextService authData =
                    ((Nequeo.Xml.Authorisation.Communication.Data.contextService)serial.Deserialise(typeof(Nequeo.Xml.Authorisation.Communication.Data.contextService), xml));

                // Return the communication data.
                return(authData);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #4
0
        /// <summary>
        /// Start the process.
        /// </summary>
        public void Start()
        {
            try
            {
                string xmlValidationMessage = string.Empty;

                // Get the xml file location and
                // the xsd file schema.
                string xml = Nequeo.Maintenance.Properties.Settings.Default.LogFileListXmlPath;
                string xsd = Nequeo.Maintenance.Properties.Resources.LogFileList;

                // Validate the filter xml file.
                if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                {
                    throw new Exception("Xml validation. " + xmlValidationMessage);
                }

                // Deserialise the xml file into
                // the log directory list object
                GeneralSerialisation serial        = new GeneralSerialisation();
                LogDirectoryList     directoryList = ((LogDirectoryList)serial.Deserialise(typeof(LogDirectoryList), xml));

                // Start the deletion process.
                _timer = new IntervalControl(directoryList.Interval);
                _timer.Start(u => DeleteLogFiles(u), directoryList);
            }
            catch (Exception e)
            {
                // Detect a thread abort exception.
                if (e is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
            }
        }
Example #5
0
        /// <summary>
        /// Get the current SHA1 hashcode for the data type
        /// </summary>
        /// <param name="data">The data to get the hash code for.</param>
        /// <returns>The hash code for the data.</returns>
        public static string GetHashCode(object data)
        {
            GeneralSerialisation serialise = new GeneralSerialisation();
            string xml      = System.Text.Encoding.UTF8.GetString(serialise.Serialise(data, data.GetType()));
            string hashCode = Nequeo.Cryptography.Hashcode.GetHashcodeSHA1(xml);

            return(hashCode);
        }
Example #6
0
        /// <summary>
        /// Get the mime type context data.
        /// </summary>
        /// <returns>The collection of mime types.</returns>
        public static Nequeo.Net.Data.context GetMimeType()
        {
            try
            {
                string xmlValidationMessage = string.Empty;

                // Get the xml file location and
                // the xsd file schema.
                string xml = Nequeo.Net.Common.Helper.MimeTypeXmlPath;
                string xsd = Nequeo.Net.Properties.Resources.MimeType;

                // Validate the filter xml file.
                if (!Validation.IsXmlValidEx(xsd, xml, out xmlValidationMessage))
                {
                    throw new Exception("Xml validation. " + xmlValidationMessage);
                }

                // Deserialise the xml file into
                // the log directory list object
                GeneralSerialisation    serial       = new GeneralSerialisation();
                Nequeo.Net.Data.context mimeTypeData =
                    ((Nequeo.Net.Data.context)serial.Deserialise(typeof(Nequeo.Net.Data.context), xml));

                // Return the mime types.
                return(mimeTypeData);
            }
            catch (Exception ex)
            {
                // Log the error.
                LogHandler.WriteTypeMessage(
                    ex.Message,
                    MethodInfo.GetCurrentMethod(),
                    Nequeo.Net.Common.Helper.EventApplicationName);

                return(null);
            }
        }
Example #7
0
        /// <summary>
        /// Load the encrypted data.
        /// </summary>
        private void LoadData()
        {
            // Disable the group box.
            groupBoxItem.Enabled = false;
            _items.Clear();
            _manager = null;

            // Get the current user.
            _currentPassword = txtPasswordFile.Text.Trim();
            _currentFile     = txtFile.Text.Trim();

            FileStream file = null;

            try
            {
                // Remove all current items in the list.
                if (listBoxPasswordName.Items.Count > 0)
                {
                    listBoxPasswordName.Items.Clear();
                }

                // Open the file.
                file = new FileStream(_currentFile, FileMode.Open,
                                      FileAccess.Read, FileShare.ReadWrite);

                // If the file contains data.
                if (file.Length > 0)
                {
                    byte[] decryptedData = null;

                    // Create a new cryptography instance.
                    using (AdvancedAES cryto = new AdvancedAES())
                    {
                        // Read the file data into
                        // the byte array.
                        Byte[] array = new byte[file.Length];
                        file.Read(array, 0, array.Length);

                        // if using the key.
                        if (!String.IsNullOrEmpty(_cryptoKey))
                        {
                            // Decrypt with key.
                            byte[] decryptedInt = cryto.DecryptFromMemory(array, _cryptoKey);
                            array = new byte[0].Combine(decryptedInt);
                        }

                        // Decrypt the data.
                        decryptedData = cryto.DecryptFromMemory(array, _currentPassword);
                    }

                    // Was the data decrypted.
                    if (decryptedData == null)
                    {
                        MessageBox.Show("Incorrect file password.");
                    }
                    else
                    {
                        // Load the xml data.
                        // Deserialise the xml file.
                        GeneralSerialisation serial = new GeneralSerialisation();
                        _manager = ((Nequeo.Forms.UI.Security.Data.passwordManager)serial.Deserialise(typeof(Nequeo.Forms.UI.Security.Data.passwordManager), decryptedData));

                        // Create an empty manager.
                        if (_manager == null)
                        {
                            _manager = new Data.passwordManager();
                        }

                        // If items exist.
                        if (_manager != null && _manager.item != null)
                        {
                            // Add the items to the list.
                            _items.AddRange(_manager.item);

                            // For each item found.
                            foreach (Nequeo.Forms.UI.Security.Data.passwordManagerItem item in _manager.item)
                            {
                                // Load the names into the list box.
                                listBoxPasswordName.Items.Add(item.name);
                            }

                            // If no items exist.
                            if (listBoxPasswordName.Items.Count > 0)
                            {
                                btnRemoveItem.Enabled = true;
                            }
                        }

                        // Enable the data container.
                        listBoxPasswordName.Enabled = true;
                        btnAddItem.Enabled          = true;

                        // User has logged in.
                        _loggedIn            = true;
                        btnFile.Enabled      = false;
                        btnAuthenticate.Text = "Re-Load";
                    }
                }
                else
                {
                    // Create an empty manager.
                    _manager = new Data.passwordManager();

                    // Enable the data container.
                    listBoxPasswordName.Enabled = true;
                    btnAddItem.Enabled          = true;

                    // User has logged in.
                    _loggedIn            = true;
                    btnFile.Enabled      = false;
                    btnAuthenticate.Text = "Re-Load";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }
            }
        }
Example #8
0
        /// <summary>
        /// Save the data.
        /// </summary>
        /// <param name="e">The closing state.</param>
        /// <param name="closing">Is the application closing.</param>
        private void SaveData(FormClosingEventArgs e, bool closing = true)
        {
            // Get the current user.
            _currentPassword = txtPasswordFile.Text.Trim();
            _currentFile     = txtFile.Text.Trim();

            // If no file password has been supplied.
            if ((String.IsNullOrEmpty(_currentPassword) || String.IsNullOrEmpty(_currentFile)) && (_loggedIn))
            {
                // Cancel the close operation.
                if (closing)
                {
                    e.Cancel = true;
                }

                MessageBox.Show("A valid file password must be entered.");
            }
            else if (_loggedIn)
            {
                FileStream file = null;

                try
                {
                    // If data exists
                    if (_manager != null)
                    {
                        // Assign all the current items.
                        _manager.item = _items.ToArray();

                        // Create a new file stream
                        // truncate the file.
                        file = new FileStream(_currentFile, FileMode.Truncate,
                                              FileAccess.Write, FileShare.ReadWrite);

                        // Create a new cryptography instance.
                        using (AdvancedAES cryto = new AdvancedAES())
                        {
                            // Deserialise the xml file.
                            GeneralSerialisation serial = new GeneralSerialisation();
                            byte[] decryptedData        = serial.Serialise(_manager, typeof(Nequeo.Forms.UI.Security.Data.passwordManager));

                            // Encrypt the data.
                            Byte[] encryptedData = cryto.EncryptToMemory(decryptedData, _currentPassword);

                            // if using the key.
                            if (!String.IsNullOrEmpty(_cryptoKey))
                            {
                                byte[] encrytedInt = new byte[0].Combine(encryptedData);
                                encryptedData = cryto.EncryptToMemory(encrytedInt, _cryptoKey);
                            }

                            // Write the data to the file.
                            file.Write(encryptedData, 0, encryptedData.Length);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                    if (closing)
                    {
                        e.Cancel = true;
                    }
                }
                finally
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                }
            }
        }