예제 #1
0
        protected void cbStart_Click(object sender, EventArgs e)
        {
            // create/confirm client table exists
            CloudStorageAccount cloudStorageAccount =
                CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));
            CloudTableClient cloudClient = cloudStorageAccount.CreateCloudTableClient();
            cloudClient.CreateTableIfNotExist("client");

            // if table exists
            if (cloudClient.DoesTableExist("client"))
            {
                // create a new client info record to persist to table storage
                ClientInformation clientInfo = new ClientInformation(
                            txtName.Text,
                            PASSKEY,
                            TEAM_NUMBER,
                            Double.Parse(txtLatitudeValue.Value),
                            Double.Parse(txtLongitudeValue.Value),
                            Request.ServerVariables["SERVER_NAME"]);

                // add client info record
                var ctx = new ClientDataContext(
                   cloudStorageAccount.TableEndpoint.ToString(),
                   cloudStorageAccount.Credentials);
                ctx.AddObject("client", clientInfo);
                ctx.SaveChanges();

                // redirect to the status page
                Response.Redirect("/Status.aspx");
            }
        }
예제 #2
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();
        }