コード例 #1
0
ファイル: Vertex.cs プロジェクト: 2014-sed-team3/term-project
 public Vertex(string ID, string Name, string Type)
 {
     this.ID = ID;
     this.Name = Name;
     this.Type = Type;
     Attributes = new AttributesDictionary<JSONObject>();            
 }
コード例 #2
0
ファイル: Vertex.cs プロジェクト: 2014-sed-team3/term-project
 public Vertex(string ID, string Name, string Type, AttributesDictionary<JSONObject> Attributes)
 {
     this.ID = ID;
     this.Name = Name;            
     this.Type = Type;
     this.Attributes = Attributes;
 }
コード例 #3
0
 public void SetGraph(VertexCollection<String> okVertices, EdgeCollection<String> okEdges, AttributesDictionary<bool> okDialogAttributes, AttributesDictionary<string> okDraphAttributes)
 {
     vertices = okVertices;
     edges = okEdges;
     dialogAttributes = okDialogAttributes;
     graphAttributes = okDraphAttributes;
 }
コード例 #4
0
ファイル: GraphEventArgs.cs プロジェクト: rcsir/RuNetImporter
 public GraphEventArgs(VertexCollection<String> vertices, EdgeCollection<String> edges, AttributesDictionary<bool> dialogAttributes, AttributesDictionary<string> graphAttributes)
 {
     Type = Types.GraphGenerated;
     Vertices = vertices;
     Edges = edges;
     DialogAttributes = dialogAttributes;
     GraphAttributes = graphAttributes;
 }
コード例 #5
0
ファイル: GraphStorage.cs プロジェクト: rcsir/RuNetImporter
 internal void AddFriendVertex(JSONObject friend, AttributesDictionary<String> attributes)
 {
     vertices.Add(makeVertex(friend, attributes, "Friend"));
 }
コード例 #6
0
ファイル: GraphStorage.cs プロジェクト: rcsir/RuNetImporter
 internal void MakeEgoVertex(JSONObject ego, AttributesDictionary<String> attributes)
 {
     egoVertex = makeVertex(ego, attributes, "Ego");
     includeEgo = true;
 }
コード例 #7
0
        BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Debug.Assert(sender is BackgroundWorker);
            BackgroundWorker bw = sender as BackgroundWorker;

            Debug.Assert(e.Argument is NetworkAsyncArgs);
            NetworkAsyncArgs args = e.Argument as NetworkAsyncArgs;

            this.requestStatistics = new RequestStatistics();

            try
            {
                CheckCancellationPending();
                ReportProgress("Starting");

                // shell include ego node in the graph
                this.includeEgo = args.includeMe;

                // prepare rest contexts
                var context = new VkRestApi.VkRestContext(args.userId, args.accessToken);

                // get ego node
                vkRestApi.CallVkFunction(VkFunction.GetProfiles, context);

                // wait for the user data
                readyEvent.WaitOne();

                CheckCancellationPending();
                ReportProgress("Retrieving friends");

                // prepare fields context parameter
                StringBuilder sb = new StringBuilder("fields=");
                sb.Append(args.fields);
                context.Parameters = sb.ToString();

                // get friends node
                vkRestApi.CallVkFunction(VkFunction.LoadFriends, context);

                // wait for the friends data
                readyEvent.WaitOne();

                int total = this.friendIds.Count;
                int current = 0;

                foreach (string targetId in this.friendIds)
                {
                    CheckCancellationPending();
                    current++;
                    ReportProgress("Retrieving friends mutual " + current + " out of " + total);

                    // Append target friend ids
                    sb.Length = 0;
                    sb.Append("target_uid=");
                    sb.Append(targetId);

                    context.Parameters = sb.ToString();
                    context.Cookie = targetId; // pass target id in the context's cookie field
                    
                    // get mutual friends 
                    vkRestApi.CallVkFunction(VkFunction.FriendsGetMutual, context);

                    // wait for the mutual data
                    readyEvent.WaitOne();

                    // play it nice, sleep for 1/3 sec to stay within 3 requests/second limit
                    // TODO: account for time spent in processing
                    Thread.Sleep(333);
                }

                if (includeEgo)
                {
                    CreateIncludeMeEdges();
                }

                CheckCancellationPending();
                ReportProgress("Building network graph document");

                // create default attributes (values will be empty)
                AttributesDictionary<String> attributes = new AttributesDictionary<String>(VKAttributes);

                // build the file
                XmlDocument graph = GenerateNetworkDocument(vertices, edges, attributes);

                if (this.requestStatistics.UnexpectedExceptions > 0)
                {
                    // there was errors - pop up partial network dialog
                    throw new PartialNetworkException(graph, this.requestStatistics);
                }
                else
                {
                    // all good
                    e.Result = graph;
                }

            }
            catch (CancellationPendingException)
            {
                e.Cancel = true;
            }
        }
コード例 #8
0
        private AttributesDictionary<String> createAttributes(JObject obj)
        {
            AttributesDictionary<String> attributes = new AttributesDictionary<String>(VKAttributes);
            List<AttributeUtils.Attribute> keys = new List<AttributeUtils.Attribute>(attributes.Keys);
            foreach (AttributeUtils.Attribute key in keys)
            {
                String name = key.value;
                if (obj[name] != null)
                {
                    // assert it is null?
                    String value = obj[name].ToString();
                    attributes[key] = value;
                }
            }

            return attributes;
        }
コード例 #9
0
        //*************************************************************************
        //  Method: getAttributes()
        //
        /// <summary>
        /// Gets the selected attributes for all the friends
        /// </summary>
        ///
        /// <param name="attributes">
        /// The dictionary that holds the attributes and states
        /// for each of them if they are included
        /// </param>
        /// 
        /// <param name="friendUIDs">
        /// A list with friend's UIDs
        /// </param> 
        ///
        /// <param name="fb">
        /// A FacebookAPI instance to make calls to Facebook
        /// </param>
        ///    
        /// <returns>
        /// A dictionary with the attributes' values
        /// </returns>
        //*************************************************************************       

        private void DownloadAttributes
        (
            AttributesDictionary<bool> attributes       
        )
        {            
            int nrOfFriendsPerQuery = 20;
            int totalNrOfqueries = 10;
            int nrOfMultiqueries = (int)(Math.Ceiling((double)oVertices.Count / (nrOfFriendsPerQuery*totalNrOfqueries)));
            int startIndex, endIndex, computedEndIndex;
            Dictionary<string, string> queries = new Dictionary<string, string>();
            JSONObject returnedAttributes;
            Dictionary<string, Dictionary<string, JSONObject>> attributeValues = new Dictionary<string, Dictionary<string, JSONObject>>();
            CurrentStep++;                       

            //Build the first part of the queries
            string firstPartQuery = "SELECT uid,";
            foreach (KeyValuePair<AttributeUtils.Attribute, bool> kvp in attributes)
            {
                if (kvp.Value)
                {
                    firstPartQuery += kvp.Key.value + ",";
                }
            }
            firstPartQuery = firstPartQuery.Remove(firstPartQuery.Length - 1);
            firstPartQuery += " FROM user WHERE uid IN ";
            string sIDs; ;

            for (int k = 0; k < nrOfMultiqueries; k++)
            {
                queries.Clear();
                //Build the queries and add them to a dictionary
                for (int i = 0; i < totalNrOfqueries; i++)
                {
                    startIndex = i * nrOfFriendsPerQuery + k*totalNrOfqueries*nrOfFriendsPerQuery;
                    computedEndIndex = (i + 1) * nrOfFriendsPerQuery + k * totalNrOfqueries * nrOfFriendsPerQuery;
                    endIndex = computedEndIndex >= oVertices.Count ? oVertices.Count - 1 : computedEndIndex;
                    //Build IDs string
                    sIDs = "";
                    for (int j = startIndex; j <= endIndex; j++)
                    {
                        sIDs += oVertices[j].ID+",";
                    }
                    sIDs = sIDs.Remove(sIDs.Length - 1);
                    queries.Add("query" + (i + 1).ToString(), firstPartQuery + "(" + sIDs + ")");
                    if (endIndex != computedEndIndex)
                    {
                        break;
                    }
                }

                //Execute the queries and report progress
                ReportProgress(String.Format("Step {0}/{1}: Getting Attributes (Batch {2}/{3})",
                                            CurrentStep,NrOfSteps,(k+1),nrOfMultiqueries));
                returnedAttributes = m_oFb.ExecuteFQLMultiquery(queries);

                //Extract attributes from the JSONObject
                //and insert them to a dictionary.
                //Loop through the queries
                for (int i = 0; i < returnedAttributes.Array.Length; i++)
                {
                    //Loop through the results of the queries
                    for (int j = 0; j < returnedAttributes.Array[i].Dictionary["fql_result_set"].Array.Length; j++)
                    {
                        string sUID = returnedAttributes.Array[i].Dictionary["fql_result_set"].Array[j].Dictionary["uid"].String;

                        foreach (KeyValuePair<string,JSONObject> kvp in returnedAttributes.Array[i].Dictionary["fql_result_set"].Array[j].Dictionary)
                        {
                            try
                            {                               
                                if (kvp.Key == "name" &&
                                    String.IsNullOrEmpty(oVertices[sUID].Name))
                                {
                                    oVertices[sUID].Name = ManageDuplicateNames(kvp.Value.String);
                                }
                                if (kvp.Key == "profile_update_time")
                                {
                                    int iTimeStamp;
                                    if (int.TryParse(kvp.Value.String, out iTimeStamp))
                                    {
                                        oVertices[sUID].Attributes[kvp.Key] = JSONObject.CreateFromString("\""+DateUtil.ConvertToDateTime(iTimeStamp).ToString()+"\"");
                                    }

                                }
                                else
                                {
                                    oVertices[sUID].Attributes[kvp.Key] = kvp.Value;
                                }
                                
                            }
                            catch (Exception e)
                            {

                            }
                        }
                    }
                }
            }

            //Some commenters, likers or users tagged are pages
            //and we can not get attributes for them,
            //so they are removed from the vertices list
            oVertices.RemoveWhere(x => String.IsNullOrEmpty(x.Name));
        }
コード例 #10
0
        private void makeGraphAttributes()
        {
//            OkDialogAttributes["name"] = true;
            graphAttributes = new AttributesDictionary<string>();
            List<AttributeUtils.Attribute> keys = new List<AttributeUtils.Attribute>(graphAttributes.Keys);
            foreach (AttributeUtils.Attribute key in keys)
                if (!OkDialogAttributes.ContainsKey(key) || !OkDialogAttributes[key])
                    graphAttributes.Remove(key);
        }
コード例 #11
0
        GetFriendsNetworkInternal
        (
            string sAccessToken,            
            List<NetworkType> oEdgeType,
            bool bDownloadFromPostToPost,
            bool bDownloadBetweenDates,
            bool bEgoTimeline,
            bool bFriendsTimeline,
            int iFromPost,
            int iToPost,
            DateTime oStartDate,
            DateTime oEndDate,
            bool bLimitCommentsLikes,
            int iNrLimit,
            bool bGetTooltips,
            bool bIncludeMe,
            AttributesDictionary<bool> attributes
        )

        {
            Debug.Assert(!String.IsNullOrEmpty(sAccessToken));            
            AssertValid();           

            //Set the total nr of steps
            if (bGetTooltips) NrOfSteps++;            

            oTimer.Elapsed += new System.Timers.ElapsedEventHandler(oTimer_Elapsed);

            oGraphMLXmlDocument = CreateGraphMLXmlDocument(attributes);
            RequestStatistics oRequestStatistics = new RequestStatistics();


            var fb = new FacebookAPI(sAccessToken);

            m_oFb = fb;
            
            Dictionary<string, string> friends = new Dictionary<string, string>();
            List<string> friendsUIDs = new List<string>();            
            XmlNode oVertexXmlNode;
            string attributeValue = "";
            Dictionary<String, List<Dictionary<string, object>>> statusUpdates = new Dictionary<string, List<Dictionary<string, object>>>();
            Dictionary<String, List<Dictionary<string, object>>> wallPosts = new Dictionary<string,List<Dictionary<string,object>>>();
            
            string currentStatusUpdate="";
            string currentWallPost = "";
            string currentWallTags = "";
            string currentStatusTags = "";
            List<Dictionary<string,object>>.Enumerator en;            
            bool bGetUsersTagged = oEdgeType.Contains(NetworkType.TimelineUserTagged);
            bool bGetCommenters = oEdgeType.Contains(NetworkType.TimelineUserComments);
            bool bGetLikers = oEdgeType.Contains(NetworkType.TimelineUserLikes);
            bool bGetPostAuthors = oEdgeType.Contains(NetworkType.TimelinePostAuthors);
            bool bGetPosts = oEdgeType.Count > 0;

            DownloadFriends();

            if (bEgoTimeline || bIncludeMe)
            {
                GetEgo();
            }

            oVerticesToQuery = VerticesToQuery(bEgoTimeline, bFriendsTimeline);

            if (bGetPosts)
            {
                DownloadPosts(bDownloadFromPostToPost, bDownloadBetweenDates, iFromPost,
                                iToPost, oStartDate, oEndDate, bGetUsersTagged ,
                                bGetCommenters, bGetLikers);                
            }

            DownloadVertices(bGetUsersTagged, bGetCommenters, bGetLikers, bGetPosts, bLimitCommentsLikes, iNrLimit);

            DownloadAttributes(attributes);

            if(bGetTooltips)
            {
                GetTooltips();
            }           

            CreateEdges(bGetUsersTagged, bGetCommenters, bGetLikers, bGetPostAuthors, bIncludeMe);

            AddVertices();

            ReportProgress(String.Format("Completed downloading {0} friends data", friends.Count));            

            AddEdges();          
            

           

            ReportProgress("Importing downloaded network into NodeXL");

            //After successfull download of the network
            //get the network description
            OnNetworkObtainedWithoutTerminatingException(oGraphMLXmlDocument, oRequestStatistics,
                GetNetworkDescription(oEdgeType, bDownloadFromPostToPost, bDownloadBetweenDates,
                                        iFromPost, iToPost, oStartDate,
                                        oEndDate, bLimitCommentsLikes, iNrLimit,
                                        oGraphMLXmlDocument));

            return oGraphMLXmlDocument;
            
        }
コード例 #12
0
        GetNetwork
        (
            String s_accessToken,            
            List<NetworkType> oEdgeType,
            bool bDownloadFromPostToPost,
            bool bDownloadBetweenDates,
            bool bEgoTimeline,
            bool bFriendsTimeline,
            int iFromPost,
            int iToPost,
            DateTime oStartDate,
            DateTime oEndDate,
            bool bLimitCommentsLikes,
            int iNrLimit,
            bool bGetTooltips,
            bool bIncludeMe,
            AttributesDictionary<bool> attributes
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(s_accessToken));
            AssertValid();


            return (GetFriendsNetworkInternal(s_accessToken, oEdgeType, bDownloadFromPostToPost,
                                                bDownloadBetweenDates, bEgoTimeline, bFriendsTimeline,
                                                iFromPost, iToPost, oStartDate,
                                                oEndDate,bLimitCommentsLikes, iNrLimit,
                                                bGetTooltips, bIncludeMe, attributes));
        }
コード例 #13
0
        CreateGraphMLXmlDocument
        (
            AttributesDictionary<bool> attributes
        )
        {
            AssertValid();

            GraphMLXmlDocument oGraphMLXmlDocument = new GraphMLXmlDocument(false);

            DefineImageFileGraphMLAttribute(oGraphMLXmlDocument);
            DefineCustomMenuGraphMLAttributes(oGraphMLXmlDocument);
            oGraphMLXmlDocument.DefineGraphMLAttribute(false, TooltipID,
            "Tooltip", "string", null);
            oGraphMLXmlDocument.DefineGraphMLAttribute(false, "type", "Type", "string", null);

            oGraphMLXmlDocument.DefineGraphMLAttribute(true, "e_type", "Edge Type", "string", null);
            oGraphMLXmlDocument.DefineGraphMLAttribute(true, "e_comment", "Tweet", "string", null);
            oGraphMLXmlDocument.DefineGraphMLAttribute(true, "e_origin", "Feed of Origin", "string", null);
            oGraphMLXmlDocument.DefineGraphMLAttribute(true, "e_timestamp", "Timestamp", "string", null);
            DefineRelationshipGraphMLAttribute(oGraphMLXmlDocument);

            foreach (KeyValuePair<AttributeUtils.Attribute, bool> kvp in attributes)
            {
                if (kvp.Value)
                {
                    if (kvp.Key.value.Equals("hometown_location"))
                    {
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, "hometown",
                        "Hometown", "string", null);
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, "hometown_city",
                        "Hometown City", "string", null);
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, "hometown_state",
                        "Hometown State", "string", null);
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, "hometown_country",
                        "Hometown Country", "string", null);
                    }
                    else if (kvp.Key.value.Equals("current_location"))
                    {
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, "location",
                        "Current Location", "string", null);
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, "location_city",
                        "Current Location City", "string", null);
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, "location_state",
                        "Current Location State", "string", null);
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, "location_country",
                        "Current Location Country", "string", null);
                    }
                    else
                    {
                        oGraphMLXmlDocument.DefineGraphMLAttribute(false, kvp.Key.value,
                        kvp.Key.name, "string", null);
                    }
                }
            }            

            return (oGraphMLXmlDocument);
        }
コード例 #14
0
        GetNetworkAsync
        (
            String s_accessToken,            
            List<NetworkType> oEdgeType,
            bool bDownloadFromPostToPost,
            bool bDownloadBetweenDates,
            bool bEgoTimeline,
            bool bFriendsTimeline,
            int iFromPost,
            int iToPost,
            DateTime oStartDate,
            DateTime oEndDate,
            bool bLimitCommentsLikes,
            int iNrLimit,
            bool bGetTooltips,
            bool bIncludeMe,
            AttributesDictionary<bool> attributes
        )
        {            
            Debug.Assert(!String.IsNullOrEmpty(s_accessToken));
            AssertValid();
            
            const String MethodName = "GetNetworkAsync";
            CheckIsBusy(MethodName);

            GetNetworkAsyncArgs oGetNetworkAsyncArgs = new GetNetworkAsyncArgs();

            oGetNetworkAsyncArgs.AccessToken = s_accessToken;            
            oGetNetworkAsyncArgs.attributes = attributes;            
            oGetNetworkAsyncArgs.EdgeType = oEdgeType;
            oGetNetworkAsyncArgs.DownloadFromPostToPost = bDownloadFromPostToPost;
            oGetNetworkAsyncArgs.DownloadBetweenDates = bDownloadBetweenDates;
            oGetNetworkAsyncArgs.EgoTimeline = bEgoTimeline;
            oGetNetworkAsyncArgs.FriendsTimeline = bFriendsTimeline;
            oGetNetworkAsyncArgs.FromPost = iFromPost;
            oGetNetworkAsyncArgs.ToPost = iToPost;
            oGetNetworkAsyncArgs.StartDate = oStartDate;
            oGetNetworkAsyncArgs.EndDate = oEndDate;
            oGetNetworkAsyncArgs.LimitCommentsLikes = bLimitCommentsLikes;
            oGetNetworkAsyncArgs.Limit = iNrLimit;
            oGetNetworkAsyncArgs.GetTooltips = bGetTooltips;
            oGetNetworkAsyncArgs.IncludeMe = bIncludeMe;
            
            m_oBackgroundWorker.RunWorkerAsync(oGetNetworkAsyncArgs);
        }
コード例 #15
0
ファイル: GraphStorage.cs プロジェクト: rcsir/RuNetImporter
 private Vertex<String> makeVertex(JSONObject token, AttributesDictionary<String> attributes, string type)
 {
     return new Vertex<String>(token.Dictionary["uid"].String, token.Dictionary["name"].String, type, attributes);
 }
コード例 #16
0
 internal AttributesDictionary<string> CreateVertexAttributes(JSONObject obj)
 {
     AttributesDictionary<string> attributes = new AttributesDictionary<string>();
     List<AttributeUtils.Attribute> keys = new List<AttributeUtils.Attribute>(attributes.Keys);
     foreach (AttributeUtils.Attribute key in keys) {
         if (!isNeeded(key.value)) {
             attributes.Remove(key);
             continue;
         }
         string name = convertKey(key.value);
         if (obj.Dictionary.ContainsKey(name)) {
             string value = name.Contains("location") ? calcLocation(obj, name) : obj.Dictionary[name].String;
             attributes[key] = value;
         }
     }
     return attributes;
 }
コード例 #17
0
        public XmlDocument analyze(String userId, String authToken)
        {
            var context = new VkRestApi.VkRestContext(userId, authToken);

            this.requestStatistics = new RequestStatistics();

            vkRestApi.CallVkFunction(VkFunction.GetProfiles, context);

            // wait for the user data
            readyEvent.WaitOne();
            context.Parameters = "fields=uid,first_name,last_name,sex,bdate,photo_50,city,country,relation,nickname";
            vkRestApi.CallVkFunction(VkFunction.LoadFriends, context);

            // wait for the friends data
            readyEvent.WaitOne();
            foreach (string targetId in this.friendIds)
            {
                StringBuilder sb = new StringBuilder("target_uid=");
                // Append target friend ids
                sb.Append(targetId);

                context.Parameters = sb.ToString();
                context.Cookie = targetId; // pass target id in the cookie context field
                vkRestApi.CallVkFunction(VkFunction.FriendsGetMutual, context);

                // wait for the mutual data
                readyEvent.WaitOne();

                // play nice, sleep for 1/3 sec to stay within 3 requests/second limit
                // TODO: account for time spent in processing
                Thread.Sleep(333);
            }

            if (includeEgo)
            {
                CreateIncludeMeEdges();
            }

            // create default attributes (values will be empty)
            AttributesDictionary<String> attributes = new AttributesDictionary<String>(VKAttributes);

            return GenerateNetworkDocument(vertices, edges, attributes);
        }
コード例 #18
0
 private void makeOkDialogAttributes()
 {
     okDialogAttributes = new AttributesDictionary<bool>();
     foreach (KeyValuePair<AttributeUtils.Attribute, bool> kvp in dialogAttributes)
         if (!isNeeded(kvp.Key.value))
             okDialogAttributes.Remove(kvp.Key);
         else
             okDialogAttributes[kvp.Key] = dialogAttributes[kvp.Key];
 }
コード例 #19
0
ファイル: OKDialog.cs プロジェクト: rcsir/RuNetImporter
        //*************************************************************************
        //  Protected constants
        //*************************************************************************


        //*************************************************************************
        //  Protected fields
        //*************************************************************************

        // These are static so that the dialog's controls will retain their values
        // between dialog invocations.  Most NodeXL dialogs persist control values
        // via ApplicationSettingsBase, but this plugin does not have access to
        // that and so it resorts to static fields.

        /// Tag to get the related tags for.  Can be empty but not null.
//        protected static String m_sTag = "sociology";
        /// Network level to include.
        //protected static NetworkLevel m_eNetworkLevel = NetworkLevel.OnePointFive;
        /// true to include a sample thumbnail for each tag.
//        protected static Boolean m_bIncludeSampleThumbnails = false;

        private void addAttributes(AttributesDictionary<bool> dialogAttributes)
        {
            int i = 0;
            dgAttributes.Rows.Add(dialogAttributes.Count);
            foreach (KeyValuePair<AttributeUtils.Attribute, bool> kvp in dialogAttributes) {
                dgAttributes.Rows[i].Cells[0].Value = kvp.Key.name;
                dgAttributes.Rows[i].Cells[1].Value = kvp.Value;
                dgAttributes.Rows[i].Cells[2].Value = kvp.Key.value;
                i++;
            }
        }