示例#1
0
        public ActionResult DisableAutoTagging(string id)
        {
            LogHelper.Log("Entering DisableAutoTagging");
            try
            {
                var          spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
                AppWebHelper hlp       = new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
                using (var ctx = spContext.CreateUserClientContextForSPHost())
                {
                    string[] ids = id.Split(new char[] { '_' });
                    LogHelper.Log("Inside DisableAutoTagging");
                    if (hlp.DisableTaggingOnListField(ids[1], ids[0]) == 0) //Only delete the RER if no more fields are enabled.
                    {
                        List TargetList = ctx.Web.Lists.GetById(new Guid(ids[0]));
                        ctx.Load(TargetList.EventReceivers);
                        ctx.Load(TargetList);
                        ctx.ExecuteQuery();
                        LogHelper.Log("Before EnableDisableTagging");
                        ConfigurationHelper.EnableDisableTagging(ctx, TargetList, false, hlp);
                        LogHelper.Log("After EnableDisableTagging");
                    }

                    return(PartialView("ListFields", GetModel(ctx, new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string))));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
                throw;
            }
        }
        public ActionResult Upload(HttpPostedFileBase file)
        {
            LogHelper.Log("in upload");
            try
            {
                if (file != null && file.ContentLength > 0)
                {
                    LogHelper.Log("in file");
                    using (StreamReader sr = new StreamReader(file.InputStream))
                    {
                        LogHelper.Log("in StreamReader");

                        LogHelper.Log("in spContext " + HttpContext.Request.Form[Constants.SPAppWebUrl]);
                        LogHelper.Log("in spContext " + HttpContext.Request.QueryString[Constants.SPAppWebUrl]);
                        AppWebHelper hlp = new AppWebHelper(
                            HttpContext.Request.Form[Constants.SPAppWebUrl] as string);
                        hlp.UploadEmptyWords(sr.ReadToEnd());
                    }
                }
                LogHelper.Log("appweb:" + HttpContext.Request.QueryString["SPAppWebUrl"]);
                return(RedirectToAction("Index", "EmptyWords",
                                        new
                {
                    SPHostUrl = HttpContext.Request.Form["SPHostUrl"],
                    SPAppWebUrl = HttpContext.Request.Form["SPAppWebUrl"]
                }));
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
                throw;
            }
        }
示例#3
0
        public ActionResult EnableAutoTagging(string id)
        {
            LogHelper.Log("Entering tEnableAutoTagging");

            try
            {
                var          spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
                AppWebHelper hlp       = new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
                using (var ctx = spContext.CreateUserClientContextForSPHost())
                {
                    if (hlp.EnableTaggingOnListField(id) == 1) //we register only one RER per list.
                    {
                        string[] ids        = id.Split(new char[] { '_' });
                        List     TargetList = ctx.Web.Lists.GetById(new Guid(ids[0]));
                        ctx.Load(TargetList);
                        ctx.Load(TargetList.EventReceivers);
                        ctx.ExecuteQuery();
                        LogHelper.Log("Adding Event Receivers");
                        ConfigurationHelper.EnableDisableTagging(ctx, TargetList, true, hlp);
                    }
                    return(PartialView("ListFields", GetModel(ctx, hlp)));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
                throw;
            }
        }
示例#4
0
        public void HandleAutoTaggingFieldDeleted(SPRemoteEventProperties properties)
        {
            string TargetFieldId = GetFieldId(properties.ListEventProperties.FieldXml);

            LogHelper.Log("Field " + TargetFieldId + " was deleted, cleaning config list");
            Uri    webUri      = new Uri(properties.ListEventProperties.WebUrl);
            string realm       = TokenHelper.GetRealmFromTargetUrl(webUri);
            string accessToken = TokenHelper.GetAppOnlyAccessToken(
                TokenHelper.SharePointPrincipal, webUri.Authority, realm).AccessToken;

            using (var ctx = TokenHelper.GetClientContextWithAccessToken(properties.ListEventProperties.WebUrl, accessToken))
            {
                if (ctx != null)
                {
                    ctx.Load(ctx.Web.AllProperties);
                    ctx.ExecuteQuery();
                    AppWebHelper hlp = new AppWebHelper(properties.ListEventProperties.WebUrl, false);
                    if (hlp.DisableTaggingOnListField(TargetFieldId, properties.ListEventProperties.ListId.ToString()) == 0) //Only delete the RER if no more fields are enabled.
                    {
                        List TargetList = ctx.Web.Lists.GetById(properties.ListEventProperties.ListId);
                        ctx.Load(TargetList.EventReceivers);
                        ctx.Load(TargetList);
                        ctx.ExecuteQuery();
                        LogHelper.Log("Before EnableDisableTagging");
                        ConfigurationHelper.EnableDisableTagging(ctx, TargetList, false, hlp);
                        LogHelper.Log("After EnableDisableTagging");
                    }
                }
            }
        }
示例#5
0
        // GET: Administrators
        public ActionResult Index()
        {
            AppWebHelper         hlp   = new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
            List <Administrator> model = hlp.GetAdministrators();

            return(View(model));
        }
        public ActionResult Index()
        {
            AppWebHelper         hlp   = new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
            List <GlobalSetting> model = hlp.GetGlobalSettings();

            return(View(model));
        }
示例#7
0
        List <SPTaggableList> GetModel(ClientContext ctx, AppWebHelper hlp)
        {
            List <SPTaggableList> model = null;

            try
            {
                model = new List <SPTaggableList>();
                LogHelper.Log("Inside getmodel");
                if (ctx != null)
                {
                    ListCollection lists = ctx.Web.Lists;

                    ctx.Load(lists, ListQuery => ListQuery.Include(
                                 l => l.Id, l => l.Title, l => l.BaseType,
                                 l => l.Fields.Where(
                                     f => f.TypeAsString == "TaxonomyFieldTypeMulti" || f.TypeAsString == "TaxonomyFieldType")
                                 ));

                    ctx.ExecuteQuery();

                    foreach (List list in lists)
                    {
                        if (list.BaseType == BaseType.DocumentLibrary && list.Fields.Count > 0)
                        {
                            SPTaggableList NewList = new SPTaggableList();
                            NewList.Title        = list.Title;
                            NewList.Id           = list.Id.ToString();
                            NewList.Disabled     = (hlp.ListsInfo.ContainsKey(NewList.Id) && hlp.ListsInfo[NewList.Id].ChildCount > 0) ? "Disabled" : string.Empty;
                            NewList.Asynchronous = (hlp.ListsInfo.ContainsKey(NewList.Id)) ? hlp.ListsInfo[NewList.Id].Asynchronous : true;

                            List <SPTaggableField> ListFields = new List <SPTaggableField>();
                            foreach (Field field in list.Fields)
                            {
                                TaxonomyField TaxField  = field as TaxonomyField;
                                string        key       = string.Concat(NewList.Id, "_", TaxField.Id.ToString());
                                var           isEnabled = hlp.CurrentlyEnabledFields.Where(c => c["Title"].Equals(key)).SingleOrDefault();
                                ListFields.Add(new SPTaggableField
                                {
                                    Id             = TaxField.Id.ToString(),
                                    Title          = TaxField.Title,
                                    TaggingEnabled = (isEnabled != null) ? true : false
                                });
                            }
                            NewList.Fields = ListFields;
                            model.Add(NewList);
                        }
                    }
                }

                return(model);
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace);
                throw;
            }
        }
示例#8
0
 // GET: Administrators/Delete/5
 public ActionResult Delete(int id)
 {
     try
     {
         AppWebHelper hlp = new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
         return(View(hlp.GetAdministrator(id)));
     }
     catch (Exception ex)
     {
         LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
         throw;
     }
 }
示例#9
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         AppWebHelper hlp = new AppWebHelper(
             HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
         hlp.AddAdministrator(collection["LoginName"] as string);
         return(View("Index", hlp.GetAdministrators()));
     }
     catch (Exception ex)
     {
         LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
         throw;
     }
 }
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         AppWebHelper hlp = new AppWebHelper(
             HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
         hlp.CreateEmptyWord(collection);
         return(View("Index", hlp.GetEmptyWords(collection["word"].Substring(0, 1))));
     }
     catch (Exception ex)
     {
         LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
         throw;
     }
 }
        public ActionResult ByLetter(string letter)
        {
            List <EmptyWord> model = null;

            try
            {
                AppWebHelper hlp = new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
                model = hlp.GetEmptyWords(letter);
                return(PartialView("words", model));
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
                throw;
            }
        }
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         AppWebHelper hlp = new AppWebHelper(
             HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
         hlp.UpdateGlobalSetting(id, collection["key"], collection["value"]);
         AutoTaggingHelper.GlobalConfigNeedsRefresh = true;
         return(View("Index", hlp.GetGlobalSettings()));
     }
     catch (Exception ex)
     {
         LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
         throw;
     }
 }
示例#13
0
 public ActionResult SetSync(bool sync, string id)
 {
     try
     {
         var          spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
         AppWebHelper hlp       = new AppWebHelper(HttpContext.Request.QueryString[Constants.SPAppWebUrl] as string);
         hlp.SetSync(id, sync);
         LogHelper.Log("sync:" + sync + " id:" + id);
         SPEnabledList m = new SPEnabledList();
         m.Disabled = (hlp.ListsInfo.ContainsKey(id) && hlp.ListsInfo[id].ChildCount > 0) ? true : false;
         return(PartialView("SyncStatus", m));
     }
     catch (Exception ex)
     {
         LogHelper.Log(ex.Message + ex.StackTrace);
         throw;
     }
 }
示例#14
0
 /// <summary>
 /// The RER are a little buggy. Depending on the event triggered, using this:
 /// TokenHelper.CreateAppEventClientContext(properties, true) returns a null appweb although the
 /// app web exists...Therefore, as I know the name of my App and since the AppWeb's url corresponds to it
 /// I assume that the default appweb location is https://hostweb/appweb. This isn't valid when the App is deployed
 /// trough the AppCatalog. That's why I record the URL of the AppCatalog in case the App gets installed in the
 /// AppCatalog since this info isn't available from CSOM.
 /// </summary>
 /// <param name="properties"></param>
 void AppInstalled(SPRemoteEventProperties properties)
 {
     LogHelper.Log("The application was installed on " + properties.AppEventProperties.HostWebFullUrl);
     using (ClientContext ctx = TokenHelper.CreateAppEventClientContext(properties, false))
     {
         ctx.Load(ctx.Web);
         ctx.Load(ctx.Web.CurrentUser);
         ctx.ExecuteQuery();
         if (ctx.Web.WebTemplate == Constants.AppCatalogTemplate)
         {
             LogHelper.Log("Writing app catalog url", LogSeverity.Error);
             using (StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath("~/App_Data/AppCataLog.xml")))
             {
                 sw.Write(ctx.Web.Url);
             }
         }
         AppWebHelper hlp = new AppWebHelper(properties.AppEventProperties.AppWebFullUrl.AbsoluteUri, true);
         hlp.AddAdministrator(ctx.Web.CurrentUser.LoginName);
     }
 }