I use NetOffice.PowerPointApi to play some Powerpoint-Slides of an existing PPTX. This is how this is done:
PowerPoint.Application powerApplication = new PowerPoint.Application();
PowerPoint.Presentation presentation = powerApplication.Presentations.Open("C:\\dev\\test.pptx", MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoTrue);
// presentation.SlideShowSettings.StartingSlide = 2;
presentation.SlideShowSettings.Run();
while (powerApplication.ActivePresentation.SlideShowWindow.View.CurrentShowPosition < 4)
{
System.Threading.Thread.Sleep(2000);
powerApplication.ActivePresentation.SlideShowWindow.View.Next();
}
Now my plan was to display slide 3 to 4.
But when I set the startingSlide (commented out in my example) I receive an error on powerApplication.ActivePresentation.SlideShowWindow.View.CurrentShowPosition :
{"SlideShowView.CurrentShowPosition : Invalid request. There is
currently no slide show view for this presentation."}
This only happens when I set the property StartingSlide. If I don't, the presentation runs from the first until the 4th slide.
You need to set more properties of the SlideShowSettings object:
using NetOffice.OfficeApi.Enums;
using NetOffice.PowerPointApi.Enums;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PowerPoint = NetOffice.PowerPointApi;
namespace PlayPowerPoint
{
class Program
{
static void Main(string[] args)
{
using (var app = new PowerPoint.Application())
{
var presentation = app.Presentations.Open(Path.GetFullPath("Test.pptx"), MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
var slideShowSettings = presentation.SlideShowSettings;
slideShowSettings.StartingSlide = 2;
slideShowSettings.EndingSlide = 4;
slideShowSettings.RangeType = PpSlideShowRangeType.ppShowSlideRange;
slideShowSettings.AdvanceMode = PpSlideShowAdvanceMode.ppSlideShowManualAdvance;
slideShowSettings.Run();
var slideShowView = presentation.SlideShowWindow.View;
while (slideShowView.CurrentShowPosition < slideShowSettings.EndingSlide)
{
Thread.Sleep(2000);
slideShowView.Next();
}
presentation.Saved = MsoTriState.msoTrue;
presentation.Close();
app.Quit();
}
}
}
}
Related
I'm trying to detect circles on an image, however I don't know what I'm doing wrong but the code is getting for me only 2 circles on the right as shown on the image below:
Here it is the code that I have tried:
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Windows.Forms.VisualStyles;
using OpenCvSharp;
using Point = System.Drawing.Point;
namespace ConsoleApplication1
{
internal class Program
{
public static void Main(string[] args)
{
Mat image = Cv2.ImRead(#"C:\Users\User\Desktop\pool.jpg", ImreadModes.Color);
Mat cImage = image.Clone();
Mat grayedColor = new Mat();
Cv2.CvtColor(cImage, grayedColor, ColorConversionCodes.BGR2GRAY);
var cirlce = Cv2.HoughCircles(grayedColor, HoughModes.Gradient, 1.2, 1);
foreach (var cirl in cirlce)
{
cImage.Circle(cirl.Center.ToPoint(), (int)cirl.Radius, Scalar.Magenta, 2, LineTypes.Link4);
}
Stopwatch timer = new Stopwatch();
timer.Start();
Cv2.ImShow("Original", cImage);
Cv2.ImShow("Grayed Color", grayedColor);
Console.WriteLine(timer.Elapsed.ToString(#"m\:ss\.fff"));
Cv2.WaitKey();
Cv2.DestroyAllWindows();
}
}
}
Please if you post a solution explain to me what I'm doing wrong exactly.
I try to get balance in address.
It is my code:
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nethereum.Web3;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Bananas().Wait();
}
static private async Task Bananas()
{
var publicKey = "0xC0b4ec83028307053Fbe8d00ba4372384fe4b52B";
var web3 = new Nethereum.Web3.Web3("https://ropsten.infura.io/myInfura");
//var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(publicKey);
var balance = await web3.Eth.GetBalance.SendRequestAsync(publicKey);
var etherAmount = Web3.Convert.FromWei(balance.Value);
Console.WriteLine(web3);
Console.WriteLine("Get txCount ", etherAmount);
Console.ReadLine();
}
}
}`
I installed Nethereum via PM console: Nethereum.
I use a normal link of infura.
Why don`t I get a next result without the balance in address?
I have just made a console application with your code and all the data is coming back fine from Nethereum.
Your issue is with your Console.WriteLine(... You are passing the etherAmount as a arg0 property into the Console.WriteLine which will not output correctly on the console when you run it.
Try this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nethereum.Web3;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Bananas().Wait();
}
static private async Task Bananas()
{
var publicKey = "0xC0b4ec83028307053Fbe8d00ba4372384fe4b52B";
var web3 = new Nethereum.Web3.Web3("https://ropsten.infura.io/myInfura");
//var txCount = await web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(publicKey);
var balance = await web3.Eth.GetBalance.SendRequestAsync(publicKey);
var etherAmount = Web3.Convert.FromWei(balance.Value);
Console.WriteLine(web3);
Console.WriteLine("Get txCount " + etherAmount);
Console.ReadLine();
}
}
}
ps nice 1110.337873197299357846 ETH ;) (i know it is only test ETH but we can dream)
And when I quit the program the mp4 file deleted automatic.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DirectShowLib;
using DirectShowLib.BDA;
using DirectShowLib.DES;
using DirectShowLib.DMO;
using DirectShowLib.Dvd;
using DirectShowLib.MultimediaStreaming;
using DirectShowLib.SBE;
using System.Runtime.InteropServices;
using System.Management;
using System.IO;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Video.FFMPEG;
using AForge.Video.VFW;
using System.Drawing.Imaging;
namespace Youtube_Manager
{
public partial class Elgato_Video_Capture : Form
{
IFileSinkFilter sink;
IFilterGraph2 graph;
ICaptureGraphBuilder2 captureGraph;
Size videoSize;
string error = "";
List<Object> devices = new List<Object>();
IMediaControl mediaControl;
public Elgato_Video_Capture()
{
InitializeComponent();
if (comboBox1.Items.Count == 0)
{
for (int xx = 1; xx <= 8; xx++)
{
comboBox1.Items.Add(xx);
}
}
InitDevice();
}
IPin outPin;
IPin inPin;
private void InitDevice()
{
try
{
//Set the video size to use for capture and recording
videoSize = new Size(827, 505);//1280, 720);
//Initialize filter graph and capture graph
graph = (IFilterGraph2)new FilterGraph();
captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
captureGraph.SetFiltergraph(graph);
//Create filter for Elgato
Guid elgatoGuid = new Guid("39F50F4C-99E1-464A-B6F9-D605B4FB5918");
Type comType = Type.GetTypeFromCLSID(elgatoGuid);
IBaseFilter elgatoFilter = (IBaseFilter)Activator.CreateInstance(comType);
graph.AddFilter(elgatoFilter, "Elgato Video Capture Filter");
//Create smart tee filter, add to graph, connect Elgato's video out to smart tee in
IBaseFilter smartTeeFilter = (IBaseFilter)new SmartTee();
graph.AddFilter(smartTeeFilter, "Smart Tee");
outPin = GetPin(elgatoFilter, "Video");
inPin = GetPin(smartTeeFilter, "Input");
graph.Connect(outPin, inPin);
//Create video renderer filter, add it to graph, connect smartTee Preview pin to video renderer's input pin
IBaseFilter videoRendererFilter = (IBaseFilter)new VideoRenderer();
graph.AddFilter(videoRendererFilter, "Video Renderer");
outPin = GetPin(smartTeeFilter, "Capture");
inPin = GetPin(videoRendererFilter, "Input");
graph.Connect(outPin, inPin);
captureGraph.SetOutputFileName(MediaSubType.Avi, #"e:\screenshots\test1.mp4", out smartTeeFilter, out sink);
sink.SetFileName(#"e:\screenshots\test1.mp4", null);
//Render stream from video renderer
captureGraph.RenderStream(PinCategory.Capture, MediaType.Video, videoRendererFilter, null, null);
//Set the video preview to be the videoFeed panel
IVideoWindow vw = (IVideoWindow)graph;
vw.put_Owner(pictureBox1.Handle);
vw.put_MessageDrain(this.Handle);
vw.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
vw.SetWindowPosition(0, 0, 827, 505);
//Start the preview
mediaControl = graph as IMediaControl;
mediaControl.Run();
}
catch (Exception err)
{
error = err.ToString();
}
}
IPin GetPin(IBaseFilter filter, string pinname)
{
IEnumPins epins;
int hr = filter.EnumPins(out epins);
checkHR(hr, "Can't enumerate pins");
IntPtr fetched = Marshal.AllocCoTaskMem(4);
IPin[] pins = new IPin[1];
while (epins.Next(1, pins, fetched) == 0)
{
PinInfo pinfo;
pins[0].QueryPinInfo(out pinfo);
bool found = (pinfo.name == pinname);
DsUtils.FreePinInfo(pinfo);
if (found)
return pins[0];
}
checkHR(-1, "Pin not found");
return null;
}
public void checkHR(int hr, string msg)
{
if (hr < 0)
{
MessageBox.Show(msg);
DsError.ThrowExceptionForHR(hr);
}
}
}
I added this part now to my code:
captureGraph.SetOutputFileName(MediaSubType.Avi, #"e:\screenshots\test1.mp4", out smartTeeFilter, out sink);
sink.SetFileName(#"e:\screenshots\test1.mp4", null);
I see the preview but the mp4 file is empty it's not saving the video to the file at all.
What I wanted to do is to save the video stream using the directshow to a mp4 file.
Now all I can get is to see a preview of the video in a pictureBox.
You don't capture to a MP4-File, you capture to an AVI-File with just an MP4-extension! DirectShow has no native MP4-Mux. You need to install one seperatly like the GDCL MP4 Mux.
I don't think your connections are working correctly. With DirectShowNet you need to check the return codes and then throw the exceptions yourself, like:
int hr = graph.Connect(outPin, inPin);;
DsError.ThrowExceptionForHR(hr);
Your captureGraph.RenderStream is useless because a VideoRender-Filter has no output-pin. Please look at the meaning of this function. You can better build this graph with just RenderStream, it is even inserting the SmartTee-Filter for you.
Unable to connect to server localhost:27017:
No connection could be made because the target machine actively refused it 127.0.0.1:27017.
This exception appears when i run a console application with C# using mongoDB
I've downloaded CSharpDriver-1.4.1.4490.msi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace ConsoleApplication4
{
public class Entity
{
public ObjectId Id { get; set; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
var connectionString = "mongodb://localhost:27017";
var server = MongoServer.Create(connectionString);
var database = server.GetDatabase("test");
var collection = database.GetCollection<Entity>("entities");
var entity = new Entity { Name = "Tom" };
collection.Insert(entity);
var id = entity.Id;
var query = Query.EQ("_id", id);
entity = collection.FindOne(query);
entity.Name = "Dick";
collection.Save(entity);
var update = Update.Set("Name", "Harry");
collection.Update(query, update);
collection.Remove(query);
}
}
I would follow the directions here, on the Mongo site. Windows quickstart is a really good resource to get started using Mongo on windows.
As far as connecting to the Mongo instance in .Net, if you didn't do anything special during the installation of Mongo, you shouldn't have to explicitly give a connection string. The following code works for my generic set up of Mongo.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Conventions;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Bson.Serialization.Options;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver.Builders;
using MongoDB.Driver.GridFS;
using MongoDB.Driver.Wrappers;
namespace MongoDB
{
class Program
{
static void Main(string[] args)
{
MongoServer server;
MongoDatabase moviesDb;
server = MongoServer.Create();
moviesDb = server.GetDatabase("movies_db");
//Create some data
var movie1 = new Movie { Title = "Indiana Jones and the Raiders of the Lost Ark", Year = "1981" };
movie1.AddActor("Harrison Ford");
movie1.AddActor("Karen Allen");
movie1.AddActor("Paul Freeman");
var movie2 = new Movie { Title = "Star Wars: Episode IV - A New Hope", Year = "1977" };
movie2.AddActor("Mark Hamill");
movie2.AddActor("Harrison Ford");
movie2.AddActor("Carrie Fisher");
var movie3 = new Movie { Title = "Das Boot", Year = "1981" };
movie3.AddActor("Jürgen Prochnow");
movie3.AddActor("Herbert Grönemeyer");
movie3.AddActor("Klaus Wennemann");
//Insert the movies into the movies_collection
var moviesCollection = moviesDb.GetCollection<Movie>("movies_collection");
//moviesCollection.Insert(movie1);
//moviesCollection.Insert(movie2);
//moviesCollection.Insert(movie3);
var query = Query.EQ("Year","1981");
var movieFound = moviesDb.GetCollection<Movie>("movies_collection").Drop();
}
}
}
I got a new question, what firewall settings is needed for blocking an IP address ? I found the property "RemoteAddress", like firewallRule.RemoteAddress, but I dont know how to use it. This is what I found on stackoverflow ( following code blocks all access to internet ), Thanks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NETCONLib;
using NATUPNPLib;
using NetFwTypeLib;
namespace WindowsFormsApplication1
{
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
INetFwRule firewallRule = (INetFwRule)Activator.CreateInstance(
Type.GetTypeFromProgID("HNetCfg.FWRule"));
firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;
firewallRule.Description = "Used to block all internet access.";
firewallRule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_OUT;
firewallRule.Enabled = true;
firewallRule.InterfaceTypes = "All";
firewallRule.Name = "Block Internet";
INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(
Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
firewallPolicy.Rules.Add(firewallRule);
}
}
}
You can use list of ip addresses (subnets, aliases) splitted by commas
$Rule.RemoteAddresses = RemoteAddresses = 'LocalSubnet,10.1.1.1/255.255.255.255,12.5.0.0/255.255.0.0'
As far as I can tell, you have to retrieve the RemoteAddresses list first before adding to it. Otherwise, it just overwrites each IP with the next one. The format needs to be as Jan described in his/her answer. However, the subnet "/255.255.255.255" is not needed when adding a single IP address. My app only blocks a single ip at a time, but you can put ranges in there as Jan describes. Most the credit goes to others on SO with exception of the RemoteAddresses part. If there's a better/cleaner way, I would love to hear it. Here's how I ended up doing it:
private void BlockIp(string ip, string ruleName)
{
INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
INetFwRule firewallRule = firewallPolicy.Rules.OfType<INetFwRule>().Where(x => x.Name == ruleName).FirstOrDefault();
if (firewallRule == null)
{
firewallRule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
firewallRule.Name = ruleName;
firewallPolicy.Rules.Add(firewallRule);
firewallRule.Description = "Block inbound traffic";
firewallRule.Profiles = (int)NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_ALL;
firewallRule.Protocol = (int)NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP;
firewallRule.Direction = NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN;
firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;
//firewallRule.LocalPorts = "8080";
//firewallRule.Grouping = "#firewallapi.dll,-23255";
firewallRule.Enabled = true;
firewallRule.RemoteAddresses = ip;
//firewallPolicy.Rules.Add(firewallRule); //throws error, not needed
} else {
var remoteAddresses = firewallRule.RemoteAddresses;
firewallRule.RemoteAddresses = remoteAddresses + "," + ip;
}
}