private void CallSystemInfoService(string url, SystemMessageExchange ds) { SystemInfoService.SystemInfoClient client = null; BasicHttpBinding bind = new BasicHttpBinding(); try { EndpointAddress endpoint = new EndpointAddress(url); client = new SystemInfoService.SystemInfoClient(bind, endpoint); client.SendSystemInfo(ds); WindowsAzureSystemHelper.LogInfo(String.Format("Sent message to Service URL {0}", url)); } catch (Exception ex) { WindowsAzureSystemHelper.LogError("CallSystemInfoService():" + ex.Message); } finally { if (client != null) { if (client.State == CommunicationState.Faulted) { client.Abort(); } else { client.Close(); } } } }
private void ListMachines() { try { IList <string> messages = WindowsAzureSystemHelper.ReadAllLinesFromLocalStorage( SystemInfo.SYSTEM_INFO_MACHINE_NAMES, SystemInfo.LOCAL_STORAGE_NAME); lbMachines.Items.Clear(); foreach (string message in messages) { lbMachines.Items.Add(message); } string sysInfoPath = Path.Combine(WindowsAzureSystemHelper.GetLocalStorageRootPath(SystemInfo.LOCAL_STORAGE_NAME), SystemInfo.SYS_INFO_CACHE_XML); if (File.Exists(sysInfoPath)) { string sysInfoFileContents = File.ReadAllText(sysInfoPath); if (!string.IsNullOrEmpty(sysInfoFileContents)) { SystemMessageExchange ds = new SystemMessageExchange(); ds.ReadXml(new StringReader(sysInfoFileContents)); GridView1.DataSource = ds.SystemInfo; GridView1.DataBind(); } } } catch (Exception ex) { WindowsAzureSystemHelper.LogError(ex.Message); } }
private void MountSnapshot(string snapshotUri) { string storageAccountName = txtStorageAccountName.Text; string storageAccountKey = txtStorageAccountKey.Text; try { LocalResource resource = WindowsAzureSystemHelper.GetLocalStorageResource(LOCAL_STORAGE_NAME); int cacheSize = int.Parse(txtCacheSize.Text); if (resource.MaximumSizeInMegabytes < cacheSize) { throw new Exception(String.Format("Cache size {0} MB cannot be more than maximum permitted size {1} MB", cacheSize, resource.MaximumSizeInMegabytes)); } bool wasAlreadyMounted; string driveName = WADriveHelper.MountAzureDrive(storageAccountName, storageAccountKey, new Uri(snapshotUri), LocalStoragePath + txtCacheDirName.Text + ".snapshot", int.Parse(txtCacheSize.Text), int.Parse(txtDriveSize.Text), DriveMountOptions.None, out wasAlreadyMounted); lblMsg.Text = String.Format("Mounted Snapshot {0} to Drive {1}", snapshotUri, driveName); ListAllMountedDrives(); } catch (Exception ex) { lblMsg.Text = ex.Message; } }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("WebWorkerExchange_WorkerRole entry point called", "Information"); WindowsAzureSystemHelper.LogInfo("Worker Process entry point called"); ThreadSleepInMillis = WindowsAzureSystemHelper.GetIntConfigurationValue("ThreadSleepTimeInMillis"); while (true) { ExecuteExchange(); Thread.Sleep(ThreadSleepInMillis); WindowsAzureSystemHelper.LogInfo("Working"); } }
public void SendSystemInfo(SystemMessageExchange ds) { if (ds != null && ds.SystemInfo.Rows.Count > 0) { string machineName = ds.SystemInfo[0].MachineName; string machineLocalStoragePath = ds.SystemInfo[0].LocalStoragePath; //Log the message WindowsAzureSystemHelper.LogInfo(machineName + ">" + ds.GetXml()); // WindowsAzureSystemHelper.PingIps(ds.SystemInfo[0].IPAddress); //Add machine names WindowsAzureSystemHelper.WriteLineToLocalStorage(SYSTEM_INFO_MACHINE_NAMES, LOCAL_STORAGE_NAME, machineName, false); //Copy the file to LocalStorage string localStoragePath = WindowsAzureSystemHelper.GetLocalStorageRootPath(LOCAL_STORAGE_NAME); try { string query = String.Format("MachineName = '{0}' AND LocalStoragePath = '{1}'", machineName, machineLocalStoragePath); //string query = String.Format("MachineName = '{0}'", machineName); WindowsAzureSystemHelper.LogInfo("Query = " + query); System.Data.DataRow[] dRows = sysDS.SystemInfo.Select(query); if (dRows != null && dRows.Length > 0) { sysDS.SystemInfo.Rows.Remove(dRows[0]); } sysDS.SystemInfo.Merge(ds.SystemInfo); sysDS.AcceptChanges(); sysDS.WriteXml(Path.Combine(localStoragePath, SYS_INFO_CACHE_XML)); WindowsAzureSystemHelper.LogInfo("SystemInfoCache.xml -- " + sysDS.GetXml()); } catch (Exception ex) { WindowsAzureSystemHelper.LogError("SendSystemInfo():" + ex.Message); } } else { WindowsAzureSystemHelper.LogInfo("SendSystemInfo(): null message received"); } }
private void MountDrive() { string storageAccountName = txtStorageAccountName.Text; string storageAccountKey = txtStorageAccountKey.Text; try { LocalResource resource = WindowsAzureSystemHelper.GetLocalStorageResource(LOCAL_STORAGE_NAME); int cacheSize = int.Parse(txtCacheSize.Text); if (resource.MaximumSizeInMegabytes < cacheSize) { throw new Exception(String.Format("Cache size {0} MB cannot be more than maximum permitted size {1} MB", cacheSize, resource.MaximumSizeInMegabytes)); } bool wasAlreadyMounted; string driveName = WADriveHelper.MountAzureDrive(storageAccountName, storageAccountKey, txtContainerName.Text, txtPageBlobName.Text, LocalStoragePath + txtCacheDirName.Text, int.Parse(txtCacheSize.Text), int.Parse(txtDriveSize.Text), DriveMountOptions.None, out wasAlreadyMounted); lblMsg.Text = String.Format("Mounted Blob {0} to Drive {1}", txtPageBlobName.Text, driveName); if (cbCreateTestFile.Checked) { try { WADriveHelper.WriteTestFile(driveName + System.Guid.NewGuid().ToString("N") + "silverlining-test.txt", "test"); } catch (Exception ey) { lblMsg.Text = "Could not write test file to the drive " + ey.Message; } } ListAllMountedDrives(); FillTree(); } catch (Exception ex) { lblMsg.Text = ex.Message; } }
private void ExecuteExchange() { try { SystemMessageExchange ds = WindowsAzureSystemHelper.GetSystemInfo(SystemInfo.LOCAL_STORAGE_NAME, "Web"); if (ds == null) { WindowsAzureSystemHelper.LogError("ExecuteExchange():SystemMessageExchange DataSet is null"); } else { WindowsAzureSystemHelper.LogInfo(ds.GetXml()); ISystemInfo sys = new SystemInfo(); sys.SendSystemInfo(ds); } } catch (Exception ex) { WindowsAzureSystemHelper.LogError("ExecuteExchange():" + ex.Message); } }
private void ExecuteExchange() { try { SystemMessageExchange ds = WindowsAzureSystemHelper.GetSystemInfo(LOCAL_STORAGE_NAME, "Worker"); if (ds == null) { WindowsAzureSystemHelper.LogError("ExecuteExchange():SystemMessageExchange DataSet is null"); } else { WindowsAzureSystemHelper.LogInfo(ds.GetXml()); string url = WindowsAzureSystemHelper.GetStringConfigurationValue("SystemInfoServiceURL"); CallSystemInfoService(url, ds); } } catch (Exception ex) { WindowsAzureSystemHelper.LogError("ExecuteExchange():" + ex.Message); } }