示例#1
0
    private void Start()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else if (Instance != this)
        {
            Debug.Log("Instance already exists, destroying object!");
            Destroy(this);
        }

        if (!Directory.Exists(Constants.DirectoryPath))
        {
            Entry.GenerateNewDirectory();
        }
        else
        {
            if (!File.Exists(Constants.FilePath))
            {
                Entry.GenerateNewFile();
                return;
            }
            else
            {
                Entry._foundDocument = XDocument.Load(Constants.FilePath);
                Entry.DocumentHandler();
            }
        }
        Entry.x = x;
    }
示例#2
0
    public static bool Save(XMLDataManager levelData, Texture2D screenshot)
    {
        string levelSavePath = string.Format("{0}/{1}/{1}.xml", savePath, levelData.lName);
        string picSavePath   = string.Format("{0}/{1}/{1}.png", savePath, levelData.lName);

        byte[]        picToSave = screenshot.EncodeToPNG();
        bool          success;
        XmlSerializer xml = new XmlSerializer(typeof(XMLDataManager));

        try
        {
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            if (!Directory.Exists(savePath + "/" + levelData.lName))
            {
                Directory.CreateDirectory(savePath + "/" + levelData.lName);
            }
            using (FileStream stream = new FileStream(levelSavePath, FileMode.Create))
            {
                xml.Serialize(stream, levelData);
                File.WriteAllBytes(picSavePath, picToSave);
            }
            success = true;
        }
        catch (System.Exception)
        {
            success = false;
        }
        return(success);
    }
        private static string CreateJob(string xmlData, bool enqueue)
        {
            var result               = "success";
            var xmlDataManager       = new XMLDataManager(xmlData);
            var siteId               = new Guid(xmlDataManager.GetPropVal("SiteId"));
            var webId                = new Guid(xmlDataManager.GetPropVal("WebId"));
            var listGuid             = Guid.Empty;
            var attachedItemListGuid = xmlDataManager.GetPropVal("AttachedItemListGuid");

            if (!string.IsNullOrWhiteSpace(attachedItemListGuid))
            {
                listGuid = new Guid(attachedItemListGuid);
            }
            var itemId         = -1;
            var attachedItemId = xmlDataManager.GetPropVal("AttachedItemId");

            if (!string.IsNullOrWhiteSpace(attachedItemId))
            {
                itemId = int.Parse(attachedItemId);
            }
            SPSecurity.RunWithElevatedPrivileges(
                () =>
            {
                using (var site = new SPSite(siteId))
                {
                    using (var web = site.OpenWeb(webId))
                    {
                        using (var con = new SqlConnection(CoreFunctions.getConnectionString(site.WebApplication.Id)))
                        {
                            con.Open();
                            var timerJobGuid = Guid.NewGuid();
                            var cmd          = new SqlCommand
                            {
                                CommandText =
                                    "INSERT INTO TIMERJOBS (timerjobuid, siteguid, jobtype, jobname, scheduletype, webguid, listguid, itemid, jobdata) VALUES (@timerjobuid,@siteguid, 100, 'Create Workspace', 0, @webguid, @listguid, @itemid, @jobdata)",
                                Connection = con
                            };

                            cmd.Parameters.Add(new SqlParameter("@timerjobuid", timerJobGuid));
                            cmd.Parameters.Add(new SqlParameter("@siteguid", site.ID.ToString()));
                            cmd.Parameters.Add(new SqlParameter("@webguid", web.ID.ToString()));
                            cmd.Parameters.Add(new SqlParameter("@listguid", listGuid.ToString()));
                            cmd.Parameters.Add(new SqlParameter("@itemid", itemId.ToString()));
                            cmd.Parameters.Add(new SqlParameter("@jobdata", xmlData));
                            cmd.ExecuteNonQuery();

                            if (enqueue)
                            {
                                CoreFunctions.enqueue(timerJobGuid, 0, site);
                                result = "Successfully queued create workspace job.";
                            }
                        }
                    }
                }
            });

            return(result);
        }
        private TemplateSource GetTempType(string data)
        {
            TemplateSource t    = TemplateSource.online;
            XMLDataManager mgr  = new XMLDataManager(data);
            string         type = mgr.GetPropVal("TemplateSource");

            if (!string.IsNullOrEmpty(type))
            {
                t = (TemplateSource)Enum.Parse(typeof(TemplateSource), type);
            }
            return(t);
        }
        public static string AddCreateWorkspaceJobAndWait(string xmlData)
        {
            string result   = string.Empty;
            var    mgr      = new XMLDataManager(xmlData);
            var    sid      = new Guid(mgr.GetPropVal("SiteId"));
            var    wid      = new Guid(mgr.GetPropVal("WebId"));
            Guid   listguid = Guid.Empty;

            if (!string.IsNullOrEmpty(mgr.GetPropVal("AttachedItemListGuid")))
            {
                listguid = new Guid(mgr.GetPropVal("AttachedItemListGuid"));
            }
            int itemid = -1;

            if (!string.IsNullOrEmpty(mgr.GetPropVal("AttachedItemId")))
            {
                itemid = int.Parse(mgr.GetPropVal("AttachedItemId"));
            }
            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (var site = new SPSite(sid))
                {
                    using (SPWeb web = site.OpenWeb(wid))
                    {
                        using (var con = new SqlConnection(CoreFunctions.getConnectionString(site.WebApplication.Id)))
                        {
                            con.Open();
                            Guid timerjobguid = Guid.NewGuid();
                            var cmd           = new SqlCommand
                            {
                                CommandText =
                                    "INSERT INTO TIMERJOBS (timerjobuid, siteguid, jobtype, jobname, scheduletype, webguid, listguid, itemid, jobdata, [key]) VALUES (@timerjobuid,@siteguid, 100, 'Create Workspace', 0, @webguid, @listguid, @itemid, @jobdata, @key)",
                                Connection = con
                            };

                            cmd.Parameters.Add(new SqlParameter("@timerjobuid", timerjobguid));
                            cmd.Parameters.Add(new SqlParameter("@siteguid", site.ID.ToString()));
                            cmd.Parameters.Add(new SqlParameter("@webguid", web.ID.ToString()));
                            cmd.Parameters.Add(new SqlParameter("@listguid", listguid.ToString()));
                            cmd.Parameters.Add(new SqlParameter("@itemid", itemid.ToString()));
                            cmd.Parameters.Add(new SqlParameter("@jobdata", xmlData));
                            cmd.Parameters.Add(new SqlParameter("@key", SecKey));
                            cmd.ExecuteNonQuery();

                            result = "Successfully queued create workspace job.";
                        }
                    }
                }
            });

            return(result);
        }
示例#6
0
    public static void Load(LevelManager.Level level, out XMLDataManager Level_Container)
    {
        XmlSerializer xml = new XmlSerializer(typeof(XMLDataManager));

        try
        {
            using (FileStream stream = new FileStream(level.LevelPath, FileMode.Open))
            {
                Level_Container = xml.Deserialize(stream) as XMLDataManager;
            }
        }
        catch (System.Exception)
        {
            Level_Container = new XMLDataManager();
        }
    }
        public static string QueueCreateWorkspace(string xmlData)
        {
            var  mgr      = new XMLDataManager(xmlData);
            var  sid      = new Guid(mgr.GetPropVal("SiteId"));
            var  wid      = new Guid(mgr.GetPropVal("WebId"));
            Guid listguid = Guid.Empty;

            if (!string.IsNullOrEmpty(mgr.GetPropVal("AttachedItemListGuid")))
            {
                listguid = new Guid(mgr.GetPropVal("AttachedItemListGuid"));
            }
            int itemid = -1;

            if (!string.IsNullOrEmpty(mgr.GetPropVal("AttachedItemId")))
            {
                itemid = int.Parse(mgr.GetPropVal("AttachedItemId"));
            }
            return(QueueCreateWorkspace(sid, wid, listguid, itemid));
        }
示例#8
0
        public void BuildWebInfoXml_WhenCalled_ReturnsString()
        {
            // Arrange
            const int    number         = 111;
            const string expectedString = "CustomValue";

            var webId = $"{GuidString},1";
            var data  = string.Format(@"
                <Data>
                    <Param key=""RListName"">{0}</Param>
                    <Param key=""ListName"">{0}</Param>
                    <Param key=""IsNew"">True</Param>
                    <Param key=""IsTemplate"">True</Param>
                    <Param key=""NewTempItemID"">{1}</Param>
                </Data>",
                                      expectedString, number);
            var dataManager = new XMLDataManager(data);

            spList.FormsGet = () => new ShimSPFormCollection()
            {
                ItemGetPAGETYPE = _ => new ShimSPForm()
                {
                    ServerRelativeUrlGet = () => expectedString
                }
            };
            spWeb.ServerRelativeUrlGet = () => "/";
            spListItem.IDGet           = () => number;

            // Act
            var actual = XDocument.Parse((string)privateObj.Invoke(
                                             BuildWebInfoXmlMethodName,
                                             BindingFlags.Static | BindingFlags.NonPublic,
                                             new object[] { webId, dataManager, spSite.Instance, spWeb.Instance, spSite.Instance, spWeb.Instance }));

            // Assert
            actual.ShouldSatisfyAllConditions(
                () => actual.Element("WebInfo").Element("ID").Value.ShouldBe(guid.ToString("B")),
                () => actual.Element("WebInfo").Element("ServerRelativeUrl").Value.ShouldBe("/"),
                () => actual.Element("WebInfo").Element("ProjectEditFormUrl").Value.ShouldBe($"{expectedString}?ID={number}"),
                () => actual.Element("WebInfo").Element("TemplateEditFormUrl").Value.ShouldBe($"{expectedString}?ID={number}"));
        }
 public AnalyticsData(string xml, AnalyticsType t, AnalyticsAction a)
 {
     mgr    = new XMLDataManager(xml);
     Type   = t;
     Action = a;
 }
示例#10
0
        public void CreateProjectInExistingWorkspace_DoNotDeleteTrue_Deletes()
        {
            // Arrange
            const string doNotDelRequest = "False";
            const string originItemId    = "1";
            const string url             = "/";

            var validationCount = 0;
            var data            = string.Format(@"
                <Data>
                    <Param key=""IsNew"">True</Param>
                    <Param key=""ParentWebUrl"">ParentWebUrl</Param>
                    <Param key=""SourceWebUrl"">SourceWebUrl</Param>
                    <Param key=""RListName"">RListName</Param>
                    <Param key=""ListName"">ListName</Param>
                    <Param key=""SiteTitle"">SiteTitle</Param>
                    <Param key=""DoNotDelRequest"">False</Param>
                    <Param key=""CopyFrom"">1</Param>
                    <Param key=""ListGuid"">{0}</Param>
                </Data>",
                                                GuidString);
            var dataManager = new XMLDataManager(data);

            spListItem.Delete = () =>
            {
                validationCount = validationCount + 1;
            };
            spList.Update = () =>
            {
                validationCount = validationCount + 1;
            };

            spListItem.ItemGetString       = _ => DummyString;
            spListItem.ItemSetStringObject = (key, value) =>
            {
                if (key.Equals(DummyString) && value.GetType().Equals(typeof(string)))
                {
                    if (DummyString.Equals((string)value))
                    {
                        validationCount = validationCount + 1;
                    }
                }
            };
            spListItem.Update = () =>
            {
                validationCount = validationCount + 1;
            };
            spWeb.ServerRelativeUrlGet = () => url;

            ShimSPField.AllInstances.TypeGet = _ => SPFieldType.Attachments;
            ShimSPFieldCollection.AllInstances.ContainsFieldString = (_, __) => true;
            ShimSPListItemCollection.AllInstances.Add = _ =>
            {
                validationCount = validationCount + 1;
                return(spListItem);
            };
            ShimSPBaseCollection.AllInstances.GetEnumerator = _ => new List <SPField>()
            {
                new ShimSPField()
                {
                    InternalNameGet = () => DummyString,
                    ReorderableGet  = () => true,
                    TypeGet         = () => SPFieldType.Attachments
                }
            }.GetEnumerator();

            // Act
            privateObj.Invoke(
                CreateProjectInExistingWorkspaceMethodName,
                BindingFlags.Static | BindingFlags.NonPublic,
                new object[] { dataManager, spSite.Instance, spWeb.Instance, spSite.Instance, spWeb.Instance });

            // Assert
            validationCount.ShouldBe(6);
        }
        public static string QueueWorkspaceJobOnHoldForSecurity(string xmlData)
        {
            string result   = string.Empty;
            var    mgr      = new XMLDataManager(xmlData);
            var    sid      = new Guid(mgr.GetPropVal("SiteId"));
            var    wid      = new Guid(mgr.GetPropVal("WebId"));
            Guid   listguid = Guid.Empty;

            if (!string.IsNullOrEmpty(mgr.GetPropVal("AttachedItemListGuid")))
            {
                listguid = new Guid(mgr.GetPropVal("AttachedItemListGuid"));
            }
            int itemid = -1;

            if (!string.IsNullOrEmpty(mgr.GetPropVal("AttachedItemId")))
            {
                itemid = int.Parse(mgr.GetPropVal("AttachedItemId"));
            }
            SPSecurity.RunWithElevatedPrivileges(() =>
            {
                using (var s = new SPSite(sid))
                {
                    using (SPWeb w = s.OpenWeb(wid))
                    {
                        using (var con = new SqlConnection(CoreFunctions.getConnectionString(s.WebApplication.Id)))
                        {
                            Guid wsJobUid = Guid.Empty;
                            con.Open();
                            var cmd = new SqlCommand
                            {
                                Connection  = con,
                                CommandText = string.Format("SELECT timerjobuid FROM TIMERJOBS WHERE webguid='{0}' AND listguid='{1}' AND itemid={2} AND [key]='{3}'", w.ID, listguid, itemid, SecKey)
                            };
                            SqlDataReader rdr = cmd.ExecuteReader();

                            while (rdr.Read())
                            {
                                try
                                {
                                    wsJobUid = new Guid(rdr[0].ToString());
                                }
                                catch
                                {
                                }
                            }

                            if (wsJobUid != Guid.Empty)
                            {
                                using (var update = new SqlCommand
                                {
                                    Connection = con,
                                    CommandText = string.Format("UPDATE TIMERJOBS SET [key] = '{1}' WHERE timerjobuid='{0}'", wsJobUid, Completed)
                                })
                                {
                                    update.ExecuteNonQuery();
                                }
                                CoreFunctions.enqueue(wsJobUid, 0, s);
                            }
                        }
                    }
                }
            });

            return(result);
        }
示例#12
0
    // serializes the objects in the scene into an xml file
    void SaveLevel()
    {
        Camera.main.transform.SetParent(null);
        Camera.main.fieldOfView        = 60;
        Camera.main.transform.position = cameraPos;
        XMLDataManager.Player playerToSave = new XMLDataManager.Player();
        foreach (KeyValuePair <Vector3, GameObject> p in players)
        {
            playerToSave.loc        = p.Key;
            playerToSave.playerName = p.Value.name;
        }
        List <XMLDataManager.Bot> botsToSave = new List <XMLDataManager.Bot>();

        foreach (KeyValuePair <Vector3, GameObject> o in bots)
        {
            XMLDataManager.Bot bot = new XMLDataManager.Bot
            {
                botName = "Bot", location = o.Key
            };
            if (botsWithPPoints != null)
            {
                if (botsWithPPoints.ContainsKey(o.Value))
                {
                    bot.pPoints = botsWithPPoints[o.Value].ToArray();
                }
            }

            else
            {
                bot.pPoints = null;
            }
            botsToSave.Add(bot);
        }
        List <XMLDataManager.Wall> wallsToSave = new List <XMLDataManager.Wall>();

        foreach (KeyValuePair <Vector3, GameObject> o in walls)
        {
            XMLDataManager.Wall wall = new XMLDataManager.Wall
            {
                wallName = "wall", loc = o.Key
            };
            wallsToSave.Add(wall);
        }
        List <XMLDataManager.Goal> goalsToSave = new List <XMLDataManager.Goal>();

        foreach (KeyValuePair <Vector3, GameObject> g in goals)
        {
            XMLDataManager.Goal goal = new XMLDataManager.Goal
            {
                goalName = "goal", loc = g.Key
            };
            goalsToSave.Add(goal);
        }
        saveDialog.SetActive(false);
        string         formattedLevelName = levelName.text.Replace(' ', '_');
        XMLDataManager toSave             = new XMLDataManager
        {
            bots  = botsToSave.ToArray(), goals = goalsToSave.ToArray(), walls = wallsToSave.ToArray(),
            lName = formattedLevelName, player = playerToSave, timesPlayed = 0
        };

        XMLDataLoaderSaver.Save(toSave, levelScreenshot);
        LevelManager.RebuildLists();
    }