Exemplo n.º 1
0
        /// <summary>
        /// Create a PI-message.
        /// </summary>
        /// <param name="MessageID">The message ID.</param>
        /// <param name="TTL">The time to live.</param>
        /// <param name="Encryption">Indicates if the message is encrypted or not.</param>
        /// <param name="Parameters">The list of the parameters with prefixes.</param>
        public Ping(string MessageID, int TTL, bool Encryption, string[] Parameters)
            : base(Commands.PI, MessageID, TTL, Encryption)
        {
            if (((Parameters.Length - 1) % 3) == 0)
            {
                Parameters[0] = Parameters[0].Remove(0, 4);

                int nFiles = (Parameters.Length - 1) / 3;

                int i;

                for (int n = 1; n <= nFiles; n++)
                {
                    i = n * 3;

                    Ping.File file = new Ping.File();

                    Parameters[(i - 2)] = Parameters[(i - 2)].Remove(0, 3);
                    Parameters[(i - 1)] = (Parameters[(i - 1)]).Remove(0, 3);
                    Parameters[i] = Parameters[i].Remove(0, 3);
                }

                this.CreatePing(Parameters);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a PI-message.
        /// </summary>
        /// <param name="Parameters">The list of the parameters without prefixes.</param>
        private void CreatePing(params string[] Parameters)
        {
            // if Parameters is empty it will automatic created
            if (Parameters[0] == "")
            {
                this.m_strPeerID = Global.MyPeerID;

                this.m_arrFiles = new Ping.File[Lists.FilesList.Count];

                for (int i = 0; i < m_arrFiles.Length; i++)
                {
                    if (i < Lists.FilesList.Count)
                    {
                        Objects.SharedFile file = Lists.FilesList.List[i];

                        Ping.File PIfile = new Ping.File();

                        PIfile.Name = file.Name;
                        PIfile.Size = file.Size;
                        PIfile.SHA1 = file.SHA1;

                        if (i < m_arrFiles.Length)
                        {
                            this.m_arrFiles[i] = PIfile;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        Array.Resize(ref this.m_arrFiles, i);

                        break;
                    }
                }
            }
            else
            {
                this.m_strPeerID = Parameters[0];

                int nFiles = (Parameters.Length - 1) / 3;

                this.m_arrFiles = new Ping.File[nFiles];

                int i;

                for (int n = 1; n <= nFiles; n++)
                {
                    i = n * 3;

                    Ping.File file = new Ping.File();

                    file.Name = Parameters[(i - 2)];
                    file.Size = uint.Parse((Parameters[(i - 1)]));
                    file.SHA1 = Parameters[i];

                    this.m_arrFiles[(n - 1)] = file;
                }
            }
        }