Exemplo n.º 1
0
        public void Rename(ProjectItemMeta meta, string name)
        {
            //Implementation could be removed in your own IProjectManager implementation

            if (PersistentData != null && PersistentData.Length != 0)
            {
                if (PersistentData.Length > 1)
                {
                    Dictionary <long, PersistentData> dataDictionary = PersistentData.ToDictionary(d => d.InstanceId);

                    PersistentData persistentData;
                    if (dataDictionary.TryGetValue(meta.Descriptor.InstanceId, out persistentData))
                    {
                        PersistentObjects.PersistentObject persistentObject = persistentData.AsPersistentObject;
                        persistentObject.name = name;
                        if (meta.Descriptor.Components != null)
                        {
                            for (int i = 0; i < meta.Descriptor.Components.Length; ++i)
                            {
                                if (dataDictionary.TryGetValue(meta.Descriptor.Components[i].InstanceId, out persistentData))
                                {
                                    persistentObject      = persistentData.AsPersistentObject;
                                    persistentObject.name = name;
                                }
                            }
                        }
                    }
                }
                else
                {
                    PersistentObjects.PersistentObject persistentObject = PersistentData[0].AsPersistentObject;
                    persistentObject.name = name;
                }
            }
        }
Exemplo n.º 2
0
        //public void SaveProjectData(string name, ProjectData data, ProjectEventHandler callback)
        //{
        //    m_storage.SaveFile(name + ".rtpdata", m_serializer.Serialize(data), saveDataCompleted =>
        //    {
        //        if (callback != null)
        //        {
        //            callback(new ProjectPayload());
        //        }
        //    });
        //}

        //public void Load(ProjectItem folder, ProjectEventHandler<ProjectItem[]> callback, params int[] exceptTypes)
        //{
        //    string folderPath = folder.ToString();
        //    m_storage.GetFiles(folderPath, getFilesResult =>
        //    {
        //        string[] path = getFilesResult.Data.Where(filePath => filePath.EndsWith("." + FileMetaExt)).ToArray();
        //        Array.Resize(ref path, path.Length + path.Length);
        //        for (int i = path.Length; i < path.Length + path.Length; ++i)
        //        {
        //            path[path.Length + i] = path[i];
        //            path[i] = path[i].Remove(path[i].LastIndexOf("." + FileMetaExt));
        //        }

        //        HashSet<int> exceptTypesHs = null;
        //        if(exceptTypes != null && exceptTypes.Length > 0)
        //        {
        //            exceptTypesHs = new HashSet<int>();
        //            for(int i = 0; i < exceptTypes.Length; ++i)
        //            {
        //                if(!exceptTypesHs.Contains(exceptTypes[i]))
        //                {
        //                    exceptTypesHs.Add(exceptTypes[i]);
        //                }
        //            }
        //        }
        //        m_storage.LoadFiles(path, loadFilesResult =>
        //        {
        //            List<ProjectItem> loadedItems = new List<ProjectItem>();
        //            for (int i = 0; i < path.Length; ++i)
        //            {
        //                byte[] dataRaw = loadFilesResult.Data[i];
        //                byte[] metaRaw = loadFilesResult.Data[path.Length + i];
        //                if (dataRaw != null && metaRaw != null)
        //                {
        //                    ProjectItemMeta meta = m_serializer.Deserialize<ProjectItemMeta>(metaRaw);
        //                    bool loadData = exceptTypesHs == null || !exceptTypesHs.Contains(meta.Type);

        //                    ProjectItemData data = loadData ? m_serializer.Deserialize<ProjectItemData>(dataRaw) : null;
        //                    loadedItems.Add(new ProjectItem(meta, data) { Parent = folder });
        //                }
        //            }
        //            callback(new ProjectPayload<ProjectItem[]>(loadedItems.ToArray()));
        //        });
        //    });
        //}

        public void Load(string[] path, ProjectEventHandler <ProjectItem[]> callback, params int[] exceptTypes)
        {
            int pathLength = path.Length;

            Array.Resize(ref path, pathLength + pathLength);
            for (int i = 0; i < pathLength; ++i)
            {
                path[pathLength + i] = path[i] + "." + FileMetaExt;
            }

            HashSet <int> exceptTypesHs = null;

            if (exceptTypes != null && exceptTypes.Length > 0)
            {
                exceptTypesHs = new HashSet <int>();
                for (int i = 0; i < exceptTypes.Length; ++i)
                {
                    if (!exceptTypesHs.Contains(exceptTypes[i]))
                    {
                        exceptTypesHs.Add(exceptTypes[i]);
                    }
                }
            }

            m_storage.LoadFiles(path, loadFilesResult =>
            {
                List <ProjectItem> loadedItems = new List <ProjectItem>();
                for (int i = 0; i < pathLength; ++i)
                {
                    byte[] dataRaw = loadFilesResult.Data[i];
                    byte[] metaRaw = loadFilesResult.Data[pathLength + i];
                    if (dataRaw != null && metaRaw != null)
                    {
                        ProjectItemMeta meta = m_serializer.Deserialize <ProjectItemMeta>(metaRaw);
                        bool loadData        = exceptTypesHs == null || !exceptTypesHs.Contains(meta.TypeCode);

                        ProjectItemData data = loadData ? m_serializer.Deserialize <ProjectItemData>(dataRaw) : null;
                        loadedItems.Add(new ProjectItem(meta, data));
                    }
                }
                callback(new ProjectPayload <ProjectItem[]>(loadedItems.ToArray()));
            });
        }
Exemplo n.º 3
0
 public ProjectItem(ProjectItemMeta meta, ProjectItemData data)
 {
     Internal_Meta = meta;
     Internal_Data = data;
 }
Exemplo n.º 4
0
        private void LoadFiles(ProjectItem item, ProjectEventHandler callback, bool metaOnly = true, HashSet <int> exceptTypesHS = null)
        {
            ProjectItem[] folders = item.Children != null?item.Children.Where(c => c.IsFolder).ToArray() : new ProjectItem[0];

            Action <ProjectEventHandler>[] loadFilesActions = new Action <ProjectEventHandler> [folders.Length];
            for (int i = 0; i < folders.Length; ++i)
            {
                ProjectItem childItem = folders[i];
                loadFilesActions[i] = cb => LoadFiles(childItem, cb, metaOnly, exceptTypesHS);
            }

            m_storage.GetFiles(item.ToString(), getFilesCompleted =>
            {
                string[] path = getFilesCompleted.Data;

                if (path == null && path.Length > 0)
                {
                    Parallel(loadFilesActions, parallelCallback =>
                    {
                        if (callback != null)
                        {
                            callback(new ProjectPayload());
                        }
                    });
                }
                else
                {
                    int metaLength;
                    if (metaOnly)
                    {
                        path       = path.Where(n => n.EndsWith("." + FileMetaExt)).ToArray();
                        metaLength = path.Length;
                    }
                    else
                    {
                        path       = path.Where(n => n.EndsWith("." + FileMetaExt)).ToArray();
                        metaLength = path.Length;
                        Array.Resize(ref path, metaLength + metaLength);
                        for (int i = 0; i < metaLength; ++i)
                        {
                            path[metaLength + i] = path[i].Remove(path[i].LastIndexOf("." + FileMetaExt));
                        }
                    }

                    if (metaLength > 0)
                    {
                        m_storage.LoadFiles(path, loadFilesCompleted =>
                        {
                            if (item.Children == null)
                            {
                                item.Children = new List <ProjectItem>();
                            }

                            for (int i = 0; i < metaLength; ++i)
                            {
                                ProjectItemMeta meta = null;
                                ProjectItemData data = null;

                                byte[] metaRaw = loadFilesCompleted.Data[i];
                                if (metaRaw != null)
                                {
                                    meta = m_serializer.Deserialize <ProjectItemMeta>(metaRaw);
                                }

                                if (!metaOnly)
                                {
                                    bool loadData = meta != null && (exceptTypesHS == null || !exceptTypesHS.Contains(meta.TypeCode));
                                    if (loadData)
                                    {
                                        byte[] dataRaw = loadFilesCompleted.Data[metaLength + i];
                                        if (dataRaw != null)
                                        {
                                            data = m_serializer.Deserialize <ProjectItemData>(dataRaw);
                                        }
                                    }
                                }

                                if (meta.TypeCode == ProjectItemTypes.Folder)
                                {
                                    ProjectItem folder = item.Children.Where(c => c.IsFolder && c.NameExt == meta.Name).FirstOrDefault();
                                    if (folder != null)
                                    {
                                        folder.Internal_Meta = meta;
                                    }
                                }
                                else
                                {
                                    ProjectItem childItem = new ProjectItem(meta, data);
                                    item.AddChild(childItem);
                                }
                            }

                            Parallel(loadFilesActions, parallelCallback =>
                            {
                                if (callback != null)
                                {
                                    callback(new ProjectPayload());
                                }
                            });
                        });
                    }
                    else
                    {
                        Parallel(loadFilesActions, parallelCallback =>
                        {
                            if (callback != null)
                            {
                                callback(new ProjectPayload());
                            }
                        });
                    }
                }
            });
        }