Ejemplo n.º 1
0
        //evento che viene richiamato ogni qualvolta scade il timer
        //Effettua una chiamata al servizio KPeople. La prima volta che
        //viene richiamato effettua un add della custom column. Tutte le volte
        //successive effettua semplicemente un update dei valori della colonna.
        private void myTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            using (SPWeb spWeb = property.Feature.Parent as SPWeb)
            {
                if (spWeb.Fields.ContainsField(columnName))
                {
                    updateExistColumn(property, spWeb);
                }
                else
                {
                    string choiceFieldName01 = spWeb.Fields.Add(columnName, SPFieldType.Choice, true);
                    choiceField = (SPFieldChoice)spWeb.Fields.GetFieldByInternalName(choiceFieldName01);
                    try
                    {
                        MetadataService.ProcessMetadataService metadataService = new MetadataService.ProcessMetadataService();
                        User user = null;
                        ProcessMetadataSet retrivedAvailableMetadataSetXml = metadataService.getMetadataProcessV1(user);
                        metadataValues = parserXml(retrivedAvailableMetadataSetXml);

                        for (int i = 0; i < metadataValues.Count; i++)
                        {
                            choiceField.Choices.Add(metadataValues[i]);

                        }
                        choiceField.Group = columnGroup;
                        choiceField.Update();
                        spWeb.Dispose();

                    }
                    catch (System.Exception ex)
                    {
                        sSource = "Kpeople Sharepoint";
                        sLog = "Application";
                        sEvent = ex.Message;

                        if (!EventLog.SourceExists(sSource))
                            EventLog.CreateEventSource(sSource, sLog);

                        EventLog.WriteEntry(sSource, sEvent);
                        EventLog.WriteEntry(sSource, sEvent,
                            EventLogEntryType.Error, 234);

                    }

                }
            }
        }
Ejemplo n.º 2
0
        //@param properties oggetto di tipo SPFeatureReceiverProperties
        //@param spWeb oggetto di tipo SPWeb
        //Effettua la connessione al servizio KPeople, scarica quindi i metadati
        //ed effettua un update dei valori della custom column.
        private void updateExistColumn(SPFeatureReceiverProperties properties, SPWeb spWeb)
        {
            bool found = false;
            int indexMetadato = 0;
            int indexFieldColumn = 0;
            choiceField = (SPFieldChoice)spWeb.Fields.GetFieldByInternalName(columnName);
            try
            {
                MetadataService.ProcessMetadataService metadataService = new MetadataService.ProcessMetadataService();
                User user = null;
                ProcessMetadataSet retrivedAvailableMetadataSetXml = metadataService.getMetadataProcessV1(user);
                metadataValues = parserXml(retrivedAvailableMetadataSetXml);

                for (int i = 0; i < metadataValues.Count; i++)
                {
                    for (int j = 0; j < choiceField.Choices.Count; j++)
                    {
                        if (metadataValues[i] == choiceField.Choices[j])
                        {
                            found = true;
                            indexMetadato = i;
                            indexFieldColumn = j;
                        }
                    }
                    if (!found)
                    {
                        choiceField.Choices.Add(metadataValues[i]);
                    }
                    else
                    {
                        choiceField.Choices[indexFieldColumn] = metadataValues[indexMetadato];
                    }
                    found = false;
                }
                choiceField.Update();
                updateAllLists(spWeb, metadataValues);
            }
            catch (System.Exception ex)
            {

                sSource = "Kpeople Sharepoint";
                sLog = "Application";
                sEvent = ex.Message;

                if (!EventLog.SourceExists(sSource))
                    EventLog.CreateEventSource(sSource, sLog);

                EventLog.WriteEntry(sSource, sEvent);
                EventLog.WriteEntry(sSource, sEvent,
                    EventLogEntryType.Error, 234);

            }
        }