示例#1
0
        /// <summary>
        /// Makes an asynchronous batch request to the Facebook server.
        /// </summary>
        /// <param name="batchParameters">
        /// List of batch parameters.
        /// </param>
        /// <param name="userState">
        /// The user state.
        /// </param>
        /// <param name="cancellationToken">
        /// The cancellation token.
        /// </param>
        /// <returns>
        /// The json result task.
        /// </returns>
        public virtual Task <object> BatchTaskAsync(FacebookBatchParameter[] batchParameters, object userState, CancellationToken cancellationToken

                                                    , System.IProgress <FacebookUploadProgressChangedEventArgs> uploadProgress

                                                    )
        {
            return(BatchTaskAsync(batchParameters, userState, null, cancellationToken

                                  , uploadProgress

                                  ));
        }
示例#2
0
        public static async System.Threading.Tasks.Task DownloadAsync(this System.Net.Http.HttpClient client
                                                                      , string requestUri
                                                                      , System.IO.Stream destination
                                                                      , System.IProgress <float> progress = null
                                                                      , System.Threading.CancellationToken cancellationToken = default)
        {
            // Get the http headers first to examine the content length
            using (System.Net.Http.HttpResponseMessage response = await client.GetAsync(
                       requestUri,
                       System.Net.Http.HttpCompletionOption.ResponseHeadersRead)
                   )
            {
                long?contentLength = response.Content.Headers.ContentLength;

                using (System.IO.Stream download = await response.Content.ReadAsStreamAsync())
                {
                    // Ignore progress reporting when no progress reporter was
                    // passed or when the content length is unknown
                    if (progress == null || !contentLength.HasValue)
                    {
                        await download.CopyToAsync(destination);

                        return;
                    }

                    // Convert absolute progress (bytes downloaded) into relative progress (0% - 100%)
                    System.Progress <long> relativeProgress = new System.Progress <long>(
                        delegate(long totalBytes)
                    {
                        if (contentLength.Value == 0)
                        {
                            progress.Report(99.99999f);
                            return;
                        }

                        float reportedValue = (float)totalBytes * 100.0f / contentLength.Value;
                        if (reportedValue == 100.0f)
                        {
                            reportedValue = 99.99999f;
                        }

                        progress.Report(reportedValue);
                    }
                        );

                    // Use extension method to report progress while downloading
                    await download.CopyToAsync(destination, 81920, relativeProgress, cancellationToken);

                    progress.Report(100.0f);
                } // End Using download
            }     // End Using response
        }         // End Task DownloadAsync
示例#3
0
        /// <summary>
        /// Makes an asynchronous batch request to the Facebook server.
        /// </summary>
        /// <param name="batchParameters">
        /// List of batch parameters.
        /// </param>
        /// <param name="userState">
        /// The user state.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <param name="cancellationToken">
        /// The cancellation token.
        /// </param>
        /// <returns>
        /// The json result task.
        /// </returns>
        public virtual Task <object> BatchTaskAsync(FacebookBatchParameter[] batchParameters, object userState, object parameters, CancellationToken cancellationToken

                                                    , System.IProgress <FacebookUploadProgressChangedEventArgs> uploadProgress

                                                    )
        {
            var actualParameter = PrepareBatchRequest(batchParameters, parameters);

            return(PostTaskAsync(null, actualParameter, userState, cancellationToken

                                 , uploadProgress

                                 ));
        }
示例#4
0
        public static async System.Threading.Tasks.Task CopyToAsync(this System.IO.Stream source
                                                                    , System.IO.Stream destination
                                                                    , int bufferSize
                                                                    , System.IProgress <long> progress = null
                                                                    , System.Threading.CancellationToken cancellationToken = default)
        {
            if (source == null)
            {
                throw new System.ArgumentNullException(nameof(source));
            }
            if (!source.CanRead)
            {
                throw new System.ArgumentException("Has to be readable", nameof(source));
            }
            if (destination == null)
            {
                throw new System.ArgumentNullException(nameof(destination));
            }
            if (!destination.CanWrite)
            {
                throw new System.ArgumentException("Has to be writable", nameof(destination));
            }
            if (bufferSize < 0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(bufferSize));
            }

            byte[] buffer         = new byte[bufferSize];
            long   totalBytesRead = 0;
            int    bytesRead;

            while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
            {
                await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false);

                totalBytesRead += bytesRead;
                progress?.Report(totalBytesRead);
            } // Whend
        }     // End Task CopyToAsync
示例#5
0
 /// <summary>
 /// Converts a regular .NET progress handler to a NanoByte.Common progress handler.
 /// </summary>
 public static IProgress <T> ToNanoByte <T>(System.IProgress <T> progress)
 {
     return(new Progress <T>(progress.Report));
 }
示例#6
0
 public OperationTaskCompletionCallback(System.IProgress <bool>?progress, CancellationToken cancellationToken) :
     base(progress, cancellationToken)
 {
 }
示例#7
0
 public TaskCompletionCallback(System.IProgress <bool>?progress, CancellationToken cancellationToken)
 {
     progress_          = progress;
     _cancellationToken = cancellationToken;
 }
示例#8
0
        public void Calculate(bool isEnableStop, int minRerolls, int maxRerolls, System.IProgress <int> p)
        {
            Result.Clear();

            if (m_Mode == Mode.Cuda35)
            {
                // 分割bit数
                int partitionBit = CudaLoopPartition;

                // 探索範囲
                int searchLower = 0;
                int searchUpper = (1 << partitionBit) - 1;

                // 途中経過
                int progress    = 0;
                int progressMax = (1 << partitionBit) * (maxRerolls - minRerolls + 1);

                p?.Report(0);

                // 計算前のCUDA初期化
                CudaCalcInitialize();

                for (int i = minRerolls; i <= maxRerolls; ++i)
                {
                    // C++ライブラリ側の事前計算
                    PrepareCuda(i);

                    for (int ivs = searchLower; ivs <= searchUpper; ++ivs)
                    {
                        SearchCuda((uint)ivs, partitionBit);
                        int resultCount = GetResultCount();
                        if (resultCount > 0)
                        {
                            for (int a = 0; a < resultCount; ++a)
                            {
                                Result.Add(GetResult(a));
                                if (isEnableStop)
                                {
                                    break;
                                }
                            }
                            if (Result.Count > 0 && isEnableStop)
                            {
                                break;
                            }
                        }
                        ++progress;
                        p?.Report(progress * 1000 / progressMax);
                    }

                    if (Result.Count > 0 && isEnableStop)
                    {
                        break;
                    }
                }

                // 計算が終わったのでCUDA終了
                CudaCalcFinalize();

                // 結果を加工([-3]にする)
                for (int i = 0; i < Result.Count; ++i)
                {
                    for (int a = 0; a < 3; ++a)
                    {
                        Result[i] = Result[i] + 0x7d5d4e8add6295a5ul;
                    }
                }
            }
            else if (m_Mode == Mode.Star12)
            {
                // 探索範囲
                int searchLower = 0;
                int searchUpper = 0xFFFFFFF;

                // 途中経過
                int chunkPart = 16;

                int progress   = 0;
                int chunkSize  = searchUpper / chunkPart;
                int chunkMax   = chunkPart * (maxRerolls - minRerolls + 1);
                int chunkCount = 1;

                p?.Report(0);

                for (int i = minRerolls; i <= maxRerolls; ++i)
                {
                    int chunkOffset = (i - minRerolls) * chunkPart;

                    progress   = 0;
                    chunkCount = 0;

                    // C++ライブラリ側の事前計算
                    Prepare(i);

                    // 並列探索
                    if (isEnableStop)
                    {
                        // 中断あり
                        Parallel.For(searchLower, searchUpper, (ivs, state) =>
                        {
                            ulong result = Search((ulong)ivs);
                            if (result != 0)
                            {
                                Result.Add(result);
                                state.Stop();
                            }
                            Interlocked.Increment(ref progress);
                            if (progress >= chunkCount * chunkSize)
                            {
                                lock (lockObj)
                                {
                                    if (progress >= chunkCount * chunkSize)
                                    {
                                        p?.Report((chunkCount + chunkOffset) * 1000 / chunkMax);
                                        ++chunkCount;
                                    }
                                }
                            }
                        });
                        if (Result.Count > 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        // 中断なし
                        Parallel.For(searchLower, searchUpper, (ivs) =>
                        {
                            ulong result = Search((ulong)ivs);
                            if (result != 0)
                            {
                                Result.Add(result);
                            }
                            Interlocked.Increment(ref progress);
                            if (progress >= chunkCount * chunkSize)
                            {
                                lock (lockObj)
                                {
                                    if (progress >= chunkCount * chunkSize)
                                    {
                                        p?.Report((chunkCount + chunkOffset) * 1000 / chunkMax);
                                        ++chunkCount;
                                    }
                                }
                            }
                        });
                    }
                }
            }
            else if (m_Mode == Mode.Star35_5 || m_Mode == Mode.Star35_6)
            {
                // 探索範囲
                int searchLower = 0;
                int searchUpper = (m_Mode == Mode.Star35_5 ? 0x1FFFFFF : 0x3FFFFFFF);

                // 途中経過
                int chunkPart = 32;

                int progress   = 0;
                int chunkSize  = searchUpper / chunkPart;
                int chunkMax   = chunkPart * (maxRerolls - minRerolls + 1);
                int chunkCount = 1;

                p?.Report(0);

                for (int i = minRerolls; i <= maxRerolls; ++i)
                {
                    int chunkOffset = (i - minRerolls) * chunkPart;

                    progress   = 0;
                    chunkCount = 0;

                    // C++ライブラリ側の事前計算
                    PrepareSix(i);

                    // 並列探索
                    if (isEnableStop)
                    {
                        // 中断あり
                        Parallel.For(searchLower, searchUpper, (ivs, state) =>
                        {
                            ulong result = SearchSix((ulong)ivs);
                            if (result != 0)
                            {
                                Result.Add(result);
                                state.Stop();
                            }
                            Interlocked.Increment(ref progress);
                            if (progress >= chunkCount * chunkSize)
                            {
                                lock (lockObj)
                                {
                                    if (progress >= chunkCount * chunkSize)
                                    {
                                        p?.Report((chunkCount + chunkOffset) * 1000 / chunkMax);
                                        ++chunkCount;
                                    }
                                }
                            }
                        });
                        if (Result.Count > 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        // 中断なし
                        Parallel.For(searchLower, searchUpper, (ivs) =>
                        {
                            ulong result = SearchSix((ulong)ivs);
                            if (result != 0)
                            {
                                Result.Add(result);
                            }
                            Interlocked.Increment(ref progress);
                            if (progress >= chunkCount * chunkSize)
                            {
                                lock (lockObj)
                                {
                                    if (progress >= chunkCount * chunkSize)
                                    {
                                        p?.Report((chunkCount + chunkOffset) * 1000 / chunkMax);
                                        ++chunkCount;
                                    }
                                }
                            }
                        });
                    }
                }

                // 結果を加工([-3]にする)
                for (int i = 0; i < Result.Count; ++i)
                {
                    for (int a = 0; a < 3; ++a)
                    {
                        Result[i] = Result[i] + 0x7d5d4e8add6295a5ul;
                    }
                }
            }
        }
        protected override async System.Threading.Tasks.Task InitializeAsync(System.Threading.CancellationToken cancellationToken, System.IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            InitializeSettings();
        }
示例#10
0
 public static System.Threading.Tasks.Task <TResult> AsTask <TResult, TProgress>(this global::Windows.Foundation.IAsyncOperationWithProgress <TResult, TProgress> source, System.Threading.CancellationToken cancellationToken, System.IProgress <TProgress> progress)
 {
     throw null;
 }
示例#11
0
 public static System.Threading.Tasks.Task AsTask <TProgress>(this global::Windows.Foundation.IAsyncActionWithProgress <TProgress> source, System.IProgress <TProgress> progress)
 {
     throw null;
 }
 public FunctionReader(ILogger logger, System.IProgress <FunctionProgress> progress)
 {
     Logger   = logger;
     Progress = progress;
 }
示例#13
0
        public void Calculate(bool isEnableStop, int minRerolls, int maxRerolls, System.IProgress <int> p)
        {
            Result.Clear();

            if (m_Mode == Mode.Star12)
            {
                // 探索範囲
                int searchLower = 0;
                int searchUpper = 0xFFFFFFF;

                // 途中経過
                int chunkPart = 16;

                int progress   = 0;
                int chunkSize  = searchUpper / chunkPart;
                int chunkMax   = chunkPart * (maxRerolls - minRerolls + 1);
                int chunkCount = 1;

                p.Report(0);

                for (int i = minRerolls; i <= maxRerolls; ++i)
                {
                    int chunkOffset = (i - minRerolls) * chunkPart;

                    progress   = 0;
                    chunkCount = 0;

                    // C++ライブラリ側の事前計算
                    Prepare(i);

                    // 並列探索
                    if (isEnableStop)
                    {
                        // 中断あり
                        Parallel.For(searchLower, searchUpper, (ivs, state) =>
                        {
                            ulong result = Search((ulong)ivs);
                            if (result != 0)
                            {
                                Result.Add(result);
                                state.Stop();
                            }
                            Interlocked.Increment(ref progress);
                            if (progress >= chunkCount * chunkSize)
                            {
                                lock (lockObj)
                                {
                                    if (progress >= chunkCount * chunkSize)
                                    {
                                        p.Report((chunkCount + chunkOffset) * 1000 / chunkMax);
                                        ++chunkCount;
                                    }
                                }
                            }
                        });
                        if (Result.Count > 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        // 中断なし
                        Parallel.For(searchLower, searchUpper, (ivs) =>
                        {
                            ulong result = Search((ulong)ivs);
                            if (result != 0)
                            {
                                Result.Add(result);
                            }
                            Interlocked.Increment(ref progress);
                            if (progress >= chunkCount * chunkSize)
                            {
                                lock (lockObj)
                                {
                                    if (progress >= chunkCount * chunkSize)
                                    {
                                        p.Report((chunkCount + chunkOffset) * 1000 / chunkMax);
                                        ++chunkCount;
                                    }
                                }
                            }
                        });
                    }
                }
            }
            else if (m_Mode == Mode.Star35_5 || m_Mode == Mode.Star35_6)
            {
                // 探索範囲
                int searchLower = 0;
                int searchUpper = (m_Mode == Mode.Star35_5 ? 0x1FFFFFF : 0x3FFFFFFF);

                // 途中経過
                int chunkPart = 32;

                int progress   = 0;
                int chunkSize  = searchUpper / chunkPart;
                int chunkMax   = chunkPart * (maxRerolls - minRerolls + 1);
                int chunkCount = 1;

                p.Report(0);

                for (int i = minRerolls; i <= maxRerolls; ++i)
                {
                    int chunkOffset = (i - minRerolls) * chunkPart;

                    progress   = 0;
                    chunkCount = 0;

                    // C++ライブラリ側の事前計算
                    PrepareSix(i);

                    // 並列探索
                    if (isEnableStop)
                    {
                        // 中断あり
                        Parallel.For(searchLower, searchUpper, (ivs, state) => {
                            ulong result = SearchSix((ulong)ivs);
                            if (result != 0)
                            {
                                Result.Add(result);
                                state.Stop();
                            }
                            Interlocked.Increment(ref progress);
                            if (progress >= chunkCount * chunkSize)
                            {
                                lock (lockObj)
                                {
                                    if (progress >= chunkCount * chunkSize)
                                    {
                                        p.Report((chunkCount + chunkOffset) * 1000 / chunkMax);
                                        ++chunkCount;
                                    }
                                }
                            }
                        });
                        if (Result.Count > 0)
                        {
                            break;
                        }
                    }
                    else
                    {
                        // 中断なし
                        Parallel.For(searchLower, searchUpper, (ivs) => {
                            ulong result = SearchSix((ulong)ivs);
                            if (result != 0)
                            {
                                Result.Add(result);
                            }
                            Interlocked.Increment(ref progress);
                            if (progress >= chunkCount * chunkSize)
                            {
                                lock (lockObj)
                                {
                                    if (progress >= chunkCount * chunkSize)
                                    {
                                        p.Report((chunkCount + chunkOffset) * 1000 / chunkMax);
                                        ++chunkCount;
                                    }
                                }
                            }
                        });
                    }
                }

                // 結果を加工([-3]にする)
                for (int i = 0; i < Result.Count; ++i)
                {
                    for (int a = 0; a < 3; ++a)
                    {
                        Result[i] = Result[i] + 0x7d5d4e8add6295a5ul;
                    }
                }
            }
        }