Exemple #1
0
        /// <summary>
        /// Upload part #orderFile to IPFS and send a message on DCore
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="orderFile"></param>
        /// <exception cref = "member" > HttpRequestException </ exception >
        async void IpfsUploadDCore(string FilePath, int orderFile)
        {
            var ipfs = new IpfsClient(ipfsServer);

            Ipfs.CoreApi.AddFileOptions options = default(Ipfs.CoreApi.AddFileOptions);
            //token = source.Token;
            CancellationToken token = default(CancellationToken);

//            form.buttonSend.Text = "Sending";
            try
            {
                Ipfs.IFileSystemNode node = await ipfs.FileSystem.AddFileAsync(FilePath, options, token);

//                form.buttonSend.Text = "Send";
//                form.textBoxFilePath.Text = "";
                Console.WriteLine("Cid = {0}", node.Id);
                Console.WriteLine("Size = {0}", node.Size);
                //We want to return the cid
//                form.richTextBox1.Text = "File on IPFS under the cid:" + node.Id;
                // S1 - global var
                fs.AddFileNameCID(FilePath, node.Id, orderFile);
                //AddFileNameCID(FilePath, node.Id, orderFile);
                AddCidDCore(node.Id);
                File.Delete(FilePath);
            }
            catch (HttpRequestException)
            {
                Console.WriteLine("FAIL! Don't forget to run IPFS on your computer");
            }
        }
Exemple #2
0
        /// <summary>
        /// Upload to Ipfs and add cid to DCore Blockchain
        /// </summary>
        /// <param name="SplittedFile"></param>
        /// <param name="EntryFileCid"></param>
        /// <exception cref = "member" > HttpRequestException </ exception >
        public async void IpfsUploadDCore(string filepath, int orderFile, List <string> EntryFileCid)
        { //async void cannot have ref or out
            var ipfs = new IpfsClient(ipfsServer);

            Ipfs.CoreApi.AddFileOptions options = default(Ipfs.CoreApi.AddFileOptions);
            CancellationToken           token   = default(CancellationToken);

            //token = source.Token;
//            form.buttonSend.Text = "Sending";
            try
            {
                Ipfs.IFileSystemNode node = await ipfs.FileSystem.AddFileAsync(filepath, options, token);

//                form.buttonSend.Text = "Send";
//                form.textBoxFilePath.Text = "";
                Console.WriteLine("Cid = {0}", node.Id);
                Console.WriteLine("Size = {0}", node.Size);
                //We want to return the cid
//                form.richTextBox1.Text = "File on IPFS under the cid:" + node.Id;

                EntryFileCid[orderFile] += node.Id;
                Console.WriteLine("Adding the node.Id {0} at position {1} to the entry", node.Id, orderFile);
                AddCidDCore(node.Id);
                File.Delete(filepath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (e.InnerException is TaskCanceledException)
                {
                    Console.WriteLine("=> IPFS Upload DCore failed. The task was alredy run before and now canceled");
                }

                if (e.InnerException is HttpRequestException)
                {
                    Console.WriteLine("=> IPFS Upload DCore failed. Don't forget to run IPFS on your computer");
                }

                /*
                 * switch e.InnerException
                 * {
                 * case TaskCanceledException:
                 *  Console.WriteLine("IPFS Upload DCore failed. The task was alredy run before and now canceled");
                 *  break;
                 * case HttpRequestException:
                 *  Console.WriteLine("FAIL! Don't forget to run IPFS on your computer");
                 *  break;
                 * default:
                 *  Console.WriteLine("Default case");
                 *  break;
                 * }
                 */
            }
        }
Exemple #3
0
        public async static void UploadFile()
        {
            var ipfs = new IpfsClient("http://localhost:5001");

            Ipfs.CoreApi.AddFileOptions options = default(Ipfs.CoreApi.AddFileOptions);
            CancellationTokenSource     source  = new CancellationTokenSource();
            CancellationToken           token   = source.Token;
            string path = "C:\\Blockget\\ifmalesuperfherodressedlikewomen.jpg";

            Ipfs.IFileSystemNode node = await ipfs.FileSystem.AddFileAsync(path, options, token);

            Console.WriteLine("Cid = {0}", node.Id);
            Console.WriteLine("Size = {0}", node.Size);
        }
Exemple #4
0
        /// <summary>
        /// Creation IPFS Task: upload file to IPFS and add the CID on DCore. Drop file on IPFS using dotnet library: https://github.com/richardschneider/net-ipfs-http-client
        /// </summary>
        /// <param name="FilePath"></param>
        private async void creationIpfsTask(string FilePath)
        {
            var ipfs = new IpfsClient(ipfsServer);

            Ipfs.CoreApi.AddFileOptions options = default(Ipfs.CoreApi.AddFileOptions);
            CancellationToken           token   = default(CancellationToken);

            //token = source.Token;
//            form.buttonSend.Text = "Sending";
            Ipfs.IFileSystemNode node = await ipfs.FileSystem.AddFileAsync(FilePath, options, token);

//            form.buttonSend.Text = "Send";
            //We want to display a few properties:
            Console.WriteLine("Cid = {0}", node.Id);    // Qma1PbECNH6DsoTps9pmtqTAZQ3s17jzQEgEVQ97X5BDHN
            Console.WriteLine("Size = {0}", node.Size); //20
            Console.WriteLine("Links = {0}", node.Links);
            Console.WriteLine("Directory? = {0}", node.IsDirectory);
            Console.WriteLine("DataBytes = {0}", node.DataBytes);
            Console.WriteLine("DataStream = {0}", node.DataStream);
            //We want to return the hash
            //return text; can't it's async
//            form.richTextBox1.Text = "File on IPFS under the hash:" + node.Id;
            AddCidDCore(node.Id);
        }