Пример #1
0
        public void HandleAutoTaggingItemAdded(SPRemoteEventProperties properties)
        {
            string webUrl = properties.ItemEventProperties.WebUrl;
            Uri    webUri = new Uri(webUrl);

            using (var ctx = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (ctx != null)
                {
                    ListItem DocumentItem = null;

                    string FileContent = FileHelper.GetFileContent(
                        ctx, properties.ItemEventProperties.ListId, properties.ItemEventProperties.ListItemId, out DocumentItem);
                    if (FileContent != null)
                    {
                        LogHelper.Log("filee content is not null and document item is " + (DocumentItem == null));
                        AutoTaggingHelper.SetTaxonomyFields(
                            ctx, DocumentItem,
                            FileContent.Replace("\u00a0", "\u0020"),
                            properties.ItemEventProperties.ListId.ToString(), webUrl);
                    }
                    else
                    {
                        LogHelper.Log("The parsing did not return any character");
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Used to Handle the ItemAdding Event
 /// </summary>
 /// <param name="properties"></param>
 /// <param name="result"></param>
 public void HandleAutoTaggingItemAdding(SPRemoteEventProperties properties, SPRemoteEventResult result)
 {
     using (ClientContext ctx = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
     {
         if (ctx != null)
         {
             var itemProperties   = properties.ItemEventProperties;
             var _userLoginName   = properties.ItemEventProperties.UserLoginName;
             var _afterProperites = itemProperties.AfterProperties;
             if (!_afterProperites.ContainsKey(ScenarioHandler.FLD_CLASSIFICATION_INTERNAL_NAME))
             {
                 string _classficationToSet = ProfileHelper.GetProfilePropertyFor(ctx, _userLoginName, Constants.UPA_CLASSIFICATION_PROPERTY);
                 if (!string.IsNullOrEmpty(_classficationToSet))
                 {
                     var _formatTaxonomy = AutoTaggingHelper.GetTaxonomyFormat(ctx, _classficationToSet);
                     result.ChangedItemProperties.Add(ScenarioHandler.FLD_CLASSIFICATION_INTERNAL_NAME, _formatTaxonomy);
                 }
             }
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Used to handle the ItemAdded event.
        /// </summary>
        /// <param name="properties"></param>
        public void HandleAutoTaggingItemAdded(SPRemoteEventProperties properties)
        {
            using (ClientContext ctx = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (ctx != null)
                {
                    string _userLoginName = properties.ItemEventProperties.UserLoginName;
                    List   _library       = ctx.Web.Lists.GetById(properties.ItemEventProperties.ListId);
                    var    _itemToUpdate  = _library.GetItemById(properties.ItemEventProperties.ListItemId);
                    ctx.Load(_itemToUpdate);
                    ctx.ExecuteQuery();

                    Hashtable _model = new Hashtable();
                    string    _classficationToSet = ProfileHelper.GetProfilePropertyFor(ctx, _userLoginName, Constants.UPA_CLASSIFICATION_PROPERTY);
                    if (!string.IsNullOrEmpty(_classficationToSet))
                    {
                        _model.Add(ScenarioHandler.FLD_CLASSIFICATION_INTERNAL_NAME, _classficationToSet);
                        AutoTaggingHelper.SetTaxonomyField(ctx, _itemToUpdate, _model);
                    }
                }
            }
        }
        public ActionResult Index()
        {
            try
            {
                DocumentInformation model = new DocumentInformation();
                model.Tokens = new List <string>();
                var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

                using (var ctx = spContext.CreateUserClientContextForSPHost())
                {
                    LogHelper.Log("ctx is null " + (ctx == null));
                    ListItem DocumentItem = null;
                    string   FileContent  = FileHelper.GetFileContent(
                        ctx,
                        new Guid(HttpContext.Request.QueryString["SPListId"]),
                        Convert.ToInt32(HttpContext.Request.QueryString["SPListItemId"]),
                        out DocumentItem);

                    Dictionary <string, int> tokens = AutoTaggingHelper.Tokenize(FileContent);
                    var SortedTokens = tokens.OrderByDescending(x => x.Value);

                    foreach (var token in SortedTokens)
                    {
                        model.Tokens.Add(string.Concat(token.Key, " (", token.Value, " ) | "));
                    }
                    System.Text.StringBuilder locations     = new System.Text.StringBuilder();
                    System.Text.StringBuilder organizations = new System.Text.StringBuilder();
                    System.Text.StringBuilder persons       = new System.Text.StringBuilder();
                    Dictionary <string, int>  entities      = NlpHelper.GetNamedEntititesForText(FileContent, false);
                    LogHelper.Log("entities : " + entities.Count);
                    foreach (KeyValuePair <string, int> entity in entities)
                    {
                        switch (entity.Value)
                        {
                        case 1:
                            //location
                            locations.AppendFormat("{0} - ", entity.Key);
                            break;

                        case 2:
                            //person
                            persons.AppendFormat("{0} - ", entity.Key);
                            break;

                        case 3:
                            //org
                            organizations.AppendFormat("{0} - ", entity.Key);
                            break;
                        }
                    }
                    model.Locations     = locations.ToString();
                    model.Persons       = persons.ToString();
                    model.Organizations = organizations.ToString();
                }
                return(View(model));
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
                throw;
            }
        }