Last active
December 18, 2015 10:39
-
-
Save FembotDBA/5769863 to your computer and use it in GitHub Desktop.
MicroStrategy Update intelligence cubes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UpdateCubes | |
{ | |
public class MSSession : IDisposable | |
{ | |
private DSSCOMMasterLib.IDSSDataSource _ds; | |
private DSSCOMMasterLib.IDSSSession _session; | |
public DSSCOMMasterLib.IDSSDataSource DataSource | |
{ | |
get | |
{ | |
return _ds; | |
} | |
} | |
public DSSCOMMasterLib.IDSSSession NativeSession | |
{ | |
get | |
{ | |
return _session; | |
} | |
} | |
public MSSession(string projectSource) | |
: this(projectSource, true) | |
{ | |
} | |
public MSSession(string projectSource, bool usePassword) | |
{ | |
_ds = GetProjectSource(projectSource); | |
_ds.login = _ds.Administrator; | |
if (usePassword) | |
{ | |
_ds.Passwd = "PASSWORD"; | |
} | |
_ds.Init(); | |
_session = _ds.CreateSession(); | |
} | |
public void Dispose() | |
{ | |
if (_session != null) | |
{ | |
_session.Close(); while (Marshal.ReleaseComObject(_session) > 0) ; | |
} | |
if (_ds != null) | |
{ | |
_ds.Reset(); while (Marshal.ReleaseComObject(_ds) > 0) ; | |
} | |
} | |
} | |
public static IDSSDataSource GetProjectSource(string projectSource) | |
{ | |
DSSCOMMasterLib.IDSSDataSourceEnumerator e = null; | |
try | |
{ | |
e = new DSSDataSourceEnumeratorClass(); | |
e.LoadFromRegistry(); | |
for (int i = 1; i <= e.Count(); i++) | |
{ | |
object o = i; | |
DSSCOMMasterLib.IDSSDataSource ds = e.Item(ref o); | |
if (ds.Name.Equals(projectSource, StringComparison.OrdinalIgnoreCase)) | |
{ | |
return ds; | |
} | |
} | |
return null; | |
} | |
finally | |
{ | |
if (e != null) while (Marshal.ReleaseComObject(e) > 0) ; | |
} | |
} | |
public static IDSSDataSource GetProject(MSSession session, string projectName) | |
{ | |
DSSCOMMasterLib.IDSSDataSourceEnumerator e = null; | |
try | |
{ | |
e = session.DataSource.get_Enumerator(DSSCOMMasterLib.EnumDSSDataSourceRefreshOption.DssDataSourceRefreshOptionNotRefresh); | |
for (int i = 1; i <= e.Count(); i++) | |
{ | |
object o = i; | |
DSSCOMMasterLib.IDSSDataSource ds2 = e.Item(ref o); | |
if (ds2.ProjectName.Equals(projectName, StringComparison.OrdinalIgnoreCase)) | |
{ | |
return ds2; | |
} | |
} | |
return null; | |
} | |
finally | |
{ | |
if (e != null) while (Marshal.ReleaseComObject(e) > 0) ; | |
} | |
} | |
public static void UpdateAllCubes(string projectSource, string projectName) | |
{ | |
DSSCOMMasterLib.IDSSDataSourceEnumerator e = null; | |
DSSCOMMasterLib.IDSSDataSource project = null; | |
try | |
{ | |
using (MSSession session = new MSSession(projectSource)) | |
{ | |
project = GetProject(session, projectName); | |
if (project != null) | |
{ | |
project.Init(); | |
DSSCOMMasterLib.IDSSSession projSession = project.CreateSession(); | |
DSSCOMMasterLib.IDSSServerAdmin9 myadmin = (DSSCOMMasterLib.IDSSServerAdmin9)session.DataSource.ServerAdmin; | |
DSSCOMMasterLib.IDSSCubeAdmin mycube = myadmin.get_CubeAdministrator(project.InternalProjectID); | |
mycube.RefreshAll(); | |
} | |
} | |
} | |
finally | |
{ | |
if (project != null) while (Marshal.ReleaseComObject(project) > 0) ; | |
if (e != null) while (Marshal.ReleaseComObject(e) > 0) ; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment