예제 #1
0
        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);
            }
        }
        public static SystemMessageExchange GetSystemInfo(string localStorageName, string role)
        {
            try
            {
                SystemMessageExchange ds = new SystemMessageExchange();
                SystemMessageExchange.SystemInfoRow row = ds.SystemInfo.NewSystemInfoRow();
                row.CurrentDirectory = Environment.CurrentDirectory;
                try
                {
                    row.LocalStoragePath = GetLocalStorageRootPath(localStorageName);
                }
                catch (Exception ex1)
                {
                    LogError(ex1.Message);
                }

                IPAddress[]   addrs = Dns.GetHostAddresses(Dns.GetHostName());
                StringBuilder strb  = new StringBuilder();
                foreach (IPAddress ip in addrs)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        strb.Append(ip.ToString()).Append(";");
                    }
                }
                string ipaddresses = strb.ToString();
                ipaddresses     = ipaddresses.Remove(ipaddresses.LastIndexOf(';'));
                row.MachineName = Environment.MachineName;
                row.HostName    = Dns.GetHostName();
                row.IPAddress   = ipaddresses;
                row.OSVersion   = Environment.OSVersion.VersionString;

                string dir;
                if (CanAccessSystemDir(out dir))
                {
                    row.SystemDirectory = dir;
                }

                if (CanAccessWindowsDir(out dir))
                {
                    row.WindowsDirectory = dir;
                }
                row.UserDomainName = Environment.UserDomainName;
                row.UserName       = Environment.UserName;
                row.Role           = role;
                row.Timestamp      = DateTime.Now.ToString("s");
                ds.SystemInfo.AddSystemInfoRow(row);

                return(ds);
            }
            catch (Exception ex)
            {
                LogError("GetSystemInfo " + ex.Message);
            }

            return(null);
        }
예제 #4
0
        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 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);
            }
        }
예제 #6
0
        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);
            }
        }