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


C# Utilities.GetValue方法代码示例

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


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

示例1: C_ReciveFiles

        public bool C_ReciveFiles(List<string> cfilePaths, List<string> sfilePaths, ref Utilities.UpdateInfo notify)
        {
            // UpdateInfo[0] = Cancel/Complate - bool 
            // UpdateInfo[1] = ProgreeBarFiles Max Value - int 
            // UpdateInfo[2] = ProgreeBarFiles Value - int
            // UpdateInfo[3] = ProgreeBarFile Max Value - int
            // UpdateInfo[4] = ProgreeBarFile Value - int

            notify.SetValue(1, sfilePaths.Count);

            byte[] Buffers;
            Socket Sok = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            string contains = string.Empty;
            foreach (string item in sfilePaths)
            {
                contains += item + ";";
            }
            contains = contains.Substring(0, contains.Length - 1);
            Buffers = GetCmd(OpCodeProcess.C_ReciveFiles, contains);

            Sok.Connect(config.IP, config.PORT);
            if (Sok.Connected == true)
            {
                Sok.Send(Buffers, Buffers.Length, SocketFlags.None);
            }
            Buffers = Utilities.Buffers.GetBuffer();
            Sok.Receive(Buffers, SocketFlags.None);
            if (Buffers[0] != (byte)OpCodeProcess.S_OK)
                throw new Exception("Server Refuse");
            List<long> FileLen = new List<long>();
            for (int i = 0; i < sfilePaths.Count; i++)
            {
                FileLen.Add(BitConverter.ToInt64(Buffers, 1 + (i * 8)));
            }

            int readSize = 0;
            Buffers = Utilities.Buffers.GetBuffer();
            for (int fileIndex = 0; fileIndex < cfilePaths.Count; fileIndex++)
            {
                notify.SetValue(3, FileLen[fileIndex]);//Set File progress Max value
                notify.SetValue(4, 0);//Set File progress value = 0

                FileStream fs = File.OpenWrite(cfilePaths[fileIndex]);
                for (int offset = 0; offset < FileLen[fileIndex]; )
                {
                    if (offset + Buffers.Length > FileLen[fileIndex])
                        readSize = Sok.Receive(Buffers, (int)(FileLen[fileIndex] - offset), SocketFlags.None);
                    else
                        readSize = Sok.Receive(Buffers, Buffers.Length, SocketFlags.None);

                    fs.Write(Buffers, 0, readSize);
                    offset += readSize;
                    notify.SetValue(4, Convert.ToInt32(notify.GetValue(4)) + readSize);//File progress value

                    if ((bool)notify.GetValue(0))
                        return false;

                }
                fs.Flush(); fs.Close(); fs.Dispose();
                notify.SetValue(2, Convert.ToInt32(notify.GetValue(2)) + 1);//Files progress value


            }
            return true;
        }
开发者ID:EgyFalseX,项目名称:Winform,代码行数:65,代码来源:nsLib.cs

示例2: C_SendFiles

        public bool C_SendFiles(List<string[]> filePaths,ref Utilities.UpdateInfo notify)
        {
            /* UpdateInfo[0] = Cancel/Complate - bool
             * UpdateInfo[1] = ProgreeBarFiles Max Value - int
             * UpdateInfo[2] = ProgreeBarFiles Value - int
             * UpdateInfo[3] = ProgreeBarFile Max Value - int
             * UpdateInfo[4] = ProgreeBarFile Value - int
             */

            notify.SetValue(1, filePaths.Count);

            byte[] Buffers;
            Socket Sok = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            string contains = string.Empty;
            foreach (string[] item in filePaths)
            {
                //item[0] = client filename ; item[1] = server filename
                contains += new FileInfo(item[0]).Length + ";" + item[1] + ";";
            }
            contains = contains.Substring(0, contains.Length - 1);
            Buffers = GetCmd(OpCodeProcess.C_SendFiles, contains);

            Sok.Connect(config.IP, config.PORT);
            if (Sok.Connected == true)
            {
                Sok.Send(Buffers, Buffers.Length, SocketFlags.None);
            }

            Sok.Receive(Buffers, SocketFlags.None);
            if (Buffers[0] != (byte)OpCodeProcess.S_OK)
                throw new Exception("Server Refuse");

            int readed = 0;
            Buffers = new byte[4097];
            foreach (string[] item in filePaths)
            {
                FileStream fs = File.OpenRead(item[0]);
                
                notify.SetValue(3, fs.Length);
                notify.SetValue(4, 0);
                
                for (int i = 0; i < fs.Length; )
                {
                    readed = fs.Read(Buffers, 0, Buffers.Length - 1);
                    Sok.Send(Buffers, readed, SocketFlags.None);
                    i += readed;
                    notify.SetValue(4, Convert.ToInt32(notify.GetValue(4)) + readed);// File progress value
                }
                fs.Flush(); fs.Close(); fs.Dispose();
                notify.SetValue(2, Convert.ToInt32(notify.GetValue(2)) + 1);// Files progress value
            }
            return true;
        }
开发者ID:EgyFalseX,项目名称:Winform,代码行数:53,代码来源:nsLib.cs


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