コード例 #1
0
ファイル: Program.cs プロジェクト: neilunadkat/usage
 private static void Convert(dynamic obj, AppInfo appInfo)
 {
     obj.application_id = appInfo.ApplicationId ;
     obj.application_name = appInfo.ApplicationName ;
     obj.account_name = appInfo.AccountName ;
     obj.account_id = appInfo.AccountId;
     obj.email = appInfo.Email ;
     obj.username = appInfo.Username ;
     obj.totalapicalls = appInfo.TotalApiCalls ;
     obj.totalarticleservicecalls = appInfo.TotalArticleServiceSalls ;
     obj.totalconnectionservicecalls = appInfo.TotalConnectionServiceCalls ;
     obj.totaluserservicecalls = appInfo.TotalUserServiceCalls ;
     obj.totalpushservicecalls = appInfo.TotalPushServiceCalls ;
     obj.totalsearchservicecalls = appInfo.TotalSearchServiceCalls ;
     obj.totalhttpdeletecalls = appInfo.TotalHttpDeleteCalls ;
     obj.totalhttpgetcalls = appInfo.TotalHttpGetCalls ;
     obj.totalhttppostcalls = appInfo.TotalHttpPostCalls ;
     obj.totalhttpputcalls = appInfo.TotalHttpPutCalls ;
     obj.sumofdurationofdeletecalls = appInfo.SumOfDurationOfDeleteCalls ;
     obj.sumofdurationofpostcalls = appInfo.SumOfDurationOfPostCalls ;
     obj.sumofdurationofgetcalls = appInfo.SumOfDurationOfGetCalls ;
     obj.sumofdurationofputcalls = appInfo.SumOfDurationPfPutCalls ;
     obj.day = DataSource.DayFormat(appInfo.Day) ;
     obj.totalfileservicecalls = appInfo.TotalFileServiceCalls;
     obj.sandbox_deploymentid = appInfo.Sandbox_DeploymentId;
     obj.live_deploymentid = appInfo.Live_DeploymentId;
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: neilunadkat/usage
        private async Task<string> CreateAppArticle(AppInfo appInfo)
        {
            dynamic obj = new Article("appdayusage");
            Convert(obj,appInfo);
            await obj.SaveAsync();
            var created = obj as Article;
            return created.Id;

        }
コード例 #3
0
ファイル: Program.cs プロジェクト: neilunadkat/usage
 private async Task CreateAppMonthlyUsage(string month, AppInfo appInfo)
 {
         if (this._appMonthlyArticleIds.ContainsKey(GetAppMonthId(appInfo.ApplicationId, month)) == false)
         {
             this._appMonthlyArticleIds[GetAppMonthId(appInfo.ApplicationId, month)] = "0";
             var query = BooleanOperator.And(new[]
             {
                 Query.Property("application_id").IsEqualTo(appInfo.ApplicationId),
                 Query.Property("month").IsEqualTo(month)
             })
                                          .AsString()
                   ;
             var appMonthly = await Articles.FindAllAsync("appmonthlyusage", query);
             if (appMonthly.Count == 0)
             {
                 dynamic obj = new Article("appmonthlyusage");
                 obj.application_id = appInfo.ApplicationId;
                 obj.application_name = appInfo.ApplicationName;
                 obj.account_name = appInfo.AccountName;
                 obj.email = appInfo.Email;
                 obj.application_name = appInfo.ApplicationName;
                 obj.month = month;
                 obj.sandbox_deploymentid = appInfo.Sandbox_DeploymentId;
                 obj.live_deploymentid = appInfo.Live_DeploymentId;
                 obj.account_id = appInfo.AccountId;
                 await obj.SaveAsync();
                 var created = obj as Article;
                 if (string.IsNullOrEmpty(created.Id) == false)
                 {
                     this._appMonthlyArticleIds[GetAppMonthId(appInfo.ApplicationId, month)] = created.Id;
                 }
             }
             else 
             {
                 this._appMonthlyArticleIds[GetAppMonthId(appInfo.ApplicationId, month)] = appMonthly[0].Id;
             }
         }
         else if (this._appMonthlyArticleIds[GetAppMonthId(appInfo.ApplicationId, month)] == "0") 
         {
             while (this._appMonthlyArticleIds[GetAppMonthId(appInfo.ApplicationId, month)] == "0") 
             {
                 Thread.Sleep(50);
             }
         }
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: neilunadkat/usage
        public AppInfo GetAppInfo(long appId, string tableName, DateTime day)
        {
            var nextDay = day.AddDays(1);
            AppInfo appInfo = new AppInfo();
            var query = string.Format("call spGetAppUsageInfo('{0}','{1}',{2},'{3}');", DayFormat(day), DayFormat(nextDay), appId, tableName);
            var dataSet = this.GetAppInfoQuery(query);
            appInfo.TotalApiCalls = (long)dataSet.Tables[0].Rows[0]["count"];

            if (appInfo.TotalApiCalls > 0)
            {
                appInfo.Day = day;
                var serviceTable = dataSet.Tables.Count > 1 ? dataSet.Tables[1] : null;
                var httpMethodTable = dataSet.Tables.Count > 2 ? dataSet.Tables[2] : null;
                var accountInfo = dataSet.Tables.Count > 3 ? dataSet.Tables[3] : null;
                var deploymentInfo = dataSet.Tables.Count > 4 ? dataSet.Tables[4] : null;

                if (accountInfo != null && accountInfo.Rows.Count > 0)
                {
                    var accountRow = accountInfo.Rows[0];
                    appInfo.ApplicationId = appId.ToString();
                    appInfo.ApplicationName = (string)accountRow["appName"];
                    var username = (string)accountRow["userid"];
                    var splitUsername = username.Split(new[] { "_!..._" }, StringSplitOptions.None);
                    appInfo.AccountName = splitUsername[0];
                    appInfo.Email = splitUsername[1];
                    appInfo.Username = username;
                    appInfo.AccountId = (long)accountRow["accId"];

                    if (serviceTable != null)
                    {
                        for (int i = 0; i < serviceTable.Rows.Count; i++)
                        {
                            var row = serviceTable.Rows[i];
                            if (row["service"] != DBNull.Value)
                            {
                                switch (((string)row["service"]).ToLower())
                                {
                                    case "articleservice":

                                        appInfo.TotalArticleServiceSalls = (long)row["count"];
                                        break;
                                    case "connectionservice":
                                        appInfo.TotalConnectionServiceCalls = (long)row["count"];
                                        break;
                                    case "userservice":
                                        appInfo.TotalUserServiceCalls = (long)row["count"];
                                        break;
                                    case "pushservice":
                                        appInfo.TotalPushServiceCalls = (long)row["count"];
                                        break;
                                    case "search":
                                        appInfo.TotalSearchServiceCalls = (long)row["count"];
                                        break;
                                    case "fileservice":
                                        appInfo.TotalFileServiceCalls = (long)row["count"];
                                        break;
                                }
                            }
                        }
                    }

                    if (httpMethodTable != null)
                    {
                        for (int i = 0; i < httpMethodTable.Rows.Count; i++)
                        {
                            var row = httpMethodTable.Rows[i];
                            if (row["httpmethod"] != DBNull.Value)
                            {
                                switch (((string)row["httpmethod"]).ToLower())
                                {
                                    case "get":
                                        appInfo.SumOfDurationOfGetCalls = (decimal)row["sum"];
                                        appInfo.TotalHttpGetCalls = (long)row["count"];
                                        break;
                                    case "put":
                                        appInfo.SumOfDurationPfPutCalls = (decimal)row["sum"];
                                        appInfo.TotalHttpPutCalls = (long)row["count"];
                                        break;
                                    case "post":
                                        appInfo.SumOfDurationOfPostCalls = (decimal)row["sum"];
                                        appInfo.TotalHttpPostCalls = (long)row["count"];
                                        break;
                                    case "delete":
                                        appInfo.SumOfDurationOfDeleteCalls = (decimal)row["sum"];
                                        appInfo.TotalHttpDeleteCalls = (long)row["count"];
                                        break;
                                }
                            }
                        }
                    }

                    if (deploymentInfo != null)
                    {
                        for (int i = 0; i < deploymentInfo.Rows.Count; i++)
                        {
                            var row = deploymentInfo.Rows[i];
                            if (row["deploymentName"] != DBNull.Value)
                            {
                                var name = (string)row["deploymentName"];
                                var did = ((long)row["deploymentId"]).ToString();
                                if (name.ToLower().Contains("sandbox"))
                                {
                                    appInfo.Sandbox_DeploymentId = did;
                                }
                                else
                                    appInfo.Live_DeploymentId = did;
                            }
                        }
                    }
                    return appInfo;
                }

            }
            return null;
        }