Exemple #1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (DisplayName.Length != 0)
            {
                hash ^= DisplayName.GetHashCode();
            }
            if (Description.Length != 0)
            {
                hash ^= Description.GetHashCode();
            }
            if (ValueType != global::Google.Cloud.AIPlatform.V1.TensorboardTimeSeries.Types.ValueType.Unspecified)
            {
                hash ^= ValueType.GetHashCode();
            }
            if (createTime_ != null)
            {
                hash ^= CreateTime.GetHashCode();
            }
            if (updateTime_ != null)
            {
                hash ^= UpdateTime.GetHashCode();
            }
            if (Etag.Length != 0)
            {
                hash ^= Etag.GetHashCode();
            }
            if (PluginName.Length != 0)
            {
                hash ^= PluginName.GetHashCode();
            }
            if (PluginData.Length != 0)
            {
                hash ^= PluginData.GetHashCode();
            }
            if (metadata_ != null)
            {
                hash ^= Metadata.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        private void RetrieveDataFromFTPServer()
        {
            FtpWebRequest  ftpRequest;
            FtpWebResponse ftpResponse;

            xDoc = new XmlDocument();

            ProgressForm formPB = new ProgressForm();

            formPB.Show();

            try
            {
                formPB.Text  = "Downloading Database";
                formPB.Value = 0;
                formPB.Refresh();

                #region Attempt to download plugin database file
                try
                {
                    // Create a request for the database file
                    ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPdbFile);
                    // Set default authentication for retrieving the file info
                    ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);

                    ftpRequest.Method = WebRequestMethods.Ftp.GetFileSize;
                    ftpResponse       = (FtpWebResponse)ftpRequest.GetResponse();
                    // Ask the server for the file size and store it
                    long fileSize = ftpResponse.ContentLength;
                    ftpResponse.Close();

                    WebClient wc = new WebClient();
                    wc.Credentials = ftpRequest.Credentials;
                    xDoc.LoadXml(wc.DownloadString(pluginsFTPdbFile));
                }
                catch
                {
                    xDoc.AppendChild(xDoc.CreateElement("Plugins"));
                }
                #endregion

                formPB.Text = "Check File Dates/Times";
                #region Retrieve list of all files & directories from FTP server
                try
                {
                    // Create a request to the directory we are working in
                    ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPServer);
                    // Set default authentication for retrieving the file info
                    ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                    ftpRequest.Method      = WebRequestMethods.Ftp.ListDirectoryDetails;
                    ftpResponse            = (FtpWebResponse)ftpRequest.GetResponse();
                    StreamReader streamReader = new StreamReader(ftpResponse.GetResponseStream());

                    List <string> files = new List <string>();
                    string        line  = streamReader.ReadLine();
                    while (!string.IsNullOrEmpty(line))
                    {
                        files.Add(line);
                        line = streamReader.ReadLine();
                    }

                    foreach (string s in files)
                    {
                        formPB.Value = files.IndexOf(s) * 100 / files.Count;
                        formPB.Refresh();
                        if (s[0].ToString().ToLower() == "d")
                        {
                            continue;
                        }

                        // Create a request to the directory we are working in
                        ftpRequest             = (FtpWebRequest)WebRequest.Create(pluginsFTPServer + s.Substring(62));
                        ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                        ftpRequest.Method      = WebRequestMethods.Ftp.GetDateTimestamp;
                        ftpResponse            = (FtpWebResponse)ftpRequest.GetResponse();
                        DateTime dt = ftpResponse.LastModified;
                        listing.Add(new FileData(s, dt));
                        ftpResponse.Close();
                    }
                }
                catch (Exception ex)
                {
                }
                #endregion

                HashSet <string> hashTable  = new HashSet <string>();
                bool             xDocChange = false;
                foreach (FileData fd in listing)
                {
                    // We only want files (non-directories)
                    if ((fd.attrib | FileAttributes.Directory) != FileAttributes.Directory)
                    {
                        string[] fName        = fd.name.ToLower().Split('.', '-');
                        string   modifiedName = fName[0].Replace('!', '_').Replace('+', '_');

                        #region Update information box
                        formPB.Text  = "Analyzing: \n" + fd.name;
                        formPB.Value = listing.IndexOf(fd) * 100 / listing.Count;
                        formPB.Refresh();
                        #endregion

                        if (fName[fName.Length - 1] != "ent")
                        {
                            continue;
                        }

                        /*
                         * if (fName.Length > 3)
                         * {
                         *  string ver = fName[1];
                         *  for (int i = 2; i < fName.Length - 1; i++)
                         *      ver += '.' + fName[i];
                         *  fVer = new Version(ver);
                         * }
                         */

                        // Check for the matching tag HASHCODE name
                        XmlNodeList xnl   = null;
                        XmlNode     xNode = null;

                        if (fName.Length > 2)
                        {
                            xnl = xDoc.GetElementsByTagName("_" + fName[1]);
                        }


                        // Search through each return value for the one in the desired parent TAG TYPE
                        if (xnl != null && xnl.Count > 0)
                        {
                            foreach (XmlNode xn in xnl)
                            {
                                if (xn.ParentNode.Name == modifiedName)
                                {
                                    xNode = xn;
                                    break;
                                }
                            }
                        }

@updatePlugin:
                        // If we do not get any results for the HASHCODE, check for parent TAG TYPE
                        if (xNode == null)
                        {
                            // Search for a matching TAG TYPE
                            XmlNodeList xml = xDoc.GetElementsByTagName(modifiedName);

                            // No matching TAG TYPE was found, so create a tag placeholder (eg. SCNR)
                            if (xml.Count == 0)
                            {
                                xNode = xDoc.CreateElement(modifiedName);
                                xDoc.FirstChild.AppendChild(xNode);
                            }
                            // We found a matching TAG TYPE, so select it
                            else
                            {
                                xNode = xml[0];
                            }

                            // Retrieve the plugin from the server & parse for needed info
                            WebClient wc = new WebClient();
                            wc.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                            try
                            {
                                string      tempPlugin = wc.DownloadString(pluginsFTPServer + fd.name);
                                XmlDocument xd         = new XmlDocument();
                                xd.LoadXml(tempPlugin);
                                XmlNodeList XList;
                                XmlNode     xnA; // Holds author attribute info
                                XmlNode     xnV; // Holds version attribute info
                                string      tag;

                                try
                                {
                                    XList = xd.GetElementsByTagName("revision");
                                    xnA   = XList[0].Attributes.GetNamedItem("author");
                                    xnV   = XList[0].Attributes.GetNamedItem("version");
                                    try
                                    {
                                        XList = xd.GetElementsByTagName("plugin");
                                        tag   = XList[0].Attributes.GetNamedItem("class").Value;
                                    }
                                    catch
                                    {
                                        tag = fName[0].ToLower();
                                    }
                                }
                                catch
                                {
                                    try
                                    {
                                        XList = xd.GetElementsByTagName("plugin");
                                        xnA   = XList[0].Attributes.GetNamedItem("author");
                                        xnV   = XList[0].Attributes.GetNamedItem("version");
                                        tag   = XList[0].Attributes.GetNamedItem("class").Value;
                                    }
                                    catch
                                    {
                                        // Bad plugin?
                                        continue;
                                    }
                                }

                                //
                                // Need to generate name first & will rename later
                                //
                                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                                string md5 = GetChecksum(encoding.GetBytes(tempPlugin));

                                if (fName.Length > 2)
                                {
                                    xNode = xNode.AppendChild(xDoc.CreateElement("_" + fName[1]));
                                }
                                else
                                {
                                    xNode = xNode.AppendChild(xDoc.CreateElement("_---"));
                                }

                                // Append author & version to xNode
                                // (This needs to be after the xNode is possibly set to xNode.Child)

                                // MD5 Hashcode
                                XmlAttribute xAttr = xDoc.CreateAttribute("md5");
                                xAttr.InnerText = md5;
                                xNode.Attributes.Append(xAttr);

                                // Author info
                                xAttr           = xDoc.CreateAttribute("tagtype");
                                xAttr.InnerText = tag;
                                xNode.Attributes.Append(xAttr);

                                // Author info
                                xAttr           = xDoc.CreateAttribute("author");
                                xAttr.InnerText = xnA.Value;
                                xNode.Attributes.Append(xAttr);

                                // Version info
                                xAttr           = xDoc.CreateAttribute("version");
                                xAttr.InnerText = xnV.Value;
                                xNode.Attributes.Append(xAttr);

                                // States that changes need to be made to database file
                                xDocChange = true;
                            }
                            catch (Exception ex)
                            {
                                Globals.Global.ShowErrorMsg("Error from plugin server: ", ex);
                            }
                        }
                        PluginData pd = new PluginData(fd, xNode);
                        if (pd.md5 == string.Empty)
                        {
                            xNode = null;
                            goto @updatePlugin;
                        }
                        if (hashTable.Contains(pd.md5))
                        {
                            // Duplicate file found, erase file & remove entry
                            try
                            {
                                ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPServer + fd.name);
                                // Set default authentication for retrieving the file info
                                ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);

                                ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;
                                ftpResponse       = (FtpWebResponse)ftpRequest.GetResponse();
                                // Ask the server for the file size and store it
                                ftpResponse.Close();
                                xDocChange = true;
                            }
                            catch
                            { }
                            continue;
                        }

                        hashTable.Add(pd.md5);

                        // 1827
                        // "_fx_-87943969.ent"
                        // {27/10/2012 1:49:00 AM}
                        // "Grimdoomer"
                        // "0.99"

                        // Create a unique short hash code for this plugin using author, version & file date/time stamp
                        string hashcode = pd.GetHashCode().ToString();
                        string fileName = fName[0] + '-' + hashcode + ".ent";
                        if (fd.name.ToLower() != fileName)
                        {
                            // Rename the node to reflect the [new] hashcode
                            if (xNode.Name != "_" + hashcode)
                            {
                                xNode = RenameNode(xNode, string.Empty, '_' + hashcode);
                            }
                            #region Rename file to naming sequence
                            // Create a request to the directory we are working in
                            ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPServer + fd.name);
                            // Set default authentication for retrieving the file info
                            ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                            ftpRequest.Method      = WebRequestMethods.Ftp.Rename;
                            ftpRequest.RenameTo    = fileName;
                            ftpResponse            = (FtpWebResponse)ftpRequest.GetResponse();
                            ftpResponse.Close();
                            #endregion
                            fd.name = fileName;
                        }

                        if (pd.version == "0.0")
                        {
                            int a = 0;
                        }
                        this.Add(fName[0], pd);
                    }
                }
                if (xDocChange)
                {
                    // WriteXDoc back out
                    WebClient wc = new WebClient();
                    wc.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                    wc.UploadString(pluginsFTPdbFile, xDoc.InnerXml);
                }
            }
            finally
            {
                // Clean up our loading form
                formPB.Dispose();
            }
        }
Exemple #3
0
        private void RetrieveDataFromFTPServer()
        {
            FtpWebRequest ftpRequest;
            FtpWebResponse ftpResponse;

            xDoc = new XmlDocument();

            ProgressForm formPB = new ProgressForm();
            formPB.Show();

            try
            {
                formPB.Text = "Downloading Database";
                formPB.Value = 0;
                formPB.Refresh();

                #region Attempt to download plugin database file
                try
                {
                    // Create a request for the database file
                    ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPdbFile);
                    // Set default authentication for retrieving the file info
                    ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);

                    ftpRequest.Method = WebRequestMethods.Ftp.GetFileSize;
                    ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                    // Ask the server for the file size and store it
                    long fileSize = ftpResponse.ContentLength;
                    ftpResponse.Close();

                    WebClient wc = new WebClient();
                    wc.Credentials = ftpRequest.Credentials;
                    xDoc.LoadXml(wc.DownloadString(pluginsFTPdbFile));
                }
                catch
                {
                    xDoc.AppendChild(xDoc.CreateElement("Plugins"));
                }
                #endregion

                formPB.Text = "Check File Dates/Times";
                #region Retrieve list of all files & directories from FTP server
                try
                {
                    // Create a request to the directory we are working in
                    ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPServer);
                    // Set default authentication for retrieving the file info
                    ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                    ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
                    ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                    StreamReader streamReader = new StreamReader(ftpResponse.GetResponseStream());

                    List<string> files = new List<string>();
                    string line = streamReader.ReadLine();
                    while (!string.IsNullOrEmpty(line))
                    {
                        files.Add(line);
                        line = streamReader.ReadLine();
                    }

                    foreach (string s in files)
                    {
                        formPB.Value = files.IndexOf(s) * 100 / files.Count;
                        formPB.Refresh();
                        if (s[0].ToString().ToLower() == "d")
                            continue;

                        // Create a request to the directory we are working in
                        ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPServer + s.Substring(62));
                        ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                        ftpRequest.Method = WebRequestMethods.Ftp.GetDateTimestamp;
                        ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                        DateTime dt = ftpResponse.LastModified;
                        listing.Add(new FileData(s, dt));
                        ftpResponse.Close();
                    }

                }
                catch (Exception ex)
                {
                }
                #endregion

                HashSet<string> hashTable = new HashSet<string>();
                bool xDocChange = false;
                foreach (FileData fd in listing)
                {
                    // We only want files (non-directories)
                    if ((fd.attrib | FileAttributes.Directory) != FileAttributes.Directory)
                    {
                        string[] fName = fd.name.ToLower().Split('.', '-');
                        string modifiedName = fName[0].Replace('!', '_').Replace('+', '_');

                        #region Update information box
                        formPB.Text = "Analyzing: \n" + fd.name;
                        formPB.Value = listing.IndexOf(fd) * 100 / listing.Count;
                        formPB.Refresh();
                        #endregion

                        if (fName[fName.Length - 1] != "ent")
                            continue;

                        /*
                        if (fName.Length > 3)
                        {
                            string ver = fName[1];
                            for (int i = 2; i < fName.Length - 1; i++)
                                ver += '.' + fName[i];
                            fVer = new Version(ver);
                        }
                        */

                        // Check for the matching tag HASHCODE name
                        XmlNodeList xnl = null;
                        XmlNode xNode = null;

                        if (fName.Length > 2)
                            xnl = xDoc.GetElementsByTagName("_" + fName[1]);

                        // Search through each return value for the one in the desired parent TAG TYPE
                        if (xnl != null && xnl.Count > 0)
                            foreach (XmlNode xn in xnl)
                            {
                                if (xn.ParentNode.Name == modifiedName)
                                {
                                    xNode = xn;
                                    break;
                                }
                            }

                    @updatePlugin:
                        // If we do not get any results for the HASHCODE, check for parent TAG TYPE
                        if (xNode == null)
                        {
                            // Search for a matching TAG TYPE
                            XmlNodeList xml = xDoc.GetElementsByTagName(modifiedName);

                            // No matching TAG TYPE was found, so create a tag placeholder (eg. SCNR)
                            if (xml.Count == 0)
                            {
                                xNode = xDoc.CreateElement(modifiedName);
                                xDoc.FirstChild.AppendChild(xNode);
                            }
                            // We found a matching TAG TYPE, so select it
                            else
                            {
                                xNode = xml[0];
                            }

                            // Retrieve the plugin from the server & parse for needed info
                            WebClient wc = new WebClient();
                            wc.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                            try
                            {
                                string tempPlugin = wc.DownloadString(pluginsFTPServer + fd.name);
                                XmlDocument xd = new XmlDocument();
                                xd.LoadXml(tempPlugin);
                                XmlNodeList XList;
                                XmlNode xnA;    // Holds author attribute info
                                XmlNode xnV;    // Holds version attribute info
                                string tag;

                                try
                                {
                                    XList = xd.GetElementsByTagName("revision");
                                    xnA = XList[0].Attributes.GetNamedItem("author");
                                    xnV = XList[0].Attributes.GetNamedItem("version");
                                    try
                                    {
                                        XList = xd.GetElementsByTagName("plugin");
                                        tag = XList[0].Attributes.GetNamedItem("class").Value;
                                    }
                                    catch
                                    {
                                        tag = fName[0].ToLower();
                                    }
                                }
                                catch
                                {
                                    try
                                    {
                                        XList = xd.GetElementsByTagName("plugin");
                                        xnA = XList[0].Attributes.GetNamedItem("author");
                                        xnV = XList[0].Attributes.GetNamedItem("version");
                                        tag = XList[0].Attributes.GetNamedItem("class").Value;
                                    }
                                    catch
                                    {
                                        // Bad plugin?
                                        continue;
                                    }
                                }

                                //
                                // Need to generate name first & will rename later
                                //
                                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                                string md5 = GetChecksum(encoding.GetBytes(tempPlugin));

                                if (fName.Length > 2)
                                    xNode = xNode.AppendChild(xDoc.CreateElement("_" + fName[1]));
                                else
                                    xNode = xNode.AppendChild(xDoc.CreateElement("_---"));

                                // Append author & version to xNode
                                // (This needs to be after the xNode is possibly set to xNode.Child)

                                // MD5 Hashcode
                                XmlAttribute xAttr = xDoc.CreateAttribute("md5");
                                xAttr.InnerText = md5;
                                xNode.Attributes.Append(xAttr);

                                // Author info
                                xAttr = xDoc.CreateAttribute("tagtype");
                                xAttr.InnerText = tag;
                                xNode.Attributes.Append(xAttr);

                                // Author info
                                xAttr = xDoc.CreateAttribute("author");
                                xAttr.InnerText = xnA.Value;
                                xNode.Attributes.Append(xAttr);

                                // Version info
                                xAttr = xDoc.CreateAttribute("version");
                                xAttr.InnerText = xnV.Value;
                                xNode.Attributes.Append(xAttr);

                                // States that changes need to be made to database file
                                xDocChange = true;
                            }
                            catch (Exception ex)
                            {
                                Globals.Global.ShowErrorMsg("Error from plugin server: ", ex);
                            }
                        }
                        PluginData pd = new PluginData(fd, xNode);
                        if (pd.md5 == string.Empty)
                        {
                            xNode = null;
                            goto @updatePlugin;
                        }
                        if (hashTable.Contains(pd.md5))
                        {
                            // Duplicate file found, erase file & remove entry
                            try
                            {
                                ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPServer + fd.name);
                                // Set default authentication for retrieving the file info
                                ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);

                                ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;
                                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                                // Ask the server for the file size and store it
                                ftpResponse.Close();
                                xDocChange = true;
                            }
                            catch
                            { }
                            continue;
                        }

                        hashTable.Add(pd.md5);

                        // 1827
                        // "_fx_-87943969.ent"
                        // {27/10/2012 1:49:00 AM}
                        // "Grimdoomer"
                        // "0.99"

                        // Create a unique short hash code for this plugin using author, version & file date/time stamp
                        string hashcode = pd.GetHashCode().ToString();
                        string fileName = fName[0] + '-' + hashcode + ".ent";
                        if (fd.name.ToLower() != fileName)
                        {
                            // Rename the node to reflect the [new] hashcode
                            if (xNode.Name != "_" + hashcode)
                                xNode = RenameNode(xNode, string.Empty, '_' + hashcode);
                            #region Rename file to naming sequence
                            // Create a request to the directory we are working in
                            ftpRequest = (FtpWebRequest)WebRequest.Create(pluginsFTPServer + fd.name);
                            // Set default authentication for retrieving the file info
                            ftpRequest.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                            ftpRequest.Method = WebRequestMethods.Ftp.Rename;
                            ftpRequest.RenameTo = fileName;
                            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                            ftpResponse.Close();
                            #endregion
                            fd.name = fileName;
                        }

                        if (pd.version == "0.0")
                        {
                            int a = 0;
                        }
                        this.Add(fName[0], pd);
                    }

                }
                if (xDocChange)
                {
                    // WriteXDoc back out
                    WebClient wc = new WebClient();
                    wc.Credentials = new NetworkCredential(updateFTPName, updateFTPPass);
                    wc.UploadString(pluginsFTPdbFile, xDoc.InnerXml);
                }
            }
            finally
            {
                // Clean up our loading form
                formPB.Dispose();
            }
        }