Resources in MSProject AddIn: Add a server related resource to the local version of the project - ms-project

Currently I am developing an AddIn for MS Project 2010.
In this AddIn the user filters all employees stored as MS Project Resources on the Project Server by several criteria. After finding a matching human resource the user should be able to add this resource to a selected task.
Unfortunately I do not find the link between adding the resource locally by
_activeProject.Resources.Add("ResourceName")
and the resource being stored on the server. "ResourceName" shown in Project has no connection to "ResourceName" on the server.
I tried to load the Microsoft.Office.Interop.MSProject.Resource somehow from the server via the PSI and add it to the project team by:
Dim projectTeamRow As SvcProject.ProjectTeamDataSet.ProjectTeamRow = projectTeamDs.ProjectTeam.NewProjectTeamRow()
projectTeamRow.PROJ_UID = projectGuid
projectTeamRow.RES_UID = resGuid
projectTeamRow.NEW_RES_UID = resGuid
projectTeamDs.ProjectTeam.AddProjectTeamRow(projectTeamRow)
But that's not really what I want. I simply need to add a server related resource to the local version of the project. In other words: I am looking for a way to convert a SvcProject.ProjectTeamDataSet.ProjectTeamRow to a Microsoft.Office.Interop.MSProject.Resource.
I really hope somebody can help me, since all my researches failed.

To add resource from Project server to your project you need to know ID of the resource (Not GUID). This information is stored in the RES_ID column. Just quest resource from server and get the ID.
If you plan to add several resources - I would recommend to cache a list of resources locally. I'm using this query to organize several dictionaries inside of my add-on:
ResourceDataSet resourceDs = new ResourceDataSet();
PSLibrary.Filter resourceFilter = new Microsoft.Office.Project.Server.Library.Filter();
resourceFilter.FilterTableName = resourceDs.Resources.TableName;
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_IDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_NAMEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_TYPEColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_INITIALSColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_EXTERNAL_IDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_IS_WINDOWS_USERColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.WRES_ACCOUNTColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.WRES_EMAILColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceFilter.Fields.Add(new PSLibrary.Filter.Field(resourceDs.Resources.TableName, resourceDs.Resources.RES_TIMESHEET_MGR_UIDColumn.ColumnName, PSLibrary.Filter.SortOrderTypeEnum.None));
resourceDs = ReadResources(resourceFilter.GetXml(), false);
The query is defined as extension of ResourceClient class from PSI.
As soon as you know ID of the resource just execute: Application.EnterpriseResourceGet(resId, omissing);
Application is from Microsoft.Office.Interop.MSProject.
This command will load the resource from Project Server into Active Project. Oh yes, please don't forget to check that your project is active when you call the command.

Related

Is it possible to get the application pool an applicaiton is running in (without knowing the website beforehand)?

I'm running an ASP.NET application (.NET Framework 4.6) on a Windows Server with IIS 10.
I've read a few examples where you get the application pool for specific sites.
ServerManager manager = new ServerManager();
Site defaultSite = manager.Sites["Default Web Site"];
foreach (Application app in defaultSite.Applications)
{
Console.WriteLine(
"{0} is assigned to the '{1}' application pool.",
app.Path, app.ApplicationPoolName);
}
But in these examples I have to define the Website (as far as I understand) under which the application is running.
Now when I don't want to fixate that in the source code (as it can change), I'm wondering how can I get under which application pool name is the application running?
Get the current site name and path via the HostingEnvironment.SiteName and HostingEnvironment.ApplicationVirtualPath respectively.
With them, getting the desired information from the server manager can be done like
using Microsoft.Web.Administration;
using System.Web.Hosting;
//...
var manager = new ServerManager();
var siteName = HostingEnvironment.SiteName;
var site = manager.Sites[siteName];
var applicationPath = HostingEnvironment.ApplicationVirtualPath;
var application = site.Applications[applicationPath];
Console.WriteLine(
"{0} is assigned to the '{1}' application pool.",
application.Path, application.ApplicationPoolName);
var appPoolName = application.ApplicationPoolName;
var applicationPool = manager.ApplicationPools[appPoolName];

Dynamics AX 2012 RegConfig does not work

I'm currently developping a failover service for an environment using Dynamics AX and 2 mirrored SQL servers, and I have some issues getting AX to work the way I expect it to.
I have developped a service which does the following :
- try to connect to the SQL servers instances
- start Dynamics AX using the reachable SQL server.
To do this, I have created 2 AX configuration files (.axc), each one pointing to a SQL server.
But when I try to start the service, no mater which way I use, AX always start using the configuration that is set using the AX server configuration tool.
Here are the command I've tried to start the AX service :
sc start AOS60$01 -regConfig=Config1
net start AOS60$01 /"-regConfig=Config1"
The service always start successfully, but doesn't care about the regConfig parameter.
As anybody an idea about how to solve this issue?
Regards,
Thomas T.
After looking for a while after a way to start the service with the -regConfig parameter, I finally gave up and developped a method which directly edit the Registry key holding the startup configuration value.
private void UpdateRegistry(string parameter)
{
RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\Dynamics Server\\6.0\\01", true);
key.SetValue("Current", parameter, RegistryValueKind.String);
key.Close();
}
public void StartLocalServiceWithCLI(string serviceToStart, string parameter)
{
try
{
UpdateRegistry(parameter);
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = string.Format("/C sc start {0} ", serviceToStart);
process.StartInfo = startInfo;
process.Start();
logger.WriteInfo(string.Format("Process {0} starting, parameters [{1}]", serviceToStart, parameter));
}
catch (Exception e)
{
logger.WriteError(string.Format("Error starting process {0}, parameters [{1}]\nError details :{2}", serviceToStart, parameter, e.Message));
}
}

CRMService.asmx - 401 Unauthorized error

CRM Portal is setup on "crmstaging" machine, on port 5555.
Following is the path of CRM Service:
http://crmstaging:5555/MSCrmServices/2007/CrmService.asmx
I am creating an ASP.NET Website on my dev machine "crmdev", and have added reference of the above service.
Now, I am trying to use various methods of this service to perform operations on my CRM entities, for that, I have written following code in button click of the page:
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "MyCompany";
CrmService service = new CrmService();
service.CrmAuthenticationTokenValue = token;
service.Credentials = new System.Net.NetworkCredential("username","password","domainname");
//service.Credentials = System.Net.CredentialCache.DefaultCredentials;
string fetch1 = #"<fetch mapping=""logical"">
<entity name=""account"">
<all-attributes/>
</entity>
</fetch>";
String result1 = service.Fetch(fetch1);
txtBox1.Text = result1;
In above code, I have passed credentials of the user having access on CRM Staging machine.
While trying to execute this code, I get an error saying "401 Unauthorized".
How to resolve this issue?

Upload video fail to youtube from asp.net website by data api

I am trying to upload video in my ASP.net website to YouTube using the data API but I am getting this error: "The remote server returned an error: (403) Forbidden."
I am using the below code:
YouTubeRequestSettings settings = new YouTubeRequestSettings("VideoPortal", "Developer_Key", "username", "password");
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "testvideo";//txttitle.Text.Trim();
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "testvideo";//txtkeyword.Text.Trim();
newVideo.Description = "testvideodesc";//txtdesc.Text.Trim();
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
// newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");
string path = Server.MapPath("video/Screen-Recording.mov");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(path,
"video/quicktime");
settings.Timeout = 100000000;
Video createdVideo = request.Upload(newVideo);
Can anybody please suggest to me how I can make this code work and resolve the error?
what the HTTP response body's content is when you get back your HTTP 403 response? There should be an error message in the response body that provides an explanation of what went wrong

Can i run WCF Workflow Service using WorkflowApplication class?

im wondering is it possible to load xamlx wcf workflow from file and run it using WorkflowApplication?
Desired result:
using (Stream xaml = File.OpenRead("Service1.xamlx"))
{
activity = ActivityXamlServices.Load(xaml);
}
var workflowApplication = new WorkflowApplication(activity);
workflowApplication.Run();
Extract the WorkflowService Root and run it on wfApp
var svc = (WorkflowService)XamlServices.Load("c:\\path\\Service1.xamlx");
WorkflowApplication wfApp = new WorkflowApplication(svc.Body);
wfApp.Run();
Still not understanding the reason to run a WorkflowService in a WorkflowApplication. Keep in mind that the inverse(run activity workflow with a receive activity as a WorkflowService) is totally valid.
WorkflowApplication was not made to expose endpoints. Use WorkflowServiceHost instead
WorkflowServiceHost host = new WorkflowServiceHost(activityLoadedFromXaml, baseAddress);
host.Description.Behaviors.Add(new System.ServiceModel.Description.ServiceMetadataBehavior() { HttpGetEnabled = true });
host.AddDefaultEndpoints();
host.Open();

Resources