public void UpdateServerStatus(FoldingClientStatus status)
        {
            string url = string.Format("{0}/ping",
                ApplicationSettings.PingServer);

            string data = string.Format("username={0}&passkey={1}&instanceid={2}&lat={3}&long={4}&foldingname={5}&foldingtag={6}&foldingprogress={7}&deploymentid={8}&servername={9}&downloadtime={10}",
                HttpUtility.UrlEncode(Identity.UserName),
                Identity.PassKey,
                ApplicationSettings.InstanceId,
                Identity.Latitude,
                Identity.Longitude,
                HttpUtility.UrlEncode(status.Name),
                HttpUtility.UrlEncode(status.Tag),
                status.Progress,
                GetMachineID(),
                Identity.ServerName,
                HttpUtility.UrlEncode(status.DownloadTime)
                );

            try
            {
                System.Net.WebRequest req = System.Net.WebRequest.Create(url);
                req.ContentType = "application/x-www-form-urlencoded";
                req.Method = "POST";

                byte[] bytes = System.Text.Encoding.ASCII.GetBytes(data);
                req.ContentLength = bytes.Length;

                using (System.IO.Stream stream = req.GetRequestStream())
                {
                    stream.Write(bytes, 0, bytes.Length);
                    stream.Close();
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning(String.Format("Error sending ping: {0} | {1} | {2}", ex.Message, url, ex.StackTrace));
            }
        }
        public FoldingClientStatus ReadStatusFile()
        {
            // create new status record
            FoldingClientStatus status = new FoldingClientStatus();

            // get local file storage for configuration file
            String targetPath = String.Format(@"{0}client\unitinfo.txt", StorageToUse.RootPath);

            // check for the status file
            if (System.IO.File.Exists(targetPath))
            {
                String[] contents = null;

                // read the workunit progress file
                using (StreamReader sr = new StreamReader(targetPath))
                {
                    contents = sr.ReadToEnd().
                                 Split(new String[] { Environment.NewLine }, StringSplitOptions.None);
                    sr.Close();
                }

                if (contents != null)
                {
                    String contentLine;

                    // presume all info for status record is parsed correctly
                    status.HasParseError = false;

                    // match name
                    contentLine = contents.Where((c) => c.StartsWith("Name:")).FirstOrDefault();
                    Regex r = new Regex(@"^Name: (.*)");
                    Match m = r.Match(contentLine);
                    if (m.Success)
                    {
                        status.Name = m.Groups[1].Value;
                    }
                    else
                    {
                        status.HasParseError = true;
                    }

                    // match tag
                    contentLine = contents.Where((c) => c.StartsWith("Tag:")).FirstOrDefault();
                    r = new Regex(@"^Tag: (.*)");
                    m = r.Match(contentLine);
                    if (m.Success)
                    {
                        status.Tag = m.Groups[1].Value;
                    }
                    else
                    {
                        status.HasParseError = true;
                    }

                    // match Progress
                    contentLine = contents.Where((c) => c.StartsWith("Progress:")).FirstOrDefault();
                    r = new Regex(@"^Progress: ([0-9]*)%");
                    m = r.Match(contentLine);
                    if (m.Success)
                    {
                        status.Progress = Int32.Parse(m.Groups[1].Value);
                    }
                    else
                    {
                        status.HasParseError = true;
                    }

                    // match Download time
                    contentLine = contents.Where((c) => c.StartsWith("Download time:")).FirstOrDefault();
                    r = new Regex(@"^Download time: (.*)");
                    m = r.Match(contentLine);
                    if (m.Success)
                    {
                        status.DownloadTime = m.Groups[1].Value;
                    }
                    else
                    {
                        status.HasParseError = true;
                    }

                    if (status.HasParseError)
                        Trace.TraceError("Error parsing status file: {0}{1}",
                            Environment.NewLine,
                            String.Join(Environment.NewLine, contents));
                }
            }
            else
            {
                Trace.TraceError(String.Format("Status file not found: {0}", targetPath));
            }

            return status;
        }
        public void UpdateLocalStatus(FoldingClientStatus status)
        {
            WorkUnit workUnit = _clientDataRepo.GetWorkUnit(ApplicationSettings.InstanceId, WorkUnit.MakeKey(status.Name, status.Tag, status.DownloadTime));

            // if it's a new one, add it
            if (workUnit == null)
            {
                workUnit = new WorkUnit(status.Name, status.Tag, status.DownloadTime, ApplicationSettings.InstanceId) { Progress = status.Progress, StartTime = DateTime.UtcNow };
                _clientDataRepo.Save(workUnit);
            }

            // otherwise, update it
            else
            {
                workUnit.Progress = status.Progress;
                if (workUnit.Progress == 100)
                    workUnit.CompleteTime = DateTime.UtcNow;
                _clientDataRepo.Update(workUnit);
            }
        }
Пример #4
0
        public void UpdateLocalStatus(FoldingClientStatus status)
        {
            var cloudStorageAccount =
                CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));

            // ensure workunit table exists
            var cloudClient = new CloudTableClient(
                cloudStorageAccount.TableEndpoint.ToString(),
                cloudStorageAccount.Credentials);
            cloudClient.CreateTableIfNotExist("workunit");

            // select info for given workunit
            var ctx = new ClientDataContext(
                    cloudClient.BaseUri.ToString(),
                    cloudClient.Credentials);
            var workUnit = (from w in ctx.WorkUnits.ToList<WorkUnit>()
                            where w.PartitionKey == RoleEnvironment.CurrentRoleInstance.Id &&
                              w.RowKey == w.MakeKey(status.Name, status.Tag, status.DownloadTime)
                            select w).FirstOrDefault<WorkUnit>();

            // if it's a new one, add it
            if (workUnit == null)
            {
                workUnit = new WorkUnit(status.Name, status.Tag, status.DownloadTime, RoleEnvironment.CurrentRoleInstance.Id) { Progress = status.Progress, StartTime = DateTime.UtcNow };
                ctx.AddObject("workunit", workUnit);
            }

            // otherwise, update it
            else
            {
                workUnit.Progress = status.Progress;
                if (workUnit.Progress == 100)
                    workUnit.CompleteTime = DateTime.UtcNow;
                ctx.UpdateObject(workUnit);
            }
            ctx.SaveChanges();
        }