I am having trouble finding a way to store persistent settings for an office.js add-in on Mac.
On windows localStorage works perfect as it saves settings that persist through closing and opening Word.
On Mac localStorage does not persist closing and opening Word, not even through a refresh or closing and opening of the add-in.
Here is a simple code sample:
var settingString = 'mySetting';
var oldValue = localStorage.getItem(settingString);
write('oldValue: "' + oldValue + '"');
var d = new Date();
var newValue = d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
localStorage.setItem(settingString, newValue);
write('newValue: "' + newValue + '"');
iOS currently has a bug that's preventing us from fixing this localStorage issue yet. In the meantime, you have two potential workarounds:
Cookies
If you want the setting to be persisted across documents, use JavaScript cookies (w3schools doc) until the bug is fixed:
var settingString = 'mySetting';
var oldValue;
var myCookies = document.cookie.split(';');
for(var i = 0;i < myCookies.length;i++){
var myCookie = myCookies[i].trim();
if(myCookie.indexOf(settingString + "=") == 0){
oldValue = myCookie.substring(settingString + 1,myCookie.length);
}
}
write('oldValue: "' + oldValue + '"');
var d = new Date();
var newValue = d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
var expiry = d.setTime(d.getTime() + (14 * 86400000)); // # milliseconds in a day
document.cookie = settingString + "=" + newValue + "; expires=" + expiry.toGMTString();
write('newValue: "' + newValue + '"');
Settings
If it's sufficient for you to persist the value only in the current document, you can use the Office Settings API (Office.js Settings object doc):
var settingString = 'mySetting';
var oldValue = Office.context.Settings.get(settingString);
write('oldValue: "' + oldValue + '"');
var d = new Date();
var newValue = d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
Office.context.Settings.set(settingString, newValue);
Office.context.Settings.saveAsync(function(asyncResult){
write('newValue: "' + newValue + '"');
});
-Michael Saunders, program manager for Office add-ins
Related
I want to use client side rendering(js link) for document library, the challenge for me is Sharepoint document library will be created dynamically when the remote event receiver triggers.
I know we need to pass js link reference in elements.xml file, but in my case list will be created later, so how can I achieve it?
Thanks in advance.
You can add script (JSLink) programmatically, after your condition event receiver:
C#:
using (SPSite site = new SPSite("http://sp/sites/test"))
{
SPWeb web = site.RootWeb;
SPFile page = web.GetFile("SitePages/Test.aspx");
page.CheckOut();
using (SPLimitedWebPartManager wpmgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
XmlElement p = new XmlDocument().CreateElement("p");
p.InnerText = "<script type='text/javascript'>alert('Hello World');</script>";
ContentEditorWebPart cewp = new ContentEditorWebPart
{
Content = p
};
wpmgr.AddWebPart(cewp, "Header", 0);
}
page.CheckIn(String.Empty);
}
JS:
var siteUrl = '/sites/MySiteCollection';
var serverRelativeUrl = '/sites/MySiteCollection/Default.aspx';
function addWebPart() {
var clientContext = new SP.ClientContext(siteUrl);
var oFile = clientContext.get_web().getFileByServerRelativeUrl(serverRelativeUrl);
var limitedWebPartManager = oFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
var webPartXml = '<?xml version=\"1.0\" encoding=\"utf-8\"?>' +
'<WebPart xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"' +
' xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"' +
' xmlns=\"http://schemas.microsoft.com/WebPart/v2\">' +
'<Title>My Web Part</Title><FrameType>Default</FrameType>' +
'<Description>Use for formatted text, tables, and images.</Description>' +
'<IsIncluded>true</IsIncluded><ZoneID></ZoneID><PartOrder>0</PartOrder>' +
'<FrameState>Normal</FrameState><Height /><Width /><AllowRemove>true</AllowRemove>' +
'<AllowZoneChange>true</AllowZoneChange><AllowMinimize>true</AllowMinimize>' +
'<AllowConnect>true</AllowConnect><AllowEdit>true</AllowEdit>' +
'<AllowHide>true</AllowHide><IsVisible>true</IsVisible><DetailLink /><HelpLink />' +
'<HelpMode>Modeless</HelpMode><Dir>Default</Dir><PartImageSmall />' +
'<MissingAssembly>Cannot import this Web Part.</MissingAssembly>' +
'<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge><IsIncludedFilter />' +
'<Assembly>Microsoft.SharePoint, Version=13.0.0.0, Culture=neutral, ' +
'PublicKeyToken=94de0004b6e3fcc5</Assembly>' +
'<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>' +
'<ContentLink xmlns=\"http://schemas.microsoft.com/WebPart/v2/ContentEditor\">' + '/sites/SiteAssets/Test.js</ContentLink>' +
'<Content xmlns=\"http://schemas.microsoft.com/WebPart/v2/ContentEditor\">' +
'<![CDATA[This is a first paragraph!<DIV> </DIV>And this is a second paragraph.]]></Content>' +
'<PartStorage xmlns=\"http://schemas.microsoft.com/WebPart/v2/ContentEditor\" /></WebPart>';
var oWebPartDefinition = limitedWebPartManager.importWebPart(webPartXml);
this.oWebPart = oWebPartDefinition.get_webPart();
limitedWebPartManager.addWebPart(oWebPart, 'Left', 1);
clientContext.load(oWebPart);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
alert('Web Part added: ' + oWebPart.get_title());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
I have a button that does the following:
1) Delete the current information in the form.
2) Runs javascript to create new entries in the form.
The information is displayed in a viewpanel. The problem is that the information that is displayed is incomplete and old. I added an additional button that only does a partial refresh. Once the first button is finished running, I click on the second panel and this second refresh displays the latest data. I have been playing with putting variations of XSP.partialRefreshGet("#{id:WrapperPanel}", {}); in the oncomplete event of the first button - to no avail.
Here is the code:
<xp:button id="button34"
value="Check Teacher Information"
styleClass="BlueButtonSmall">
<xp:eventHandler event="onclick"
submit="true" refreshMode="complete" id="eventHandler50">
<xp:this.action><![CDATA[#{javascript:var serverName:NotesDatabase = database.getServer();
var PosdbName = new Array(serverName,"Position.nsf");
var CamdbName = new Array(serverName,"Campus.nsf");
var currentDB:NotesDatabase=session.getCurrentDatabase();
//Delete old records
var i = 0;
var crview = database.getView("ChangeReport");
var crvec:NotesViewEntryCollection = crview.getAllEntries();
var crentry:NotesViewEntry = crvec.getFirstEntry();
while (crentry != null) {
crDoc = crentry.getDocument();
crDoc.remove(true);
crDoc.recycle();
if (i > 100) {
print("Possible Loop HRMainX - breaking");
break;
}
i++
var tmpentry:NotesViewEntry = crvec.getNextEntry(crentry);
crentry.recycle();
crentry = tmpentry;
}
database.updateFTIndex(false);
var aview = database.getView("NISDTeacher");
var vec:NotesViewEntryCollection = aview.getAllEntries();
var entry:NotesViewEntry = vec.getFirstEntry();
var i = 0;
while (entry != null) {
var Enumber:string = entry.getDocument().getItemValueString("TeacherEnumber");
var Firstname = entry.getDocument().getItemValueString("TeacherFirst");
var Lastname = entry.getDocument().getItemValueString("TeacherLast");
var Active = #DbLookup(PosdbName,"All",Enumber,"Posd_Active");
var Status = #DbLookup(PosdbName,"All",Enumber,"Posd_Status");
if (Active === "Y" || Status === "A") {
var CurrCampusNum = #DbLookup(PosdbName,"ActiveID",Enumber,"Posd_Campus");
var CurrCampusType = #DbLookup(CamdbName,"Campus",CurrCampusNum,"Cmp_Level");
if (CurrCampusType === "SP" || CurrCampusType === "EL" || CurrCampusType === "MS" || CurrCampusType === "HS") {
var CampusNum = entry.getDocument().getItemValueString("CampusNum");
var PositionCode = entry.getDocument().getItemValueString("TeacherPCode");
var CurrFirstname = #Trim(#ProperCase(#DbLookup(PosdbName,"ActiveID",Enumber,"Posd_FName")));
var CurrLastname = #Trim(#ProperCase(#DbLookup(PosdbName,"ActiveID",Enumber,"Posd_lname")));
var CurrPositionCode = #DbLookup(PosdbName,"ActiveID",Enumber,"Posd_Job_Code");
if (CurrFirstname !== Firstname) {
var reportDate = session.createDateTime(#Now());
var changeDoc = currentDB.createDocument();
changeDoc.replaceItemValue("Form","ChangeReport");
changeDoc.replaceItemValue("DateReported",reportDate);
var Change = Enumber + " " + Firstname + " " + Lastname + " has a new Firstname of " + CurrFirstname;
changeDoc.replaceItemValue("Change",Change)
changeDoc.save();
}
if (CurrLastname !== Lastname) {
var reportDate = session.createDateTime(#Now());
var changeDoc = currentDB.createDocument();
changeDoc.replaceItemValue("Form","ChangeReport");
changeDoc.replaceItemValue("DateReported",reportDate);
var Change = Enumber + " " + Firstname + " " + Lastname + " has a new Lastname of " + CurrLastname;
changeDoc.replaceItemValue("Change",Change)
changeDoc.save();
}
if (CurrCampusNum !== CampusNum) {
var reportDate = session.createDateTime(#Now());
var changeDoc = currentDB.createDocument();
changeDoc.replaceItemValue("Form","ChangeReport");
changeDoc.replaceItemValue("DateReported",reportDate);
var CampusName = entry.getDocument().getItemValueString("CampusName");
var CurrCampusName = #DbLookup(CamdbName,"Campus",CurrCampusNum,"Cmp_ShortName");
var Change = Enumber + " " + Firstname + " " + Lastname + " was teaching at " + CampusName + " (" + CampusNum + ") " +
"and is now teaching at " + CurrCampusName + " (" + CurrCampusNum + ")";
changeDoc.replaceItemValue("Change",Change)
changeDoc.save();
}
if (CurrPositionCode !== PositionCode) {
var reportDate = session.createDateTime(#Now());
var changeDoc = currentDB.createDocument();
changeDoc.replaceItemValue("Form","ChangeReport");
changeDoc.replaceItemValue("DateReported",reportDate);
var PositionTitle = entry.getDocument().getItemValueString("TeacherPTitle");
var CurrPositionTitle = #DbLookup(PosdbName,"ActiveID",Enumber,"Posd_Title");
var Change = Enumber + " " + Firstname + " " + Lastname + " was teaching " + PositionTitle + " (" + PositionCode + ") " +
"and is now teaching " + CurrPositionTitle + " (" + CurrPositionCode + ")";
changeDoc.replaceItemValue("Change",Change)
changeDoc.save();
}
} else {
var reportDate = session.createDateTime(#Now());
var changeDoc = currentDB.createDocument();
changeDoc.replaceItemValue("Form","ChangeReport");
changeDoc.replaceItemValue("DateReported",reportDate);
var Change = Enumber + " " + Firstname + " " + Lastname + " no longer works as a classroom teacher.";
changeDoc.replaceItemValue("Change",Change);
changeDoc.save();
}
} else {
var reportDate = session.createDateTime(#Now());
var changeDoc = currentDB.createDocument();
changeDoc.replaceItemValue("Form","ChangeReport");
changeDoc.replaceItemValue("DateReported",reportDate);
var Change = Enumber + " " + Firstname + " " + Lastname + " no longer works at the district.";
changeDoc.replaceItemValue("Change",Change)
changeDoc.save();
}
var tmpentry:NotesViewEntry = vec.getNextEntry(entry);
entry.recycle();
entry = tmpentry;
if (i > 2000) {
print("Possible Loop HRMainX - breaking");
break;
}
i++
}
database.updateFTIndex(false);
//view.postScript("alert('Done checking teacher information.')");
viewScope.resultsCellVis = true;
//view.postScript("partialRefreshPost('#{id:WrapperPanel}')")
}]]></xp:this.action>
<xp:this.onComplete><![CDATA[XSP.partialRefreshGet("#{id:WrapperPanel}", {});]]></xp:this.onComplete>
</xp:eventHandler>
</xp:button>
Thanks for any pointers.
---Lisa&
I'm not sure if this will work, but it may be that it's caching the view content (effectively doing a setAutoUpdate(false) on the view). What may work is, instead of the onComplete event doing a partial refresh, adding a server-side call at the end of your SSJS to context.reloadPage(). That will recreate all the components again. Theoretically, I would expect that to dump it's cached version of the view and retrieve it from scratch. You should also be able to do this with a partial refresh rather than the complete refresh you currently have coded.
See this blog post I did explaining the differences between full refresh, context.reloadPage, context.redirectToPage() etc http://www.intec.co.uk/viewscope-full-refresh-reloadpage/.
I am trying to generate Account SAS token:
MSDN DOC
When I am trying to use generated token, I get following:
AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:89959111-0001-00c8-24d1-e0515b000000
Time:2016-07-18T08:49:00.8383767Z
Signature did not match. String to sign used was [accountName]
rl
b
sc
2017-01-01
2015-04-05
Here are my code:
var signedVersion = "2015-04-05";
var signedServices = "b";
var signedResourceTypes = "sc";
var signedPermission = "rl";
var signedExpiry = "2017-01-01";
var stringToSign =
accountName + "\n" +
signedPermission + "\n" +
signedServices + "\n" +
signedResourceTypes + "\n" +
signedExpiry + "\n" +
signedVersion + "\n"
;
var keyBytes = Encoding.UTF8.GetBytes(accountKey);
byte[] hash;
using (var mac = new HMACSHA256(keyBytes))
{
var stringToSignBytes = Encoding.UTF8.GetBytes(stringToSign);
hash = mac.ComputeHash(stringToSignBytes);
}
var str = Convert.ToBase64String(hash);
var sig = HttpUtility.UrlEncode(str);
var url = $"https://{accountName}.blob.core.windows.net/?comp=list&sv={signedVersion}&ss={signedServices}&srt={signedResourceTypes}&sp={signedPermission}&se={signedExpiry}&sig={sig}";
What am I doing wrong?
I noticed a few issues with the code:
First, to convert account key into byte array you would need to use Convert.FromBase64String(accountKey) instead of Encoding.UTF8.GetBytes(accountKey);.
Next, even if you're not using start time, signed protocol and signed IP addresses, you would need to include them in your stringToSign.
Once you do these things, the code should work. Based on these, I have included the modified code below. I tested it for listing containers in my storage account and it works.
static void AccountSas()
{
var signedVersion = "2015-04-05";
var signedServices = "b";
var signedResourceTypes = "sc";
var signedPermission = "rl";
var signedExpiry = "2017-01-01";
var signedStart = "";
var signedIP = "";
var signedProtocol = "";
var stringToSign =
accountName + "\n" +
signedPermission + "\n" +
signedServices + "\n" +
signedResourceTypes + "\n" +
signedStart + "\n" +
signedExpiry + "\n" +
signedIP + "\n" +
signedProtocol + "\n" +
signedVersion + "\n"
;
var keyBytes = Convert.FromBase64String(accountKey);
byte[] hash;
using (var mac = new HMACSHA256(keyBytes))
{
var stringToSignBytes = Encoding.UTF8.GetBytes(stringToSign);
hash = mac.ComputeHash(stringToSignBytes);
}
var str = Convert.ToBase64String(hash);
var sig = HttpUtility.UrlEncode(str);
var url = string.Format("https://{0}.blob.core.windows.net/?comp=list&sv={1}&ss={2}&srt={3}&sp={4}&se={5}&sig={6}", accountName, signedVersion, signedServices, signedResourceTypes, signedPermission, signedExpiry, sig);
}
Hi All i'm having an application which pulls YouTube analytics data but it is not working from sometime. The details are below with code
for (int ISOCountryCode = 0; ISOCountryCode < ds.Tables[0].Rows.Count; ISOCountryCode++)
{
//validation to check if date is null
string strdimensions = "day";
string strmetrics = "views,comments,favoritesAdded,favoritesRemoved,likes,dislikes,shares,estimatedMinutesWatched,averageViewDuration,averageViewPercentage,annotationClickThroughRate,annotationCloseRate,subscribersGained,subscribersLost,uniques";
string strstartdate = Convert.ToDateTime(WeekStartDate).ToString("yyyy-MM-dd");
string strenddate = Convert.ToDateTime(WeekEndDate).ToString("yyyy-MM-dd");
string DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==" + ChannelID + "&start-date=" + strstartdate + "&end-date=" + strenddate + "&metrics=" + strmetrics + "&key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&access_token=" + token + "&dimensions=" + strdimensions + "&alt=csv&filters=country==" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString());
urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");
strdimensions = "day,operatingSystem,deviceType";
strmetrics = "estimatedMinutesWatched,views";
DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel=={2}&start-date=" + strstartdate + "&end-date=" + strenddate + "&metrics=" + strmetrics + "&key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&access_token={0}&dimensions=" + strdimensions + "&alt=csv&filters=country=={1}", token, ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString(), ChannelID);
urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world-device_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");
strdimensions = "day,operatingSystem,deviceType";
strmetrics = "estimatedMinutesWatched,views";
DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel=={2}&start-date=" + strstartdate + "&end-date=" + strenddate + "&metrics=" + strmetrics + "&key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&access_token={0}&dimensions=" + strdimensions + "&alt=csv&filters=country=={1}", token, ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString(), ChannelID);
urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world-deviceType_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");
}
The Code in the urlDownload.Download is :-
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(strURLFileandPath);
HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
Stream str = ws.GetResponseStream(); - > Line Of Error
On the last line where it asks for the response stream it errors out and says "500 Internal Server Error"
Data I would like to have:
Num From , Num To , Duration, Codec, Context, Hold status
ofc in realtime update
I using node.js + nami
what the best way to get this information?
tried use an action Status(), but this gives me not full information about call and if I run it every second browser dies.
here is what I have:
updateCallList();
function updateCallList() {
socket.emit('GET_ACTIVE_CALLS', function(calls) {
$("#callsList").find("tr:gt(0)").remove();
if (calls.response != 'Success') return;
var calls = calls.events;
for (call in calls) {
if (calls[call].privilege == 'Call') {
var callFrom = calls[call].calleridnum + '<' + calls[call].calleridname + '>';
var callTo = calls[call].extension;
var callDuration = calls[call].seconds;
var callRoute = calls[call].context;
var tmpRow = '<tr>';
tmpRow = tmpRow + '<td>' + callFrom + '</td>';
tmpRow = tmpRow + '<td>' + callTo + '</td>';
tmpRow = tmpRow + '<td>' + callDuration + '</td>';
tmpRow = tmpRow + '<td>' + callRoute + '</td>';
tmpRow = tmpRow + '</tr>';
$('#callsList tr:last').after(tmpRow);
}
}
setInterval(function(){
updateCallList();
},1000);
});
}
server side
socket.on('GET_ACTIVE_CALLS', function (callback) {
action = new namiLib.Actions.Status();
nami.send(action, function (response) {
callback(response);
});
});
You need start daemon which will collect NewExten, Link, Unlink, Hangup events and create list of channels.
http://www.voip-info.org/wiki/view/asterisk+manager+events
Also you can do action command with "core show channels" "core show channel XXXXX", but asterisk will die if you do alot of that.
http://www.voip-info.org/wiki/view/Asterisk+Manager+API+Action+Command