コード例 #1
0
        public List <FileListModel> GetAmazonS3List(int planId, string directory, PlatformInsertModel planData)
        {
            dynamic  platformDetail = JObject.Parse(planData.JsonData);
            AmazonS3 s3             = new AmazonS3();

            return(s3.GetDirectoryList(directory, platformDetail.apiAccessKey.ToString() + "-" + platformDetail.apiSecretKey.ToString() + "-" + platformDetail.region.ToString()));
        }
コード例 #2
0
        public void UpdatePlan(PlatformInsertModel model, int organizationId)
        {
            string sql = "update public.\"Plan\" set \"Name\" = @name , \"Type\" = @type , \"PlanData\" = @planData " +
                         "where \"Id\" = @id and \"OrganizationId\" = @organizationId ";
            object data = new { name = model.Name, type = model.Type, organizationId = organizationId, planData = model.JsonData, id = model.Id };

            _connection.Execute(sql, data);
        }
コード例 #3
0
        public List <FileListModel> GetGoogleDriveList(int planId, string directory, PlatformInsertModel planData)
        {
            PlatformGoogle gg = new PlatformGoogle(_env.ContentRootPath);



            dynamic platformDetail = JObject.Parse(planData.JsonData);
            string  token          = "";

            if (WebUtilities.ConvertDatabaseDateTime(platformDetail.tokenExpire.ToString()) > DateTime.Now)
            {
                token = platformDetail.accessToken;
            }
            else
            {
                var trp = gg.AuthCodeToAccessToken("", "", platformDetail.refreshToken.ToString());

                dynamic dData = null;
                if (!String.IsNullOrEmpty(planData.JsonData))
                {
                    dData = JObject.Parse(planData.JsonData);
                }

                List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >();
                list.Add(new KeyValuePair <string, string>("accountId", planId.ToString()));
                list.Add(new KeyValuePair <string, string>("accessToken", trp.AccessToken));
                if (!String.IsNullOrEmpty(trp.RefreshToken))
                {
                    list.Add(new KeyValuePair <string, string>("refreshToken", trp.RefreshToken));
                }
                else if (dData != null)
                {
                    list.Add(new KeyValuePair <string, string>("refreshToken", dData.refreshToken.ToString()));
                }
                list.Add(new KeyValuePair <string, string>("tokenExpire", DateTime.Now.AddSeconds(trp.ExpiresInSeconds).ToString()));
                string jsonData = "";
                foreach (var item in list)
                {
                    string header = item.Key;
                    string data   = item.Value;
                    jsonData += "\"" + header + "\": \"" + data + "\",";
                }
                jsonData = jsonData.Substring(0, jsonData.Length - 1);
                jsonData = "{ " + jsonData + " }";

                planData.JsonData = jsonData;
                operations.Plan.UpdatePlan(planData, GetOrganizationId());

                token = trp.AccessToken;
            }
            GoogleDriveAuthInformation inf = new GoogleDriveAuthInformation()
            {
                access_token = token
            };

            return(gg.GetDirectoryList(directory, inf.access_token));
        }
コード例 #4
0
        public int InsertPlatform(PlatformInsertModel model)
        {
            string sql = "insert into public.\"Plan\"(\"Name\",\"Type\",\"OrganizationId\",\"PlanData\",\"ActiveStatus\") " +
                         "values(@Name, @Type, @OrganizationId, @PlanData,1)   RETURNING \"Id\" ";
            object data = new { Name           = model.Name,
                                Type           = model.Type,
                                OrganizationId = model.OrganizationId,
                                PlanData       = model.JsonData,
                                ActiveStatus   = ActiveStatus.Active };

            return(_connection.ExecuteScalar <int>(sql, data));
        }
コード例 #5
0
        public IActionResult _GoogleDrive(string id)
        {
            var drive = operations.Plan.GetPlanById(GetOrganizationId(), WebUtilities.DecryptId(id, GetUserName(), GetOrganizationId()));

            drive.HashedPlatformId = WebUtility.UrlEncode(id);
            if (drive != null)
            {
                return(View(drive));
            }
            else
            {
                PlatformInsertModel model = new PlatformInsertModel();
                return(View(model));
            }
        }
コード例 #6
0
        public IActionResult New(string id)
        {
            int realId = WebUtilities.DecryptId(id, GetUserName(), GetOrganizationId());

            if (realId > 0)
            {
                PlatformInsertModel model = operations.Plan.GetPlanById(GetOrganizationId(), realId);
                model.HashedPlatformId = WebUtilities.EncryptId(model.Id, GetUserName(), GetOrganizationId());
                return(View(model));
                //return View();
            }
            else
            {
                PlatformInsertModel model = new PlatformInsertModel();
                return(View(model));
            }
        }
コード例 #7
0
        private TokenResponse ResetGoogleDriveToken(PlatformInsertModel planData, int planId, DpOperations db, int organizationId)
        {
            PlatformGoogle pg    = new PlatformGoogle(_env.ContentRootPath);
            dynamic        dData = null;

            if (!String.IsNullOrEmpty(planData.JsonData))
            {
                dData = JObject.Parse(planData.JsonData);
            }

            TokenResponse trp = pg.AuthCodeToAccessToken("", "", dData.refreshToken.ToString());

            List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("accountId", planId.ToString()));
            list.Add(new KeyValuePair <string, string>("accessToken", trp.AccessToken));
            if (!String.IsNullOrEmpty(trp.RefreshToken))
            {
                list.Add(new KeyValuePair <string, string>("refreshToken", trp.RefreshToken));
            }
            else if (dData != null)
            {
                list.Add(new KeyValuePair <string, string>("refreshToken", dData.refreshToken.ToString()));
            }
            list.Add(new KeyValuePair <string, string>("tokenExpire", DateTime.Now.AddSeconds(trp.ExpiresInSeconds.Value).ToString()));
            string jsonData = "";

            foreach (var item in list)
            {
                string header = item.Key;
                string data   = item.Value;
                jsonData += "\"" + header + "\": \"" + data + "\",";
            }
            jsonData = jsonData.Substring(0, jsonData.Length - 1);
            jsonData = "{ " + jsonData + " }";

            planData.JsonData = jsonData;
            db.Plan.UpdatePlan(planData, organizationId);

            return(trp);
        }
コード例 #8
0
        private BackupJobModelGoogle ReturnGoogleJobModel(PlatformInsertModel plan, DevicePlanInsertModel model, DpOperations db, string googleApiCode)
        {
            dynamic  platformDetail = JObject.Parse(plan.JsonData);
            DateTime?expireToken    = null;

            if (!String.IsNullOrEmpty(platformDetail.tokenExpire.ToString()))
            {
                expireToken = Convert.ToDateTime(platformDetail.tokenExpire.ToString());
            }

            BackupJobModelGoogle returnModel = new BackupJobModelGoogle();

            if (expireToken.HasValue && expireToken.Value > DateTime.Now)

            {
                returnModel.PlanType           = plan.Type;
                returnModel.LocalDirectory     = "'" + model.LocalSource + "'";
                returnModel.RemoteDirectory    = "'" + model.RemoteSource + "'";
                returnModel.DevicePlanId       = "'" + model.Id.ToString() + "'";
                returnModel.GoogleAccessToken  = "'" + platformDetail.accessToken + "'";
                returnModel.GoogleApiCode      = "'" + googleApiCode + "'";
                returnModel.GoogleTokenExpired = "'" + platformDetail.tokenExpire.ToString() + "'";
            }
            else
            {
                //PlatformGoogle gg = new PlatformGoogle();
                TokenResponse tr = ResetGoogleDriveToken(plan, plan.Id, db, plan.OrganizationId);

                returnModel.PlanType           = plan.Type;
                returnModel.LocalDirectory     = "'" + model.LocalSource + "'";
                returnModel.RemoteDirectory    = "'" + model.RemoteSource + "'";
                returnModel.DevicePlanId       = "'" + model.Id.ToString() + "'";
                returnModel.GoogleAccessToken  = "'" + platformDetail.accessToken + "'";
                returnModel.GoogleApiCode      = "'" + googleApiCode + "'";
                returnModel.GoogleTokenExpired = "'" + platformDetail.tokenExpire.ToString() + "'";
            }
            return(returnModel);
        }
コード例 #9
0
        public IActionResult New(PlatformInsertModel model)
        {
            model.CloseModal = false;
            if (String.IsNullOrEmpty(model.Name))
            {
                TempData["Notification"] = WebUtilities.InsertNotification("Platform ismi boş geçilemez.");
                return(View(model));
            }
            if (model.Type == Database.Enum.PlanType.Seçiniz)
            {
                TempData["Notification"] = WebUtilities.InsertNotification("Platform tipini seçiniz.");
                return(View(model));
            }
            string jsonData = "";

            foreach (var item in Request.Form)
            {
                if (item.Key.StartsWith("Form:") == true)
                {
                    string header = item.Key.Replace("Form:", "");
                    string data   = item.Value;
                    jsonData += "\"" + header + "\": \"" + data + "\",";
                }
            }
            if ((!String.IsNullOrEmpty(model.HashedPlatformId) && model.Type == Database.Enum.PlanType.GoogleDrive) || model.Type != Database.Enum.PlanType.GoogleDrive)
            {
                jsonData = jsonData.Substring(0, jsonData.Length - 1);
                jsonData = "{ " + jsonData + " }";

                model.JsonData = jsonData;
            }
            model.OrganizationId = GetOrganizationId();

            if (String.IsNullOrEmpty(model.HashedPlatformId))
            {
                model.OrganizationId = GetOrganizationId();



                int returnValue = operations.Plan.InsertPlatform(model);

                if (returnValue > 0)
                {
                    model.HashedPlatformId   = WebUtilities.EncryptId(returnValue, GetUserName(), GetOrganizationId());
                    TempData["Notification"] = WebUtilities.InsertNotification("Cihaz başarılı bir şekilde eklenmiştir.");
                    model.CloseModal         = true;
                    return(View(model));
                }
                else
                {
                    TempData["Notification"] = WebUtilities.InsertNotification("Ekleme sırasında bir hata oluştu lütfen sistem yöneticisine başvurunuz.");
                    model.CloseModal         = false;
                    return(View(model));
                }
            }
            else
            {
                int realId = WebUtilities.DecryptId(WebUtility.UrlDecode(model.HashedPlatformId), GetUserName(), GetOrganizationId());
                if (realId > 0)
                {
                    model.CloseModal = true;
                    model.Id         = realId;
                    operations.Plan.UpdatePlan(model, GetOrganizationId());
                    return(View(model));
                }
                else
                {
                    TempData["Notification"] = WebUtilities.InsertNotification("Hatalı işlem lütfen pencereyi kapatıp tekrar deneyiniz.");
                    model.CloseModal         = false;
                    return(View(model));
                }
            }
        }