当前位置: 首页>>代码示例>>C#>>正文


C# Area.ImportDB方法代码示例

本文整理汇总了C#中Area.ImportDB方法的典型用法代码示例。如果您正苦于以下问题:C# Area.ImportDB方法的具体用法?C# Area.ImportDB怎么用?C# Area.ImportDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Area的用法示例。


在下文中一共展示了Area.ImportDB方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Clone

        public bool Clone(bool full)
        {
            if (Workspace != null)
                return false;
            try
            {
                if (!full)
                {
                    ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.Clone }, ProtoBuf.PrefixStyle.Fixed32);
                    var clonePack = Utilities.ReceiveEncrypted<ClonePayload>(SharedInfo);
                    Workspace = Area.InitRemote(BaseDirectory, clonePack, SkipContainmentCheck);
                }
                else
                {
                    ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.FullClone }, ProtoBuf.PrefixStyle.Fixed32);

                    var response = ProtoBuf.Serializer.DeserializeWithLengthPrefix<NetCommand>(Connection.GetStream(), ProtoBuf.PrefixStyle.Fixed32);
                    if (response.Type == NetCommandType.Acknowledge)
                    {
                        int dbVersion = (int)response.Identifier;
                        if (!WorkspaceDB.AcceptRemoteDBVersion(dbVersion))
                        {
                            Printer.PrintError("Server database version is incompatible (v{0}). Use non-full clone to perform the operation.", dbVersion);
                            ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.Error }, ProtoBuf.PrefixStyle.Fixed32);
                            return false;
                        }
                        else
                            ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.Acknowledge }, ProtoBuf.PrefixStyle.Fixed32);
                    }

                    System.IO.FileInfo fsInfo = new System.IO.FileInfo(System.IO.Path.GetRandomFileName());
                    Printer.PrintMessage("Attempting to import metadata file to temp path {0}", fsInfo.FullName);
                    var printer = Printer.CreateSimplePrinter("Progress", (obj) =>
                    {
                        return string.Format("#b#{0}## received.", Versionr.Utilities.Misc.FormatSizeFriendly((long)obj));
                    });
                    try
                    {
                        long total = 0;
                        using (var stream = fsInfo.OpenWrite())
                        {
                            while (true)
                            {
                                var data = Utilities.ReceiveEncrypted<DataPayload>(SharedInfo);
                                stream.Write(data.Data, 0, data.Data.Length);
                                total += data.Data.Length;
                                printer.Update(total);
                                if (data.EndOfStream)
                                    break;
                            }
                            printer.End(total);
                            response = ProtoBuf.Serializer.DeserializeWithLengthPrefix<NetCommand>(Connection.GetStream(), ProtoBuf.PrefixStyle.Fixed32);
                            if (response.Type == NetCommandType.Error)
                            {
                                Printer.PrintError("Server failed to clone the database.");
                                return false;
                            }
                        }
                        Printer.PrintMessage("Metadata written, importing DB.");
                        Area area = new Area(Area.GetAdminFolderForDirectory(BaseDirectory));
                        try
                        {
                            fsInfo.MoveTo(area.MetadataFile.FullName);
                            if (!area.ImportDB())
                                throw new Exception("Couldn't import data.");
                            Workspace = Area.Load(BaseDirectory);
                            SharedInfo.Workspace = Workspace;
                            return true;
                        }
                        catch
                        {
                            if (area.MetadataFile.Exists)
                                area.MetadataFile.Delete();
                            area.AdministrationFolder.Delete();
                            throw;
                        }
                    }
                    catch
                    {
                        if (fsInfo.Exists)
                            fsInfo.Delete();
                        return false;
                    }
                }
                SharedInfo.Workspace = Workspace;
                return true;
            }
            catch (Exception e)
            {
                Printer.PrintError(e.ToString());
                return false;
            }
        }
开发者ID:eatplayhate,项目名称:versionr,代码行数:93,代码来源:Client.cs


注:本文中的Area.ImportDB方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。