i need to give statistic about my publisher app
like how many subscribers are there?
i cant seen to get that information from the redis server
i already tried to find in the 'ServiceStack.Redis.RedisSubscription'
i found this:
var channel = ConfigurationManager.AppSettings["redis_channel"];
var _redisClient = new RedisClient("localhost", 6379);
var subscription = _redisClient.CreateSubscription();
//subscription.SubscribeToChannels(channel);
var subscription_count = (int)subscription.SubscriptionCount
but it returning 0 every time.
any ideas?
edit:
i found this http://redis.io/commands/client-list
but steel need some help on how to use it
thanks : )
i got it!
if anyone need that's i did:
var redis_ip = ConfigurationManager.AppSettings["redis_server_ip"];
var redis_port = ConfigurationManager.AppSettings["redis_server_port"];
int redis_port_int = 0;
if (!int.TryParse(redis_port, out redis_port_int))
{
redis_port_int = 6739;
}
RedisNativeClient rnClient = new RedisNativeClient(redis_ip, redis_port_int);
var clientlist_byte = rnClient.ClientList();
var clientlist_string = Encoding.UTF8.GetString(clientlist_byte);
var clientamount_double = clientlist_string.Split("\n".ToCharArray()).Length;
var clientlist_int = (clientamount_double/2) - 1;
return clientlist_int;
the '-1' is to remove my selt from the count,
the /2 it's because after the split i get a doubled amount
Related
This is my code for query.
String query = 'abc';
CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey });
Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query);
listRequest.Cx = searchEngineId;
search_results = listRequest.Execute();
How can I add options like filtering here?
I searched whole internet and github but I couldn't find any sample code or proper documentation.
I changed the code like this and it works.
CustomsearchService customSearchService = new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey });
Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query);
listRequest.Cx = searchEngineId;
listRequest.Start = 20;
listRequest.Num = 5;
search_results = listRequest.Execute();
But it generates error if listRequest.Start = 100 or listRequest.Num = 12
If the question is like in title about paging then CseResource.ListRequest listRequest has property Start - there you can specify from which result you want to get data (keep in mind only 10 results per query are returned).
So first time you execute it without Start set, and every sub-call to execute should increase Start by 10.
If additional filters - also listRequest contains properties like i.e. FileType, DateRestrict etc.
EDIT:
I'm using this page:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list
I've used NEST for elasticsearch for a while now and up until now I've used the regular ElasticSearchClient.Index(...) function, but now I want to index many items in a bulk operation.
I found the IndexMany(...) function, but I must do something wrong because nothing is added to the elastic search database as it does with the regular Index(...) function?
Does anyone have any idea?
Thanks in advance!
I found the problem. I had to specifiy the index name in the call to IndexMany
var res = ElasticClient.CreateIndex("pages", i => i.Mappings(m => m.Map<ESPageViewModel>(mm => mm.AutoMap())));
var page = new ESPageViewModel
{
Id = dbPage.Id,
PageId = dbPage.PageId,
Name = dbPage.Name,
Options = pageTags,
CustomerCategoryId = saveTagOptions.CustomerCategoryId,
Link = dbPage.Link,
Price = dbPage.Price
};
var pages = new List<ESPageViewModel>() { page };
var res2 = ElasticClient.IndexManyAsync<ESPageViewModel>(pages, "pages");
This works as expected. Guess I could specify a default index name in the configuration to avoid specifying the index for the IndexMany call.
If you are using C# you should create a list of objects that you want to insert then call the IndexMany function.
Example :
List<Business> businessList = new List<Business>();
#region Fill the business list
...............................
#endregion
if (businessList.Count == 1000) // the size of the bulk.
{
EsClient.IndexMany<Business>(businessList, IndexName);
businessList.Clear();
}
And in the end check again
if (businessList.Count > 0)
{
EsClient.IndexMany<Business>(businessList, IndexName);
}
Thanks in advance.
I am trying to query an object and create anonymous type from the result. I am using a function inside the linq query. At this stage i am getting an error saying "Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function..."
Please find below my sample code.
var serviceResult = _service.GeResponse(panId, numberOfTransactions, startDate, endDate);
var balanceTrans = GetAllTypes<BalanceAdjustment>(serviceResult);
var presentmentTrans = GetAllTypes<Presentment>(serviceResult);
var test = balanceTrans.AsEnumerable();
var obj = test.Select(item => new SearchCardTransactionResult
{
PanId = item.PanId,
CardNumber = item.CardNumberFormatted,
Balance = item.FinancialBalance,
BillingAmount = Math.Abs(item.BillingAmount).Format(),
BillingCurrency = GetCurrencyCode(item.BillingCurrency)
});
private IList<T> GetAllTypes<T>(GetTransactionsResponse result)
where T : ValitorServices.ValitorPanWS.AbstractFinancialTransaction
{
return result.FinanacialTransactions.OfType<T>().ToList();
}
Could anyone advice what am i doing wrong here?
Many Thanks
I managed to resolve by using the following code.
var currencyCodes = _service.GetCurrencyCodes().ToList();
var test = balanceTrans.AsEnumerable();
var obj = test.AsEnumerable().Select(item => new SearchCardTransactionResult
{
PanId = item.PanId,
CardNumber = item.CardNumberFormatted,
Balance = item.FinancialBalance,
BillingAmount = Math.Abs(item.BillingAmount).Format(),
BillingCurrency = currencyCodes.First(c=>c.NumericCode.Equals(item.BillingCurrency)).AlphabeticCode
});
I know what index out of bounds is all about. When I debug I see why as well. basically what is happening is I do a filter on my database to look for records that are potential/pending. I then gather a array of those numbers send them off to another server to check to see if those numbers have been upgraded to a sale. If it has been upgraded to a sale the server responds back with the new Sales Order ID and my old Pending Sales Order ID (SourceID). I then do a for loop on that list to filter it down that specific SourceID and update the SourceID to be the Sales Order ID and change a couple of other values. Problem is is that when I use that filter on the very first one it throws a index out of bounds error. I check the results returned by the filter and it says 0. Which i find kind of strange because I took the sales order number from the list so it should be there. So i dont know what the deal is. Here is the code in question that throws the error. And it doesn't do it all the time. Like I just ran the code this morning and it didn't throw the error. But last night it did before I went home.
filter.RowFilter = string.Format("Stage = '{0}'", Potential.PotentialSale);
if (filter.Count > 0)
{
var Soids = new int[filter.Count];
Console.Write("Searching for Soids - (");
for (int i = 0; i < filter.Count; i++)
{
Console.Write(filter[i][1].ToString() + ",");
Soids[i] = (int)filter[i][1];
}
Console.WriteLine(")");
var pendingRecords = Server.GetSoldRecords(Soids);
var updateRecords = new NameValueCollection();
for (int i = 0; i < pendingRecords.Length; i++)
{
filter.RowFilter = "Soid = " + pendingRecords[i][1];
filter[0].Row["Soid"] = pendingRecords[i][0];
filter[0].Row["SourceId"] = pendingRecords[i][1];
filter[0].Row["Stage"] = Potential.ClosedWon;
var potentialXML = Potential.GetUpdatePotentialXML(filter[0].Row["Soid"].ToString(), filter[0].Row["Stage"].ToString());
updateRecords.Add(filter[0].Row["ZohoID"].ToString(), potentialXML);
}
if i'm counting right line 17 is the error where the error is thrown. pendingRecords is a object[][] array. pendingRecords[i] is the individual records. pendingRecords[i][0] is the new Sales OrderID (SOID) and pendingRecords[i][1] is the old SOID (now the SourceID)
Any help on this one? is it because i'm changing the SOID to the new SOID, and the filter auto updates itself? I just don't know
Well I ended up changing how it worked all together and it actually sorts it a bit nicer now. The code i am about to post has a bunch of hard coded numbers due to the structure of my table that is returned. Sorry about that. I have learned since then to not do that, but i am working on a different project now and will change that when I have to change the program. But here is the solution.
var potentials = Server.GetNewPotentials(); //loads all records from server
for (int i = 0; i < potentials.Length; i++)
{
var filter = AllPotentials.DefaultView;
var result1 = CheckSoidOrSource(potentials[i].Soid, true);
var result2 = CheckSoidOrSource(potentials[i].SourceID,false) ;
//This potential can't be found at all so let's add it to our table
if (result1+result2==0)
{
Logger.WriteLine("Found new record. Adding it to DataTable and sending it to Zoho");
AllPotentials.Add(potentials[i]);
filter.RowFilter = string.Format("Soid = '{0}'", potentials[i].SourceID);
var index = AllPotentials.Rows.IndexOf(filter[0].Row);
ZohoPoster posterInsert = new ZohoPoster(Zoho.Fields.Potentials, Zoho.Calls.insertRecords);
AllPotentials.Rows[index]["ZohoID"] = posterInsert.PostNewPotentialRecord(3, filter[0].Row);
}
//This potential is not found, but has a SourceId that matches a Soid of another record.
if (result1==0 && result2 == 1)
{
Logger.WriteLine("Found a record that needs to be updated on Zoho");
ZohoPoster posterUpdate = new ZohoPoster(Zoho.Fields.Potentials, Zoho.Calls.updateRecords);
filter.RowFilter = string.Format("Soid = '{0}'", potentials[i].SourceID);
var index = AllPotentials.Rows.IndexOf(filter[0].Row);
AllPotentials.Rows[index]["Soid"] = potentials[i].Soid;
AllPotentials.Rows[index]["SourceId"] = potentials[i].SourceID;
AllPotentials.Rows[index]["PotentialStage"] = potentials[i].PotentialStage;
AllPotentials.Rows[index]["UpdateRecord"] = true;
AllPotentials.Rows[index]["Amount"] = potentials[i].Amount;
AllPotentials.Rows[index]["ZohoID"] = posterUpdate.UpdatePotentialRecord(3, filter[0].Row);
}
}
AllPotentials.AcceptChanges();
}
private int CheckSoidOrSource(string Soid, bool checkSource)
{
var filter = AllPotentials.DefaultView;
if (checkSource)
filter.RowFilter = string.Format("Soid = '{0}' OR SourceId = '{1}'",Soid, Soid);
else
filter.RowFilter = string.Format("Soid = '{0}'", Soid);
return filter.Count;
}
basically what is happening is that i noticed something about my data when I filter it this way. The two results would only return the following results (0,0) (0,1) and (1,0) (0,0) means that the record doesn't exist at all in this table so I need to add it. (1,0) means that the Sales Order ID (Soid) matches another Soid in the table so it already exists. Lastly (0,1) means that the Soid doesn't exist in this table but i found a record that has the Soid as it's source...which to me means that the one that had it as a source has been upgraded from a potential to a sale, which in turn means i have to update the record and Zoho. This worked out to much less work for me because now I don't have to search for won and lost records, i only have to search for lost records. less code same results is always a good thing :)
A list of every update and hotfix that has been installed on my computer, coming from either Microsoft Windows Update or from the knowledge base. I need the ID of each in the form of KBxxxxxx or some similar representation...
Currently I have:
const string query = "SELECT HotFixID FROM Win32_QuickFixEngineering";
var search = new ManagementObjectSearcher(query);
var collection = search.Get();
foreach (ManagementObject quickFix in collection)
Console.WriteLine(quickFix["HotFixID"].ToString());
But this does not seem to list everything, it only lists QFE's.
I need it to work on Windows XP, Vista and 7.
After some further search on what I've found earlier. (Yes, the same as VolkerK suggests first)
Under VS2008 CMD in %SystemRoot%\System32\ run a command to get a managed dll:
tlbimp.exe wuapi.dll /out=WUApiInterop.dll
Add WUApiInterop.dll as a project reference so we see the functions.
Using the following code I can get a list from which I can extract the KB numbers:
var updateSession = new UpdateSession();
var updateSearcher = updateSession.CreateUpdateSearcher();
var count = updateSearcher.GetTotalHistoryCount();
var history = updateSearcher.QueryHistory(0, count);
for (int i = 0; i < count; ++i)
Console.WriteLine(history[i].Title);
You can use IUpdateSession3::QueryHistory Method.
The properties of the returned entries are described at http://msdn.microsoft.com/en-us/library/aa386400(VS.85).aspx
Set updateSearch = CreateObject("Microsoft.Update.Session").CreateUpdateSearcher
Set updateHistory = updateSearch.QueryHistory(1, updateSearch.GetTotalHistoryCount)
For Each updateEntry in updateHistory
Wscript.Echo "Title: " & updateEntry.Title
Wscript.Echo "application ID: " & updateEntry.ClientApplicationID
Wscript.Echo " --"
Next
edit: also take a look at http://msdn.microsoft.com/en-us/library/aa387287%28VS.85%29.aspx
const string querys = "SELECT HotFixID FROM Win32_QuickFixEngineering";
var search = new ManagementObjectSearcher(querys);
var collection = search.Get();
foreach (ManagementObject quickfix in collection)
{
hotfix = quickfix["HotFixID"].ToString();
}
listBox1.Items.Add(hotfix);
This will populate the listbox with currently installed Hotfixes or Updates
If you want to list all history of updates and hotfixes to show
then, the above example of Tom Wijsman as stated will work
Just in case you just want the list of updates and don't care if you get it via code or a GUI, here is how to do it in Powershell:
Open PowerShell (preferably "run as admin")
Type "get-hotfix" and hit enter. That's it.
string ExtractString(string s)
{
// You should check for errors in real-world code, omitted for brevity
try
{
var startTag = "(";
int startIndex = s.IndexOf(startTag) + startTag.Length;
int endIndex = s.IndexOf(")", startIndex);
return s.Substring(startIndex, endIndex - startIndex);
}
catch
{
return ("CNVFL");
}
}
Above is a simple extract string method I use to find that KB is in the security package like Tom Wijsman had mentioned and run his.
var updateSession = new UpdateSession();
var updateSearcher = updateSession.CreateUpdateSearcher();
var count = updateSearcher.GetTotalHistoryCount();
var history = updateSearcher.QueryHistory(0, count);
for (int i = 0; i < count; ++i){
//sets KB here!!
string _splitstring = ExtractString(history[i].Title);
Console.WriteLine(_splitstring);
}
this would get you the KB number like you're looking for I believe