Example #1
0
        /// <summary>
        /// Build & return the full MetaTree
        /// </summary>
        ///
        public Dictionary <string, MetaTreeNode> GetMetaTree2()
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusMetaDataService,
                    MobiusMetaDataService.Build,
                    new object[] { false });

                // Get the cache from the server if newer than the client cache

                string cacheFile       = ServicesIniFile.Read("CachedTreeFile", DefaultCachedTreeFile);
                string serverCacheFile = @"<MetaDataDir>\MetaTrees\" + cacheFile;

                string clientCacheFile = ClientDirs.CacheDir + @"\" + cacheFile;
                //ServerFile.Get(serverCacheFile, clientCacheFile); // debug, always get
                bool changed = ServerFile.GetIfChanged(serverCacheFile, clientCacheFile);                 // just get if changed

                // Build the tree from the local copy of the cache

                MetaFactoryNamespace.MetaTreeFactory.BuildFromCache(ClientDirs.CacheDir, false);

                return(Mfn.MetaTreeFactory.Nodes);
            }

            else
            {
                Mfn.MetaTreeFactory.Build();
                return(Mfn.MetaTreeFactory.Nodes);
            }
        }
Example #2
0
        /// <summary>
        /// GetCurrentSessionCount
        /// </summary>
        /// <returns></returns>

        public static int GetCurrentSessionCount()
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusUsageService,
                    MobiusUsageService.GetCurrentSessionCount,
                    null);

                if (resultObject != null && resultObject.Value is int)
                {
                    return((int)resultObject.Value);
                }

                else
                {
                    return(-1);
                }
            }

            else
            {
                return(1);             // just us
            }
        }
Example #3
0
        /// <summary>
        /// Get MetaTree in xml format for editing
        /// </summary>
        /// <returns>Tree in XML</returns>

        public static string LockAndReadMetatreeXml()
        {
            string treeXml = null;

            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusMetaDataService,
                    MobiusMetaDataService.LockAndReadMetatreeXml,
                    null);

                if (resultObject != null && resultObject.Value != null)
                {
                    byte[] ba = resultObject.Value as byte[];
                    treeXml = Mobius.ComOps.GZip.Decompress(ba);
                }

                return(treeXml);
            }

            else
            {
                treeXml = Mobius.MetaFactoryNamespace.MetaTreeFactory.LockAndReadMetatreeXml();
                return(treeXml);
            }
        }
Example #4
0
        /// <summary>
        /// GetServiceServerRebootTime
        /// </summary>
        /// <returns></returns>

        public static DateTime GetServiceServerRebootTime()
        {
            int tickCount = 0;

            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusUsageService,
                    MobiusUsageService.GetLastBootUpTime,
                    null);

                if (resultObject != null && resultObject.Value is int)
                {
                    return((DateTime)resultObject.Value);
                }

                else
                {
                    return(DateTime.MinValue);
                }
            }

            else
            {
                return(SystemUtil.GetLastBootUpTime());
            }
        }
Example #5
0
        /// <summary>
        /// Get MetaTree in xml format
        /// </summary>
        /// <param name="rootNodeName"></param>
        /// <param name="includeCurrentUsersObjects"></param>
        /// <param name="includeAllUsersObjects"></param>
        /// <returns></returns>

        public static string GetMetatreeXml(
            string rootNodeName,
            bool includeCurrentUsersObjects,
            bool includeAllUsersObjects)
        {
            string treeXml = null;

            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusMetaDataService,
                    MobiusMetaDataService.GetMetaTreeXml,
                    new object[] { rootNodeName, includeCurrentUsersObjects, includeAllUsersObjects });

                if (resultObject != null && resultObject.Value != null)
                {
                    treeXml = resultObject.Value.ToString();
                }

                return(treeXml);
            }

            else
            {
                treeXml = Mobius.MetaFactoryNamespace.MetaTreeFactory.GetMetatreeXml(rootNodeName, includeCurrentUsersObjects, includeAllUsersObjects);
                return(treeXml);
            }
        }
Example #6
0
        /// <summary>
        /// Get subtree starting at specified node
        /// </summary>
        /// <param name="rootNodeName"></param>
        /// <returns></returns>

        public MetaTreeNode GetAfsSubtree(string rootNodeName)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusMetaDataService,
                    MobiusMetaDataService.GetAfsSubtree,
                    new object[] { rootNodeName });

                if (resultObject == null)
                {
                    return(null);
                }
                MetaTreeNode mtn = resultObject.Value as MetaTreeNode;
                return(mtn);
            }

            else
            {
                if (MetaTreeFactoryInstance == null)
                {
                    MetaTreeFactoryInstance = new Mobius.MetaFactoryNamespace.MetaTreeFactory();
                }
                return(MetaTreeFactoryInstance.GetAfsSubtree(rootNodeName));
            }
        }
Example #7
0
		/// <summary>
		/// See if user authorized & logon as current user if so
		/// </summary>
		/// <param name="userName"></param>
		/// <param name="domainName"></param>
		/// <param name="clientName"></param>
		/// <returns></returns>

		public static bool Logon(
			string userName,
			string domainName,
			string clientName)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.Logon,
					new object[] { userName, domainName, clientName });
				bool succeeded = (bool)resultObject.Value;
				if (succeeded)
				{
					UserName = userName;
				}
				return succeeded;
			}

			else if (!UAL.Security.Logon(userName, domainName, clientName))
				return false;

			UserName = userName;
			return true;
		}
Example #8
0
		/// <summary>
		/// Create a new user entry
		/// </summary>
		/// <param name="userInfo"></param>
		/// <returns></returns>

		public static void CreateUser(
			UserInfo userInfo)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.CreateUser,
					new object[] { userInfo.Serialize() });
			}
			else UAL.Security.CreateUser(userInfo);
		}
Example #9
0
		/// <summary>
		/// Revoke a privilege from a user
		/// </summary>
		/// <param name="userName"></param>
		/// <param name="privilege"></param>
		/// <returns></returns>
		public static void RevokePrivilege(
			string userName,
			string privilege)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.RevokePrivilege,
					new object[] { userName, privilege });
			}
			else UAL.Security.RevokePrivilege(userName, privilege);
		}
Example #10
0
		/// <summary>
		/// See if a user is an administrator
		/// </summary>
		/// <param name="userName"></param>
		/// <returns></returns>

		public static bool IsAdministrator(
			string userName)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.IsAdministrator,
					new object[] { userName });
				bool isAdmin = (bool)resultObject.Value;
				return isAdmin;
			}
			else return UAL.Security.IsAdministrator(userName);
		}
Example #11
0
		/// <summary>
		/// Create a new user entry
		/// </summary>
		/// <param name="userInfo"></param>
		/// <returns></returns>

		public static bool DeleteUser(
			string userName)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.DeleteUser,
					new object[] { userName });
				bool result = (bool)resultObject.Value;
				return result;
			}

			else return UAL.Security.DeleteUser(userName);
		}
Example #12
0
		/// <summary>
		/// Set the username, use must be already authenticated elsewhere
		/// (When using the services, authentication was required to obtain a session)
		/// </summary>

		public static void SetUser(
			string userName)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.SetUser,
					new object[] { userName });
			}
			else UAL.Security.SetUser(userName);

			UserName = userName;
			return;
		}
Example #13
0
		/// <summary>
		/// See if a user has a given privilege
		/// </summary>
		/// <param name="userName"></param>
		/// <param name="privilege"></param>
		/// <returns></returns>

		public static bool HasPrivilege(
			string userName,
			string privilege)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.HasPrivilege,
					new object[] { userName, privilege });
				bool hasPriv = (bool)resultObject.Value;
				return hasPriv;
			}
			else return UAL.Security.HasPrivilege(userName, privilege);
		}
Example #14
0
		/// <summary>
		/// Get email address for a user
		/// </summary>
		/// <param name="userName"></param>
		/// <returns></returns>

		public static string GetUserEmailAddress(
			string userName)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.GetUserEmailAddress,
					new object[] { userName });
				if (resultObject == null) return null;
				string emailAddress = (string)resultObject.Value;
				return emailAddress;
			}
			else return UAL.Security.GetUserEmailAddress(userName);
		}
Example #15
0
        /// <summary>
        /// Execute a command
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>

        public static string Execute(string command, string commandArgs)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                ScheduledTaskTypes taskType =                 // get type of scheduled task
                                              (ScheduledTaskTypes)Enum.Parse(typeof(ScheduledTaskTypes), command);

                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusTaskSchedulerService,
                    MobiusTaskSchedulerService.Execute,
                    new object[] { (int)taskType, commandArgs });

                if (resultObject == null)
                {
                    return(null);
                }

                string        result        = "";
                ScheduledTask scheduledTask = resultObject.Value as ScheduledTask;
                if (scheduledTask == null)
                {
                    throw new Exception("Command failed (null resultObject)");
                }

                else
                {
                    if (scheduledTask.Status == ScheduledTaskStatus.Succeeded)
                    {
                        if (scheduledTask.Result != null)
                        {
                            result = scheduledTask.Result.ToString();
                        }
                    }
                    else
                    {
                        result = scheduledTask.Status.ToString() +
                                 ((scheduledTask.Result == null) ? "" : ": " + scheduledTask.Result.ToString());
                        throw new Exception(result);
                    }
                }
                return(result);
            }

            else
            {
                return(Mobius.ToolServices.CommandLineService.ExecuteCommand(commandArgs));
            }
        }
Example #16
0
		/// <summary>
		/// Get user info for a single user from user object table
		/// </summary>
		/// <param name="userName"></param>
		/// <returns></returns>

		public static UserInfo ReadUserInfo(
			string userName)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
						ServiceCodes.MobiusSecurityService,
						MobiusSecurityService.ReadUserInfo,
						new object[] { userName });
				if (resultObject == null) return null;
				UserInfo userInfo = UserInfo.Deserialize((string)resultObject.Value);
				return userInfo;
			}

			else return UAL.Security.ReadUserInfo(userName);
		}
Example #17
0
/// <summary>
/// Get the last write time for a server file
/// </summary>
/// <param name="serverFile"></param>
/// <returns></returns>

        public static DateTime GetLastWriteTime(string serverFile)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusFileService,
                    MobiusFileService.GetLastWriteTime,
                    new object[] { serverFile });
                DateTime result = (DateTime)resultObject.Value;
                return(result);
            }

            else
            {
                return(UAL.ServerFile.GetLastWriteTime(serverFile));
            }
        }
Example #18
0
        /// <summary>
        /// Release the editing of the metatree xml
        /// </summary>

        public static void ReleaseMetaTreeXml()
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusMetaDataService,
                    MobiusMetaDataService.ReleaseMetaTreeXml,
                    null);

                return;
            }

            else
            {
                Mobius.MetaFactoryNamespace.MetaTreeFactory.ReleaseMetaTreeXml();
                return;
            }
        }
Example #19
0
		public static string UserName; // current username

		/// <summary>
		/// Authenticate user
		/// </summary>
		/// <param name="userId"></param>
		/// <param name="password"></param>
		/// <returns></returns>

		public static bool Authenticate(
			string userName,
			string password)
		{
			if (ServiceFacade.UseRemoteServices)
			{
				NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
					ServiceCodes.MobiusSecurityService,
					MobiusSecurityService.Authenticate,
					new object[] { userName, password });
				bool result = (bool)resultObject.Value;
				return result;
			}
			else if (!UAL.Security.Authenticate(userName, password))
				return false;

			UserName = userName;
			return true;
		}
Example #20
0
        /// <summary>
        /// Log a usage event
        /// </summary>
        /// <param name="eventName"></param>
        /// <param name="eventData"></param>
        /// <param name="eventNumber"></param>

        public static void LogEvent(
            string eventName,
            string eventData,
            int eventNumber)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusUsageService,
                    MobiusUsageService.LogEvent,
                    new object[] { eventName, eventData, eventNumber });
                return;
            }

            else
            {
                UAL.UsageDao.LogEvent(eventName, eventData, eventNumber);
            }
        }
Example #21
0
        /// <summary>
        /// Save edited metatree xml
        /// </summary>
        /// <param name="treeXml"></param>

        public static void SaveMetaTreeXml(string treeXml)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                byte[] ba = Mobius.ComOps.GZip.Compress(treeXml);

                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusMetaDataService,
                    MobiusMetaDataService.SaveMetaTreeXml,
                    new object[] { ba });

                return;
            }

            else
            {
                Mobius.MetaFactoryNamespace.MetaTreeFactory.SaveMetaTreeXml(treeXml);
                return;
            }
        }
Example #22
0
/// <summary>
/// Return true if Mobius can write to the specified file from the service side
/// </summary>
/// <param name="path"></param>
/// <returns></returns>

        public static bool CanWriteFileFromServiceAccount(string path)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusFileService,
                    MobiusFileService.CanWriteFileFromServiceAccount,
                    new object[] { path });
                if (resultObject == null)
                {
                    return(false);
                }
                bool result = (bool)resultObject.Value;
                return(result);
            }
            else
            {
                return(UAL.ServerFile.CanWriteFileFromServiceAccount(path));
            }
        }
Example #23
0
        /// <summary>
        /// Mark the MetaTree cache for rebuilding
        /// </summary>

        public void MarkCacheForRebuild()
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusMetaDataService,
                    MobiusMetaDataService.MarkCacheForRebuild,
                    null);
                return;
            }

            else
            {
                if (MetaTreeFactoryInstance == null)
                {
                    MetaTreeFactoryInstance = new Mobius.MetaFactoryNamespace.MetaTreeFactory();
                }

                MetaTreeFactoryInstance.MarkCacheForRebuild();
            }
        }
Example #24
0
        /// <summary>
        /// Build & return the full MetaTree
        /// </summary>

        public Dictionary <string, MetaTreeNode> ReloadMetaTree()
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusMetaDataService,
                    MobiusMetaDataService.GetFullTree,
                    null);

                Dictionary <string, MetaTreeNode> metaTree = (resultObject != null) ? (Dictionary <string, MetaTreeNode>)resultObject.Value : null;
                return(metaTree);
            }

            else
            {
                if (MetaTreeFactoryInstance == null)
                {
                    MetaTreeFactoryInstance = new Mobius.MetaFactoryNamespace.MetaTreeFactory();
                }
                return(MetaTreeFactoryInstance.ReloadMetaTree());
            }
        }
Example #25
0
        /// <summary>
        /// Get a temp file on the server side
        /// </summary>
        /// <param name="extension"></param>
        /// <param name="deleteOnAppExit"></param>
        /// <returns></returns>

        public static string GetTempFileName(
            string extension,
            bool deleteOnAppExit)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusFileService,
                    MobiusFileService.GetTempFileName,
                    new object[] { extension, deleteOnAppExit });
                if (resultObject == null)
                {
                    return(null);
                }
                string tempFileName = (string)resultObject.Value;
                return(tempFileName);
            }
            else
            {
                return(UAL.ServerFile.GetTempFileName(extension, deleteOnAppExit));
            }
        }
Example #26
0
        /// <summary>
        /// Commandline command to analyse usage data
        /// </summary>
        /// <param name="commandLine"></param>
        /// <returns></returns>

        public static string AnalyzeUsageData(
            string commandArgs)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                    ServiceCodes.MobiusUsageService,
                    MobiusUsageService.AnalyzeUsageData,
                    new object[] { commandArgs });

                if (resultObject == null)
                {
                    return(null);
                }
                string result = (string)resultObject.Value;
                return(result);
            }
            else
            {
                return(UAL.UsageDao.AnalyzeUsageData(commandArgs));
            }
        }
Example #27
0
        /// <summary>
        /// Copy file from server to client
        /// </summary>
        /// <param name="serverFile"></param>
        /// <param name="clientFile2"></param>

        public static void CopyToClient(
            string serverFile,
            string clientFile)
        {
            FileStream fw = null;

            try
            {
                string tempFile = TempFile.GetTempFileName();

                if (ServiceFacade.UseRemoteServices)
                {
                    fw = new FileStream(tempFile, FileMode.Create, FileAccess.Write);
                    while (true)
                    {
                        NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                            ServiceCodes.MobiusFileService,
                            MobiusFileService.CopyToClient,
                            new object[] { serverFile });

                        byte[] buffer = (byte[])resultObject.Value;
                        if (buffer == null)
                        {
                            break;
                        }
                        fw.Write(buffer, 0, buffer.Length);
                        if (buffer.Length < UAL.ServerFile.TransferChunkSize)
                        {
                            break;
                        }
                        serverFile = null;                         // null to get subsequent chunks
                        System.Windows.Forms.Application.DoEvents();
                    }

                    fw.Close();
                }

                else                 // direct call
                {
                    fw = new FileStream(tempFile, FileMode.Create, FileAccess.Write);
                    while (true)
                    {
                        byte[] buffer = UAL.ServerFile.CopyToClient(serverFile);
                        if (buffer == null)
                        {
                            break;
                        }
                        fw.Write(buffer, 0, buffer.Length);
                        if (buffer.Length < UAL.ServerFile.TransferChunkSize)
                        {
                            break;
                        }
                        serverFile = null;                         // null to get subsequent chunks
                        System.Windows.Forms.Application.DoEvents();
                    }

                    fw.Close();
                }

                bool normalFile = !SharePointUtil.IsSharePointName(clientFile);
                if (normalFile)
                {                 // normal file, move temp file to dest file
                    FileUtil.ReplaceFile(clientFile, tempFile);
                }

                else                 // sharepoint
                {
                    SharePointUtil.CopyToSharePoint(tempFile, clientFile);
                    File.Delete(tempFile);                     // delete any temp file
                }
                return;
            }

            catch (Exception ex)             // close file on any exception
            {
                if (fw != null)
                {
                    try { fw.Close(); }     catch { }
                }
                throw new Exception(ex.Message, ex);
            }
        }
Example #28
0
        /// <summary>
        /// Copy file from client to server
        /// </summary>
        /// <param name="clientFile2"></param>
        /// <param name="serverFile"></param>

        public static void CopyToServer(
            string clientFile,
            string serverFile)
        {
            string clientFile2 = SharePointUtil.CacheLocalCopyIfSharePointFile(clientFile);

            if (ServiceFacade.UseRemoteServices)
            {
                FileStream fs = new FileStream(clientFile2, FileMode.Open, FileAccess.Read);
                while (true)
                {
                    byte[] buffer = new byte[UAL.ServerFile.TransferChunkSize];
                    int    bufLen = fs.Read(buffer, 0, buffer.Length);

                    if (bufLen < UAL.ServerFile.TransferChunkSize)                                     // at end
                    {
                        fs.Close();

                        byte[] buffer2 = new byte[bufLen];
                        Array.Copy(buffer, buffer2, bufLen);
                        buffer = buffer2;
                    }

                    NativeMethodTransportObject resultObject = ServiceFacade.CallServiceMethod(
                        ServiceCodes.MobiusFileService,
                        MobiusFileService.CopyToServer,
                        new object[] { buffer, serverFile });

                    if (bufLen < UAL.ServerFile.TransferChunkSize)
                    {
                        break;
                    }
                    serverFile = null;                                     // null for subsequent calls
                }
            }

            else             // direct call
            {
                FileStream fs = new FileStream(clientFile2, FileMode.Open, FileAccess.Read);
                while (true)
                {
                    byte[] buffer = new byte[UAL.ServerFile.TransferChunkSize];
                    int    bufLen = fs.Read(buffer, 0, buffer.Length);

                    if (bufLen < UAL.ServerFile.TransferChunkSize)                     // at end
                    {
                        fs.Close();

                        byte[] buffer2 = new byte[bufLen];
                        Array.Copy(buffer, buffer2, bufLen);
                        buffer = buffer2;
                    }

                    UAL.ServerFile.CopyToServer(serverFile, buffer);
                    if (bufLen < UAL.ServerFile.TransferChunkSize)
                    {
                        break;
                    }
                    serverFile = null;                     // null for subsequent calls
                }
            }

            if (clientFile2 != clientFile)
            {
                File.Delete(clientFile2);                                        // delete any temp file
            }
            return;
        }