public static int Main(string[] args) { // hook API logger Logger.SetLogSink(HandleLogEntry); try { string ncHostname = "JoshVM-2003"; int ncPort = 80; using (IServerSession ncSession = CSAPI.Create().CreateServerSession(ncHostname, ncPort)) { if (!Authenticate(ncSession)) { return(-1); } Console.Write("Creating proxied connection..."); INodeConnection playerConn; using (var result = ncSession.CreateProxiedConnectionToNode((Oid)PLAYER_NODE_ID)) { if (result.IsSuccess) { Console.WriteLine("success"); playerConn = result.Value; } else { Console.WriteLine("failed: " + result.ToString()); return(-2); } } Console.Write("Querying proxied node info..."); playerConn.SocketTimeout = 30; using (var result = playerConn.ExecuteCommand("Coolsign.System.GetInfo", null)) { if (result.IsSuccess) { Console.WriteLine("success" + Console.Out.NewLine + result.ReadBody()); } else { Console.WriteLine("failed: " + result.ToString()); return(-3); } } } return(0); } finally { Console.WriteLine("Press enter to continue..."); Console.ReadLine(); // unhook logger Logger.SetLogSink(null); } }
public static int Main(string[] args) { // hook API logger Logger.SetLogSink(HandleLogEntry); try { string ncHostname = "JoshVM-2003"; int ncPort = 80; using (IServerSession ncSession = CSAPI.Create().CreateServerSession(ncHostname, ncPort)) { if (!Authenticate(ncSession)) { return(-1); } // read all nodes joined to node infos Console.Write("Reading node statuses..."); using (var readResult = ncSession.DataAccess.Brokers.Node.Read( ncSession.DataAccess.ModelFactory.CreateAllSelector(), new IRelationshipMetaData[] { MetaData.NodeToNodeInfo })) { if (readResult.IsSuccess) { Console.WriteLine("found {0}", readResult.Value.Count); foreach (var node in readResult.Value.Items) { INodeInfo info = null; foreach (var i in node.NodeInfo.Items) { info = i; break; } Console.WriteLine(" Node \"{0}\": {1}", node.Name, null != info ? info.Status : ""); } } else { Console.WriteLine("failed: {0}", readResult.ToString()); return(-1); } } } return(0); } finally { // unhook logger Logger.SetLogSink(null); } }
public static int Main(string[] args) { // hook API logger Logger.SetLogSink(HandleLogEntry); try { string ncHostname = "JoshVM-2003"; int ncPort = 80; using (IServerSession ncSession = CSAPI.Create().CreateServerSession(ncHostname, ncPort)) { if (!Authenticate(ncSession)) { return(-1); } // read all Content objects from server Console.Write("Reading content objects..."); using (IValueResult <IModelCollection <IContent> > readResult = ncSession.DataAccess.Brokers.Content.Read(ncSession.ModelFactory.CreateAllSelector(), null)) { if (readResult.IsSuccess) { Console.WriteLine("success"); Console.WriteLine("Found {0} content objects", readResult.Value.Count); Console.WriteLine("["); foreach (IContent content in readResult.Value.Items) { Console.WriteLine(" {{Name=\"{0}\", Id=\"{1}\"}}", content.Name, content.Id); } Console.WriteLine("]"); } else { Console.WriteLine("failed: " + readResult.ToString()); return(-2); } } } return(0); } finally { Console.WriteLine("Press enter to continue..."); Console.ReadLine(); // unhook logger Logger.SetLogSink(null); } }
public DataTableEditorWindow() { m_api = CSAPI.Create(); InitializeComponent(); OnLoad(); m_connectButton.Click += m_connectButton_Click; m_tableComboBox.SelectionChanged += m_tableComboBox_SelectionChanged; m_addRowButton.Click += m_addRowButton_Click; m_saveRowsButton.Click += m_saveRowsButton_Click; m_addTableToWatch.Click += m_addTableToWatch_Click; m_editWatchSets.Click += m_editWatchSets_Click; }
public static int Main(string[] args) { // hook API logger Logger.SetLogSink(HandleLogEntry); try { string ncHostname = "JoshVM-2003"; int ncPort = 80; using (IServerSession ncSession = CSAPI.Create().CreateServerSession(ncHostname, ncPort)) { if (!Authenticate(ncSession)) { return(-1); } // find datatable id for trigger payload if (!IdentifyTriggerPayloadDataTable(ncSession)) { return(-2); } // clear out old triggers -- you don't have to do this, payload rows will be automatically GC'd after their expiration date; this is just an example of how to synchronously deactivate triggers if (!DeactivateTriggers(ncSession)) { return(-3); } // activate trigger if (!ActivateTrigger(ncSession)) { return(-4); } } return(0); } finally { Console.WriteLine("Press enter to continue..."); Console.ReadLine(); // unhook logger Logger.SetLogSink(null); } }
public static int Main(string[] args) { // hook API logger Logger.SetLogSink(HandleLogEntry); try { // in most cases this would just be localhost, but I'm actually connecting to a remote node string hostname = "JoshVM-XP"; int port = 80; // we use INodeConnection here because this node does not have to be (and probably is not) the NC Console.WriteLine("Connecting to node..."); using (INodeConnection conn = CSAPI.Create().CreateNodeConnection(hostname, port)) { // pull the data local to this node (part of which are the node attributes) Console.Write("Retrieving node data..."); using (var result = conn.LocalData.ReadNodeData()) { if (result.IsSuccess) { Console.WriteLine("success, {0} node attributes found", result.Value.Attributes.Count); foreach (string attrName in result.Value.Attributes.Keys) { Console.WriteLine(" NodeAttribute {{ Name = \"{0}\", Value = \"{1}\" }}", attrName, result.Value.Attributes[attrName]); } } else { Console.WriteLine("failed: " + result.ToString()); return(-1); } } } return(0); } finally { // unhook API logger Logger.SetLogSink(null); } }
public MainWindow() { InitializeComponent(); m_nodeComboBox.ItemsSource = m_nodes; m_nodeComboBox.SelectionChanged += m_nodeComboBox_SelectionChanged; m_transferView.ItemsSource = m_transfers; m_session = CSAPI.Create().CreateServerSession(HOST, PORT); using (var result = m_session.Authenticate(USERNAME, PASSWORD)) { if (!result.IsSuccess) { m_errors.Text = "Login failed: " + result.ToString(); m_session.Dispose(); m_session = null; return; } } using (var result = m_session.DataAccess.Brokers.Node.Read(m_session.ModelFactory.CreateAllSelector(), null)) { if (result.IsSuccess) { foreach (INode node in result.Value.Items) { NodeModel nm = new NodeModel() { Name = node.Name, Id = node.Id.ToString(), }; m_nodes.Add(nm); } } else { m_errors.Text = result.ToString(); return; } } }
public static int Main(string[] args) { // hook API logger Logger.SetLogSink(HandleLogEntry); try { string ncHostname = "JoshVM-2003"; int ncPort = 80; using (IServerSession ncSession = CSAPI.Create().CreateServerSession(ncHostname, ncPort)) { if (!Authenticate(ncSession)) { return(-1); } // read all node attribute definitions var attrDefs = ReadAllAttributeDefs(ncSession); if (null == attrDefs) { return(-2); } // delete any defs with my name if (!DeleteMyAttributes(ncSession)) { return(-3); } // read all node attribute definitions attrDefs = ReadAllAttributeDefs(ncSession); if (null == attrDefs) { return(-2); } // create my custom node attribute defintion if (!CreateMyAttribute(ncSession)) { return(-4); } // read all node attribute definitions attrDefs = ReadAllAttributeDefs(ncSession); if (null == attrDefs) { return(-2); } // update the default value of my node attribute definition if (!UpdateMyAttribute(ncSession)) { return(-5); } // read all node attribute definitions attrDefs = ReadAllAttributeDefs(ncSession); if (null == attrDefs) { return(-2); } // find a node id (you'll probably already know the node id or name you're interested in, but here's how to do it) Oid nodeId = FindANodeId(ncSession); if (null == nodeId) { return(-6); } // read the current values of the node's attributes if (!ReadNodeAttributeValues(nodeId, ncSession)) { return(-7); } // set the value of my node attribute for the node if (!SetNodeAttributeValue(nodeId, "new value", ncSession)) { return(-8); } // read the current values of the node's attributes if (!ReadNodeAttributeValues(nodeId, ncSession)) { return(-7); } } return(0); } finally { // unhook logger Logger.SetLogSink(null); } }
public static int Main(string[] args) { Logger.SetLogSink(HandleLogEntry); try { CSAPI api = CSAPI.Create(); // first create a node connection directly to the node whose local data store we want to modify using (INodeConnection tnConn = api.CreateNodeConnection(HOST, PORT)) { // we need a local session context to use the local data table apis Console.Write("Establishing local session with node..."); using (var result = tnConn.CreateLocalSession()) { if (result.IsSuccess) { Console.WriteLine("success"); } else { Console.WriteLine("failed: " + result.ToString()); return(1001); } } // we need to figure out if the table already exists in the local store or not, so we'll try to read it from there first bool isAlreadyInLocalStore; Console.Write("Reading table from local data store..."); using (var result = tnConn.LocalData.ReadLocalDataTable(TABLE_ID)) { if (result.IsSuccess) { Console.WriteLine("found it"); isAlreadyInLocalStore = true; } else if (result.ErrorType == CommandErrorType.ServerError && result.ServerErrorCode == ServerErrorType.ObjectNotFound) { Console.WriteLine("doesn't exist"); isAlreadyInLocalStore = false; } else { Console.WriteLine("failed: " + result.ToString()); return(1002); } } // this is the object which will contain all the changes we're going to make to the table IDataTableChangeSet changes = tnConn.LocalData.CreateDataTableChangeSet(); // if the table does not yet exist in the local store, then we must save the schema with the update; if it does already exist then we can just update rows if (!isAlreadyInLocalStore) { // what is the schema? we'll pull it from the network cached version of the table (the one downloaded from the parent node) // for this to work, the table would need to be associated with the node in some way. E.g. if it were bound to a content in the schedule of this node, or one if this node's descendants. Console.Write("Reading table from network cache..."); using (var result = tnConn.LocalData.ReadCachedDataTable(TABLE_ID)) { if (result.IsSuccess) { Console.WriteLine("found it"); IDataTable networkCopy = result.Value; // add the table & fields to our local store changes changes.UpdateTable(networkCopy); foreach (IDataTableField field in networkCopy.DataTableDesigns.Items.First().DataTableFields.Items) { changes.UpdateField(field); } } else if (result.ErrorType == CommandErrorType.ServerError && result.ServerErrorCode == ServerErrorType.ObjectNotFound) { Console.WriteLine("doesn't exist, aborting"); return(1003); } else { Console.WriteLine("failed: " + result.ToString()); return(1004); } } } // first delete all existing rows, you may not want to do this if you're appending a row changes.DeleteAllRows(); // now add the new row IDataRow row = tnConn.ModelFactory.CreateDataRow(); row.ActivationDate = new DateTime(1600, 1, 1); row.ExpirationDate = new DateTime(3000, 1, 1); row.SequenceNumber = 0; row.Values[FIELD_1] = "some value"; changes.UpdateRow(row); // save changes into local store Console.Write("Updating table in local store..."); using (var result = tnConn.LocalData.UpdateLocalDataTable(TABLE_ID, changes, false)) { if (result.IsSuccess) { Console.WriteLine("success"); } else { Console.WriteLine("failed: " + result.ToString()); return(1005); } } } } finally { Console.WriteLine("Press enter to exit"); Console.ReadLine(); Logger.SetLogSink(null); } return(0); }
public static int Main(string[] args) { int ret = 0; Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; Program.interrupted = true; }; int res; string ncHostname = "10.50.149.13"; int ncPort = 80; IServerSession session = CSAPI.Create().CreateServerSession(ncHostname, ncPort); //Authenticate(session); bool authenticated; do { authenticated = Authenticate(session); }while (!authenticated); while (!Program.interrupted) { Console.WriteLine("Updating internal database..."); Console.WriteLine((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + Properties.Settings.Default.dbfilepath)); WatchedSets sets = new WatchedSets((Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + Properties.Settings.Default.dbfilepath)); foreach (w_set toLoad in sets.all_set) { workingConf = new SetConfig(toLoad.TABLE_DB_PATH); res = importItem(session, workingConf); Console.WriteLine("Updating table: " + toLoad.TABLE_NAME); if (res == 2) //Server Timeout { Console.WriteLine("Server timeout, disconnecting . . ."); bool reauthen = false; do { Thread.Sleep(5000); session = CSAPI.Create().CreateServerSession(ncHostname, ncPort); reauthen = Authenticate(session); }while (!reauthen); break; } else if (res == -1) { Console.WriteLine("Authentication error, retrying . . ."); bool reauthen = false; do { Thread.Sleep(5000); session = CSAPI.Create().CreateServerSession(ncHostname, ncPort); reauthen = Authenticate(session); }while (!reauthen); break; } else { Console.WriteLine("Updated: " + toLoad.TABLE_NAME); } } Console.WriteLine("Finished... Sleeping..."); Thread.Sleep(900000); } return(ret); }