예제 #1
0
        /// <summary>
        /// 注意静态构造函数不允许有访问修饰符
        /// 默认都是Public的?
        ///
        /// </summary>
        static MyFastDFSClient()
        {
            List <IPEndPoint> trackerIPs = new List <IPEndPoint>();

            //从配置文件中读取Common/Config/Fdfs/TrackerSection相关对象中对应的配置
            #region 从配置文件中读取Common/Config/Fdfs/TrackerSection相关对象中对应的配置
            //TrackerSection trackersSection = ConfigurationManager.GetSection("TrackerSection") as TrackerSection;
            //foreach (MyTracker item in trackersSection.Trackers)
            //{
            //    trackerIPs.Add(new IPEndPoint(IPAddress.Parse(item.Host), item.Port));
            //}
            #endregion

            /*
             *  读取fastdfs配置节下的配置文件
             *  以FastDFS.Client.Config 中FastDFSConfig 对象的方式读取出来
             */
            var config = FastDfsManager.GetConfigSection();
            try
            {
                //根据指定群组名称获取存储节点
                DefaultGroup = GetStorageNode(config.GroupName);
                foreach (var item in config.FastDfsServer)
                {
                    trackerIPs.Add(new IPEndPoint(IPAddress.Parse(item.IpAddress), item.Port));
                }
                //初始化
                ConnectionManager.Initialize(trackerIPs);
            }
            catch (Exception ex)
            {
                //Logger.LoggerFactory.Instance.Logger_Error(ex);
            }
        }
예제 #2
0
        /// <summary>
        /// 初始化节点
        /// </summary>
        protected void InitStorageNode()
        {
            //读取配置文件中的fdfs配置节
            var config = FastDfsManager.GetConfigSection();

            try
            {
                //注意需要先初始化tracker
                ConnectionManager.InitializeForConfigSection(config);
                this.DFSGroupName = config.GroupName;
                this.Host         = config.FastDfsServer.FirstOrDefault().IpAddress;
                //根据指定群组名称获取存储节点
                Node = FastDFSClient.GetStorageNode(config.GroupName);
                foreach (var item in config.FastDfsServer)
                {
                    trackerIPs.Add(new IPEndPoint(IPAddress.Parse(item.IpAddress), item.Port));
                }
                //初始化
                ConnectionManager.Initialize(trackerIPs);
            }
            catch (Exception ex)
            {
                //Logger.LoggerFactory.Instance.Logger_Error(ex);
            }
        }
예제 #3
0
 protected void Application_Start()
 {
     if (ConfigHelper.GetConfigString("SaveMode") == "Distributed")
     {
         FastDfsConfig globalConfig = FastDfsManager.GetConfigSection();
         ConnectionManager.InitializeForConfigSection(globalConfig);
         FastDfsGlobalConfig.Config = globalConfig;
     }
     GlobalConfiguration.Configure(WebApiConfig.Register);
 }
예제 #4
0
        static void Main(string[] args)
        {
            var config = FastDfsManager.GetConfigSection();

            StorageNode storageNode = null;

            var fileName = "";

            ConnectionManager.InitializeForConfigSection(config);

            do
            {
                // Console.WriteLine("\r\n1.Init");
                Console.WriteLine("\r\n");
                Console.WriteLine("1.GetAllStorageNode");
                Console.WriteLine("2.GetStorageNode");
                Console.WriteLine("3.UploadFile");
                Console.WriteLine("4.RemoveFile");

                Console.Write("请输入命令:");
                var cmd = Console.ReadLine();

                switch (cmd)
                {
                case "1":
                    var list = FastDFSClient.GetStorageNodes(config.GroupName);
                    foreach (var item in list)
                    {
                        Console.WriteLine(item.EndPoint.ToString());
                        Console.WriteLine(item.StorePathIndex);
                    }
                    break;

                case "2":
                    storageNode = FastDFSClient.GetStorageNode(config.GroupName);
                    Console.WriteLine(storageNode.GroupName);
                    Console.WriteLine(storageNode.EndPoint);
                    Console.WriteLine(storageNode.StorePathIndex);
                    break;

                case "3":
                    fileName = FastDFSClient.UploadFile(storageNode, File.ReadAllBytes("test.jpg"), "jpg");
                    Console.WriteLine(fileName);
                    break;

                case "4":
                    FastDFSClient.RemoveFile(config.GroupName, fileName);
                    break;
                }
            } while (true);
        }
예제 #5
0
        static void Main(string[] args)
        {
            //
            var config = FastDfsManager.GetConfigSection();
            //测试第二种方式
            //TrackerSection trackersSection = ConfigurationManager.GetSection("TrackerSection") as TrackerSection;
            //测试第三种方式
            //MyFastDFSClient.Test();

            StorageNode storageNode = null;

            var fileName = "";

            if (!File.Exists("test.jpg"))
            {
                return;
            }
            FileStream streamUpload = new FileStream(@"test.jpg", FileMode.Open);

            Console.WriteLine("进行上传图片/文件 测试");
            IUpload uploadFile = UploadFactory.Instance;
            //1 测试上传文件(非图片)——可行
            var fileUploadPara = new FileUploadParameter()
            {
                FileName = "test.jpg",
                //Content= File.ReadAllBytes("test.jpg"),
                Stream = streamUpload
            };
            //uploadFile.UploadFile(fileUploadPara);
            //2 测试上传图片
            //**注意,maxSize以后改为读取配置文件
            var fileUploadImage = new ImageUploadParameter(streamUpload, "test.jpg", null, 2 * 1024 * 1024)
            {
            };
            //FilePath:http://192.168.0.113/group1/M00/00/00/wKgAcVjHVVKAGNhPAAInn_BrY3k026.jpg
            var result = uploadFile.UploadImage(fileUploadImage);

            Console.WriteLine("上传成功,上传图片为{0}", result.FullFilePath);
            Console.WriteLine("*******************************");
            Console.WriteLine("1.直接获取刚才上传的文件的名称");
            Console.WriteLine("2.手动收入文件名称");
            Console.Write("请输入命令:");
            var    index            = Console.ReadLine();
            string filename_console = null;

            switch (index)
            {
            case "1":
                filename_console = result.FileName;
                Console.WriteLine("刚才上传的文件名为:{0}", filename_console);
                break;

            case "2":
                Console.WriteLine("请输入命令:");
                Console.WriteLine("请输入文件路径准备下载指定文件");
                filename_console = Console.ReadLine();
                break;

            default:
                Console.WriteLine("输入有误!");
                return;
            }

            IDownload downloadFile = DownloadFactory.Instance;

            Console.WriteLine("*******************************");
            var result_download = downloadFile.GetTargetFile(new FileDownParameter()
            {
                FileName = filename_console
            });

            Console.WriteLine("下载成功");
            Console.ReadLine();
            do
            {
                Console.WriteLine("\r\n1.Init");
                Console.WriteLine("2.GetStorageNode");
                Console.WriteLine("3.UploadFile");
                Console.WriteLine("4.RemoveFile");

                Console.Write("请输入命令:");
                var cmd = Console.ReadLine();

                switch (cmd)
                {
                case "1":
                    ConnectionManager.InitializeForConfigSection(config);
                    break;

                case "2":
                    storageNode = MyFastDFSClient.GetStorageNode(config.GroupName);
                    Console.WriteLine(storageNode.EndPoint);
                    break;

                case "3":
                    //暂时注释掉
                    fileName = MyFastDFSClient.UploadFile(storageNode, File.ReadAllBytes("test.jpg"), "jpg");


                    //此处不需要手动关闭了
                    //streamUpload.Close();
                    Console.WriteLine(fileName);
                    break;

                case "4":
                    MyFastDFSClient.RemoveFile(config.GroupName, fileName);
                    break;
                }
            } while (true);
        }
예제 #6
0
 static FastDFSService()
 {
     config = FastDfsManager.GetConfigSection();
     ConnectionManager.InitializeForConfigSection(config);
 }
예제 #7
0
 static FastDfsHelper()
 {
     Config = FastDfsManager.GetConfigSection("fastdfs");
     ConnectionManager.InitializeForConfigSection(Config);
 }