public static void SetTenantData(string language)
        {
            try
            {
                using (var backupClient = new BackupServiceClient())
                {
                    int tenantID = CoreContext.TenantManager.GetCurrentTenant().TenantId;
                    BackupResult result = null;
                    do
                    {
                        if (result == null)
                        {
                            result = backupClient.RestorePortal(tenantID, language);
                        }
                        else
                        {
                            result = backupClient.GetRestoreStatus(tenantID);
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(5));

                    } while (!result.Completed);
                    //Thread.Sleep(TimeSpan.FromSeconds(15)); // wait to invalidate users cache...
                }

                var apiServer = new ApiServer();
                apiServer.CallApiMethod(SetupInfo.WebApiBaseUrl + "/crm/settings", "PUT");
            }
            catch (Exception error)
            {
                LogManager.GetLogger("ASC.Web").Error("Can't set default data", error);
            }
        }
示例#2
0
        private String GetProjectTitle(object folderID)
        {
            if (!ApiServer.Available)
            {
                return string.Empty;
            }

            var cacheKey = "documents/folders/" + folderID.ToString();

            var projectTitle = Convert.ToString(_cache.Get(cacheKey));

            if (!String.IsNullOrEmpty(projectTitle)) return projectTitle;

            var bunchObjectID = GetBunchObjectID(folderID);

            if (String.IsNullOrEmpty(bunchObjectID))
                throw new Exception("Bunch Object id is null for " + folderID);

            if (!bunchObjectID.StartsWith("projects/project/"))
                return String.Empty;

            var bunchObjectIDParts = bunchObjectID.Split('/');

            if (bunchObjectIDParts.Length < 3)
                throw new Exception("Bunch object id is not supported format");

            var projectID = Convert.ToInt32(bunchObjectIDParts[bunchObjectIDParts.Length - 1]);

            if (HttpContext.Current == null)
                return string.Empty;

            var apiServer = new ApiServer();

            var apiUrl = String.Format("{0}project/{1}.json", SetupInfo.WebApiBaseUrl, projectID);

            var responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiServer.GetApiResponse(apiUrl, "GET"))))["response"];

            if (responseApi != null && responseApi.HasValues)
            {
                projectTitle = Global.ReplaceInvalidCharsAndTruncate(responseApi["title"].Value<String>());
            }
            else
            {
                return string.Empty;
            }
            if (!String.IsNullOrEmpty(projectTitle))
            {
                _cache.Remove(cacheKey);
                _cache.Insert(cacheKey, projectTitle, null, Cache.NoAbsoluteExpiration,
                              TimeSpan.FromMinutes(15));
            }
            return projectTitle;
        }