Example #1
0
        public void ExtractEmailsAsync()
        {
            while (!isTerminating)
            {
                // Check if the folder exists and contains atleast 1 text file
                if (TotalFiles(Scrapers.Pastebin.SaveLocation) == 0)
                {
                    return;
                }

                // Create a worker and a call back
                MergeWorkerDelegate worker            = new MergeWorkerDelegate(ExtractEmailWorker);
                AsyncCallback       completedCallback = new AsyncCallback(MergeCompletedCallBack);

                // Lock the operation and fire up the worker
                lock (_sync)
                {
                    if (isMergeRunning)
                    {
                        throw new InvalidOperationException("Merge is already running, please wait till current merge completes");
                    }

                    AsyncOperation async = AsyncOperationManager.CreateOperation(null);
                    worker.BeginInvoke(completedCallback, async);
                    isMergeRunning = true;
                }
                break;
            }
        }
Example #2
0
        public void MergeFilesAsync(int byteSize, string location)
        {
            while (!isTerminating)
            {
                // Check if the folder exists and contains atleast 1 text file
                if (TotalFiles(location) == 0)
                {
                    return;
                }

                // Generate a file named after the first object in files
                try
                {
                    string path = string.Format(@"{0}\Merge{1}bytes", location, byteSize);

                    for (int i = 0; i < 1000; i++)
                    {
                        if (i == 0)
                        {
                            if (File.Exists(path + ".txt"))
                            {
                                continue;
                            }
                            else
                            {
                                path = path + ".txt";
                                FileStream f = File.Create(path);
                                f.Close();
                                break;
                            }
                        }

                        if (File.Exists(path + i + ".txt"))
                        {
                            continue;
                        }
                        else
                        {
                            path = path + i + ".txt";
                            FileStream f = File.Create(path);
                            f.Close();
                            break;
                        }
                    }
                    destinationPath = location;
                    destinationFile = path;
                }
                catch (Exception e) { Console.WriteLine("Failed to create a merge file with reason: " + e); return; }

                // Create a worker and a call back
                MergeWorkerDelegate worker            = new MergeWorkerDelegate(MergeWorker);
                AsyncCallback       completedCallback = new AsyncCallback(MergeCompletedCallBack);

                // Lock the operation and fire up the worker
                lock (_sync)
                {
                    if (isMergeRunning)
                    {
                        throw new InvalidOperationException("Merge is already running, please wait till current merge completes");
                    }

                    AsyncOperation async = AsyncOperationManager.CreateOperation(null);
                    worker.BeginInvoke(byteSize, completedCallback, async);
                    isMergeRunning = true;
                }
                break;
            }
        }