当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.Specialized.StringCollection.Clear方法代码示例

本文整理汇总了C#中System.Collections.Specialized.StringCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Specialized.StringCollection.Clear方法的具体用法?C# System.Collections.Specialized.StringCollection.Clear怎么用?C# System.Collections.Specialized.StringCollection.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Specialized.StringCollection的用法示例。


在下文中一共展示了System.Collections.Specialized.StringCollection.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReceiveClip

        private void ReceiveClip()
        {
            String text;
            System.Collections.Specialized.StringCollection paths = new System.Collections.Specialized.StringCollection();
            NetworkStream netstream = tcpClip.GetStream();
            int j;
            bool abort = false;

            while (Connected==true)
            {
                try
                {
                    string what = str.ReadLine();

                    if (MessageBox.Show("E' stata condivisa una clipboard.\n Accettarla, sovrascrivendo la clipboard attuale?", "Clipboard condivisa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (what.Substring(0, 4).Equals("File"))
                        {
                            string Reason = "Ricevendo Clipboard...";
                            this.Invoke(new DisableClipboardCallback(this.DisableClipboard), new object[] { Reason });
                            paths.Clear();
                            string qta = what.Substring(4, 1);
                            for (j = 0; j < int.Parse(qta); j++)
                            {
                                string tmp = str.ReadLine();
                                if (tmp.Equals("Abort"))
                                {
                                    abort = true;
                                    break;
                                }
                                abort = false;
                                string fileName = tmp.Substring(6);
                                byte[] clientData = Convert.FromBase64String(str.ReadLine());
                                BinaryWriter bWrite = new BinaryWriter(File.Open(Path.GetFullPath(@".\File ricevuti\") + fileName, FileMode.Create));
                                bWrite.Write(clientData, 4 + fileName.Length, clientData.Length - 4 - fileName.Length);
                                bWrite.Close();
                                paths.Add(Path.GetFullPath(@".\File ricevuti\") + fileName);
                                //SetClipboard(fileName);
                            }
                            Reason = "Condividi Clipboard";
                            this.Invoke(new DisableClipboardCallback(this.EnableClipboard), new object[] { Reason });
                            if (abort == false)
                                this.Invoke(new UpdateClipboardCallback(UpdateClipboard), new object[] { paths });
                        }

                        else if (what.Substring(0, 4).Equals("Text")) // text
                        {
                            string Reason = "Ricevendo Clipboard...";
                            this.Invoke(new DisableClipboardCallback(this.DisableClipboard), new object[] { Reason });
                            byte[] bytes = new byte[tcpClip.ReceiveBufferSize];

                            // Read can return anything from 0 to numBytesToRead.
                            // This method blocks until at least one byte is read.
                            netstream.Read(bytes, 0, (int)tcpClip.ReceiveBufferSize);
                            string textcrc = Encoding.ASCII.GetString(bytes);
                            text = TrimFromZero(textcrc);
                            IDataObject ido = new DataObject();
                            ido.SetData(text);
                            Clipboard.SetDataObject(ido, true);
                            Reason = "Condividi Clipboard";
                            this.Invoke(new DisableClipboardCallback(this.EnableClipboard), new object[] { Reason });
                            //MessageBox.Show(text);
                        }

                        else if (what.Substring(0, 4).Equals("Imag")) // bitmap
                        {
                            string Reason = "Ricevendo Clipboard...";
                            this.Invoke(new DisableClipboardCallback(this.DisableClipboard), new object[] { Reason });
                            Stream stm = tcpClip.GetStream();
                            IFormatter formatter = new BinaryFormatter();
                            Bitmap bitm = (Bitmap)formatter.Deserialize(stm);
                            Clipboard.SetImage(bitm);
                            Reason = "Condividi Clipboard";
                            this.Invoke(new DisableClipboardCallback(this.EnableClipboard), new object[] { Reason });
                        }

                    }
                }

                catch (Exception e)
                {
                    //MessageBox.Show(e.ToString());
                    break;
                }
            }
        }
开发者ID:cugni,项目名称:pds,代码行数:86,代码来源:Form1.cs

示例2: ReceiveFile

        private void ReceiveFile(object stream)
        {
            byte[] buff = new byte[1024];
            int j;
            string text, user_sharing;
            System.Collections.Specialized.StringCollection paths = new System.Collections.Specialized.StringCollection();

            TcpClient s = (TcpClient) stream;
            NetworkStream netStream = s.GetStream();
            StreamReader str = new StreamReader(s.GetStream());
            bool abort= false;

             while (ServRunning==true)
             {
                try
                {
                    string what = str.ReadLine();
                    user_sharing = what.Substring(4);
                    if (what.Substring(0, 4).Equals("File")) //someone is sharing a file-clopboard
                    {
                        string Reason = "Receving Clipboard...";
                        mf.Invoke(new DisableClipboardCallback(mf.disableClipboard), new object[] { Reason });
                        user_sharing = what.Substring(5);
                        paths.Clear();
                        string qta = what.Substring(4, 1);
                        for (j = 0; j < int.Parse(qta); j++)
                        {
                            string tmp = str.ReadLine();
                            if (tmp.Equals("Abort"))
                            {
                                abort = true;
                                break;
                            }
                            abort = false;
                            string fileName = tmp.Substring(6);
                            byte[] clientData = Convert.FromBase64String(str.ReadLine());
                            BinaryWriter bWrite = new BinaryWriter(File.Open(Path.GetFullPath(@".\File ricevuti\") + fileName, FileMode.Create));
                            bWrite.Write(clientData, 4 + fileName.Length, clientData.Length - 4 - fileName.Length);
                            bWrite.Close();
                            paths.Add(Path.GetFullPath(@".\File ricevuti\") + fileName);

                            //send file to others users
                            TcpClient[] tcpClients = new TcpClient[ChatServer.tcpClipboard.Count];
                            String[] users = new String[ChatServer.htUsers.Count];
                            ChatServer.tcpClipboard.Values.CopyTo(tcpClients, 0);
                            ChatServer.htUsers.Keys.CopyTo(users, 0);
                            for (int i = 0; i < tcpClients.Length; i++)
                            {
                                // Try sending a message to each
                                try
                                {
                                    // If the message is blank or the connection is null, break out
                                    if (tcpClients[i] == null || user_sharing == users[i])
                                    {
                                        continue;
                                    }
                                    StreamWriter sw = new StreamWriter(tcpClients[i].GetStream());
                                    sw.WriteLine("File");
                                    sw.Flush();
                                    // Send the message to the current user in the loop
                                    sw.WriteLine("File: " + Path.GetFileName(fileName));
                                    sw.Flush();
                                    sw.WriteLine(Convert.ToBase64String(clientData));
                                    sw.Flush();
                                    sw = null;
                                }
                                catch (Exception ex)// If there was a problem, the user is not there anymore, remove him
                                {
                                    //MessageBox.Show(ex.ToString());
                                    continue;
                                }
                            }
                        }
                        if (abort == false)
                        {
                            if (int.Parse(qta) == 1)
                                SendAdminMessage(user_sharing + " just shared his clipboard containing a file with us!");
                            else
                                SendAdminMessage(user_sharing + " just shared his clipboard containing some files with us!");
                            mf.Invoke(new UpdateClipboardCallback(UpdateClipboard), new object[] { paths });
                        }
                        Reason = "Share Clipboard";
                        mf.Invoke(new DisableClipboardCallback(mf.enableClipboard), new object[] { Reason });
                        //mf.enableClipboard();
                        //MessageBox.Show("file ricevuto!!"+paths.ToString());

                    }
                    else if (what.Substring(0, 4).Equals("Text"))
                    {
                        string Reason = "Receving Clipboard...";
                        mf.Invoke(new DisableClipboardCallback(mf.disableClipboard), new object[] { Reason });

                        byte[] bytes = new byte[s.ReceiveBufferSize];

                        // Read can return anything from 0 to numBytesToRead.
                        // This method blocks until at least one byte is read.
                        netStream.Read(bytes, 0, (int)s.ReceiveBufferSize);
                        string textcrc = Encoding.ASCII.GetString(bytes);
                        text = TrimFromZero(textcrc);
                        //text = str.ReadLine();
//.........这里部分代码省略.........
开发者ID:cugni,项目名称:pds,代码行数:101,代码来源:ChatServer.cs

示例3: GetSections

 /// <summary>
 /// Возвращает коллекцию строк
 /// с именами секций в ini файле
 /// </summary>
 /// <param name="filename"><c>Путь к ini файлу</c></param>
 /// <returns><c>Коллекция строк из класса System.Collections.Specialized.StringCollection</c></returns>
 public System.Collections.Specialized.StringCollection GetSections(string filename)
 {
     System.Collections.Specialized.StringCollection items = new System.Collections.Specialized.StringCollection();
       try
       {
     byte[] buffer = new byte[32768];
     int beg=0;
     string ss="";
     int bufLen = GetBytes(null,null,DefaultValue, buffer, buffer.GetUpperBound(0), filename);
     if (bufLen > 0)
     {
       for (int i=0; i < bufLen; i++)
       {
     if (buffer[i] != 0)
     {
       ss=System.Text.UnicodeEncoding.Default.GetString (buffer, beg, i-beg+1);
     }
     else
     {
       if (ss.Length > 0)
       {
         items.Add(ss);
         ss="";
         beg=i+1;
       }
     }
       }
     }
       }
       catch
       {
     //произошла какая-то ошибка:
     items.Clear();
       }
       return items;
 }
开发者ID:infobook,项目名称:Tools4,代码行数:42,代码来源:clsINI.cs

示例4: LoadModules

                /// -----------------------------------------------------------------------------
                /// <summary>
                /// Will load all modules in given list
                /// </summary>
                /// <param name="ModFiles"></param>
                /// <remarks>
                /// Once a module is loaded it will be added the the Module list,
                /// and will then have ModLoad called and the filename property set
                /// </remarks>
                /// <history>
                /// 	[Caleb]	6/18/2005	Created
                /// </history>
                /// -----------------------------------------------------------------------------
                public void LoadModules(string[] ModFiles)
                {
                    System.Collections.Specialized.StringCollection ModuleFiles = new System.Collections.Specialized.StringCollection();
                    Assembly tObject;
                    //File tFile;
                    int tIndex;
                    short tCount = 0;
                    string tMod;
                    string tString;
                    System.Collections.Specialized.StringCollection tFound = new System.Collections.Specialized.StringCollection();
                    foreach (string xMod in ModFiles)
                    {
                        ModuleFiles.Add(xMod);
                    }
                    BlackLightModule tModule;
                    //Cycle through the modules untill they are all loaded or removed
                    while (ModuleFiles.Count > 0)
                    {
                        try
                        {
                            //Infinate loop check
                            if (tCount > 1000)
                            {
                                Base.Core.SendLogMessage("ModuleManagement", "LoadModules", BlackLight.Services.Error.Errors.DEBUG | BlackLight.Services.Error.Errors.WARNING, "It appears we have gotten into an infinate loop while loading modules, loading halted", "Most likely cause is two or more modules require each other and will never be able to load", "", "");
                                return;
                            }
                            tCount += Convert.ToInt16(1);

                            //Get the filename
                            tMod = ModuleFiles[0].ToString();

                            //Make sure it exists
                            if (File.Exists("modules/" + tMod))
                            {

                                //Use .NET to attempt to load the class inside the dll
                                tObject = @Assembly.LoadFrom("modules/" + tMod);

                                //Make sure everything is still hawt or remove the failed module
                                if (tObject == null)
                                {
                                    ModuleFiles.RemoveAt(0);
                                }

                                //Get a list of the classes the module contains
                                Type[] tList = tObject.GetTypes();
                                //Cycle through them all
                                foreach (Type tType in tList)
                                {

                                    //Make sure it uses our module base somewhere
                                    if (tType.IsSubclassOf(typeof(BlackLightModule)) == true)
                                    {
                                        //Alrighty it's a valid module now what?

                                        //Well lets check if its a special module, currently only datadrivers

                                        //Ooooo isn't this sexy
                                        tModule = ((BlackLightModule) tType.GetConstructor(new Type[] { typeof(ServicesDaemon) }).Invoke(new object[] {Base}));

                                        //Or not :'(
                                        if (tModule == null)
                                        {
                                            ModuleFiles.RemoveAt(0);
                                        }

                                        if (tType.IsSubclassOf(typeof(DB.DataDriver)) == true)
                                        {
                                            if (DataDriver == "")
                                            {
                                                DataDriver = tModule.Name;
                                            }
                                            else
                                            {
                                                Base.Core.SendLogMessage("ModuleManagement", "LoadModules", BlackLight.Services.Error.Errors.DEBUG | BlackLight.Services.Error.Errors.WARNING, "DataBase driver already loaded!", "File does not exist", "", "");
                                                ModuleFiles.RemoveAt(0);
                                            }
                                        }

                                        //Set the internal filename for the ModuleList Class
                                        tModule.FileName = tMod;

                                        //Clear the list of found modules for requirements
                                        tFound.Clear();

                                        //Malicious module coder?
                                        if (tModule.Requires.Count < 1000)
//.........这里部分代码省略.........
开发者ID:Mediator,项目名称:Blacklight-IRC-Services,代码行数:101,代码来源:Modules.cs


注:本文中的System.Collections.Specialized.StringCollection.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。