Пример #1
0
        public void CheckVersion()
        {
            if (currentVersion < NewerVersion)
            {
                DownloadFTP dftp = new DownloadFTP(NewerVersion);

                //this.Hide();
            }
        }
Пример #2
0
        public override void Run()
        {
            var storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient();
            CloudBlobClient otherBlobStorage = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobStorage.GetContainerReference("program");
            CloudBlobContainer downloadContainer = otherBlobStorage.GetContainerReference("downloadcontainer");

            CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();
            CloudQueue queue = queueStorage.GetQueueReference("programrunner");

            Trace.TraceInformation("Creating container and queue...");

            // If the Start() method throws an exception, the role recycles.
            // If this sample is run locally and the development storage tool has not been started, this
            // can cause a number of exceptions to be thrown because roles are restarted repeatedly.
            // Lets try to create the queue and the container and check whether the storage services are running
            // at all.
            bool containerAndQueueCreated = false;
            while (!containerAndQueueCreated)
            {
                try
                {
                    container.CreateIfNotExist();
                    downloadContainer.CreateIfNotExist();

                    var permissions = container.GetPermissions();
                    var downloadPerminssions = downloadContainer.GetPermissions();

                    permissions.PublicAccess = BlobContainerPublicAccessType.Container;
                    downloadPerminssions.PublicAccess = BlobContainerPublicAccessType.Container;

                    container.SetPermissions(permissions);
                    downloadContainer.SetPermissions(downloadPerminssions);

                    permissions = container.GetPermissions();
                    downloadPerminssions = downloadContainer.GetPermissions();

                    queue.CreateIfNotExist();

                    containerAndQueueCreated = true;
                }
                catch (StorageClientException e)
                {
                    if (e.ErrorCode == StorageErrorCode.TransportError)
                    {
                        Trace.TraceError(string.Format("Connect failure! The most likely reason is that the local " +
                            "Development Storage tool is not running or your storage account configuration is incorrect. " +
                            "Message: '{0}'", e.Message));
                        System.Threading.Thread.Sleep(5000);
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            Trace.TraceInformation("Listening for queue messages...");

            // Now that the queue and the container have been created in the above initialization process, get messages
            // from the queue and process them individually.
            while (true)
            {
                try
                {
                    CloudQueueMessage msg = queue.GetMessage();
                    if (msg != null)
                    {
                        string queue_msg = msg.AsString;
                        string exe_name = queue_msg.Substring(0, queue_msg.IndexOf('+'));
                        string hdf_name = queue_msg.Substring(queue_msg.IndexOf('+')+1);

                        Trace.TraceInformation(string.Format("Dequeued '{0}'", queue_msg));

                        CloudBlockBlob exe_content = container.GetBlockBlobReference(exe_name);
                        CloudBlockBlob hdf_content = container.GetBlockBlobReference(hdf_name);

                        CloudBlockBlob output_content = container.GetBlockBlobReference("output.txt");
                        CloudBlockBlob upload_download_content = downloadContainer.GetBlockBlobReference("downloadedFile.jpg");

                        string exe_path = Path.Combine(RoleEnvironment.GetLocalResource("LocalStorage1").RootPath, exe_name);
                        string hdf_path = Path.Combine(RoleEnvironment.GetLocalResource("LocalStorage1").RootPath, hdf_name);

                        //exe_content.DownloadToFile(exe_path);
                        //hdf_content.DownloadToFile(hdf_path);

                        #region run process
                        try
                        {
                            Program HDFParser = new Program();
                            DownloadFTP ftp = new DownloadFTP();

                            //StreamReader stream = HDFParser.parseHDF(exe_path, hdf_path);
                            //String line = stream.ReadToEnd();

                            upload_download_content.UploadByteArray(ftp.getDataFromFTP());

                            //output_content.UploadText(line);
                        }
                        catch (Exception ex)
                        {
                            throw;
                            //Note: Exception.Message returns a detailed message that describes the current exception.
                            //For security reasons, we do not recommend that you return Exception.Message to end users in
                            //production environments. It would be better to return a generic error message.
                        }
                        #endregion

                        Trace.TraceInformation(string.Format("Done with '{0}'", queue_msg));

                        queue.DeleteMessage(msg);
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                catch (Exception e)
                {
                    // Explicitly catch all exceptions of type StorageException here because we should be able to
                    // recover from these exceptions next time the queue message, which caused this exception,
                    // becomes visible again.

                    System.Threading.Thread.Sleep(5000);
                    Trace.TraceError(string.Format("Exception when processing queue item. Message: '{0}'", e.Message));
                }
            }
        }