Exemple #1
0
        public static StationDetail GetDetail()
        {
            string baseurl = NetworkHelper.GetBaseURL();

            StationDetail status = new StationDetail
            {
                location      = baseurl,
                diskusage     = new List <DiskUsage>(),
                upnp          = PublicPortMapping.Instance.GetUPnPInfo(),
                computer_name = Environment.MachineName,
                version       = Assembly.GetExecutingAssembly().GetName().Version.ToString()
            };

            MongoDB.Driver.MongoCursor <Driver> drivers = DriverCollection.Instance.FindAll();

            foreach (Driver driver in drivers)
            {
                FileStorage storage = new FileStorage(driver);
                foreach (UserGroup group in driver.groups)
                {
                    status.diskusage.Add(new DiskUsage {
                        group_id = group.group_id,
                        used     = storage.GetUsedSize(),
                        avail    = storage.GetAvailSize()
                    });
                }
            }

            return(status);
        }
Exemple #2
0
        protected override void HandleRequest()
        {
            logger.Debug("GetStatus is called");
            StationDetail res = StatusChecker.GetDetail();

            RespondSuccess(
                new GetStatusResponse
            {
                api_ret_code    = 0,
                api_ret_message = "success",
                status          = 200,
                timestamp       = DateTime.UtcNow,
                station_status  = res
            });
        }
        /// <summary>
        /// Reads station's information from file.
        /// </summary>
        /// <returns>The stations.</returns>
        public static List <StationDetail> readTrainStationFromFile(String fileName)
        {
            const int MANDATORY = 2;
            const int ALL       = 4;


            List <String[]>      listOfStrings  = readFromFile(fileName);
            List <StationDetail> stationDetails = new List <StationDetail>();

            if (listOfStrings == null)
            {
                return(null);
            }
            if (listOfStrings.Count.Equals(0))
            {
                return(stationDetails);
            }

            // loop over all items in list of strings
            foreach (String[] strings in listOfStrings)
            {
                //if there is only 2 items
                if (strings.Length.Equals(MANDATORY))
                {
                    stationDetails.Add(new StationDetail(strings[0], Convert.ToInt32(strings[1])));
                }
                else if (strings.Length.Equals(ALL))
                {
                    StationDetail details = new StationDetail(strings[0], Convert.ToInt32(strings[1]));
                    if (strings[2] != "")
                    {
                        details.MinimalTransferTime = Time.ToTime(Convert.ToInt32(strings[2]));
                    }
                    if (strings[3] != "")
                    {
                        details.Town = strings[3];
                    }
                    stationDetails.Add(details);
                }
            }

            return(stationDetails);
        }
        public void Init()
        {
            List <StationDetail> list  = new List <StationDetail>();
            DirectoryEntry       pools = new DirectoryEntry(string.Format(path, ip));

            foreach (DirectoryEntry item in pools.Children)
            {
                if (item.SchemaClassName == "IIsWebServer")
                {
                    DirectoryEntry poolChild = new DirectoryEntry(string.Format(path + "/" + item.Name + "/ROOT", ip));
                    foreach (DirectoryEntry item1 in poolChild.Children)//程序池中子站点
                    {
                        if (item1.Properties["AppPoolId"].Value.ToString() == poolNmae)
                        {
                            StationDetail StationDetail = new StationDetail();
                            StationDetail.StationName = item.Properties["ServerComment"].Value.ToString();
                            list.Add(StationDetail);
                        }
                    }
                }
            }
            this.dgvStation.DataSource = list;
        }
        /// <summary>
        /// 初始化站点
        /// </summary>
        /// <param name="_ip"></param>
        /// <returns></returns>
        public List <StationDetail> InitStations(string _ip)
        {
            List <StationDetail> list = new List <StationDetail>();

            try
            {
                ServerManager server = ServerManager.OpenRemote(_ip);
                foreach (Site site in server.Sites)
                {
                    StationDetail StationDetail = new StationDetail
                    {
                        StationName = site.Name,
                        Status      = dic[((int)site.State).ToString()],
                        Site        = site
                    };
                    list.Add(StationDetail);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return(list);
        }
Exemple #6
0
        private void SendHeartbeat(Object obj)
        {
            StationDetail detail = GetDetail();

            Model.StationInfo sinfo = Model.StationCollection.Instance.FindOne();
            if (sinfo != null)
            {
                bool   locChange = false;
                string baseurl   = NetworkHelper.GetBaseURL();
                if (baseurl != sinfo.Location)
                {
                    // update location if baseurl changed
                    logger.DebugFormat("station location changed: {0}", baseurl);
                    sinfo.Location = baseurl;
                    locChange      = true;
                }

                try
                {
                    WebClient        agent = new WebClient();
                    Cloud.StationApi api   = new Cloud.StationApi(sinfo.Id, sinfo.SessionToken);
                    if (logon == false || DateTime.Now - sinfo.LastLogOn > TimeSpan.FromDays(1))
                    {
                        logger.Debug("cloud logon start");
                        api.LogOn(agent, detail);
                        logon = true;

                        // update station info in database
                        logger.Debug("update station information");
                        sinfo.LastLogOn = DateTime.Now;
                        Model.StationCollection.Instance.Save(sinfo);
                    }

                    if (locChange)
                    {
                        // update station info in database
                        logger.Debug("update station information");
                        Model.StationCollection.Instance.Save(sinfo);
                    }
                    api.Heartbeat(agent, detail);
                }
                catch (WammerCloudException ex)
                {
                    WebException webex = (WebException)ex.InnerException;
                    if (webex != null)
                    {
                        HttpWebResponse response = (HttpWebResponse)webex.Response;
                        if (response != null)
                        {
                            if (response.StatusCode == HttpStatusCode.Unauthorized)
                            {
                                // station's session token expired, it might be caused by:
                                // 1. server maintenance
                                // 2. driver registered another station
                                // in this situation, client has to re-login/re-register the station
                                functionServer.BlockAuth(true);
                            }
                        }
                    }
                    logger.Warn("cloud send heartbeat error", ex);
                }
                catch (Exception ex)
                {
                    logger.Warn("cloud send heartbeat error", ex);
                }
            }
        }
 private void dgvStation_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     curentStation = (StationDetail)dgvStation.Rows[e.RowIndex].DataBoundItem;
 }