コード例 #1
0
        public static bool TryGetMobiusSystemWindowsAccount(
            out string userName,
            out string pw)
        {
            if (ServiceFacade.UseRemoteServices)
            {
                throw new Exception("Account information is only available when Mobius is being run in \"Services - Integrated\" mode");
            }

            return(AccountAccessMx.TryGetMobiusSystemWindowsAccount(out userName, out pw));
        }
コード例 #2
0
/// <summary>
/// Return true if Mobius can write to the specified file (usually in another user's Share area or SharePoint site) from the service side
/// </summary>
/// <param name="path"></param>
/// <returns></returns>

        public static bool CanWriteFileFromServiceAccount(string path)
        {
            try
            {
                if (path.StartsWith(@"\\"))
                {
                    string shareName = NetworkResourceUtil.NormalizeConnectionStringToUncShareName(path);
                    //bool shareConnected = NetworkResourceUtil.DirectoryExists(shareName); // just verifying directory is faster if share already connected
                    //if (!shareConnected)
                    //{

                    string userName, pw;

                    if (!AccountAccessMx.TryGetMobiusSystemWindowsAccount(out userName, out pw))
                    {
                        return(false);
                    }

                    NetworkResourceUtil.AddConnection(path, userName, pw, false);
                    //}

                    FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
                    fs.Close();
                    return(true);
                }

                else if (SharePointUtil.IsSharePointName(path))
                {
                    string msg = SharePointUtil.CanWriteFile(path);                     // check for write, note: uses current user id not SystemAccountName
                    return(Lex.IsNullOrEmpty(msg));
                }

                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                DebugLog.Message("CanWriteFileFromServiceAccount failed for path: " + path + "\r\n" +
                                 ex.Message);
                return(false);
            }
        }