/// <summary>
        /// Handles the Click event of the undo control.
        /// Removes last selected vertex and edge
        /// </summary>
        private void Undo_Click(object sender, RoutedEventArgs e)
        {
            if (this.machine is FirstStateMachine)
            {
                if (this.sequenceFirstVersion.ArrayOfStep.Count > 0)
                {
                    this.sequenceFirstVersion.ArrayOfStep.RemoveAt(this.sequenceFirstVersion.ArrayOfStep.Count - 1);
                }
            }
            else
            {
                if (this.sequenceSecondVersion.ArrayOfStep.Count > 0)
                {
                    this.sequenceSecondVersion.ArrayOfStep.RemoveAt(this.sequenceSecondVersion.ArrayOfStep.Count - 1);
                }
            }

            if (this.listOfVertices.Count > 1)
            {
                this.machine.MyGraph.ChangeOneVertexColor(this.listOfVertices.Peek().Text, Colors.Wheat);
                CustomEdge edge = new CustomEdge(this.listOfVertices.ElementAt(1), this.listOfVertices.Peek());
                edge = this.machine.MyGraph.GetEdgeBetween(this.listOfVertices.ElementAt(1), this.listOfVertices.Pop());
                if (this.listOfVertices.Count == 1)
                {
                    this.machine.MyGraph.ChangeOneVertexColor(this.listOfVertices.Peek().Text, Colors.Wheat);
                }

                this.machine.MyGraph.ChangeOneEdgeColor(edge, Colors.Black);
            }
        }
Ejemplo n.º 2
0
        public override void UnhideEdges(CustomVertex vertex, List <CustomEdge> edgesIn, List <CustomEdge> edgesOut)
        {
            if (vertex.BackgroundColor == Colors.Red || vertex.Display == false)
            {
                this.MyGraph.GetVertexByName(vertex.Text).BackgroundColor = Colors.Wheat;
                this.MyGraph.GetVertexByName(vertex.Text).Display         = true;
                for (int i = 0; i < edgesIn.Count; i++)
                {
                    if (string.Compare(edgesIn[i].Target.Text, vertex.Text) == 0 || string.Compare(edgesIn[i].Trigger, vertex.Text) == 0)
                    {
                        CustomEdge edge = new CustomEdge(edgesIn[i].Trigger, edgesIn[i].Source, edgesIn[i].Target);
                        this.MyGraph.AddEdge(edge);
                        edgesIn.Remove(edgesIn[i]);
                        i--;
                    }
                }

                int lenghtOut = edgesOut.Count;
                for (int i = 0; i < edgesOut.Count; i++)
                {
                    if (string.Compare(edgesOut[i].Source.Text, vertex.Text) == 0)
                    {
                        CustomEdge edge = new CustomEdge(edgesOut[i].Trigger, edgesOut[i].Source, edgesOut[i].Target);
                        this.MyGraph.AddEdge(edge);
                        edgesOut.Remove(edgesOut[i]);
                        i--;
                    }
                }
            }
            else
            {
                MessageBox.Show("Nothing to unhide!");
            }
        }
Ejemplo n.º 3
0
        public override void HideEdges(CustomVertex vertex, List <CustomEdge> edgesIn, List <CustomEdge> edgesOut)
        {
            if (vertex.BackgroundColor == Colors.Wheat || vertex.Display == true)
            {
                this.MyGraph.GetVertexByName(vertex.Text).BackgroundColor = Colors.Red;
                this.MyGraph.GetVertexByName(vertex.Text).Display         = false;
                IEnumerable <CustomEdge> collectionIn  = this.MyGraph.InEdges(vertex);
                IEnumerable <CustomEdge> collectionOut = this.MyGraph.OutEdges(vertex);
                foreach (var item in collectionIn)
                {
                    CustomEdge edge = new CustomEdge(item.Trigger, item.Source, item.Target);
                    edgesIn.Add(edge);
                }

                foreach (var item in collectionOut)
                {
                    CustomEdge edge = new CustomEdge(item.Trigger, item.Source, item.Target);
                    edgesOut.Add(edge);
                }

                this.MyGraph.ClearEdges(vertex);
            }
            else
            {
                MessageBox.Show("Already hidden!");
            }
        }
Ejemplo n.º 4
0
        public override void UnhideEdges(CustomVertex vertex, List <CustomEdge> edgesIn, List <CustomEdge> edgesOut)
        {
            if (vertex.BackgroundColor == Colors.Red)
            {
                this.MyGraph.GetVertexByName(vertex.Text).BackgroundColor = Colors.Wheat;
                foreach (var item in edgesIn)
                {
                    if (string.Compare(item.Target.Text, vertex.Text) == 0)
                    {
                        CustomEdge edge = new CustomEdge(item.Trigger, item.Source, item.Target);
                        this.MyGraph.AddEdge(edge);
                    }
                }

                foreach (var item in edgesOut)
                {
                    if (string.Compare(item.Source.Text, vertex.Text) == 0)
                    {
                        CustomEdge edge = new CustomEdge(item.Trigger, item.Source, item.Target);
                        this.MyGraph.AddEdge(edge);
                    }
                }
            }
            else
            {
                MessageBox.Show("Nothing to unhide!");
            }
        }
        /// <summary>
        /// Handles the SelectionChanged event of the veritces control.
        /// Adds the selected vertex to current sequence
        /// </summary>
        private void Veritces_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.listOfVertices.Push((CustomVertex)veritces.SelectedItem);
            if (this.listOfVertices.Count > 1)
            {
                CustomEdge edge = new CustomEdge(this.listOfVertices.ElementAt(1), this.listOfVertices.Peek());
                edge = this.machine.MyGraph.GetEdgeBetween(this.listOfVertices.ElementAt(1), this.listOfVertices.Peek());
                if (edge != null)
                {
                    if (edge.Source.CompareTo(edge.Target))
                    {
                        this.machine.MyGraph.GetVertexByName(edge.Source.Text).Represented = true;
                    }

                    this.machine.MyGraph.ChangeOneVertexColor(this.listOfVertices.ElementAt(this.listOfVertices.Count - 1).Text, Colors.Red);
                    this.machine.MyGraph.ChangeOneVertexColor(this.listOfVertices.Peek().Text, Colors.Red);
                    this.machine.MyGraph.ChangeOneEdgeColor(edge, Colors.Red);
                    if (this.machine is FirstStateMachine)
                    {
                        ((FirstStateMachine)this.machine).AddNewStep(this.sequenceFirstVersion, edge.Trigger);
                    }
                    else
                    {
                        ((SecondStateMachine)this.machine).AddNewStep(this.sequenceSecondVersion, edge.Trigger);
                    }
                }
                else
                {
                    MessageBox.Show("There is no edge between these vertices! \r\n Please choose another one!");
                    this.listOfVertices.Pop();
                }

                this.DataContext = this.machine.MyGraph;
            }
        }
Ejemplo n.º 6
0
 public FacebookFetcher(Schema schema, string edgeKey, string subEdgeKey, Fetcher fetcher, CustomEdge customEdge)
 {
     Schema     = schema;
     EdgeKey    = edgeKey;
     SubEdgeKey = subEdgeKey;
     Fetcher    = fetcher;
     CustomEdge = customEdge;
 }
Ejemplo n.º 7
0
        private void FetchDetailsOfRow(Table table, JObject row)
        {
            /**
             * The details of a row include: metrics, insights, and nested edges.
             */
            if (Configuration.IgnoreEdges)
            {
                return;
            }

            GetLogger().Information($"Fetching details of ({table.Name},{row ? ["id"]})");
            try {
                if (SubEdgeKey != null)
                {
                    // DEPRECATED: case in which the user informed a single edge to be executed
                    if (SubEdgeKey == "insights")
                    {
                        Fetcher.FetchInsights(table, row);
                    }
                    var edge = table.Edges.GetValueOrDefault(SubEdgeKey, null);
                    var key  = (SchemaName : Schema.Name, TableName : table.Name, CustomEdgeName : SubEdgeKey);
                    if (CustomEdge.ContainsKey(key))
                    {
                        CustomEdge[key](Logger, row);
                    }
                    if (edge != null)
                    {
                        Fetcher.FetchChildrenOnEdge(edge, row);
                    }
                }
                else
                {
                    if (EdgeKey != null)
                    {
                        foreach (var subEdge in table.Edges)
                        {
                            Fetcher.FetchChildrenOnEdge(subEdge.Value, row);
                        }
                        foreach (var edge in CustomEdge.Where(x => x.Key.SchemaName == Schema.Name && x.Key.TableName == table.Name))
                        {
                            edge.Value(Logger, row);
                        }
                    }
                    Fetcher.FetchInsights(table, row);
                }
            } catch (AggregateException e) {
                foreach (var ie in e.InnerExceptions)
                {
                    if (ie is FacebookApiUnreachable)
                    {
                        throw ie;
                    }
                }
                Logger.Warning(e, $"Failure while fetching details of ({table.TableName}, {row.ToString()}");
            } catch (Exception e) {
                Logger.Warning(e, $"Failure while fetching details of ({table.TableName}, {row.ToString()}");
            }
        }
Ejemplo n.º 8
0
        private void AddEdgeWithCosts(string source, string target, string company, double price, double time, bool useTime)
        {
            var edge = new CustomEdge(source, target, company, price, time);

            _graph.AddVerticesAndEdge(edge);
            if (useTime)
            {
                _costs.Add(edge, time);
            }
            else
            {
                _costs.Add(edge, price);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the machine to next state with given step.
        /// </summary>
        /// <param name="curredntStep">The currednt step.</param>
        /// <param name="currentState">State of the current.</param>
        /// <returns></returns>
        public FSMState OneStep(FSMStep currentStep, FSMState currentState, Color color)
        {
            this.MyGraph.ChangeOneVertexColor(currentState.Name, color);
            FSMState   newState       = new FSMState();
            FSMTrigger triggerFounded = this.Configuration.FoundSteppInTriggerList(currentStep);

            if (triggerFounded != null)
            {
                AllowedTrigger allowedTrigger = new AllowedTrigger();
                allowedTrigger = currentState.FoundTriggerInCureentState(triggerFounded);
                if (allowedTrigger != null)
                {
                    newState = new FSMState();
                    if (string.IsNullOrEmpty(allowedTrigger.StateName))
                    {
                        newState = this.Configuration.FoundNextState(allowedTrigger.StateAndTriggerName);
                    }
                    else
                    {
                        newState = this.Configuration.FoundNextState(allowedTrigger.StateName);
                    }

                    if (newState != null)
                    {
                        this.MyGraph.ChangeOneVertexColor(newState.Name, color);
                        CustomEdge edge = new CustomEdge(null, null);

                        if (string.Compare(currentState.Name, newState.Name) == 0)
                        {
                            this.MyGraph.Vertices.Where(v => (string.Compare(v.Text, currentState.Name) == 0)).FirstOrDefault().Represented = true;
                        }

                        edge = this.MyGraph.GetEdgeBetween(currentState.Name, newState.Name);
                        this.MyGraph.ChangeOneEdgeColor(edge, Colors.Yellow);
                    }
                }
            }

            return(newState);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a new edge, a new allowed trigger to source vertex, a new trigger if it doesn't exist.
        /// </summary>
        /// <param name="vertexFrom">The vertex from.</param>
        /// <param name="trigger">The trigger.</param>
        /// <param name="vertexTo">The vertex to.</param>
        public override void AddNewEdge(CustomVertex vertexFrom, string trigger, CustomVertex vertexTo)
        {
            FSMVState      state = new FSMVState();
            AllowedTrigger aw    = new AllowedTrigger();
            FSMVTrigger    trig  = new FSMVTrigger();

            state.Name = vertexFrom.Text;
            if (string.IsNullOrEmpty(trigger))
            {
                CustomEdge edge = new CustomEdge(vertexTo.Text, vertexFrom, vertexTo);
                this.MyGraph.AddNewEdge(vertexTo.Text, vertexFrom, vertexTo);
                aw.StateAndTriggerName = trig.CommonID = vertexTo.Text;
            }
            else
            {
                CustomEdge edge = new CustomEdge(trigger, vertexFrom, vertexTo);
                this.MyGraph.AddNewEdge(vertexTo.Text, vertexFrom, vertexTo);
                aw.StateName    = vertexTo.Text;
                aw.TriggerName  = trigger;
                trig.Name       = vertexTo.Text;
                trig.SequenceID = trigger;
            }

            foreach (var item in this.Configuration.ArrayOfFSMVState)
            {
                if (item.Name == state.Name)
                {
                    if (item.ArrayOfAllowedTrigger == null)
                    {
                        item.ArrayOfAllowedTrigger = new Collection <AllowedTrigger>();
                    }

                    item.ArrayOfAllowedTrigger.Add(aw);
                    break;
                }
            }

            this.Configuration.AddNewTrigger(trig);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Updates an edge that has not been created with the provider
 /// </summary>
 /// <param name="e">vertex to update</param>
 public void UpdateEdge(CustomEdge e)
 {
     e.ID = m_NextID++;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Get selected edge
 /// </summary>
 private void MouseEnter_EventEdge(object sender, RoutedEventArgs e)
 {
   this.selectedEdge = (CustomEdge)(sender as EdgeControl).Edge;
 }
Ejemplo n.º 13
0
        public override IEnumerable <AbstractJob> GetJobs(JobType type, JobScope scope, IEnumerable <string> names, JobConfiguration jobConfiguration)
        {
            if (CheckTypeAndScope(type, scope))
            {
                return(NoJobs);
            }

            var jobs = new List <FacebookFetcher>();

            foreach (var schemaName in Schemas)
            {
                var schema = SchemaLoader.LoadSchema(schemaName);
                var apiMan = new ApiManager(
                    SchemaLoader.GetCredentials(schemaName),
                    IgnoreCache,
                    jobConfiguration.IgnoreAPI,
                    jobConfiguration.IgnoreTTL,
                    jobConfiguration.Paginate,
                    schema.Delay,
                    CacheDirectory,
                    jobConfiguration.DefaultNowDate
                    );
                var fetcher    = new Fetcher(apiMan, schema.PageSize);
                var customEdge = new CustomEdge();

                if (schemaName == "adaccount")
                {
                    var pageSchema      = SchemaLoader.LoadSchema("page");
                    var pageCredentials = SchemaLoader.GetCredentials("page");

                    var pageApiMan = new ApiManager(
                        SchemaLoader.GetCredentials("page"),
                        IgnoreCache,
                        jobConfiguration.IgnoreAPI,
                        jobConfiguration.IgnoreTTL,
                        jobConfiguration.Paginate,
                        schema.Delay,
                        CacheDirectory,
                        jobConfiguration.DefaultNowDate
                        );
                    var pageFetcher = new Fetcher(pageApiMan, pageSchema.PageSize);

                    var key = (SchemaName : "adaccount", TableName : "ads", CustomEdgeName : "custom_videos");
                    if (!customEdge.ContainsKey(key))
                    {
                        Action <Logger, JObject> callback = (logger, parent) => {
                            var creative = parent["creative"];

                            var video = creative ? ["video_id"];
                            if (video != null)
                            {
                                pageFetcher.GetRoot(pageSchema, "videos", video, logger);
                            }

                            var sourceFileVideoId = creative.IndexPathOrDefault <string>("object_story_spec.video_data.video_id", null);

                            if (sourceFileVideoId != null)
                            {
                                pageFetcher.GetRoot(pageSchema, "videos", sourceFileVideoId, logger);
                            }

                            var post = creative ? ["object_story_id"];
                            if (post != null)
                            {
                                pageFetcher.GetRoot(pageSchema, "posts", post, logger);
                            }
                        };

                        customEdge.Add(key, callback);
                    }
                }

                if (Schemas.Count == 1 && TableKey != null)
                {
                    // DEPRECATED: case in which the user specified a single edge to be executed
                    jobs.Add(new FacebookFetcher(schema, TableKey, EdgeKey, fetcher, customEdge));
                }
                else
                {
                    foreach (var edge in schema.Edges)
                    {
                        jobs.Add(new FacebookFetcher(schema, edge.Key, null, fetcher, customEdge));
                    }
                    if (schemaName == "instagram")
                    {
                        jobs.Add(new FacebookFetcher(schema, null, null, fetcher, customEdge));
                    }
                }
            }

            return(FilterByName(jobs, names));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the machine to next state with given step.
        /// </summary>
        /// <param name="curredntStep">The currednt step.</param>
        /// <param name="currentState">State of the current.</param>
        /// <returns></returns>
        public FSMState OneStep(FSMStep currentStep, FSMState currentState, Color color)
        {
            this.MyGraph.ChangeOneVertexColor(currentState.Name, color);
            FSMState newState = new FSMState();
            FSMTrigger triggerFounded = this.Configuration.FoundSteppInTriggerList(currentStep);
            if (triggerFounded != null)
            {
                AllowedTrigger allowedTrigger = new AllowedTrigger();
                allowedTrigger = currentState.FoundTriggerInCureentState(triggerFounded);
                if (allowedTrigger != null)
                {
                    newState = new FSMState();
                    if (string.IsNullOrEmpty(allowedTrigger.StateName))
                    {
                        newState = this.Configuration.FoundNextState(allowedTrigger.StateAndTriggerName);
                    }
                    else
                    {
                        newState = this.Configuration.FoundNextState(allowedTrigger.StateName);
                    }

                    if (newState != null)
                    {
                        this.MyGraph.ChangeOneVertexColor(newState.Name, color);
                        CustomEdge edge = new CustomEdge(null, null);

                        if (string.Compare(currentState.Name, newState.Name) == 0)
                        {
                            this.MyGraph.Vertices.Where(v => (string.Compare(v.Text, currentState.Name) == 0)).FirstOrDefault().Represented = true;
                        }

                        edge = this.MyGraph.GetEdgeBetween(currentState.Name, newState.Name);
                        this.MyGraph.ChangeOneEdgeColor(edge, Colors.Yellow);
                    }
                }
            }

            return newState;
        }
Ejemplo n.º 15
0
		/// <summary>
		/// Updates an edge that has not been created with the provider
		/// </summary>
		/// <param name="e">vertex to update</param>
		public void UpdateEdge(CustomEdge e)
		{
			e.ID = m_NextID++;
		}
Ejemplo n.º 16
0
        public override void HideEdges(CustomVertex vertex, List<CustomEdge> edgesIn, List<CustomEdge> edgesOut)
        {
            if (vertex.BackgroundColor == Colors.Wheat || vertex.Display == true)
            {
                this.MyGraph.GetVertexByName(vertex.Text).BackgroundColor = Colors.Red;
                this.MyGraph.GetVertexByName(vertex.Text).Display = false;
                IEnumerable<CustomEdge> collectionIn = this.MyGraph.InEdges(vertex);
                IEnumerable<CustomEdge> collectionOut = this.MyGraph.OutEdges(vertex);
                foreach (var item in collectionIn)
                {
                    CustomEdge edge = new CustomEdge(item.Trigger, item.Source, item.Target);
                    edgesIn.Add(edge);
                }

                foreach (var item in collectionOut)
                {
                    CustomEdge edge = new CustomEdge(item.Trigger, item.Source, item.Target);
                    edgesOut.Add(edge);
                }

                this.MyGraph.ClearEdges(vertex);
            }
            else
            {
                MessageBox.Show("Already hidden!");
            }

        }
Ejemplo n.º 17
0
        public override void UnhideEdges(CustomVertex vertex, List<CustomEdge> edgesIn, List<CustomEdge> edgesOut)
        {
            if (vertex.BackgroundColor == Colors.Red || vertex.Display == false)
            {
                this.MyGraph.GetVertexByName(vertex.Text).BackgroundColor = Colors.Wheat;
                this.MyGraph.GetVertexByName(vertex.Text).Display = true;
                for (int i = 0; i < edgesIn.Count; i++)
                {
                    if (string.Compare(edgesIn[i].Target.Text, vertex.Text) == 0 || string.Compare(edgesIn[i].Trigger, vertex.Text) == 0)
                    {
                        CustomEdge edge = new CustomEdge(edgesIn[i].Trigger, edgesIn[i].Source, edgesIn[i].Target);
                        this.MyGraph.AddEdge(edge);
                        edgesIn.Remove(edgesIn[i]);
                        i--;
                    }
                }

                int lenghtOut = edgesOut.Count;
                for (int i = 0; i < edgesOut.Count; i++)
                {
                    if (string.Compare(edgesOut[i].Source.Text, vertex.Text) == 0)
                    {
                        CustomEdge edge = new CustomEdge(edgesOut[i].Trigger, edgesOut[i].Source, edgesOut[i].Target);
                        this.MyGraph.AddEdge(edge);
                        edgesOut.Remove(edgesOut[i]);
                        i--;
                    }
                }
            }
            else
            {
                MessageBox.Show("Nothing to unhide!");
            }
        }
Ejemplo n.º 18
0
        public override void UnhideEdges(CustomVertex vertex, List<CustomEdge> edgesIn, List<CustomEdge> edgesOut)
        {
            if (vertex.BackgroundColor == Colors.Red)
            {
                this.MyGraph.GetVertexByName(vertex.Text).BackgroundColor = Colors.Wheat;
                foreach (var item in edgesIn)
                {
                    if (string.Compare(item.Target.Text, vertex.Text) == 0)
                    {
                        CustomEdge edge = new CustomEdge(item.Trigger, item.Source, item.Target);
                        this.MyGraph.AddEdge(edge);
                    }
                }

                foreach (var item in edgesOut)
                {
                    if (string.Compare(item.Source.Text, vertex.Text) == 0)
                    {
                        CustomEdge edge = new CustomEdge(item.Trigger, item.Source, item.Target);
                        this.MyGraph.AddEdge(edge);
                    }
                }

            }
            else
            {
                MessageBox.Show("Nothing to unhide!");
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Adds a new edge, a new allowed trigger to source vertex, a new trigger if it doesn't exist.
        /// </summary>
        /// <param name="vertexFrom">The vertex from.</param>
        /// <param name="trigger">The trigger.</param>
        /// <param name="vertexTo">The vertex to.</param>
        public override void AddNewEdge(CustomVertex vertexFrom, string trigger, CustomVertex vertexTo)
        {
            FSMVState state = new FSMVState();
            AllowedTrigger aw = new AllowedTrigger();
            FSMVTrigger trig = new FSMVTrigger();
            state.Name = vertexFrom.Text;
            if (string.IsNullOrEmpty(trigger))
            {
                CustomEdge edge = new CustomEdge(vertexTo.Text, vertexFrom, vertexTo);
                this.MyGraph.AddNewEdge(vertexTo.Text, vertexFrom, vertexTo);
                aw.StateAndTriggerName = trig.CommonID = vertexTo.Text;
            }
            else
            {
                CustomEdge edge = new CustomEdge(trigger, vertexFrom, vertexTo);
                this.MyGraph.AddNewEdge(vertexTo.Text, vertexFrom, vertexTo);
                aw.StateName = vertexTo.Text;
                aw.TriggerName = trigger;
                trig.Name = vertexTo.Text;
                trig.SequenceID = trigger;
            }

            foreach (var item in this.Configuration.ArrayOfFSMVState)
            {
                if (item.Name == state.Name)
                {
                    if (item.ArrayOfAllowedTrigger == null)
                    {
                        item.ArrayOfAllowedTrigger = new Collection<AllowedTrigger>();
                    }

                    item.ArrayOfAllowedTrigger.Add(aw);
                    break;
                }
            }

            this.Configuration.AddNewTrigger(trig);
        }
Ejemplo n.º 20
0
    /// <summary>
    /// Handles the Click event of the undo control.
    /// Removes last selected vertex and edge
    /// </summary>
    private void Undo_Click(object sender, RoutedEventArgs e)
    {
      if (this.machine is FirstStateMachine)
      {
        if (this.sequenceFirstVersion.ArrayOfStep.Count > 0)
        {
          this.sequenceFirstVersion.ArrayOfStep.RemoveAt(this.sequenceFirstVersion.ArrayOfStep.Count - 1);
        }
      }
      else
      {
        if (this.sequenceSecondVersion.ArrayOfStep.Count > 0)
        {
          this.sequenceSecondVersion.ArrayOfStep.RemoveAt(this.sequenceSecondVersion.ArrayOfStep.Count - 1);
        }
      }

      if (this.listOfVertices.Count > 1)
      {
        this.machine.MyGraph.ChangeOneVertexColor(this.listOfVertices.Peek().Text, Colors.Wheat);
        CustomEdge edge = new CustomEdge(this.listOfVertices.ElementAt(1), this.listOfVertices.Peek());
        edge = this.machine.MyGraph.GetEdgeBetween(this.listOfVertices.ElementAt(1), this.listOfVertices.Pop());
        if (this.listOfVertices.Count == 1)
        {
          this.machine.MyGraph.ChangeOneVertexColor(this.listOfVertices.Peek().Text, Colors.Wheat);
        }

        this.machine.MyGraph.ChangeOneEdgeColor(edge, Colors.Black);
      }
    }
Ejemplo n.º 21
0
    /// <summary>
    /// Handles the SelectionChanged event of the veritces control.
    /// Adds the selected vertex to current sequence
    /// </summary>
    private void Veritces_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
      this.listOfVertices.Push((CustomVertex)veritces.SelectedItem);
      if (this.listOfVertices.Count > 1)
      {
        CustomEdge edge = new CustomEdge(this.listOfVertices.ElementAt(1), this.listOfVertices.Peek());
        edge = this.machine.MyGraph.GetEdgeBetween(this.listOfVertices.ElementAt(1), this.listOfVertices.Peek());
        if (edge != null)
        {
          if (edge.Source.CompareTo(edge.Target))
          {
            this.machine.MyGraph.GetVertexByName(edge.Source.Text).Represented = true;
          }

          this.machine.MyGraph.ChangeOneVertexColor(this.listOfVertices.ElementAt(this.listOfVertices.Count - 1).Text, Colors.Red);
          this.machine.MyGraph.ChangeOneVertexColor(this.listOfVertices.Peek().Text, Colors.Red);
          this.machine.MyGraph.ChangeOneEdgeColor(edge, Colors.Red);
          if (this.machine is FirstStateMachine)
          {
            ((FirstStateMachine)this.machine).AddNewStep(this.sequenceFirstVersion, edge.Trigger);
          }
          else
          {
            ((SecondStateMachine)this.machine).AddNewStep(this.sequenceSecondVersion, edge.Trigger);
          }
        }
        else
        {
          MessageBox.Show("There is no edge between these vertices! \r\n Please choose another one!");
          this.listOfVertices.Pop();
        }

        this.DataContext = this.machine.MyGraph;
      }
    }
Ejemplo n.º 22
0
        public override IEnumerable <AbstractJob> GetJobs(JobType type, JobScope scope, IEnumerable <string> names, JobConfiguration jobConfiguration)
        {
            if (CheckTypeAndScope(type, scope) || !CheckNameIsScope(names))
            {
                return(NoJobs);
            }
            Schemas = SchemaLoader.SchemaList();
            var jobs = new List <FacebookFetcher>();

            try
            {
                foreach (var schemaName in Schemas)
                {
                    foreach (var file in Directory.GetFiles(SchemaLoader.GetCredentialPath(schemaName)))
                    {
                        if (!file.Contains("_credentials.json"))
                        {
                            continue;
                        }
                        SchemaLoader.credentialFileName = file;
                        var schema = SchemaLoader.LoadSchema(schemaName);
                        var apiMan = new ApiManager(
                            SchemaLoader.GetCredentials(schemaName),
                            IgnoreCache,
                            jobConfiguration.IgnoreAPI,
                            jobConfiguration.IgnoreTTL,
                            jobConfiguration.Paginate,
                            schema.Delay,
                            CacheDirectory,
                            jobConfiguration.DefaultNowDate
                            );
                        var fetcher    = new Fetcher(apiMan, schema.PageSize);
                        var customEdge = new CustomEdge();

                        if (schemaName == "adaccount")
                        {
                            var pageSchema      = SchemaLoader.LoadSchema("page");
                            var pageCredentials = SchemaLoader.GetCredentials("page");

                            var pageApiMan = new ApiManager(
                                SchemaLoader.GetCredentials("page"),
                                IgnoreCache,
                                jobConfiguration.IgnoreAPI,
                                jobConfiguration.IgnoreTTL,
                                jobConfiguration.Paginate,
                                schema.Delay,
                                CacheDirectory,
                                jobConfiguration.DefaultNowDate
                                );
                            var pageFetcher = new Fetcher(pageApiMan, pageSchema.PageSize);

                            var key = (SchemaName : "adaccount", TableName : "ads", CustomEdgeName : "custom_videos");
                            if (!customEdge.ContainsKey(key))
                            {
                                Action <Logger, JObject> callback = (logger, parent) => {
                                    var creative = parent["creative"];

                                    var video = creative ? ["video_id"];
                                    if (video != null)
                                    {
                                        pageFetcher.GetRoot(pageSchema, "videos", video, logger);
                                    }

                                    var sourceFileVideoId = creative.IndexPathOrDefault <string>("object_story_spec.video_data.video_id", null);

                                    if (sourceFileVideoId != null)
                                    {
                                        pageFetcher.GetRoot(pageSchema, "videos", sourceFileVideoId, logger);
                                    }

                                    var post = creative ? ["object_story_id"];
                                    if (post != null)
                                    {
                                        pageFetcher.GetRoot(pageSchema, "posts", post, logger);
                                    }
                                };

                                customEdge.Add(key, callback);
                            }
                        }

                        if (Schemas.Count == 1 && TableKey != null)
                        {
                            // DEPRECATED: case in which the user specified a single edge to be executed
                            jobs.Add(new FacebookFetcher(schema, TableKey, EdgeKey, fetcher, customEdge));
                        }
                        else
                        {
                            foreach (var edge in schema.Edges)
                            {
                                jobs.Add(new FacebookFetcher(schema, edge.Key, null, fetcher, customEdge, apiMan.Secret.Id));
                            }
                            if (schemaName == "instagram")
                            {
                                jobs.Add(new FacebookFetcher(schema, null, null, fetcher, customEdge, apiMan.Secret.Id));
                            }
                        }
                    }
                }
            }
            catch (Exception e) when(e is FileNotFoundException || e is DirectoryNotFoundException)
            {
                string message = String.Format("Missing or invalid Facebook credentials!\n{0}", e.Message);

                if (e is DirectoryNotFoundException)
                {
                    message = String.Format("{0}\nCheck if the path above exists!", message);
                }
                System.Console.WriteLine(message);
                return(NoJobs);
            };

            return(FilterByName(jobs, names));
        }