Exemple #1
0
        public GetImportEntriesResults GetImportEntries(GetImportEntriesRunStep importRunStep)
        {
            _lastRunTimeStamp = importRunStep.CustomData;
            GetImportEntriesResults importReturnInfo = new GetImportEntriesResults();
            List <CSEntryChange>    csentries        = new List <CSEntryChange>();

            if (!_skipPeople)
            {
                foreach (JObject person in _personDiscoveryList)
                {
                    CSEntryChange csentryPerson = CSEntryChange.Create();
                    csentryPerson.ObjectType             = CS_OBJECTTYPE_PERSON;
                    csentryPerson.ObjectModificationType = ObjectModificationType.Add;
                    foreach (KeyValuePair <string, JToken> item in person)
                    {
                        if (item.Key.ToLower().Equals(ANCHOR))
                        {
                            string itemName  = string.Format("{0}_{1}", CS_OBJECTTYPE_PERSON, ANCHOR);
                            string itemValue = string.Format("{0}_{1}", CS_OBJECTTYPE_PERSON, item.Value.ToString());
                            csentryPerson.AnchorAttributes.Add(AnchorAttribute.Create(itemName, itemValue));
                        }
                        else if (item.Key.ToLower().Equals("known_for") && item.Value.GetType().Name.Equals("JArray"))
                        {
                            if (item.Value.HasValues)
                            {
                                List <object> knowFor = new List <object>();
                                foreach (var movieObject in item.Value)
                                {
                                    MovieDiscoveryJsonTypes.Result movie = new MovieDiscoveryJsonTypes.Result();
                                    foreach (JToken itemValue in movieObject.Children())
                                    {
                                        string movieAnchor = string.Empty;
                                        if (((JProperty)itemValue).Name.Equals("id"))
                                        {
                                            movieAnchor = string.Format("{0}_{1}", CS_OBJECTTYPE_MOVIE, ((JProperty)itemValue).Value);
                                            knowFor.Add(movieAnchor);
                                            movie.id = ((int)((JProperty)itemValue).Value);
                                        }
                                        else if (((JProperty)itemValue).Name.Equals("genre_ids") ||
                                                 ((JProperty)itemValue).Name.Equals("origin_country"))
                                        {
                                        }
                                        else
                                        {
                                            movie[((JProperty)itemValue).Name] = ((JValue)((JProperty)itemValue).Value).Value;
                                        }
                                    }
                                    bool addMovie = true;
                                    for (int i = 0; i < _moviesList.Count; i++)
                                    {
                                        if (_moviesList[i].id.Equals(movie.id))
                                        {
                                            addMovie = false;
                                            break;
                                        }
                                    }
                                    if (addMovie)
                                    {
                                        _moviesList.Add(movie);
                                    }
                                }
                                csentryPerson.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(item.Key, knowFor));
                            }
                        }
                        else
                        {
                            csentryPerson.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(item.Key, item.Value.ToString()));
                        }
                    }
                    bool addPerson = true;
                    foreach (CSEntryChange item in csentries)
                    {
                        addPerson = !(item.AnchorAttributes[0].Value.Equals(csentryPerson.AnchorAttributes[0].Value));
                    }
                    if (addPerson)
                    {
                        csentries.Add(csentryPerson);
                        _objectCount++;
                    }

                    if (_objectCount >= _currentPageSize)
                    {
                        importReturnInfo.MoreToImport = true;
                        break;
                    }
                }
                _personCount = _objectCount++;
            }

            if (!importReturnInfo.MoreToImport)
            {
                for (int moviesPos = _objectCount - _personCount; moviesPos < _moviesList.Count; moviesPos++)
                {
                    CSEntryChange csentryMovie = CSEntryChange.Create();
                    csentryMovie.ObjectType             = CS_OBJECTTYPE_MOVIE;
                    csentryMovie.ObjectModificationType = ObjectModificationType.Add;

                    foreach (PropertyInfo property in _moviesList[moviesPos])
                    {
                        if (property.Name.Equals(ANCHOR))
                        {
                            string propertyName  = string.Format("{0}_{1}", CS_OBJECTTYPE_MOVIE, ANCHOR);
                            string propertyValue = string.Format("{0}_{1}", CS_OBJECTTYPE_MOVIE, _moviesList[moviesPos][ANCHOR].ToString());
                            csentryMovie.AnchorAttributes.Add(AnchorAttribute.Create(propertyName, propertyValue));
                        }
                        else if (property.Name.ToLower().Equals("item"))
                        {
                        }
                        else if (property.Name != null && _moviesList[moviesPos][property.Name] != null)
                        {
                            csentryMovie.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(property.Name, _moviesList[moviesPos][property.Name].ToString()));
                        }
                    }
                    csentries.Add(csentryMovie);
                    _objectCount++;
                    if (_objectCount >= _currentPageSize)
                    {
                        _skipPeople = true;
                        importReturnInfo.MoreToImport = true;
                        break;
                    }
                }
            }

            importReturnInfo.CSEntries = csentries;
            return(importReturnInfo);
        }
Exemple #2
0
        public Schema GetSchema(KeyedCollection <string, ConfigParameter> configParameters)
        {
            //TODO: Refactor object discover to a function
            Schema schema = Schema.Create();
            // person
            SchemaType personType = Microsoft.MetadirectoryServices.SchemaType.Create(CS_OBJECTTYPE_PERSON, false);

            PersonDiscoveryJsonTypes.Result personSchema = new PersonDiscoveryJsonTypes.Result();
            // movie
            SchemaType movieType = Microsoft.MetadirectoryServices.SchemaType.Create(CS_OBJECTTYPE_MOVIE, false);

            MovieDiscoveryJsonTypes.Result movieSchema = new MovieDiscoveryJsonTypes.Result();
            foreach (PropertyInfo item in personSchema)
            {
                if (item.Name.ToLower().Equals("id"))
                {
                    string itemName = string.Format("{0}_{1}", CS_OBJECTTYPE_PERSON, item.Name);
                    personType.Attributes.Add(SchemaAttribute.CreateAnchorAttribute(itemName, AttributeType.String));
                }
                else if (item.PropertyType.IsArray)
                {
                    switch (item.Name.ToLower())
                    {
                    case "known_for":
                        personType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(item.Name, AttributeType.Reference));
                        break;

                    default:
                        personType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(item.Name, AttributeType.String));
                        break;
                    }
                }
                else if (item.Name.ToLower().Equals("item"))
                {
                }
                else
                {
                    personType.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(item.Name, AttributeType.String));
                }
            }

            foreach (PropertyInfo item in movieSchema)
            {
                if (item.Name.ToLower().Equals("id"))
                {
                    string itemName = string.Format("{0}_{1}", CS_OBJECTTYPE_MOVIE, item.Name);
                    movieType.Attributes.Add(SchemaAttribute.CreateAnchorAttribute(itemName, AttributeType.String));
                }
                else if (item.PropertyType.IsArray)
                {
                    switch (item.Name.ToLower())
                    {
                    default:
                        movieType.Attributes.Add(SchemaAttribute.CreateMultiValuedAttribute(item.Name, AttributeType.String));
                        break;
                    }
                }
                else if (item.Name.ToLower().Equals("item"))
                {
                }
                else
                {
                    movieType.Attributes.Add(SchemaAttribute.CreateSingleValuedAttribute(item.Name, AttributeType.String));
                }
            }

            schema.Types.Add(personType);
            schema.Types.Add(movieType);
            return(schema);
        }