コード例 #1
0
        /// <summary>
        /// Retrive Performance counter data
        /// </summary>
        /// <param name="counterFullName">Perfomance counter specifier full name</param>
        /// <param name="roleInstanceName">Deployment id</param>
        /// <param name="startPeriod">Start sample date time</param>
        /// <param name="endPeriod">End sample date time</param>
        /// <returns></returns>
        public IEnumerable <PerformanceData> GetPerformanceCounters(String counterFullName, String roleInstanceName, DateTime startPeriod, DateTime endPeriod)
        {
            //create context for WAD table
            WADPerformanceTable context = new WADPerformanceTable(_accountStorage.TableEndpoint.ToString(), _accountStorage.Credentials);

            //query for pefomance counters
            CloudTableQuery <PerformanceData> query = (from row in context.Queryable
                                                       where row.CounterName == counterFullName &&
                                                       row.EventTickCount >= startPeriod.Ticks &&
                                                       row.EventTickCount <= endPeriod.Ticks &&
                                                       row.RoleInstance.Equals(roleInstanceName)
                                                       select row).AsTableServiceQuery();

            List <PerformanceData> selectedData;

            try
            {
                selectedData = query.Execute().ToList();
            }
            catch (Exception exception)
            {
                //TODO: log
                throw;
            }
            return(selectedData);
        }
コード例 #2
0
        public static IEnumerable <ABTestResult> GetResultsByGoal(string goal, string asofdate)
        {
            Dictionary <string, long> impressions = new Dictionary <string, long>();
            Dictionary <string, long> conversions = new Dictionary <string, long>();
            Dictionary <string, long> totalweight = new Dictionary <string, long>();
            Dictionary <string, long> totalviews  = new Dictionary <string, long>();

            ABTestImpressionClient             abtic           = new ABTestImpressionClient();
            CloudTableQuery <ABTestImpression> impressionQuery = abtic.GetAllByGoal(goal, asofdate);

            foreach (var i in impressionQuery.Execute())
            {
                if (impressions.ContainsKey(i.TestID))
                {
                    impressions[i.TestID]++;
                }
                else
                {
                    impressions[i.TestID] = 1;
                }
            }

            ABTestConversionClient             abtcc           = new ABTestConversionClient();
            CloudTableQuery <ABTestConversion> conversionQuery = abtcc.GetAllByGoal(goal, asofdate);

            foreach (var c in conversionQuery.Execute())
            {
                if (conversions.ContainsKey(c.TestID))
                {
                    conversions[c.TestID]++;
                    totalweight[c.TestID] += c.Weight;
                    totalviews[c.TestID]  += c.Views;
                }
                else
                {
                    conversions[c.TestID] = 1;
                    totalweight[c.TestID] = c.Weight;
                    totalviews[c.TestID]  = c.Views;
                }
            }
            List <ABTestResult> results = new List <ABTestResult>();

            foreach (var k in impressions.Keys)
            {
                results.Add(new ABTestResult
                {
                    TestID = k
                    ,
                    UniqueVisitors = impressions.ContainsKey(k) ? impressions[k] : 0
                    ,
                    TotalViews = totalviews.ContainsKey(k) ? totalviews[k] : 0
                    ,
                    ConversionCount = conversions.ContainsKey(k) ? conversions[k] : 0
                    ,
                    ConversionWeightSum = totalweight.ContainsKey(k) ? totalweight[k] : 0
                });
            }

            return(results);
        }
コード例 #3
0
        public string FixDemoSource(string startdate)
        {
            int cnt = 0;

            SkillCowRequestSubmissionClient rsc = new SkillCowRequestSubmissionClient();

            DateTime cursordate = DateTime.ParseExact(startdate, "yyyyMMdd", CultureInfo.InvariantCulture);

            List <SkillCowRequestSubmission> submissions = new List <SkillCowRequestSubmission>();

            while (cursordate < DateTime.UtcNow.AddDays(1))
            {
                CloudTableQuery <SkillCowRequestSubmission> query = rsc.GetAll(cursordate.ToString("yyyyMMdd"));

                foreach (SkillCowRequestSubmission s in query.Execute().Where(x => x.UtmSource == "demo"))
                {
                    submissions.Add(s);
                }

                cursordate = cursordate.AddDays(1);
            }

            foreach (SkillCowRequestSubmission x in submissions)
            {
                x.UtmSource   = "Kiosks";
                x.UtmCampaign = "JerseyGardens";
                x.UtmTerm     = "Station1";
                rsc.Update(x);
            }

            return(cnt.ToString() + " leads fixed");
        }
コード例 #4
0
        public MetricsTransactionsEntity[] GetMetrics(CloudStorageAccount storageAccount, DateTime startDateTimeUTC, DateTime endDateTimeUTC)
        {
            MetricsTransactionsTable table = new MetricsTransactionsTable(storageAccount,
                                                                          storageAccount.Credentials);
            //convert datetimes to partition keys
            String startingPartitionKey = startDateTimeUTC.ToString(StorageResource.TransactionPrimaryKeyTimeFormat);
            String endingPartitionKey   = endDateTimeUTC.ToString(StorageResource.TransactionPrimaryKeyTimeFormat);

            var query = from transactionsEntity in table.Queryable
                        where transactionsEntity.PartitionKey.CompareTo(startingPartitionKey) >= 0 &&
                        transactionsEntity.PartitionKey.CompareTo(endingPartitionKey) <= 0
                        select transactionsEntity;

            CloudTableQuery <MetricsTransactionsEntity> tableServiceQuery = query.AsTableServiceQuery();

            MetricsTransactionsEntity[] metricsTransactionsEntities;

            try
            {
                //execute query
                metricsTransactionsEntities = tableServiceQuery.Execute().ToArray();
            }
            catch (Exception exception)
            {
                //TODO:log
                throw;
            }

            return(metricsTransactionsEntities);
        }
コード例 #5
0
        public List <SkillCowRequestSubmission> GetByUtmSource(DateTime startdate, DateTime enddate, string source)
        {
            List <SkillCowRequestSubmission> allrecords = new List <SkillCowRequestSubmission>();

            DateTime cursordate = startdate;

            while (cursordate <= enddate)
            {
                CloudTableQuery <SkillCowRequestSubmission> query = this.GetAll(cursordate.ToString("yyyyMMdd"));
                allrecords.AddRange(query.Execute().Where(x => x.UtmSource == source).OrderBy(x => x.Timestamp));
                cursordate = cursordate.AddDays(1);
            }

            return(allrecords);
        }
コード例 #6
0
ファイル: Table.cs プロジェクト: jimoneil/Azure-Photo-Mosaics
 public IEnumerable <StatusEntry> GetStatusEntriesForJob(Guid jobId)
 {
     if (_tableClient.DoesTableExist("status"))
     {
         CloudTableQuery <StatusEntry> qry =
             (from s in Context.StatusEntries
              where s.RequestId == jobId
              select s).AsTableServiceQuery <StatusEntry>();
         return(qry.Execute());
     }
     else
     {
         return(null);
     }
 }
コード例 #7
0
ファイル: Table.cs プロジェクト: jimoneil/Azure-Photo-Mosaics
        public IEnumerable <JobEntry> GetJobsForClient(String clientId, ResultContinuation token = null)
        {
            if (_tableClient.DoesTableExist("jobs"))
            {
                CloudTableQuery <JobEntry> qry =
                    (from j in Context.Jobs
                     where j.PartitionKey == clientId
                     select j).AsTableServiceQuery <JobEntry>();

                // this will return ALL jobs for given client - alternative is to use BeginExecuteSegmented and
                // manage pagination via continuation tokens or filter criteria on client side
                return(qry.Execute());
            }
            else
            {
                return(null);
            }
        }
コード例 #8
0
        public static Dictionary <string, RoutingInfo> GetConfigDictionary()
        {
            Dictionary <string, RoutingInfo> config = (Dictionary <string, RoutingInfo>)_configCache.Get(_partitionKey);

            if (config == null)
            {
                new Dictionary <string, RoutingInfo>();
                TableServiceContext           tableContext = GetTableContext();
                CloudTableQuery <RouteEntity> routeQuery   =
                    (from e in tableContext.CreateQuery <RouteEntity>(_tableName)
                     where e.PartitionKey == _partitionKey
                     select e)
                    .AsTableServiceQuery <RouteEntity>();
                IEnumerable <RouteEntity> re = routeQuery.Execute();
                config = re.ToDictionary(r => r.RowKey, v => v.GetRoutingInfo());
                _configCache.Remove(_partitionKey);
                _configCache.Add(_partitionKey, config, DateTimeOffset.Now.AddMinutes(_expireMinutes));
            }
            return(config);
        }
コード例 #9
0
        public List <SkillCowRequestSubmission> GetKioskLeads(DateTime startdate, DateTime enddate)
        {
            List <SkillCowRequestSubmission> allrecords = new List <SkillCowRequestSubmission>();

            DateTime cursordate = startdate;

            while (cursordate <= enddate)
            {
                CloudTableQuery <SkillCowRequestSubmission> query = null;

                query = (from e in TableContext().CreateQuery <SkillCowRequestSubmission>(tableName)
                         where e.PartitionKey == cursordate.ToString("yyyyMMdd") &&
                         e.UtmSource == "Kiosks" &&
                         e.SourceForm == "schoolform"
                         select e).AsTableServiceQuery <SkillCowRequestSubmission>();

                allrecords.AddRange(query.Execute().OrderBy(x => x.Timestamp));
                cursordate = cursordate.AddDays(1);
            }

            return(allrecords);
        }
コード例 #10
0
        /// <summary>
        /// Returns the entity if present from the table service. Should only be called after
        /// checking the entity is not already present in the context.
        /// </summary>
        /// <param name="record">Request record of the entity being sought.</param>
        /// <returns>The entity if present in the table service.</returns>
        private RequestEntity GetEntityFromTable(RequestRecord record)
        {
            // Create query to return all matching entities for this record.
            CloudTableQuery <RequestEntity> query = (from entity
                                                     in _serviceContext.CreateQuery <RequestEntity>(_tableName)
                                                     where entity.PartitionKey == record.PartitionKey && entity.RowKey == record.RowKey
                                                     select entity).AsTableServiceQuery <RequestEntity>();

            // Return the first or default entity found.
            try
            {
                return(query.Execute().FirstOrDefault());
            }
            catch (DataServiceQueryException ex)
            {
                //If an exception occurs checked for a 404 error code meaning the resource was not found.
                if (ex.Response.StatusCode == 404)
                {
                    return(null);
                }
                throw ex;
            }
        }
コード例 #11
0
        public HttpResponse logoff(string location, string agent, string code)
        {
            try
            {
                Response.ContentType = "application/json";

                AgentClient ac = new AgentClient();
                Agent       a  = ac.GetAll().Execute().Where(x => x.LoginName == agent).SingleOrDefault();

                if (a == null)
                {
                    throw new Exception("Invalid agent ID or code");
                }

                if (a.LoginCode == code)
                {
                    DateTime nowTime = EasternTimeConverter.Convert(DateTime.UtcNow);


                    AgentEventClient aec       = new AgentEventClient();
                    AgentEvent       lastEvent = aec.GetAll().Execute().Where(x => x.Agent == agent).OrderByDescending(x => x.EventTime).FirstOrDefault();

                    string hoursworked = "No prior logon.";
                    string production  = "No results.";
                    if (lastEvent.EventType == "logon")
                    {
                        long     elapsedTicks = nowTime.Ticks - lastEvent.EventTime.Ticks;
                        TimeSpan ts           = new TimeSpan(elapsedTicks);
                        hoursworked = ts.Hours.ToString() + "h : " + ts.Minutes + "m logged.";

                        //Count how many leads
                        List <SkillCowRequestSubmission> allrecords = new List <SkillCowRequestSubmission>();

                        DateTime cursordate = lastEvent.EventTime;

                        SkillCowRequestSubmissionClient rsc = new SkillCowRequestSubmissionClient();
                        while (cursordate <= nowTime)
                        {
                            CloudTableQuery <SkillCowRequestSubmission> query = rsc.GetAll(cursordate.ToString("yyyyMMdd"));
                            allrecords.AddRange(query.Execute().Where(x => x.UtmCampaign == location && x.UtmContent == agent).OrderBy(x => x.Timestamp));
                            cursordate = cursordate.AddDays(1);
                        }

                        //tally up
                        int totalschoolleads = 0;
                        int totalindeedjobs  = 0;
                        int totalcourses     = 0;
                        foreach (SkillCowRequestSubmission x in allrecords)
                        {
                            switch (x.SourceForm)
                            {
                            case "schoolform":
                                totalschoolleads++;
                                break;

                            case "indeedjob":
                                totalindeedjobs++;
                                break;

                            case "udemycourse":
                                totalcourses++;
                                break;
                            }
                        }
                        if (totalschoolleads + totalindeedjobs + totalcourses > 0)
                        {
                            production  = "\n";
                            production += totalschoolleads + " school leads\n";
                            production += totalindeedjobs + " indeed jobs\n";
                            production += totalcourses + " udemy courses";
                        }
                    }

                    //Log event
                    aec.AddNewItem(new AgentEvent(agent, "logoff", location));

                    a.CurrentLocation = "";
                    a.CurrentStatus   = "loggedoff";
                    ac.Update(a);

#if DEBUG
#else
                    Telephony t = new Telephony();

                    string message = agent + " logged OFF at " + location + "\n" + hoursworked + "\n" + production;
                    //Send to Rick
                    //t.SendSMS("+19174340659", message);

                    t.SendSMS("+19179578770", message);
#endif

                    Response.Write("{\"result\": \"ok\", \"logonname\": \"" + a.LoginName + "\"}");
                    Response.End();
                }
                else
                {
                    throw new Exception("Invalid agent ID or code");
                }
            }
            catch (Exception ex)
            {
                Response.ContentType = "application/json";
                Response.Write(DefaultErrorResponse(ex.Message));
                Response.End();
            }

            return(null);
        }