Пример #1
0
 /// <summary>
 /// Set current key.
 /// </summary>
 private void SetCurrentKey()
 {
     if (NewPath.Trim().Length > 0)
     {
         if (OldPath.Trim().Length > 0)
         {
             _currentKey = "[" + NewPath + "]-[" + OldPath + "]";
         }
         else
         {
             _currentKey = "[" + NewPath + "]-[?]";
         }
     }
     else
     {
         if (OldPath.Trim().Length > 0)
         {
             _currentKey = "[?]-[" + OldPath + "]";
         }
         else
         {
             _currentKey = string.Empty;
         }
     }
 }
Пример #2
0
        protected override void Execute(CodeActivityContext context)
        {
            PropertyDescriptor ftpSessionProperty = context.DataContext.GetProperties()[WithFtpSession.FtpSessionPropertyName];
            IFtpSession        ftpSession         = ftpSessionProperty?.GetValue(context.DataContext) as IFtpSession;

            try
            {
                if (ftpSession == null)
                {
                    throw new InvalidOperationException(Resources.FTPSessionNotFoundException);
                }
                ftpSession.Move(RemotePath.Get(context), NewPath.Get(context), Overwrite);
            }
            catch (Exception e)
            {
                if (ContinueOnError.Get(context))
                {
                    Trace.TraceError(e.ToString());
                }
                else
                {
                    throw;
                }
            }
        }
 private void NewPath_FilesShow(object sender, EventArgs e)
 {
     NewPath?.Invoke();
     if (NewPath != null)
     {
         //Console.WriteLine("NewPath_FilesShow is null");
     }
     if (true)
     {
         //Console.WriteLine("NewPath_FilesShow is changed");
     }
 }
Пример #4
0
    /// <summary>
    /// Moves document.
    /// </summary>
    private void PerformAction(object parameter)
    {
        if (Action.ToLower() == "copy")
        {
            AddLog(GetString("media.copy.startcopy"));
        }
        else
        {
            AddLog(GetString("media.move.startmove"));
        }

        if (LibraryInfo != null)
        {
            // Library path (used in recursive copy process)
            string libPath = MediaLibraryInfoProvider.GetMediaLibraryFolderPath(CMSContext.CurrentSiteName, LibraryInfo.LibraryFolder);

            // Ensure libPath is in original path type
            libPath = Path.GetFullPath(libPath);

            // Original path on disk from query
            string origPath = Path.GetFullPath(DirectoryHelper.CombinePath(libPath, FolderPath));

            // New path on disk
            string newPath = null;

            // Original path in DB
            string origDBPath = MediaLibraryHelper.EnsurePath(FolderPath);

            // New path in DB
            string newDBPath = null;

            AddLog(NewPath);

            // Check if requested folder is in library root folder
            if (!origPath.StartsWith(libPath, StringComparison.CurrentCultureIgnoreCase))
            {
                CurrentError = GetString("media.folder.nolibrary");
                AddLog(CurrentError);
                return;
            }

            string origFolderName = Path.GetFileName(origPath);

            if ((String.IsNullOrEmpty(Files) && !mAllFiles) && string.IsNullOrEmpty(origFolderName))
            {
                NewPath = NewPath + "\\" + LibraryInfo.LibraryFolder;
                NewPath = NewPath.Trim('\\');
            }
            newPath = NewPath;

            // Process current folder copy/move action
            if (String.IsNullOrEmpty(Files) && !AllFiles)
            {
                newPath = newPath.TrimEnd('\\') + '\\' + origFolderName;
                newPath = newPath.Trim('\\');

                // Check if moving into same folder
                if ((Action.ToLower() == "move") && (newPath == FolderPath))
                {
                    CurrentError = GetString("media.move.foldermove");
                    AddLog(CurrentError);
                    return;
                }

                // Error if moving folder into itself
                string newRootPath           = Path.GetDirectoryName(newPath).Trim();
                string newSubRootFolder      = Path.GetFileName(newPath).ToLower().Trim();
                string originalSubRootFolder = Path.GetFileName(FolderPath).ToLower().Trim();
                if (String.IsNullOrEmpty(Files) && (Action.ToLower() == "move") && newPath.StartsWith(DirectoryHelper.EnsurePathBackSlash(FolderPath)) &&
                    (originalSubRootFolder == newSubRootFolder) && (newRootPath == FolderPath))
                {
                    CurrentError = GetString("media.move.movetoitself");
                    AddLog(CurrentError);
                    return;
                }

                // Get unique path for copy or move
                string path = Path.GetFullPath(DirectoryHelper.CombinePath(libPath, newPath));
                path    = MediaLibraryHelper.EnsureUniqueDirectory(path);
                newPath = path.Remove(0, (libPath.Length + 1));

                // Get new DB path
                newDBPath = MediaLibraryHelper.EnsurePath(newPath.Replace(DirectoryHelper.EnsurePathBackSlash(libPath), ""));
            }
            else
            {
                origDBPath = MediaLibraryHelper.EnsurePath(FolderPath);
                newDBPath  = MediaLibraryHelper.EnsurePath(newPath.Replace(libPath, "")).Trim('/');
            }

            // Error if moving folder into its subfolder
            if ((String.IsNullOrEmpty(Files) && !AllFiles) && (Action.ToLower() == "move") && newPath.StartsWith(DirectoryHelper.EnsurePathBackSlash(FolderPath)))
            {
                CurrentError = GetString("media.move.parenttochild");
                AddLog(CurrentError);
                return;
            }

            // Error if moving files into same directory
            if ((!String.IsNullOrEmpty(Files) || AllFiles) && (Action.ToLower() == "move") && (newPath.TrimEnd('\\') == FolderPath.TrimEnd('\\')))
            {
                CurrentError = GetString("media.move.fileserror");
                AddLog(CurrentError);
                return;
            }

            NewPath       = newPath;
            refreshScript = "if ((typeof(window.top.opener) != 'undefined') && (typeof(window.top.opener.RefreshLibrary) != 'undefined')) {window.top.opener.RefreshLibrary(" + ScriptHelper.GetString(NewPath.Replace('\\', '|')) + ");} else if ((typeof(window.top.wopener) != 'undefined') && (typeof(window.top.wopener.RefreshLibrary) != 'undefined')) { window.top.wopener.RefreshLibrary(" + ScriptHelper.GetString(NewPath.Replace('\\', '|')) + "); } window.top.close();";

            // If mFiles is empty handle directory copy/move
            if (String.IsNullOrEmpty(Files) && !mAllFiles)
            {
                try
                {
                    switch (Action.ToLower())
                    {
                    case "move":
                        MediaLibraryInfoProvider.MoveMediaLibraryFolder(CMSContext.CurrentSiteName, MediaLibraryID, origDBPath, newDBPath, false);
                        break;

                    case "copy":
                        MediaLibraryInfoProvider.CopyMediaLibraryFolder(CMSContext.CurrentSiteName, MediaLibraryID, origDBPath, newDBPath, false, CurrentUser.UserID);
                        break;
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    CurrentError = GetString("general.erroroccurred") + " " + GetString("media.security.accessdenied");
                    EventLogProvider ev = new EventLogProvider();
                    ev.LogEvent("MediaFolder", this.Action, ex);
                    AddLog(CurrentError);
                    return;
                }
                catch (ThreadAbortException ex)
                {
                    string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
                    if (state == CMSThread.ABORT_REASON_STOP)
                    {
                        // When canceled
                        CurrentInfo = GetString("general.actioncanceled");
                        AddLog(CurrentInfo);
                    }
                    else
                    {
                        // Log error
                        CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                        EventLogProvider ev = new EventLogProvider();
                        ev.LogEvent("MediaFolder", this.Action, ex);
                        AddLog(CurrentError);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                    EventLogProvider ev = new EventLogProvider();
                    ev.LogEvent("MediaFolder", this.Action, ex);
                    AddLog(CurrentError);
                    return;
                }
            }
            else
            {
                string origDBFilePath = null;
                string newDBFilePath  = null;

                if (!mAllFiles)
                {
                    try
                    {
                        string[] files = Files.Split('|');
                        foreach (string filename in files)
                        {
                            origDBFilePath = (string.IsNullOrEmpty(origDBPath)) ? filename : origDBPath + "/" + filename;
                            newDBFilePath  = (string.IsNullOrEmpty(newDBPath)) ? filename : newDBPath + "/" + filename;
                            AddLog(filename);
                            CopyMove(origDBFilePath, newDBFilePath);
                        }
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        CurrentError = GetString("general.erroroccurred") + " " + ResHelper.GetString("media.security.accessdenied");
                        EventLogProvider ev = new EventLogProvider();
                        ev.LogEvent("MediaFile", this.Action, ex);
                        AddLog(CurrentError);
                        return;
                    }
                    catch (ThreadAbortException ex)
                    {
                        string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
                        if (state == CMSThread.ABORT_REASON_STOP)
                        {
                            // When canceled
                            CurrentInfo = GetString("general.actioncanceled");
                            AddLog(CurrentInfo);
                        }
                        else
                        {
                            // Log error
                            CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                            EventLogProvider ev = new EventLogProvider();
                            ev.LogEvent("MediaFile", this.Action, ex);
                            AddLog(CurrentError);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                        EventLogProvider ev = new EventLogProvider();
                        ev.LogEvent("MediaFile", this.Action, ex);
                        AddLog(CurrentError);
                        return;
                    }
                }
                else
                {
                    HttpContext context = (parameter as HttpContext);
                    if (context != null)
                    {
                        HttpContext.Current = context;

                        DataSet files = GetFileSystemDataSource();
                        if (!DataHelper.IsEmpty(files))
                        {
                            foreach (DataRow file in files.Tables[0].Rows)
                            {
                                string fileName = ValidationHelper.GetString(file["FileName"], "");

                                AddLog(fileName);

                                origDBFilePath = (string.IsNullOrEmpty(origDBPath)) ? fileName : origDBPath + "/" + fileName;
                                newDBFilePath  = (string.IsNullOrEmpty(newDBPath)) ? fileName : newDBPath + "/" + fileName;

                                // Clear current httpcontext for CopyMove action in threat
                                HttpContext.Current = null;

                                try
                                {
                                    CopyMove(origDBFilePath, newDBFilePath);
                                }
                                catch (UnauthorizedAccessException ex)
                                {
                                    CurrentError = GetString("general.erroroccurred") + " " + ResHelper.GetString("media.security.accessdenied");
                                    EventLogProvider ev = new EventLogProvider();
                                    ev.LogEvent("MediaFile", this.Action, ex);
                                    AddLog(CurrentError);
                                    return;
                                }
                                catch (ThreadAbortException ex)
                                {
                                    string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
                                    if (state == CMSThread.ABORT_REASON_STOP)
                                    {
                                        // When canceled
                                        CurrentInfo = GetString("general.actioncanceled");
                                        AddLog(CurrentInfo);
                                    }
                                    else
                                    {
                                        // Log error
                                        CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                                        EventLogProvider ev = new EventLogProvider();
                                        ev.LogEvent("MediaFile", this.Action, ex);
                                        AddLog(CurrentError);
                                        return;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                                    EventLogProvider ev = new EventLogProvider();
                                    ev.LogEvent("MediaFile", this.Action, ex);
                                    AddLog(CurrentError);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    /// <summary>
    /// Moves document.
    /// </summary>
    private void PerformAction(object parameter)
    {
        AddLog(GetString(CopyMoveAction.ToLowerCSafe() == "copy" ? "media.copy.startcopy" : "media.move.startmove"));

        if (LibraryInfo != null)
        {
            // Library path (used in recursive copy process)
            string libPath = MediaLibraryInfoProvider.GetMediaLibraryFolderPath(SiteContext.CurrentSiteName, LibraryInfo.LibraryFolder);

            // Ensure libPath is in original path type
            libPath = Path.GetFullPath(libPath);

            // Original path on disk from query
            string origPath = Path.GetFullPath(DirectoryHelper.CombinePath(libPath, FolderPath));

            // Original path in DB
            string origDBPath = Path.EnsureForwardSlashes(FolderPath);

            // New path in DB
            string newDBPath;

            AddLog(NewPath);

            // Check if requested folder is in library root folder
            if (!origPath.StartsWithCSafe(libPath, true))
            {
                CurrentError = GetString("media.folder.nolibrary");
                AddLog(CurrentError);
                return;
            }

            string origFolderName = Path.GetFileName(origPath);

            if ((String.IsNullOrEmpty(Files) && !mAllFiles) && string.IsNullOrEmpty(origFolderName))
            {
                NewPath = NewPath + "\\" + LibraryInfo.LibraryFolder;
                NewPath = NewPath.Trim('\\');
            }

            // New path on disk
            string newPath = NewPath;

            // Process current folder copy/move action
            if (String.IsNullOrEmpty(Files) && !AllFiles)
            {
                newPath = Path.EnsureEndSlash(newPath) + origFolderName;
                newPath = newPath.Trim('\\');

                // Check if moving into same folder
                if ((CopyMoveAction.ToLowerCSafe() == "move") && (newPath == FolderPath))
                {
                    CurrentError = GetString("media.move.foldermove");
                    AddLog(CurrentError);
                    return;
                }

                // Error if moving folder into itself
                string newRootPath           = Path.GetDirectoryName(newPath).Trim();
                string newSubRootFolder      = Path.GetFileName(newPath).ToLowerCSafe().Trim();
                string originalSubRootFolder = Path.GetFileName(FolderPath).ToLowerCSafe().Trim();
                if (String.IsNullOrEmpty(Files) && (CopyMoveAction.ToLowerCSafe() == "move") && newPath.StartsWithCSafe(Path.EnsureEndSlash(FolderPath)) &&
                    (originalSubRootFolder == newSubRootFolder) && (newRootPath == FolderPath))
                {
                    CurrentError = GetString("media.move.movetoitself");
                    AddLog(CurrentError);
                    return;
                }

                try
                {
                    // Get unique path for copy or move
                    string path = Path.GetFullPath(DirectoryHelper.CombinePath(libPath, newPath));
                    path    = MediaLibraryHelper.EnsureUniqueDirectory(path);
                    newPath = path.Remove(0, (libPath.Length + 1));

                    // Get new DB path
                    newDBPath = Path.EnsureForwardSlashes(newPath.Replace(Path.EnsureEndSlash(libPath), ""));
                }
                catch (Exception ex)
                {
                    CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                    Service.Resolve <IEventLogService>().LogException("MediaFolder", CopyMoveAction, ex);
                    AddLog(CurrentError);
                    return;
                }
            }
            else
            {
                origDBPath = Path.EnsureForwardSlashes(FolderPath);
                newDBPath  = Path.EnsureForwardSlashes(newPath.Replace(libPath, "")).Trim('/');
            }

            // Error if moving folder into its subfolder
            if ((String.IsNullOrEmpty(Files) && !AllFiles) && (CopyMoveAction.ToLowerCSafe() == "move") && newPath.StartsWithCSafe(Path.EnsureEndSlash(FolderPath)))
            {
                CurrentError = GetString("media.move.parenttochild");
                AddLog(CurrentError);
                return;
            }

            // Error if moving files into same directory
            if ((!String.IsNullOrEmpty(Files) || AllFiles) && (CopyMoveAction.ToLowerCSafe() == "move") && (newPath.TrimEnd('\\') == FolderPath.TrimEnd('\\')))
            {
                CurrentError = GetString("media.move.fileserror");
                AddLog(CurrentError);
                return;
            }

            NewPath      = newPath;
            AsyncNewPath = newPath;

            // If mFiles is empty handle directory copy/move
            if (String.IsNullOrEmpty(Files) && !mAllFiles)
            {
                try
                {
                    switch (CopyMoveAction.ToLowerCSafe())
                    {
                    case "move":
                        MediaLibraryInfoProvider.MoveMediaLibraryFolder(SiteContext.CurrentSiteName, MediaLibraryID, origDBPath, newDBPath);
                        break;

                    case "copy":
                        MediaLibraryInfoProvider.CopyMediaLibraryFolder(SiteContext.CurrentSiteName, MediaLibraryID, origDBPath, newDBPath, CurrentUser.UserID);
                        break;
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    CurrentError = GetString("general.erroroccurred") + " " + GetString("media.security.accessdenied");
                    Service.Resolve <IEventLogService>().LogException("MediaFolder", CopyMoveAction, ex);
                    AddLog(CurrentError);
                }
                catch (ThreadAbortException ex)
                {
                    if (CMSThread.Stopped(ex))
                    {
                        // When canceled
                        CurrentInfo = GetString("general.actioncanceled");
                        AddLog(CurrentInfo);
                    }
                    else
                    {
                        // Log error
                        CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                        Service.Resolve <IEventLogService>().LogException("MediaFolder", CopyMoveAction, ex);
                        AddLog(CurrentError);
                    }
                }
                catch (Exception ex)
                {
                    CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                    Service.Resolve <IEventLogService>().LogException("MediaFolder", CopyMoveAction, ex);
                    AddLog(CurrentError);
                }
            }
            else
            {
                string origDBFilePath;
                string newDBFilePath;

                if (!mAllFiles)
                {
                    try
                    {
                        string[] files = Files.Split('|');
                        foreach (string filename in files)
                        {
                            origDBFilePath = (string.IsNullOrEmpty(origDBPath)) ? filename : origDBPath + "/" + filename;
                            newDBFilePath  = (string.IsNullOrEmpty(newDBPath)) ? filename : newDBPath + "/" + filename;
                            AddLog(filename);
                            CopyMove(origDBFilePath, newDBFilePath);
                        }
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        CurrentError = GetString("general.erroroccurred") + " " + GetString("media.security.accessdenied");
                        Service.Resolve <IEventLogService>().LogException("MediaFile", CopyMoveAction, ex);
                        AddLog(CurrentError);
                    }
                    catch (ThreadAbortException ex)
                    {
                        if (CMSThread.Stopped(ex))
                        {
                            // When canceled
                            CurrentInfo = GetString("general.actioncanceled");
                            AddLog(CurrentInfo);
                        }
                        else
                        {
                            // Log error
                            CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                            Service.Resolve <IEventLogService>().LogException("MediaFile", CopyMoveAction, ex);
                            AddLog(CurrentError);
                        }
                    }
                    catch (Exception ex)
                    {
                        CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                        Service.Resolve <IEventLogService>().LogException("MediaFile", CopyMoveAction, ex);
                        AddLog(CurrentError);
                    }
                }
                else
                {
                    var fileNames = GetFileNames().ToList();
                    if (!fileNames.Any())
                    {
                        return;
                    }

                    foreach (string fileName in fileNames)
                    {
                        AddLog(fileName);

                        origDBFilePath = (string.IsNullOrEmpty(origDBPath)) ? fileName : origDBPath + "/" + fileName;
                        newDBFilePath  = (string.IsNullOrEmpty(newDBPath)) ? fileName : newDBPath + "/" + fileName;

                        try
                        {
                            CopyMove(origDBFilePath, newDBFilePath);
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            CurrentError = GetString("general.erroroccurred") + " " + GetString("media.security.accessdenied");
                            Service.Resolve <IEventLogService>().LogException("MediaFile", CopyMoveAction, ex);
                            AddLog(CurrentError);
                            return;
                        }
                        catch (ThreadAbortException ex)
                        {
                            if (CMSThread.Stopped(ex))
                            {
                                // When canceled
                                CurrentInfo = GetString("general.actioncanceled");
                                AddLog(CurrentInfo);
                            }
                            else
                            {
                                // Log error
                                CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                                Service.Resolve <IEventLogService>().LogException("MediaFile", CopyMoveAction, ex);
                                AddLog(CurrentError);
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            CurrentError = GetString("general.erroroccurred") + " " + ex.Message;
                            Service.Resolve <IEventLogService>().LogException("MediaFile", CopyMoveAction, ex);
                            AddLog(CurrentError);
                            return;
                        }
                    }
                }
            }
        }
    }
Пример #6
0
        private static void ReconfigureStationAccess()
        {
            var pathList      = new List <BuildingInfo.PathInfo>();
            var connectList   = new List <Vector3[]>();
            var singleGap     = 16;
            var directionList = new List <string>();

            //for (int i = 0; i < m_Info.m_paths.Length; i++)
            //{
            //    var thePath = m_Info.m_paths[i];
            //    if (thePath.m_netInfo == null || thePath.m_nodes == null || thePath.m_nodes.Count() < 2)
            //        continue;
            //    if (thePath.m_netInfo.IsUndergroundMetroStationTrack())
            //    {
            //        var xDirection = (thePath.m_nodes.First().x - thePath.m_nodes.Last().x);
            //        var zDirection = (thePath.m_nodes.First().z - thePath.m_nodes.Last().z);
            //        var direction = $"{xDirection},{zDirection}";
            //        var antiDirection = $"{-xDirection},{-zDirection}";
            //        if (directionList.Contains(direction))
            //        {
            //            continue;
            //        }
            //        if (directionList.Contains(antiDirection))
            //        {
            //            thePath.m_nodes = thePath.m_nodes.Reverse().ToArray();
            //        }
            //        else
            //        {
            //            directionList.Add(direction);
            //        }
            //    }
            //}

            for (int i = 0; i < m_Info.m_paths.Length; i++)
            {
                var thePath = m_Info.m_paths[i];
                if (thePath.m_netInfo == null || thePath.m_nodes == null || thePath.m_nodes.Count() < 2)
                {
                    continue;
                }
                if (thePath.m_netInfo.IsUndergroundSmallStationTrack() && !IsPathGenerated(thePath))
                {
                    var xCoeff = -(thePath.m_nodes.First().x - thePath.m_nodes.Last().x) / Vector3.Distance(thePath.m_nodes.First(), thePath.m_nodes.Last());
                    var zCoeff = (thePath.m_nodes.First().z - thePath.m_nodes.Last().z) / Vector3.Distance(thePath.m_nodes.First(), thePath.m_nodes.Last());

                    var multiplier       = 1;
                    var nearestTrackNode = m_Info.m_paths.Where(p => p.m_netInfo.IsUndergroundMetroStationTrack()).SelectMany(p => p.m_nodes).Where(n => n.y == thePath.m_nodes.First().y).OrderBy(n => Vector3.Distance(n, thePath.m_nodes.First())).FirstOrDefault();
                    if (Vector3.Distance(nearestTrackNode, thePath.m_nodes.First()) <= 2 * singleGap)
                    {
                        multiplier = -1;
                    }
                    var aNewPath = thePath.ShallowClone();
                    var nodeList = new List <Vector3>();
                    nodeList.Add(new Vector3()
                    {
                        x = thePath.m_nodes.First().x + multiplier * zCoeff * singleGap,
                        y = thePath.m_nodes.First().y,
                        z = thePath.m_nodes.First().z + multiplier * xCoeff * singleGap
                    });
                    nodeList.Add(new Vector3()
                    {
                        x = thePath.m_nodes.Last().x + multiplier * zCoeff * singleGap,
                        y = thePath.m_nodes.Last().y,
                        z = thePath.m_nodes.Last().z + multiplier * xCoeff * singleGap
                    });
                    aNewPath.m_nodes = nodeList.ToArray();
                    MarkPathGenerated(aNewPath);
                    pathList.Add(aNewPath);
                }
                pathList.Add(thePath);
            }

            var aPath = pathList.FirstOrDefault(p => IsPedestrianPath(p));

            if (aPath == null)
            {
                aPath = new BuildingInfo.PathInfo();
            }

            for (int i = 0; i < pathList.Count; i++)
            {
                if (pathList[i].m_netInfo != null && pathList[i].m_netInfo.IsUndergroundMetroStationTrack())
                {
                    TrackPath = pathList[i];
                    var middleBend = GetMiddle(TrackPath, true);
                    var middle     = GetMiddle(TrackPath, false);
                    BendVector = middleBend - middle;

                    //var trackNodes = new List<Vector3>();
                    //for (var j = 0; j < trackPath.m_nodes.Count(); j++)
                    //{
                    //    trackNodes.Add(new Vector3()
                    //    {
                    //        x = trackPath.m_nodes[j].x - bendVector.x,
                    //        y = trackPath.m_nodes[j].y,
                    //        z = trackPath.m_nodes[j].z - bendVector.z
                    //    });
                    //}
                    //trackPath.m_nodes = trackNodes.ToArray();
                    NewPath = aPath.ShallowClone();
                    NewPath.AssignNetInfo(SpecialNetInfo);
                    MarkPathGenerated(NewPath);

                    xCoeff = -(TrackPath.m_nodes[0].x - TrackPath.m_nodes.Last().x) / Vector3.Distance(TrackPath.m_nodes[0], TrackPath.m_nodes.Last());
                    zCoeff = (TrackPath.m_nodes[0].z - TrackPath.m_nodes.Last().z) / Vector3.Distance(TrackPath.m_nodes[0], TrackPath.m_nodes.Last());
                    var stationLength = Vector3.Distance(TrackPath.m_nodes[0], TrackPath.m_nodes.Last());
                    StairsLengthX = (((0.12f * m_BendStrength) + 1) * (stationLength * StairCoeff)) * -xCoeff;
                    StairsLengthZ = (((0.12f * m_BendStrength) + 1) * (stationLength * StairCoeff)) * zCoeff;
                    var interpolant = 0.6f;
                    Crossing = Vector3.Lerp(TrackPath.m_nodes.First(), TrackPath.m_nodes.Last(), interpolant);
                    if (TrackPath.m_netInfo.IsUndergroundIslandPlatformStationTrack())
                    {
                        pathList.AddRange(SetStationPaths(0));
                    }
                    //else if (TrackPath.m_netInfo.IsUndergroundSideIslandPlatformMetroStationTrack())
                    //{
                    //    pathList.AddRange(SetStationPaths(-14, 0, 14));
                    //}
                    else if (TrackPath.m_netInfo.IsUndergroundSmallStationTrack())
                    {
                        pathList.AddRange(SetStationPaths(5));
                    }
                    else if (TrackPath.m_netInfo.IsUndergroundPlatformLargeMetroStationTrack())
                    {
                        pathList.AddRange(SetStationPaths(-11, 11));
                    }
                    else if (TrackPath.m_netInfo.IsUndergroundDualIslandPlatformMetroStationTrack())
                    {
                        pathList.AddRange(SetStationPaths(-8.8f, -5.5f, 5.5f, 8.8f));
                    }
                    else if (TrackPath.m_netInfo.IsUndergroundSidePlatformMetroStationTrack())
                    {
                        pathList.AddRange(SetStationPaths(-7, 7));
                    }

                    if (!connectList.Contains(NewPath.m_nodes))
                    {
                        connectList.Add(NewPath.m_nodes);
                    }
                }
            }
            if (/*m_SuperInfo == null &&*/ m_Info.m_paths.Count() >= 2)
            {
                CheckPedestrianConnections();
            }
            pathList = CleanPaths(pathList);
            var lowestHighPaths = m_Info.m_paths.Where(p => IsPedestrianPath(p) && p.m_nodes.Any(n => n.y > -4) && p.m_nodes.Any(nd => nd.y <= -4)).ToList();

            if (lowestHighPaths.Count == 0)
            {
                lowestHighPaths.Add(m_Info.m_paths.Where(p => IsPedestrianPath(p))
                                    .OrderByDescending(p => p.m_nodes[0].y)
                                    .FirstOrDefault());
            }
            var connectPoints = new List <Vector3>();

            if (lowestHighPaths != null && lowestHighPaths.Count > 0)
            {
                foreach (BuildingInfo.PathInfo p in lowestHighPaths)
                {
                    if (p != null && p.m_nodes != null && p.m_nodes.Count() > 0)
                    {
                        connectPoints.Add(p.m_nodes.OrderByDescending(n => n.y).ThenBy(n => n.z).LastOrDefault());
                    }
                }
            }
            var currentVector = connectPoints.FirstOrDefault();

            if (connectPoints != null && connectPoints.Count > 0)
            {
                var pool      = new List <Vector3[]>();
                var pivotPath = pathList.FirstOrDefault(p => p.m_nodes.Any(n => n == connectPoints.FirstOrDefault()));
                pool.AddRange(connectList);

                for (var i = 0; i < connectList.Count; i++)
                {
                    var closestVector = pool.SelectMany(n => n).OrderBy(n => (currentVector.x - n.x) + (100 * (connectPoints.FirstOrDefault().y - n.y)) + (currentVector.z - n.z)).LastOrDefault();

                    var closestPath = pathList.FirstOrDefault(p => p.m_nodes.Any(n => n == closestVector));
                    BuildingInfo.PathInfo branch = null;
                    if (currentVector == connectPoints.FirstOrDefault())
                    {
                        branch = ChainPath(pivotPath, closestVector, Array.IndexOf(pivotPath.m_nodes, connectPoints.FirstOrDefault()));
                    }
                    else
                    {
                        branch = ChainPath(closestPath, currentVector, Array.IndexOf(closestPath.m_nodes, closestVector));
                    }
                    branch.AssignNetInfo(SpecialNetInfo);
                    branch.m_forbidLaneConnection = new[] { true, true };
                    pathList.Add(branch);
                    var nodeArrayToLose = pool.FirstOrDefault(na => na.Any(n => n == closestVector));
                    if (nodeArrayToLose != null)
                    {
                        currentVector = nodeArrayToLose.OrderBy(n => Vector3.Distance(closestVector, n)).LastOrDefault();
                        pool.Remove(nodeArrayToLose);
                    }
                }

                if (connectPoints.Count > 1)
                {
                    for (var i = 1; i < connectPoints.Count(); i++)
                    {
                        Vector3 node          = connectPoints[i];
                        Vector3 closestVector = connectList.SelectMany(n => n).OrderBy(n => (node.x - n.x) + (100 * (node.y - n.y)) + (node.z - n.z)).FirstOrDefault();
                        var     closestPath   = pathList.FirstOrDefault(p => p.m_nodes.Any(n => n == closestVector));
                        var     branch        = ChainPath(closestPath, node, Array.IndexOf(closestPath.m_nodes, closestVector));
                        branch.AssignNetInfo(SpecialNetInfo);
                        branch.m_forbidLaneConnection = new[] { true, true };
                        pathList.Add(branch);
                    }
                }
            }

            m_Info.m_paths = CleanPaths(pathList).ToArray();
        }
Пример #7
0
        private static List <BuildingInfo.PathInfo> SetStationPaths(params float[] connectorHalfWidths)
        {
            var retval = new List <BuildingInfo.PathInfo>();

            if (connectorHalfWidths != null)
            {
                var newNodes = new List <Vector3>();
                var connectorHalfWidthList = new List <float>();
                connectorHalfWidthList.AddRange(connectorHalfWidths);
                connectorHalfWidthList.Sort();
                var offset        = connectorHalfWidthList[0];
                var forbiddenList = new List <bool>();

                for (int i = 0; i < connectorHalfWidthList.Count(); i++)
                {
                    if (i == 0)
                    {
                        newNodes.Add(new Vector3()
                        {
                            x = Crossing.x + (connectorHalfWidthList[0] * zCoeff) - (3 * xCoeff),
                            y = TrackPath.m_nodes.Last().y + 8,
                            z = Crossing.z + (connectorHalfWidthList[0] * xCoeff) + (3 * zCoeff)
                        });
                        newNodes[0] = new Vector3(newNodes[0].x - BendVector.x, newNodes[0].y, newNodes[0].z + BendVector.z);
                    }
                    else
                    {
                        offset -= connectorHalfWidthList[i];
                        newNodes.Add(new Vector3()
                        {
                            x = newNodes[i - 1].x + (Math.Abs(offset) * zCoeff),
                            y = TrackPath.m_nodes.Last().y + 8,
                            z = newNodes[i - 1].z + (Math.Abs(offset) * xCoeff)
                        });
                        offset = connectorHalfWidthList[i];
                    }
                    forbiddenList.Add(true);
                }


                var averagedNodeList = new List <Vector3>();
                var stairNodes       = new List <Vector3>();
                if (newNodes.Count() == 1)
                {
                    averagedNodeList.Add(newNodes.First());
                    stairNodes.Add(new Vector3()
                    {
                        x = newNodes[0].x + StairsLengthX,
                        y = TrackPath.m_nodes.Last().y,
                        z = newNodes[0].z + StairsLengthZ,
                    });
                }
                else
                {
                    var mergeOnLast = false;
                    for (int i = 0; i < newNodes.Count(); i++)
                    {
                        if (i > 0)
                        {
                            if (mergeOnLast)
                            {
                                mergeOnLast = false;
                            }
                            else if (Vector3.Distance(newNodes[i], newNodes[i - 1]) < 4)
                            {
                                averagedNodeList.Add(((newNodes[i] + newNodes[i - 1]) / 2));
                                mergeOnLast = true;
                            }
                            else
                            {
                                averagedNodeList.Add(newNodes[i - 1]);
                                if (i == newNodes.Count() - 1)
                                {
                                    averagedNodeList.Add(newNodes[i]);
                                }
                            }
                        }

                        stairNodes.Add(new Vector3()
                        {
                            x = newNodes[i].x + StairsLengthX,
                            y = TrackPath.m_nodes.Last().y,
                            z = newNodes[i].z + StairsLengthZ,
                        });
                    }
                }

                NewPath.m_nodes = averagedNodeList.ToArray();
                NewPath.m_forbidLaneConnection = forbiddenList.ToArray();
                NewPath.AssignNetInfo(m_SpecialNetInfo);

                retval.Add(NewPath);

                for (var i = 0; i < stairNodes.Count(); i++)
                {
                    var closestIndex    = averagedNodeList.IndexOf(averagedNodeList.OrderBy(n => Vector3.Distance(n, stairNodes[i])).FirstOrDefault());
                    var branchPathStair = ChainPath(NewPath, stairNodes[i], closestIndex);
                    branchPathStair.m_forbidLaneConnection = new[] { true, false };
                    branchPathStair.AssignNetInfo(m_SpecialNetInfo);
                    retval.Add(branchPathStair);
                }
            }
            return(retval);
        }
Пример #8
0
 public string NewGitBookPath(string directoryPath)
 {
     return(NewPath.Replace(directoryPath, "").Replace("\\", "/"));
 }
Пример #9
0
        public PathInfo(ImageResource imgRes)
            : base(imgRes)
        {
            BinaryPSDReader reader = imgRes.GetDataReader();

            this.PathNum = this.ID - 2000;
            this.ID = 2000;

            ushort numKnots = 0;
            int cnt = 0;
            this.Commands = new List<object>();
            while (reader.BytesToEnd > 0)
            {
                RecordType rtype = (RecordType)(int)reader.ReadUInt16();
                //Should always start with PathFill (0)
                if (cnt == 0 && rtype != RecordType.PathFill)
                    throw new Exception("PathInfo start error!");

                switch (rtype)
                {
                    case RecordType.InitialFill:
                        reader.BaseStream.Position += 1;
                        bool allPixelStart = reader.ReadBoolean();
                        reader.BaseStream.Position += 22;
                        break;

                    case RecordType.PathFill:
                        if (cnt != 0)
                            throw new Exception("Path fill?!?");
                        reader.BaseStream.Position += 24;
                        break;

                    case RecordType.Clipboard:
                        ERectangleF rct = new ERectangleF();
                        rct.Top = reader.ReadPSDSingle();
                        rct.Left = reader.ReadPSDSingle();
                        rct.Bottom = reader.ReadPSDSingle();
                        rct.Right = reader.ReadPSDSingle();
                        Clipboard clp = new Clipboard();
                        clp.Rectangle = rct;
                        clp.Scale = reader.ReadPSDSingle();
                        reader.BaseStream.Position += 4;
                        this.Commands.Add(clp);
                        break;

                    case RecordType.ClosedPathLength:
                    case RecordType.OpenPathLength:
                        numKnots = reader.ReadUInt16();
                        reader.BaseStream.Position += 22;
                        NewPath np = new NewPath();
                        np.Open = (rtype == RecordType.OpenPathLength);
                        this.Commands.Add(np);
                        break;

                    case RecordType.ClosedPathBezierKnotLinked:
                    case RecordType.ClosedPathBezierKnotUnlinked:
                    case RecordType.OpenPathBezierKnotLinked:
                    case RecordType.OpenPathBezierKnotUnlinked:
                        BezierKnot bz = new BezierKnot();

                        EPointF[] pts = new EPointF[3];
                        for (int i = 0; i < 3; i++)
                        {
                            float y = reader.ReadPSDFixedSingle(); //y comes first...
                            pts[i] = new EPointF(reader.ReadPSDFixedSingle(), y) / 256;
                        }
                        bz.Control1 = pts[0];
                        bz.Anchor = pts[1];
                        bz.Control2 = pts[2];
                        bz.Linked = (rtype == RecordType.ClosedPathBezierKnotLinked || rtype == RecordType.OpenPathBezierKnotLinked);
                        //bz.Open = (rtype == RecordType.OpenPathBezierKnotLinked || rtype == RecordType.OpenPathBezierKnotUnlinked);

                        this.Commands.Add(bz);
                        numKnots--;
                        break;
                }
                cnt++;
            }

            reader.Close();
        }
Пример #10
0
        public PathInfo(ImageResource imgRes)
            : base(imgRes)
        {
            BinaryPSDReader reader = imgRes.GetDataReader();

            this.PathNum = this.ID - 2000;
            this.ID      = 2000;

            ushort numKnots = 0;
            int    cnt      = 0;

            this.Commands = new List <object>();
            while (reader.BytesToEnd > 0)
            {
                RecordType rtype = (RecordType)(int)reader.ReadUInt16();
                //Should always start with PathFill (0)
                if (cnt == 0 && rtype != RecordType.PathFill)
                {
                    throw new Exception("PathInfo start error!");
                }

                switch (rtype)
                {
                case RecordType.InitialFill:
                    reader.BaseStream.Position += 1;
                    bool allPixelStart = reader.ReadBoolean();
                    reader.BaseStream.Position += 22;
                    break;

                case RecordType.PathFill:
                    if (cnt != 0)
                    {
                        throw new Exception("Path fill?!?");
                    }
                    reader.BaseStream.Position += 24;
                    break;

                case RecordType.Clipboard:
                    ERectangleF rct = new ERectangleF();
                    rct.Top    = reader.ReadPSDSingle();
                    rct.Left   = reader.ReadPSDSingle();
                    rct.Bottom = reader.ReadPSDSingle();
                    rct.Right  = reader.ReadPSDSingle();
                    Clipboard clp = new Clipboard();
                    clp.Rectangle = rct;
                    clp.Scale     = reader.ReadPSDSingle();
                    reader.BaseStream.Position += 4;
                    this.Commands.Add(clp);
                    break;

                case RecordType.ClosedPathLength:
                case RecordType.OpenPathLength:
                    numKnots = reader.ReadUInt16();
                    reader.BaseStream.Position += 22;
                    NewPath np = new NewPath();
                    np.Open = (rtype == RecordType.OpenPathLength);
                    this.Commands.Add(np);
                    break;

                case RecordType.ClosedPathBezierKnotLinked:
                case RecordType.ClosedPathBezierKnotUnlinked:
                case RecordType.OpenPathBezierKnotLinked:
                case RecordType.OpenPathBezierKnotUnlinked:
                    BezierKnot bz = new BezierKnot();

                    EPointF[] pts = new EPointF[3];
                    for (int i = 0; i < 3; i++)
                    {
                        float y = reader.ReadPSDFixedSingle();     //y comes first...
                        pts[i] = new EPointF(reader.ReadPSDFixedSingle(), y) / 256;
                    }
                    bz.Control1 = pts[0];
                    bz.Anchor   = pts[1];
                    bz.Control2 = pts[2];
                    bz.Linked   = (rtype == RecordType.ClosedPathBezierKnotLinked || rtype == RecordType.OpenPathBezierKnotLinked);
                    //bz.Open = (rtype == RecordType.OpenPathBezierKnotLinked || rtype == RecordType.OpenPathBezierKnotUnlinked);

                    this.Commands.Add(bz);
                    numKnots--;
                    break;
                }
                cnt++;
            }

            reader.Close();
        }